七、K3 WISE 开发插件《工业单据老单插件中获取登陆用户名》

备注:如果是BOS新单,都有获取用户名的方法。在单据有m_BillInterface.K3Lib.User.UserId,在序时薄有m_ListInterface.K3Lib.User.UserID

工业单据获取用户名,源代码如下:

工程引用:

Class1代码如下:

'定义插件对象接口. 必须具有的声明, 以此来获得事件
Private WithEvents m_BillTransfer   As k3BillTransfer.Bill
 
Public Sub Show(ByVal oBillTransfer As Object)
 
    '接口实现
    '注意: 此方法必须存在, 请勿修改
    Set m_BillTransfer = oBillTransfer
 
End Sub

Private Sub Class_Terminate()
 
    '释放接口对象
    '注意: 此方法必须存在, 请勿修改
    Set m_BillTransfer = Nothing

End Sub

Private Sub m_BillTransfer_BillInitialize()
 
'*************** 开始设置菜单 ***************
 
    m_BillTransfer.AddUserMenuItem "用户自定义 1", "自定义菜单"
 
'*************** 结束设置菜单 ***************
 

End Sub

Private Sub m_BillTransfer_UserMenuClick(ByVal Index As Long, ByVal Caption As String)
 
    'TODO: 请在此处添加代码响应事件 UserMenuClick
 
 
    Select Case Caption
    Case "用户自定义 1"
        '此处添加处理 用户自定义 1 菜单对象的 Click 事件
 MsgBox UserName()
    Case Else
    End Select

End Sub

 MMTS代码如下:

Option Explicit
'子系统描述,根据自己系统内容替换
Public Const SUBID = "gl"
Public Const SUBNAME = "总帐系统"

'mts share property lockmode
Private Const LockMethod = 1
Private Const LockSetGet = 0
'mts share property
Private Const Process = 1
Private Const Standard = 0

'Private m_oSvrMgr As Object 'Server Manager
Private m_oSpmMgr As Object
Public m_oLogin As Object
Private Declare Function CanChangeMtsServer Lib "kdappsvr.dll" () As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public LoginType As String
Public LoginAcctID As Long

Public Function CheckMts(ByVal CFG As Long, Optional ByVal ChangeUser As Boolean = False) As Long
    CheckMts = False
    If CFG Then
        If Not m_oLogin Is Nothing And Not ChangeUser Then
           CheckMts = True
           Exit Function
        End If

        Dim bChangeMts As Boolean
        bChangeMts = True
        Set m_oLogin = CreateObject("KDLogin.clsLogin")
        If InStr(1, LoginType, "Straight", vbTextCompare) > 0 And Not ChangeUser Then
           If m_oLogin.LoginStraight(SUBID, SUBNAME, LoginAcctID) Then
              CheckMts = True
              Call OpenConnection
           End If
       Else
           If m_oLogin.Login(SUBID, SUBNAME, bChangeMts) Then
              CheckMts = True
              Call OpenConnection
           End If
       End If
    Else
       m_oLogin.Shutdown
       Set m_oLogin = Nothing
    End If
End Function
'登录
'Public Function CheckMts(ByVal CFG As Long, Optional ByVal ChangeUser As Boolean = False) As Long
'    '检查Mts状态
'    CheckMts = False
'    Set m_oLogin = Nothing
'    If CFG Then
'        If Not m_oLogin Is Nothing And Not ChangeUser Then
'           CheckMts = True
'           Exit Function
'        End If
'        LoginAcctID = 1
'        Dim bChangeMts As Boolean
'        bChangeMts = True
'        Set m_oLogin = CreateObject("KDLogin.clsLogin")
''        If InStr(1, LoginType, "Straight", vbTextCompare) > 0 And Not ChangeUser Then
'
'        '直接调用
'        '实现二次开发模块的隐藏登录
'        If m_oLogin.LoginStraight(SUBID, SUBNAME, LoginAcctID) Then
'           CheckMts = True
'           Call OpenConnection
'        End If
''       Else
''
''           '重新登录
''           If m_oLogin.Login(SUBID, SUBNAME, bChangeMts) Then
''              CheckMts = True
''              Call OpenConnection
''           End If
''       End If
'    Else
'       m_oLogin.ShutDown
'       Set m_oLogin = Nothing
'    End If
'End Function

Public Function UserName() As String
If m_oLogin Is Nothing Then
    UserName = GetConnectionProperty("UserName")
Else
    UserName = m_oLogin.UserName
End If
End Function
Public Function PropsString() As String
If m_oLogin Is Nothing Then
    PropsString = GetConnectionProperty("PropsString")
Else
    PropsString = m_oLogin.PropsString
End If
End Function
Public Property Get ServerMgr() As Object
    Set ServerMgr = GetConnectionProperty("KDLogin")
End Property
Public Function IsDemo() As Boolean
If m_oLogin Is Nothing Then
    IsDemo = (GetConnectionProperty("LogStatus") = 2)
Else
    IsDemo = (m_oLogin.LogStatus = 2)
End If
End Function
Public Function AcctName() As String
If m_oLogin Is Nothing Then
    AcctName = GetConnectionProperty("AcctName")
Else
    AcctName = m_oLogin.AcctName
End If
End Function
Private Function GetConnectionProperty(strName As String, Optional ByVal bRaiseError As Boolean = True) As Variant
    
    Dim spmMgr As Object
    'Dim spmGroup As Object
    'Dim spmProp As Object
    'Dim bExists As Boolean
    
    'Set spmMgr = CreateObject("MTxSpm.SharedPropertyGroupManager.1")
    'Set spmGroup = spmMgr.CreatePropertyGroup("Info", LockSetGet, Process, bExists)
    
    'Set spmProp = spmGroup.Property(strName)
    'If IsObject(spmProp.Value) Then
    '    Set GetConnectionProperty = spmProp.Value
    'Else
    '    GetConnectionProperty = spmProp.Value
    'End If
    Dim lProc As Long
    lProc = GetCurrentProcessId()
    Set spmMgr = CreateObject("PropsMgr.ShareProps")
    If IsObject(spmMgr.GetProperty(lProc, strName)) Then
        Set GetConnectionProperty = spmMgr.GetProperty(lProc, strName)
    Else
        GetConnectionProperty = spmMgr.GetProperty(lProc, strName)
    End If
End Function
Private Sub OpenConnection()
    'Dim spmMgr As Object
    'Dim spmGroup As Object
    'Dim spmProp As Object
    'Dim bExists As Boolean
    
    'Set spmMgr = CreateObject("MTxSpm.SharedPropertyGroupManager.1")
    'Set spmGroup = spmMgr.CreatePropertyGroup("Info", LockSetGet, Process, bExists)
    'Set spmProp = spmGroup.CreateProperty("UserName", bExists)
    'spmProp.Value = m_oLogin.UserName
    'Set spmProp = spmGroup.CreateProperty("PropsString", bExists)
    'spmProp.Value = m_oLogin.PropsString
    'Set spmProp = spmGroup.CreateProperty("KDLogin", bExists)
    'spmProp.Value = m_oLogin
    Dim lProc As Long
    lProc = GetCurrentProcessId()
    Set m_oSpmMgr = CreateObject("PropsMgr.ShareProps")
    m_oSpmMgr.addproperty lProc, "UserName", m_oLogin.UserName
    m_oSpmMgr.addproperty lProc, "PropsString", m_oLogin.PropsString
    m_oSpmMgr.addproperty lProc, "LogStatus", m_oLogin.LogStatus
    m_oSpmMgr.addproperty lProc, "AcctName", m_oLogin.AcctName
    m_oSpmMgr.addproperty lProc, "KDLogin", m_oLogin
End Sub
Private Sub CloseConnection()
    'On Error Resume Next
    
    Dim lProc As Long
    
    lProc = GetCurrentProcessId()
    m_oSpmMgr.delproperty lProc, "UserName"
    m_oSpmMgr.delproperty lProc, "PropsString"
    m_oSpmMgr.delproperty lProc, "LogStatus"
    m_oSpmMgr.delproperty lProc, "AcctName"
    m_oSpmMgr.delproperty lProc, "KDLogin"
    
    Set m_oSpmMgr = Nothing
End Sub

 

转载于:https://www.cnblogs.com/zhugq02/p/11236741.html

金蝶K3WISE是一款企业资源规划(ERP)软件,用于管理企业的各项业务流程,包括工业领域的单据管理。VB(Visual Basic)是一种编程语言,可以用于开发K3WISE软件的定制功能。 在进行K3WISE工业单据导入开发时,我们可以使用VB编写代码来实现相关功能。首先,需要了解K3WISE的数据结构和工业单据的具体要求。然后,可以使用VB语言连接K3WISE的数据库,并通过编写代码实现数据导入的功能。 具体步骤如下: 1. 首先,需要通过VB语言连接K3WISE的数据库。可以使用ADO(ActiveX Data Objects)技术来连接数据库,并建立连接对象。连接对象可以通过提供连接字符串、数据库用户名和密码等参数来连接到K3WISE的数据库。 2. 了解K3WISE的数据结构。在开发工业单据导入功能时,需要了解K3WISE数据库工业单据相关的表格、字段等信息。可以使用K3WISE开发文档或者数据库管理工具获取相关信息。 3. 根据工业单据的要求和K3WISE的数据结构,设计数据导入的逻辑。可以通过编写VB代码来实现数据的读取、处理和导入功能。例如,可以使用ADO的Recordset对象来读取源数据,并使用K3WISE提供的API(应用程序接口)来插入或更新数据。 4. 进行单元测试和综合测试。在开发过程,可以先进行基本的单元测试,确保代码的正确性。之后,进行综合测试,模拟实际的工业单据导入情况,确保功能的完整性和稳定性。 5. 部署和维护。完成开发和测试后,可以将代码部署到生产环境,并在日常运营进行维护和优化。 总之,通过使用VB编写代码,结合K3WISE的数据库和API,可以实现工业单据导入功能的开发。这样,企业可以更高效地管理和处理工业领域的业务数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值