ผมว่า เราเอาเฉพาะ port ที่ user ใช้จริงๆดีไม๊ครับ จะมีความเป็นมืออาชีพขึ้นมานิดหนึ่ง
แทนที่เราจะเอามาทั้ง 1090-9999 ก็เอามาซัก 5-10 port ที่ ใช้จริง
แล้ว อาจจะ ทำตาราง port ขึ้นมาเพื่อให้ user ได้เพิ่มลดได้เอง
'Create June 2017 By Apiwat Puttala
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Data.SqlClient
Public Class FormCCCScan
'Create Standalone SDK class dynamicly.
Public axCCPT1 As zkemkeeper.CZKEM
'*********************************************************************************************************************************************
'* Before you refer to this demo,we strongly suggest you read the development manual deeply first.
' ก่อนที่คุณจะอ้างถึงการสาธิตนี้,เราขอแนะนำให้คุณอ่านคู่มือการพัฒนาอย่างละเอียดก่อน *
'* This part is for demonstrating the communication with your device.There are 3 communication ways: "TCP/IP","Serial Port" and "USB Client".
'* ขั้นตอนนี้คือสำหรับส่วนที่ใช้เพื่อการแสดงการสื่อสารกับอุปกรณ์ของคุณ มี 3 วิธีการสื่อสาร ได้แก่ "TCP/IP","พอร์ตอนุกรม"และ"USB Client"
'* The communication way which you can use duing to the model of the device.
' วิธีการสื่อสารที่คุณสามารถใช้ duing กับรูปแบบของอุปกรณ์ *
'* *******************************************************************************************************************************************
#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
'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 DataGridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
If DataGridView1.Text.Trim() = "" Or DataGridView1.Text.Trim() = "" Then
MsgBox("กรุณากรอก ip หรือ DNS ด้วยครับ", MsgBoxStyle.Exclamation, "Error")
Return
End If
Dim idwErrorCode As Integer
Cursor = Cursors.WaitCursor
If DataGridView1.Text = "" Then
axCCPT1.Disconnect()
RemoveHandler axCCPT1.OnFinger, AddressOf AxCCPT_OnFinger
RemoveHandler axCCPT1.OnFingerFeature, AddressOf AxCCPT_OnFingerFeature
RemoveHandler axCCPT1.OnVerify, AddressOf AxCCPT_OnVerify
RemoveHandler axCCPT1.OnAttTransactionEx, AddressOf AxCCPT_OnAttTransactionEx
RemoveHandler axCCPT1.OnEnrollFingerEx, AddressOf AxCCPT_OnEnrollFingerEx
RemoveHandler axCCPT1.OnDeleteTemplate, AddressOf AxCCPT_OnDeleteTemplate
RemoveHandler axCCPT1.OnNewUser, AddressOf AxCCPT_OnNewUser
RemoveHandler axCCPT1.OnAlarm, AddressOf AxCCPT_OnAlarm
RemoveHandler axCCPT1.OnDoor, AddressOf AxCCPT_OnDoor
RemoveHandler axCCPT1.OnWriteCard, AddressOf AxCCPT_OnWriteCard
RemoveHandler axCCPT1.OnEmptyCard, AddressOf AxCCPT_OnEmptyCard
RemoveHandler axCCPT1.OnHIDNum, AddressOf AxCCPT_OnHIDNum
Return
End If
DataGridView1 = axCCPT1.Connect_Net(DataGridView1.Text.Trim())
If DataGridView1 = True Then
DataGridView1.Text = "ไม่เชื่อมต่อ"
DataGridView1.Refresh()
DataGridView1.ForeColor = Color.Green
DataGridView1.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 axCCPT1.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 axCCPT1.Onfinger, AddressOf AxCCPT_OnFinger
AddHandler axCCPT1.OnFingerFeature, AddressOf AxCCPT_OnFingerFeature
AddHandler axCCPT1.OnVerify, AddressOf AxCCPT_OnVerify
AddHandler axCCPT1.OnAttTransactionEx, AddressOf AxCCPT_OnAttTransactionEx
AddHandler axCCPT1.OnEnrollFingerEx, AddressOf AxCCPT_OnEnrollFingerEx
AddHandler axCCPT1.OnDeleteTemplate, AddressOf AxCCPT_OnDeleteTemplate
AddHandler axCCPT1.OnNewUser, AddressOf AxCCPT_OnNewUser
AddHandler axCCPT1.OnAlarm, AddressOf AxCCPT_OnAlarm
AddHandler axCCPT1.OnDoor, AddressOf AxCCPT_OnDoor
AddHandler axCCPT1.OnWriteCard, AddressOf AxCCPT_OnWriteCard
AddHandler axCCPT1.OnEmptyCard, AddressOf AxCCPT_OnEmptyCard
AddHandler axCCPT1.OnHIDNum, AddressOf AxCCPT_OnHIDNum
End If
Else
axCCPT1.GetLastError(idwErrorCode)
MsgBox("ไม่พบไดร์เวอร์,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If
End Sub
#End Region
Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 4001 To 5001 Step 5
Column2.Items.Add(i)
Next
End Sub
Function ReturnID(strID As String) As String
'AA6006-001
Dim s As String = strID.Replace("AA", "") '6006-001
Dim ss() As String = s.Split("-") '6006,001.
Dim sss As Integer = Convert.ToInt32(ss(1))
If ss(0).Substring(2, 2) <> Now.Month.ToString("00") Then
sss = 1 'ถ้าขึ้นเดือนใหม่ก็ให้เริ่มจาก 1
Else
sss = sss + 1 'เดือนเก่าก็ + เพิ่มซิคร้าบบบบบ
End If
Return "AA" & Now.ToString("yyMM") & "-" & sss.ToString("000")
End Function
#Region "RealTime Events"
'When you place your finger on sensor of the device,this event will be triggered
Private Sub AxCCPT_OnFinger()
lbRTShow.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 AxCCPT_OnVerify(ByVal iUserID As Integer)
lbRTShow.Items.Add("กำลังตรวจสอบลายนิ้วมือ...")
If iUserID <> -1 Then
lbRTShow.Items.Add("ลายนิ้วมือ ถูกต้อง")
Else
lbRTShow.Items.Add("ลายนิ้วมือผิดพลาดหรือไม่มีข้อมูลในระบบ ครับ...!")
End If
End Sub
'If your fingerprint(or your card) passes the verification,this event will be triggered
Private Sub AxCCPT_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)
lbRTShow.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
lbRTShow.Items.Add("บันทึกข้อมูลเรียบร้อยครับ...!")
lbRTShow.Items.Add("รายละเอียด ดังนี้")
lbRTShow.Items.Add("รหัส ID : " & sEnrollNumber)
' lbRTShow.Items.Add("...isInvalid:" & iIsInValid.ToString())
lbRTShow.Items.Add("สถานะ : " & iAttState.ToString())
'lbRTShow.Items.Add("...VerifyMethod:" & iVerifyMethod.ToString())
'lbRTShow.Items.Add("...Workcode:" & iWorkCode.ToString()) 'the difference between the event OnAttTransaction and OnAttTransactionEx
lbRTShow.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 AxCCPT_OnFingerFeature(ByVal iScore As Integer)
If iScore < 0 Then
lbRTShow.Items.Add("The quality of your fingerprint is poor")
Else
lbRTShow.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 AxCCPT_OnDeleteTemplate(ByVal iEnrollNumber As Integer, ByVal iFingerIndex As Integer)
lbRTShow.Items.Add("RTEvent OnDeleteTemplate Has been Triggered...")
lbRTShow.Items.Add("...UserID=" & iEnrollNumber.ToString() & " FingerIndex=" & iFingerIndex.ToString())
End Sub
'When you have enrolled a new user,this event will be triggered.
Private Sub AxCCPT_OnNewUser(ByVal iEnrollNumber As Integer)
lbRTShow.Items.Add("RTEvent OnNewUser Has been Triggered...")
lbRTShow.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 AxCCPT_OnHIDNum(ByVal iCardNumber As Integer)
lbRTShow.Items.Add("RTEvent OnHIDNum Has been Triggered...")
lbRTShow.Items.Add("...Cardnumber=" & iCardNumber.ToString())
End Sub
'When you are enrolling your finger,this event will be triggered.
Private Sub AxCCPT_OnEnrollFingerEx(ByVal sEnrollNumber As String, ByVal iFingerIndex As Integer, ByVal iActionResult As Integer, ByVal iTemplateLength As Integer)
If iActionResult = 0 Then
lbRTShow.Items.Add("RTEvent OnEnrollFigerEx Has been Triggered....")
lbRTShow.Items.Add(".....UserID: " & sEnrollNumber & " Index: " & iFingerIndex.ToString() & " tmpLen: " & iTemplateLength.ToString())
Else
lbRTShow.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 AxCCPT_OnAlarm(ByVal iAlarmType As Integer, ByVal iEnrollNumber As Integer, ByVal iVerified As Integer)
lbRTShow.Items.Add("RTEvnet OnAlarm Has been Triggered...")
lbRTShow.Items.Add("...alarmType=" & iAlarmType.ToString())
lbRTShow.Items.Add("...enrollNumber=" & iEnrollNumber.ToString())
lbRTShow.Items.Add("...verified=" & iVerified.ToString())
End Sub
'Door sensor event
Private Sub AxCCPT_OnDoor(ByVal iEventType As Integer)
lbRTShow.Items.Add("RTEvent Ondoor Has been Triggered...")
lbRTShow.Items.Add("...EventType=" & iEventType.ToString())
End Sub
'When you have emptyed the Mifare card,this event will be triggered.
Private Sub AxCCPT_OnEmptyCard(ByVal iActionResult As Integer)
lbRTShow.Items.Add("RTEvent OnEmptyCard Has been Triggered...")
If iActionResult = 0 Then
lbRTShow.Items.Add("...Empty Mifare Card OK")
Else
lbRTShow.Items.Add("...Empty Failed")
End If
End Sub
'When you have written into the Mifare card ,this event will be triggered.
Private Sub AxCCPT_OnWriteCard(ByVal iEnrollNumber As Integer, ByVal iActionResult As Integer, ByVal iLength As Integer)
lbRTShow.Items.Add("RTEvent OnWriteCard Has been Triggered...")
If iActionResult = 0 Then
lbRTShow.Items.Add("...Write Mifare Card OK")
lbRTShow.Items.Add("...EnrollNumber=" & iEnrollNumber.ToString())
lbRTShow.Items.Add("...TmpLength=" & iLength.ToString())
Else
lbRTShow.Items.Add("...Write Failed")
End If
End Sub
#End Region
End Class