Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form1
Public axLoop As New zkemkeeper.CZKEM
#Region "Communication"
Private bIsConnected = False
Private bIsConnected2 = False
Private iMachineNumber As Integer
Private iMachinenumber2 As Integer
Private Sub btnconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconnect.Click
Dim idwErrorCode As Integer
For i As Integer = 0 To myDgv.Rows.Count - 1
If myDgv.Rows(i).Cells(0).Value IsNot Nothing Then
Dim id As [String] = myDgv.Rows(i).Cells(1).Value.ToString()
Dim ip As [String] = myDgv.Rows(i).Cells(2).Value.ToString()
Dim port As [String] = myDgv.Rows(i).Cells(3).Value.ToString()
bIsConnected = axLoop.Connect_Net(ip.Trim(), Convert.ToInt32(port.Trim()))
If bIsConnected = True Then
btnconnect.Text = "ไม่เชื่อมต่อ"
btnconnect.Refresh()
status.DataGridView.ForeColor = Color.Green
status.DataGridView.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 axLoop.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 axLoop.OnFinger, AddressOf AxLoop_OnFinger
AddHandler axLoop.OnFingerFeature, AddressOf AxLoop_OnFingerFeature
AddHandler axLoop.OnVerify, AddressOf AxLoop_OnVerify
AddHandler axLoop.OnAttTransactionEx, AddressOf AxLoop_OnAttTransactionEx
AddHandler axLoop.OnEnrollFingerEx, AddressOf AxLoop_OnEnrollFingerEx
AddHandler axLoop.OnDeleteTemplate, AddressOf AxLoop_OnDeleteTemplate
AddHandler axLoop.OnNewUser, AddressOf AxLoop_OnNewUser
AddHandler axLoop.OnAlarm, AddressOf AxLoop_OnAlarm
AddHandler axLoop.OnDoor, AddressOf AxLoop_OnDoor
AddHandler axLoop.OnWriteCard, AddressOf AxLoop_OnWriteCard
AddHandler axLoop.OnEmptyCard, AddressOf AxLoop_OnEmptyCard
AddHandler axLoop.OnHIDNum, AddressOf AxLoop_OnHIDNum
End If
Else
axLoop.GetLastError(idwErrorCode)
MsgBox("ไม่พบไดร์เวอร์,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If
End If
Next
Cursor = Cursors.Default
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
For i As Integer = 0 To myDgv.Rows.Count - 2
If myDgv.Rows(i).Cells(0).Value IsNot Nothing Then
Dim id As [String] = myDgv.Rows(i).Cells(1).Value.ToString()
Dim ip As [String] = myDgv.Rows(i).Cells(2).Value.ToString()
Dim port As [String] = myDgv.Rows(i).Cells(3).Value.ToString()
bIsConnected = axLoop.Connect_Net(ip.Trim(), Convert.ToInt32(port.Trim()))
Cursor = Cursors.Default
axLoop.Disconnect()
RemoveHandler axLoop.OnFinger, AddressOf AxLoop_OnFinger
RemoveHandler axLoop.OnFingerFeature, AddressOf AxLoop_OnFingerFeature
RemoveHandler axLoop.OnVerify, AddressOf AxLoop_OnVerify
RemoveHandler axLoop.OnAttTransactionEx, AddressOf AxLoop_OnAttTransactionEx
RemoveHandler axLoop.OnEnrollFingerEx, AddressOf AxLoop_OnEnrollFingerEx
RemoveHandler axLoop.OnDeleteTemplate, AddressOf AxLoop_OnDeleteTemplate
RemoveHandler axLoop.OnNewUser, AddressOf AxLoop_OnNewUser
RemoveHandler axLoop.OnAlarm, AddressOf AxLoop_OnAlarm
RemoveHandler axLoop.OnDoor, AddressOf AxLoop_OnDoor
RemoveHandler axLoop.OnWriteCard, AddressOf AxLoop_OnWriteCard
RemoveHandler axLoop.OnEmptyCard, AddressOf AxLoop_OnEmptyCard
RemoveHandler axLoop.OnHIDNum, AddressOf AxLoop_OnHIDNum
bIsConnected = False
status.DataGridView.ForeColor = Color.Red
status.DataGridView.Text = "ไม่เชื่อมต่อ"
Cursor = Cursors.Default
Return
End If
Next
End Sub
#End Region
#Region "RealTime Events"
'When you place your finger on sensor of the device,this event will be triggered
Private Sub AxLoop_OnFinger()
ListView1.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 AxLoop_OnVerify(ByVal iUserID As Integer)
ListView1.Items.Add("กำลังตรวจสอบลายนิ้วมือ...")
If iUserID <> -1 Then
ListView1.Items.Add("ลายนิ้วมือ ถูกต้อง")
Else
ListView1.Items.Add("ลายนิ้วมือผิดพลาดหรือไม่มีข้อมูลในระบบ ครับ...!")
End If
End Sub
'If your fingerprint(or your card) passes the verification,this event will be triggered
Private Sub AxLoop_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)
ListView1.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
ListView1.Items.Add("บันทึกข้อมูลเรียบร้อยครับ...!")
ListView1.Items.Add("รายละเอียด ดังนี้")
ListView1.Items.Add("รหัส ID : " & sEnrollNumber)
ListView1.Items.Add("...isInvalid:" & iIsInValid.ToString())
ListView1.Items.Add("สถานะ : " & iAttState.ToString())
ListView1.Items.Add("...VerifyMethod:" & iVerifyMethod.ToString())
ListView1.Items.Add("...Workcode:" & iWorkCode.ToString()) 'the difference between the event OnAttTransaction and OnAttTransactionEx
ListView1.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 AxLoop_OnFingerFeature(ByVal iScore As Integer)
If iScore < 0 Then
ListView1.Items.Add("The quality of your fingerprint is poor")
Else
ListView1.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 AxLoop_OnDeleteTemplate(ByVal iEnrollNumber As Integer, ByVal iFingerIndex As Integer)
ListView1.Items.Add("RTEvent OnDeleteTemplate Has been Triggered...")
ListView1.Items.Add("...UserID=" & iEnrollNumber.ToString() & " FingerIndex=" & iFingerIndex.ToString())
End Sub
'When you have enrolled a new user,this event will be triggered.
Private Sub AxLoop_OnNewUser(ByVal iEnrollNumber As Integer)
ListView1.Items.Add("RTEvent OnNewUser Has been Triggered...")
ListView1.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 AxLoop_OnHIDNum(ByVal iCardNumber As Integer)
ListView1.Items.Add("RTEvent OnHIDNum Has been Triggered...")
ListView1.Items.Add("...Cardnumber=" & iCardNumber.ToString())
End Sub
'When you are enrolling your finger,this event will be triggered.
Private Sub AxLoop_OnEnrollFingerEx(ByVal sEnrollNumber As String, ByVal iFingerIndex As Integer, ByVal iActionResult As Integer, ByVal iTemplateLength As Integer)
If iActionResult = 0 Then
ListView1.Items.Add("RTEvent OnEnrollFigerEx Has been Triggered....")
ListView1.Items.Add(".....UserID: " & sEnrollNumber & " Index: " & iFingerIndex.ToString() & " tmpLen: " & iTemplateLength.ToString())
Else
ListView1.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 AxLoop_OnAlarm(ByVal iAlarmType As Integer, ByVal iEnrollNumber As Integer, ByVal iVerified As Integer)
ListView1.Items.Add("RTEvnet OnAlarm Has been Triggered...")
ListView1.Items.Add("...alarmType=" & iAlarmType.ToString())
ListView1.Items.Add("...enrollNumber=" & iEnrollNumber.ToString())
ListView1.Items.Add("...verified=" & iVerified.ToString())
End Sub
'Door sensor event
Private Sub AxLoop_OnDoor(ByVal iEventType As Integer)
ListView1.Items.Add("RTEvent Ondoor Has been Triggered...")
ListView1.Items.Add("...EventType=" & iEventType.ToString())
End Sub
'When you have emptyed the Mifare card,this event will be triggered.
Private Sub AxLoop_OnEmptyCard(ByVal iActionResult As Integer)
ListView1.Items.Add("RTEvent OnEmptyCard Has been Triggered...")
If iActionResult = 0 Then
ListView1.Items.Add("...Empty Mifare Card OK")
Else
ListView1.Items.Add("...Empty Failed")
End If
End Sub
'When you have written into the Mifare card ,this event will be triggered.
Private Sub AxLoop_OnWriteCard(ByVal iEnrollNumber As Integer, ByVal iActionResult As Integer, ByVal iLength As Integer)
ListView1.Items.Add("RTEvent OnWriteCard Has been Triggered...")
If iActionResult = 0 Then
ListView1.Items.Add("...Write Mifare Card OK")
ListView1.Items.Add("...EnrollNumber=" & iEnrollNumber.ToString())
ListView1.Items.Add("...TmpLength=" & iLength.ToString())
Else
ListView1.Items.Add("...Write Failed")
End If
End Sub
#End Region
End Class