Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Public axTest1 As New zkemkeeper.CZKEM
#Region "Communication"
Private bIsConnected = False
Private bIsConnected2 = False
Private bIsConnected3 = False
Private bIsConnected4 = False
Private bIsConnected5 = False
Private bIsConnected6 = False
Private bIsConnected7 = False
Private bIsConnected8 = False
Private bIsConnected9 = False
Private bIsConnected10 = False
Private bIsConnected11 = False
Private bIsConnected12 = False
Private bIsConnected13 = False
Private bIsConnected14 = False
Private bIsConnected15 = False
Private bIsConnected16 = False
Private bIsConnected17 = False
Private bIsConnected18 = False
Private bIsConnected19 = False
Private bIsConnected20 = False
Private iMachineNumber As Integer
Private iMachineNumber2 As Integer
Private iMachineNumber3 As Integer
Private iMachineNumber4 As Integer
Private iMachineNumber5 As Integer
Private iMachineNumber6 As Integer
Private iMachineNumber7 As Integer
Private iMachineNumber8 As Integer
Private iMachineNumber9 As Integer
Private iMachineNumber10 As Integer
Private iMachineNumber11 As Integer
Private iMachineNumber12 As Integer
Private iMachineNumber13 As Integer
Private iMachineNumber14 As Integer
Private iMachineNumber15 As Integer
Private iMachineNumber16 As Integer
Private iMachineNumber17 As Integer
Private iMachineNumber18 As Integer
Private iMachineNumber19 As Integer
Private iMachineNumber20 As Integer
Private Property objCmd As SqlCommand
'เปลี่ยนชื่อ tab
Private Sub add_Click(sender As Object, e As EventArgs)
tabControl1.SelectedTab.Text = InputBox("ป้อนชื่อ Tab ใหม่", "เปลี่ยนชื่อ Tab ที่เลือก", tabControl1.SelectedTab.Text)
End Sub
'If your device supports the TCP/IP communications, you can refer to this.
'when you are using the tcp/ip communication,you can distinguish different devices by their IP address.
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
If txtIP.Text.Trim() = "" Or txtPort.Text.Trim() = "" Then
MsgBox("กรุณากรอก ip หรือ DNS ด้วยครับ", MsgBoxStyle.Exclamation, "Error")
Return
End If
Dim idwErrorCode As Integer
Cursor = Cursors.WaitCursor
If btnConnect.Text = "ไม่เชื่อมต่อ" Then
axTest1.Disconnect()
RemoveHandler axTest1.OnFinger, AddressOf AxTest1_OnFinger
RemoveHandler axTest1.OnFingerFeature, AddressOf AxTest1_OnFingerFeature
RemoveHandler axTest1.OnVerify, AddressOf AxTest1_OnVerify
RemoveHandler axTest1.OnAttTransactionEx, AddressOf AxTest1_OnAttTransactionEx
RemoveHandler axTest1.OnEnrollFingerEx, AddressOf AxTest1_OnEnrollFingerEx
RemoveHandler axTest1.OnDeleteTemplate, AddressOf AxTest1_OnDeleteTemplate
RemoveHandler axTest1.OnNewUser, AddressOf AxTest1_OnNewUser
RemoveHandler axTest1.OnAlarm, AddressOf AxTest1_OnAlarm
RemoveHandler axTest1.OnDoor, AddressOf AxTest1_OnDoor
RemoveHandler axTest1.OnWriteCard, AddressOf AxTest1_OnWriteCard
RemoveHandler axTest1.OnEmptyCard, AddressOf AxTest1_OnEmptyCard
RemoveHandler axTest1.OnHIDNum, AddressOf AxTest1_OnHIDNum
bIsConnected = False
btnConnect.Text = "เชื่อมต่อสำเร็จ"
lblState.ForeColor = Color.Red
lblState.Text = "ไม่เชื่อมต่อ"
Cursor = Cursors.Default
Return
End If
bIsConnected = axTest1.Connect_Net(txtIP.Text.Trim(), Convert.ToInt32(txtPort.Text.Trim()))
If bIsConnected = True Then
btnConnect.Text = "ไม่เชื่อมต่อ"
btnConnect.Refresh()
lblState.ForeColor = Color.Green
lblState.Text = "เชื่อมต่อสำเร็จ"
iMachineNumber = 1 'In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
If axTest1.RegEvent(iMachineNumber, 65535) = True Then 'Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
AddHandler axTest1.OnFinger, AddressOf AxTest1_OnFinger
AddHandler axTest1.OnFingerFeature, AddressOf AxTest1_OnFingerFeature
AddHandler axTest1.OnVerify, AddressOf AxTest1_OnVerify
AddHandler axTest1.OnAttTransactionEx, AddressOf AxTest1_OnAttTransactionEx
AddHandler axTest1.OnEnrollFingerEx, AddressOf AxTest1_OnEnrollFingerEx
AddHandler axTest1.OnDeleteTemplate, AddressOf AxTest1_OnDeleteTemplate
AddHandler axTest1.OnNewUser, AddressOf AxTest1_OnNewUser
AddHandler axTest1.OnAlarm, AddressOf AxTest1_OnAlarm
AddHandler axTest1.OnDoor, AddressOf AxTest1_OnDoor
AddHandler axTest1.OnWriteCard, AddressOf AxTest1_OnWriteCard
AddHandler axTest1.OnEmptyCard, AddressOf AxTest1_OnEmptyCard
AddHandler axTest1.OnHIDNum, AddressOf AxTest1_OnHIDNum
End If
Else
axTest1.GetLastError(idwErrorCode)
MsgBox("ไม่พบไดร์เวอร์,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If
Cursor = Cursors.Default
End Sub
'math2
Private Sub btnConnect2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect2.Click
If txtIP2.Text.Trim() = "" Or txtPort2.Text.Trim() = "" Then
MsgBox("กรุณากรอก ip หรือ DNS ด้วยครับ", MsgBoxStyle.Exclamation, "Error")
Return
End If
Dim idwErrorCode2 As Integer
Cursor = Cursors.WaitCursor
If btnConnect2.Text = "ไม่เชื่อมต่อ" Then
axTest1.Disconnect()
RemoveHandler axTest1.OnFinger, AddressOf AxTest1_OnFinger
RemoveHandler axTest1.OnFingerFeature, AddressOf AxTest1_OnFingerFeature
RemoveHandler axTest1.OnVerify, AddressOf AxTest1_OnVerify
RemoveHandler axTest1.OnAttTransactionEx, AddressOf AxTest1_OnAttTransactionEx
RemoveHandler axTest1.OnEnrollFingerEx, AddressOf AxTest1_OnEnrollFingerEx
RemoveHandler axTest1.OnDeleteTemplate, AddressOf AxTest1_OnDeleteTemplate
RemoveHandler axTest1.OnNewUser, AddressOf AxTest1_OnNewUser
RemoveHandler axTest1.OnAlarm, AddressOf AxTest1_OnAlarm
RemoveHandler axTest1.OnDoor, AddressOf AxTest1_OnDoor
RemoveHandler axTest1.OnWriteCard, AddressOf AxTest1_OnWriteCard
RemoveHandler axTest1.OnEmptyCard, AddressOf AxTest1_OnEmptyCard
RemoveHandler axTest1.OnHIDNum, AddressOf AxTest1_OnHIDNum
bIsConnected2 = False
lblState2.ForeColor = Color.Red
btnConnect2.Text = "เชื่อมต่อสำเร็จ"
lblState2.Text = "ไม่เชื่อมต่อ"
Cursor = Cursors.Default
Return
End If
bIsConnected2 = axTest1.Connect_Net(txtIP2.Text.Trim(), Convert.ToInt32(txtPort2.Text.Trim()))
If bIsConnected2 = True Then
btnConnect2.Text = "ไม่เชื่อมต่อ"
btnConnect2.Refresh()
lblState2.ForeColor = Color.Green
lblState2.Text = "เชื่อมต่อสำเร็จ"
iMachineNumber2 = 1 'In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
If axTest1.RegEvent(iMachineNumber2, 65535) = True Then 'Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
AddHandler axTest1.OnFinger, AddressOf AxTest1_OnFinger
AddHandler axTest1.OnFingerFeature, AddressOf AxTest1_OnFingerFeature
AddHandler axTest1.OnVerify, AddressOf AxTest1_OnVerify
AddHandler axTest1.OnAttTransactionEx, AddressOf AxTest1_OnAttTransactionEx
AddHandler axTest1.OnEnrollFingerEx, AddressOf AxTest1_OnEnrollFingerEx
AddHandler axTest1.OnDeleteTemplate, AddressOf AxTest1_OnDeleteTemplate
AddHandler axTest1.OnNewUser, AddressOf AxTest1_OnNewUser
AddHandler axTest1.OnAlarm, AddressOf AxTest1_OnAlarm
AddHandler axTest1.OnDoor, AddressOf AxTest1_OnDoor
AddHandler axTest1.OnWriteCard, AddressOf AxTest1_OnWriteCard
AddHandler axTest1.OnEmptyCard, AddressOf AxTest1_OnEmptyCard
AddHandler axTest1.OnHIDNum, AddressOf AxTest1_OnHIDNum
End If
Else
axTest1.GetLastError(idwErrorCode2)
MsgBox("ไม่พบ ไดร์เวอร์,ErrorCode=" & idwErrorCode2, MsgBoxStyle.Exclamation, "Error")
End If
Cursor = Cursors.Default
End Sub
#End Region
'**************************************************************************************************
'* Before you refer to this demo,we strongly suggest you read the development manual deeply first.*
'* This part is for demonstrating the RealTime Events that triggered by your operations *
'**************************************************************************************************
#Region "RealTime Events"
'When you place your finger on sensor of the device,this event will be triggered
Private Sub AxTest1_OnFinger()
inboxshow.Items.Add("<<--มีการ สแกนลายนิ้วมือ-->>")
End Sub
'After you have placed your finger on the sensor(or swipe your card to the device),this event will be triggered.
'If you passes the verification,the returned value userid will be the user enrollnumber,or else the value will be -1;
Private Sub AxTest1_OnVerify(ByVal iUserID As Integer)
inboxshow.Items.Add("กำลังตรวจสอบลายนิ้วมือ...")
If iUserID <> -1 Then
inboxshow.Items.Add("ลายนิ้วมือ ถูกต้อง")
Else
inboxshow.Items.Add("ลายนิ้วมือผิดพลาดหรือไม่มีข้อมูลในระบบ ครับ...!")
End If
End Sub
'If your fingerprint(or your card) passes the verification,this event will be triggered
Private Sub AxTest1_OnAttTransactionEx(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, _
ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer, ByVal iHour As Integer, ByVal iMinute As Integer, ByVal iSecond As Integer, ByVal iWorkCode As Integer)
inboxshow.Items.Clear()
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=www.ohotime.com;User Id=ohotime; Password=mit260914; Database=ohotime_pepo; Pooling=false"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "INSERT INTO checkinout (USERID,CHECKTIME,CHECKTYPE,WorkCode,UserExtFmt) VALUES ('" & sEnrollNumber & "','" & iYear.ToString() & "-" & iMonth.ToString() & "-" & iDay.ToString() & " " & iHour.ToString() & ":" & iMinute.ToString() & ":" & iSecond.ToString() & "','" & iAttState.ToString() & "','" & 0 & "','" & 0 & "')"
objCmd = New MySqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
objConn.Close()
objConn = Nothing
inboxshow.Items.Add("บันทึกข้อมูลเรียบร้อยครับ...!")
inboxshow.Items.Add("รายละเอียด ดังนี้")
inboxshow.Items.Add("รหัส ID : " & sEnrollNumber)
' lbRTShow.Items.Add("...isInvalid:" & iIsInValid.ToString())
inboxshow.Items.Add("สถานะ : " & iAttState.ToString())
'lbRTShow.Items.Add("...VerifyMethod:" & iVerifyMethod.ToString())
'lbRTShow.Items.Add("...Workcode:" & iWorkCode.ToString()) 'the difference between the event OnAttTransaction and OnAttTransactionEx
inboxshow.Items.Add("วัน/เวลา : " & iYear.ToString() & "-" & iMonth.ToString() & "-" & iDay.ToString() & " " & iHour.ToString() & ":" & iMinute.ToString() & ":" & iSecond.ToString())
End Sub
'When you have enrolled your finger,this event will be triggered and return the quality of the fingerprint you have enrolled
Private Sub AxTest1_OnFingerFeature(ByVal iScore As Integer)
If iScore < 0 Then
inboxshow.Items.Add("The quality of your fingerprint is poor")
Else
inboxshow.Items.Add("RTEvent OnFingerFeature Has been Triggered...Score:" & iScore.ToString())
End If
End Sub
'When you have deleted one one fingerprint template,this event will be triggered.
Private Sub AxTest1_OnDeleteTemplate(ByVal iEnrollNumber As Integer, ByVal iFingerIndex As Integer)
inboxshow.Items.Add("RTEvent OnDeleteTemplate Has been Triggered...")
inboxshow.Items.Add("...UserID=" & iEnrollNumber.ToString() & " FingerIndex=" & iFingerIndex.ToString())
End Sub
'When you have enrolled a new user,this event will be triggered.
Private Sub AxTest1_OnNewUser(ByVal iEnrollNumber As Integer)
inboxshow.Items.Add("RTEvent OnNewUser Has been Triggered...")
inboxshow.Items.Add("...NewUserID=" & iEnrollNumber.ToString())
End Sub
'When you swipe a card to the device, this event will be triggered to show you the card number.
Private Sub AxTest1_OnHIDNum(ByVal iCardNumber As Integer)
inboxshow.Items.Add("RTEvent OnHIDNum Has been Triggered...")
inboxshow.Items.Add("...Cardnumber=" & iCardNumber.ToString())
End Sub
'When you are enrolling your finger,this event will be triggered.
Private Sub AxTest1_OnEnrollFingerEx(ByVal sEnrollNumber As String, ByVal iFingerIndex As Integer, ByVal iActionResult As Integer, ByVal iTemplateLength As Integer)
If iActionResult = 0 Then
inboxshow.Items.Add("RTEvent OnEnrollFigerEx Has been Triggered....")
inboxshow.Items.Add(".....UserID: " & sEnrollNumber & " Index: " & iFingerIndex.ToString() & " tmpLen: " & iTemplateLength.ToString())
Else
inboxshow.Items.Add("RTEvent OnEnrollFigerEx Has been Triggered Error,actionResult=" + iActionResult.ToString())
End If
End Sub
'/When the dismantling machine or duress alarm occurs, trigger this event.
Private Sub AxTest1_OnAlarm(ByVal iAlarmType As Integer, ByVal iEnrollNumber As Integer, ByVal iVerified As Integer)
inboxshow.Items.Add("RTEvnet OnAlarm Has been Triggered...")
inboxshow.Items.Add("...alarmType=" & iAlarmType.ToString())
inboxshow.Items.Add("...enrollNumber=" & iEnrollNumber.ToString())
inboxshow.Items.Add("...verified=" & iVerified.ToString())
End Sub
'Door sensor event
Private Sub AxTest1_OnDoor(ByVal iEventType As Integer)
inboxshow.Items.Add("RTEvent Ondoor Has been Triggered...")
inboxshow.Items.Add("...EventType=" & iEventType.ToString())
End Sub
'When you have emptyed the Mifare card,this event will be triggered.
Private Sub AxTest1_OnEmptyCard(ByVal iActionResult As Integer)
inboxshow.Items.Add("RTEvent OnEmptyCard Has been Triggered...")
If iActionResult = 0 Then
inboxshow.Items.Add("...Empty Mifare Card OK")
Else
inboxshow.Items.Add("...Empty Failed")
End If
End Sub
'When you have written into the Mifare card ,this event will be triggered.
Private Sub AxTest1_OnWriteCard(ByVal iEnrollNumber As Integer, ByVal iActionResult As Integer, ByVal iLength As Integer)
inboxshow.Items.Add("RTEvent OnWriteCard Has been Triggered...")
If iActionResult = 0 Then
inboxshow.Items.Add("...Write Mifare Card OK")
inboxshow.Items.Add("...EnrollNumber=" & iEnrollNumber.ToString())
inboxshow.Items.Add("...TmpLength=" & iLength.ToString())
Else
inboxshow.Items.Add("...Write Failed")
End If
End Sub
#End Region
End Class