VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "11210"
   ClientHeight    =   3225
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8790
   LinkTopic       =   "Form1"
   ScaleHeight     =   3225
   ScaleWidth      =   8790
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdReadCard 
      Caption         =   "读卡数据"
      Height          =   495
      Left            =   360
      TabIndex        =   13
      Top             =   2520
      Width           =   1695
   End
   Begin VB.CommandButton cmdCancelByKeyID 
      Caption         =   "以KeyID撤销"
      Height          =   495
      Left            =   6600
      TabIndex        =   12
      Top             =   2520
      Width           =   1695
   End
   Begin VB.CommandButton cmdCancelByKeycard 
      Caption         =   "读卡撤销"
      Height          =   495
      Left            =   2520
      TabIndex        =   11
      Top             =   2520
      Width           =   1695
   End
   Begin VB.CommandButton cmdCancelByDeviceID 
      Caption         =   "以设备ID撤销"
      Height          =   495
      Left            =   4560
      TabIndex        =   10
      Top             =   2520
      Width           =   1695
   End
   Begin VB.CommandButton cmdMakeEKeyPlugin 
      Caption         =   "发小程序插件钥匙"
      Height          =   495
      Left            =   6480
      TabIndex        =   9
      Top             =   1800
      Width           =   1695
   End
   Begin VB.CommandButton cmdMakeEKey 
      Caption         =   "发小程序钥匙"
      Height          =   495
      Left            =   4560
      TabIndex        =   8
      Top             =   1800
      Width           =   1695
   End
   Begin VB.CommandButton cmdMakePinCode 
      Caption         =   "发时效密码"
      Height          =   495
      Left            =   2520
      TabIndex        =   7
      Top             =   1800
      Width           =   1695
   End
   Begin VB.CommandButton cmdMakeGuestCard 
      Caption         =   "发客人卡"
      Height          =   495
      Left            =   360
      TabIndex        =   6
      Top             =   1800
      Width           =   1695
   End
   Begin VB.TextBox textDeviceID 
      Height          =   375
      Left            =   1440
      TabIndex        =   5
      Text            =   "13112"
      Top             =   1080
      Width           =   2655
   End
   Begin VB.TextBox textUserPasswd 
      Height          =   375
      Left            =   5640
      TabIndex        =   3
      Text            =   "13824491229"
      Top             =   360
      Width           =   2655
   End
   Begin VB.TextBox textUserName 
      Height          =   375
      Left            =   1320
      TabIndex        =   1
      Text            =   "13824491229"
      Top             =   360
      Width           =   2655
   End
   Begin VB.Label Label4 
      Caption         =   "设备ID:"
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   1080
      Width           =   855
   End
   Begin VB.Label Label3 
      Caption         =   "用户密码:"
      Height          =   375
      Left            =   4200
      TabIndex        =   2
      Top             =   360
      Width           =   855
   End
   Begin VB.Label Label2 
      Caption         =   "用户名:"
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   855
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Private Declare Function KCheckinByMobile Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal lockID As String, ByVal owner As String, ByVal ownerID As String, ByVal mobile As String, _
    ByVal beginDate As String, ByVal expiryDate As String, ByVal options As Long, _
    ByVal returnKeyID As Long) As Long
    
    
Private Declare Function KCheckinByMobileWithPinCode Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal lockID As String, ByVal owner As String, ByVal ownerID As String, _
    ByVal mobile As String, ByVal beginDate As String, ByVal expiryDate As String, ByVal withPinCode As Long, ByVal options As Long, _
    ByVal returnKeyID As Long, ByVal returnVerifyCode As Long, ByVal returnPassword As Long) As Long
    
Private Declare Function KCheckinByUserId Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal lockID As String, ByVal owner As String, ByVal ownerID As String, ByVal userId As String, _
    ByVal sdkClientID As String, ByVal sdkClientSecret As String, _
    ByVal beginDate As String, ByVal expiryDate As String, ByVal options As Long, _
    ByVal returnKeyID As Long) As Long

Private Declare Function KCheckinByPassword Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal lockID As String, ByVal owner As String, ByVal ownerID As String, _
    ByVal beginDate As String, ByVal expiryDate As String, ByVal options As Long, _
    ByVal returnKeyID As Long, ByVal returnPassword As Long) As Long
    
Private Declare Function KCheckinByKeycard Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal lockID As String, ByVal owner As String, ByVal ownerID As String, _
    ByVal expiryDate As String, ByVal options As Long, _
    ByVal returnKeyID As Long) As Long

Private Declare Function KCancelKeyByKeyID Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal keyID As String) As Long
    
Private Declare Function KCancelKeyByLockID Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal lockID As String) As Long

Private Declare Function KCancelKeyByKeycard Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String) As Long
    
Private Declare Function KReadKeycard Lib "libLockman.dll" (ByVal userName As String, ByVal userPasswd As String, _
    ByVal returnKeyID As Long, ByVal returnLockID As Long, ByVal returnOwner As Long, _
    ByVal returnMakeDate As Long, ByVal returnEndDate As Long) As Long
    
Private Declare Function KFireBeepSuccess Lib "libLockman.dll" () As Long

Private Declare Function KFireBeepFailure Lib "libLockman.dll" () As Long
    
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

Private Declare Function lstrlenA Lib "kernel32.dll" (ByVal lpString As Long) As Long

Private Declare Function SysAllocStringByteLen Lib "oleaut32.dll" (Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As String


Public Sub BSTR2LPSTR(ByVal BSTR As String, ByVal LPSTR As Long)
Dim STR() As Byte
STR() = StrConv(BSTR & vbNullChar, vbFromUnicode)
CopyMemory ByVal LPSTR, STR(0), UBound(STR) + 1
End Sub


Public Function GetStrFromPtrA(ByVal Ptr As Long) As String
    GetStrFromPtrA = SysAllocStringByteLen(Ptr, lstrlenA(Ptr))
End Function


Private Sub cmdCancelByDeviceID_Click()
Dim rtn As Long
Dim lockID As String

lockID = InputBox("请输入设备ID")

If Len(lockID) = 0 Then
    Exit Sub
End If

rtn = KCancelKeyByLockID(textUserName.Text, textUserPasswd.Text, lockID)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功")
End Sub

Private Sub cmdCancelByKeycard_Click()
Dim rtn As Long

rtn = KCancelKeyByKeycard(textUserName.Text, textUserPasswd.Text)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功")
End Sub

Private Sub cmdCancelByKeyID_Click()
Dim rtn As Long
Dim keyID As String

keyID = InputBox("请输入KeyID")

If Len(keyID) = 0 Then
    Exit Sub
End If

rtn = KCancelKeyByKeyID(textUserName.Text, textUserPasswd.Text, keyID)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功")

End Sub

Private Sub cmdMakeEKey_Click()
Dim rtn As Long

Dim returnKeyID() As Byte
ReDim returnKeyID(64)
Dim pReturnKeyID As Long
pReturnKeyID = VarPtr(returnKeyID(0))

Dim returnVerifyCode() As Byte
ReDim returnVerifyCode(64)
Dim pReturnVerifyCode As Long
pReturnVerifyCode = VarPtr(returnVerifyCode(0))

Dim returnPassword() As Byte
ReDim returnPassword(64)
Dim pReturnPassword As Long
pReturnPassword = VarPtr(returnPassword(0))

Dim f As New Form2
f.Show 1

If f.result = 0 Then
    Exit Sub
End If

rtn = KCheckinByMobileWithPinCode(textUserName.Text, textUserPasswd.Text, textDeviceID.Text, f.textOwner, _
    "", f.textMobile, "", f.textExpiryDate, 1, 0, pReturnKeyID, pReturnVerifyCode, pReturnPassword)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功, KeyID=" & GetStrFromPtrA(pReturnKeyID) & ",验证码为:" & GetStrFromPtrA(pReturnVerifyCode) & ",密码为:" & GetStrFromPtrA(pReturnPassword))
End Sub

Private Sub cmdMakeEKeyPlugin_Click()
Dim rtn As Long

Dim returnKeyID() As Byte
ReDim returnKeyID(32)
Dim pReturnKeyID As Long
pReturnKeyID = VarPtr(returnKeyID(0))

Dim f As New Form4
f.Show 1

If f.result = 0 Then
    Exit Sub
End If

rtn = KCheckinByUserId(textUserName.Text, textUserPasswd.Text, textDeviceID.Text, f.textOwner, _
    "", f.textUserId, f.textSDKClientID, f.textSDKClientSecret, "", f.textExpiryDate, 0, pReturnKeyID)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功, KeyID=" & GetStrFromPtrA(pReturnKeyID))
End Sub

Private Sub cmdMakeGuestCard_Click()
Dim rtn As Long

Dim returnKeyID() As Byte
ReDim returnKeyID(32)
Dim pReturnKeyID As Long
pReturnKeyID = VarPtr(returnKeyID(0))

Dim f As New Form5
f.Show 1

If f.result = 0 Then
    Exit Sub
End If

rtn = KCheckinByKeycard(textUserName.Text, textUserPasswd.Text, _
    textDeviceID.Text, f.textOwner, "", f.textExpiryDate, 0, pReturnKeyID)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功, KeyID=" & GetStrFromPtrA(pReturnKeyID))
End Sub

Private Sub cmdMakePinCode_Click()
Dim rtn As Long

Dim returnKeyID() As Byte
ReDim returnKeyID(32)
Dim pReturnKeyID As Long
pReturnKeyID = VarPtr(returnKeyID(0))

Dim returnPassword() As Byte
ReDim returnPassword(32)
Dim pReturnPassword As Long
pReturnPassword = VarPtr(returnPassword(0))


Dim f As New Form3
f.Show 1

If f.result = 0 Then
    Exit Sub
End If

rtn = KCheckinByPassword(textUserName.Text, textUserPasswd.Text, textDeviceID.Text, f.textOwner, _
    "", "", f.textExpiryDate, 0, pReturnKeyID, pReturnPassword)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功, KeyID=" & GetStrFromPtrA(pReturnKeyID) & ",密码为:" & GetStrFromPtrA(pReturnPassword))
End Sub


Private Sub cmdReadCard_Click()

Dim rtn As Long

Dim returnKeyID() As Byte
ReDim returnKeyID(32)
Dim pReturnKeyID As Long
pReturnKeyID = VarPtr(returnKeyID(0))

Dim returnLockID() As Byte
ReDim returnLockID(32)
Dim pReturnLockID As Long
pReturnLockID = VarPtr(returnLockID(0))

Dim returnOwner() As Byte
ReDim returnOwner(32)
Dim pReturnOwner As Long
pReturnOwner = VarPtr(returnOwner(0))

Dim returnMakeDate() As Byte
ReDim returnMakeDate(32)
Dim pReturnMakeDate As Long
pReturnMakeDate = VarPtr(returnMakeDate(0))

Dim returnEndDate() As Byte
ReDim returnEndDate(32)
Dim pReturnEndDate As Long
pReturnEndDate = VarPtr(returnEndDate(0))

rtn = KReadKeycard(textUserName.Text, textUserPasswd.Text, _
    pReturnKeyID, pReturnLockID, pReturnOwner, _
    pReturnMakeDate, pReturnEndDate)
If rtn <> 0 Then
    KFireBeepFailure
    MsgBox ("操作失败:" & rtn)
    Exit Sub
End If

KFireBeepSuccess
MsgBox ("操作成功, KeyID=" & GetStrFromPtrA(pReturnKeyID) & ",设备ID:" & GetStrFromPtrA(pReturnLockID) & Chr(10) _
    & "持有人:" & GetStrFromPtrA(pReturnOwner) & Chr(10) & "发卡时间:" & GetStrFromPtrA(pReturnMakeDate) _
  & Chr(10) & "失败时间:" & GetStrFromPtrA(pReturnEndDate))

End Sub

