001.
Imports
MySql.Data.MySqlClient
002.
Imports
System.Data
003.
Imports
System.Data.SqlClient
004.
005.
Public
Class
Form1
006.
Public
axTest1
As
New
zkemkeeper.CZKEM
007.
008.
#Region "Communication"
009.
Private
bIsConnected =
False
010.
Private
bIsConnected2 =
False
011.
Private
bIsConnected3 =
False
012.
Private
bIsConnected4 =
False
013.
Private
bIsConnected5 =
False
014.
Private
bIsConnected6 =
False
015.
Private
bIsConnected7 =
False
016.
Private
bIsConnected8 =
False
017.
Private
bIsConnected9 =
False
018.
Private
bIsConnected10 =
False
019.
Private
bIsConnected11 =
False
020.
Private
bIsConnected12 =
False
021.
Private
bIsConnected13 =
False
022.
Private
bIsConnected14 =
False
023.
Private
bIsConnected15 =
False
024.
Private
bIsConnected16 =
False
025.
Private
bIsConnected17 =
False
026.
Private
bIsConnected18 =
False
027.
Private
bIsConnected19 =
False
028.
Private
bIsConnected20 =
False
029.
Private
iMachineNumber
As
Integer
030.
Private
iMachineNumber2
As
Integer
031.
Private
iMachineNumber3
As
Integer
032.
Private
iMachineNumber4
As
Integer
033.
Private
iMachineNumber5
As
Integer
034.
Private
iMachineNumber6
As
Integer
035.
Private
iMachineNumber7
As
Integer
036.
Private
iMachineNumber8
As
Integer
037.
Private
iMachineNumber9
As
Integer
038.
Private
iMachineNumber10
As
Integer
039.
Private
iMachineNumber11
As
Integer
040.
Private
iMachineNumber12
As
Integer
041.
Private
iMachineNumber13
As
Integer
042.
Private
iMachineNumber14
As
Integer
043.
Private
iMachineNumber15
As
Integer
044.
Private
iMachineNumber16
As
Integer
045.
Private
iMachineNumber17
As
Integer
046.
Private
iMachineNumber18
As
Integer
047.
Private
iMachineNumber19
As
Integer
048.
Private
iMachineNumber20
As
Integer
049.
050.
Private
Property
objCmd
As
SqlCommand
051.
052.
Private
Sub
add_Click(sender
As
Object
, e
As
EventArgs)
053.
tabControl1.SelectedTab.Text = InputBox(
"ป้อนชื่อ Tab ใหม่"
,
"เปลี่ยนชื่อ Tab ที่เลือก"
, tabControl1.SelectedTab.Text)
054.
End
Sub
055.
056.
057.
058.
Private
Sub
btnConnect_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnConnect.Click
059.
If
txtIP.Text.Trim() =
""
Or
txtPort.Text.Trim() =
""
Then
060.
MsgBox(
"กรุณากรอก ip หรือ DNS ด้วยครับ"
, MsgBoxStyle.Exclamation,
"Error"
)
061.
Return
062.
End
If
063.
Dim
idwErrorCode
As
Integer
064.
Cursor = Cursors.WaitCursor
065.
If
btnConnect.Text =
"ไม่เชื่อมต่อ"
Then
066.
axTest1.Disconnect()
067.
068.
RemoveHandler
axTest1.OnFinger,
AddressOf
AxTest1_OnFinger
069.
RemoveHandler
axTest1.OnFingerFeature,
AddressOf
AxTest1_OnFingerFeature
070.
RemoveHandler
axTest1.OnVerify,
AddressOf
AxTest1_OnVerify
071.
RemoveHandler
axTest1.OnAttTransactionEx,
AddressOf
AxTest1_OnAttTransactionEx
072.
RemoveHandler
axTest1.OnEnrollFingerEx,
AddressOf
AxTest1_OnEnrollFingerEx
073.
RemoveHandler
axTest1.OnDeleteTemplate,
AddressOf
AxTest1_OnDeleteTemplate
074.
RemoveHandler
axTest1.OnNewUser,
AddressOf
AxTest1_OnNewUser
075.
RemoveHandler
axTest1.OnAlarm,
AddressOf
AxTest1_OnAlarm
076.
RemoveHandler
axTest1.OnDoor,
AddressOf
AxTest1_OnDoor
077.
RemoveHandler
axTest1.OnWriteCard,
AddressOf
AxTest1_OnWriteCard
078.
RemoveHandler
axTest1.OnEmptyCard,
AddressOf
AxTest1_OnEmptyCard
079.
RemoveHandler
axTest1.OnHIDNum,
AddressOf
AxTest1_OnHIDNum
080.
081.
bIsConnected =
False
082.
btnConnect.Text =
"เชื่อมต่อสำเร็จ"
083.
lblState.ForeColor = Color.Red
084.
lblState.Text =
"ไม่เชื่อมต่อ"
085.
Cursor = Cursors.
Default
086.
Return
087.
End
If
088.
089.
bIsConnected = axTest1.Connect_Net(txtIP.Text.Trim(), Convert.ToInt32(txtPort.Text.Trim()))
090.
If
bIsConnected =
True
Then
091.
btnConnect.Text =
"ไม่เชื่อมต่อ"
092.
btnConnect.Refresh()
093.
lblState.ForeColor = Color.Green
094.
lblState.Text =
"เชื่อมต่อสำเร็จ"
095.
iMachineNumber = 1
096.
097.
If
axTest1.RegEvent(iMachineNumber, 65535) =
True
Then
098.
099.
AddHandler
axTest1.OnFinger,
AddressOf
AxTest1_OnFinger
100.
AddHandler
axTest1.OnFingerFeature,
AddressOf
AxTest1_OnFingerFeature
101.
AddHandler
axTest1.OnVerify,
AddressOf
AxTest1_OnVerify
102.
AddHandler
axTest1.OnAttTransactionEx,
AddressOf
AxTest1_OnAttTransactionEx
103.
AddHandler
axTest1.OnEnrollFingerEx,
AddressOf
AxTest1_OnEnrollFingerEx
104.
AddHandler
axTest1.OnDeleteTemplate,
AddressOf
AxTest1_OnDeleteTemplate
105.
AddHandler
axTest1.OnNewUser,
AddressOf
AxTest1_OnNewUser
106.
AddHandler
axTest1.OnAlarm,
AddressOf
AxTest1_OnAlarm
107.
AddHandler
axTest1.OnDoor,
AddressOf
AxTest1_OnDoor
108.
AddHandler
axTest1.OnWriteCard,
AddressOf
AxTest1_OnWriteCard
109.
AddHandler
axTest1.OnEmptyCard,
AddressOf
AxTest1_OnEmptyCard
110.
AddHandler
axTest1.OnHIDNum,
AddressOf
AxTest1_OnHIDNum
111.
112.
End
If
113.
Else
114.
axTest1.GetLastError(idwErrorCode)
115.
MsgBox(
"ไม่พบไดร์เวอร์,ErrorCode="
& idwErrorCode, MsgBoxStyle.Exclamation,
"Error"
)
116.
End
If
117.
Cursor = Cursors.
Default
118.
End
Sub
119.
120.
121.
Private
Sub
btnConnect2_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnConnect2.Click
122.
If
txtIP2.Text.Trim() =
""
Or
txtPort2.Text.Trim() =
""
Then
123.
MsgBox(
"กรุณากรอก ip หรือ DNS ด้วยครับ"
, MsgBoxStyle.Exclamation,
"Error"
)
124.
Return
125.
End
If
126.
Dim
idwErrorCode2
As
Integer
127.
Cursor = Cursors.WaitCursor
128.
If
btnConnect2.Text =
"ไม่เชื่อมต่อ"
Then
129.
axTest1.Disconnect()
130.
131.
RemoveHandler
axTest1.OnFinger,
AddressOf
AxTest1_OnFinger
132.
RemoveHandler
axTest1.OnFingerFeature,
AddressOf
AxTest1_OnFingerFeature
133.
RemoveHandler
axTest1.OnVerify,
AddressOf
AxTest1_OnVerify
134.
RemoveHandler
axTest1.OnAttTransactionEx,
AddressOf
AxTest1_OnAttTransactionEx
135.
RemoveHandler
axTest1.OnEnrollFingerEx,
AddressOf
AxTest1_OnEnrollFingerEx
136.
RemoveHandler
axTest1.OnDeleteTemplate,
AddressOf
AxTest1_OnDeleteTemplate
137.
RemoveHandler
axTest1.OnNewUser,
AddressOf
AxTest1_OnNewUser
138.
RemoveHandler
axTest1.OnAlarm,
AddressOf
AxTest1_OnAlarm
139.
RemoveHandler
axTest1.OnDoor,
AddressOf
AxTest1_OnDoor
140.
RemoveHandler
axTest1.OnWriteCard,
AddressOf
AxTest1_OnWriteCard
141.
RemoveHandler
axTest1.OnEmptyCard,
AddressOf
AxTest1_OnEmptyCard
142.
RemoveHandler
axTest1.OnHIDNum,
AddressOf
AxTest1_OnHIDNum
143.
144.
bIsConnected2 =
False
145.
lblState2.ForeColor = Color.Red
146.
btnConnect2.Text =
"เชื่อมต่อสำเร็จ"
147.
lblState2.Text =
"ไม่เชื่อมต่อ"
148.
Cursor = Cursors.
Default
149.
Return
150.
End
If
151.
152.
bIsConnected2 = axTest1.Connect_Net(txtIP2.Text.Trim(), Convert.ToInt32(txtPort2.Text.Trim()))
153.
If
bIsConnected2 =
True
Then
154.
btnConnect2.Text =
"ไม่เชื่อมต่อ"
155.
btnConnect2.Refresh()
156.
lblState2.ForeColor = Color.Green
157.
lblState2.Text =
"เชื่อมต่อสำเร็จ"
158.
iMachineNumber2 = 1
159.
160.
If
axTest1.RegEvent(iMachineNumber2, 65535) =
True
Then
161.
162.
AddHandler
axTest1.OnFinger,
AddressOf
AxTest1_OnFinger
163.
AddHandler
axTest1.OnFingerFeature,
AddressOf
AxTest1_OnFingerFeature
164.
AddHandler
axTest1.OnVerify,
AddressOf
AxTest1_OnVerify
165.
AddHandler
axTest1.OnAttTransactionEx,
AddressOf
AxTest1_OnAttTransactionEx
166.
AddHandler
axTest1.OnEnrollFingerEx,
AddressOf
AxTest1_OnEnrollFingerEx
167.
AddHandler
axTest1.OnDeleteTemplate,
AddressOf
AxTest1_OnDeleteTemplate
168.
AddHandler
axTest1.OnNewUser,
AddressOf
AxTest1_OnNewUser
169.
AddHandler
axTest1.OnAlarm,
AddressOf
AxTest1_OnAlarm
170.
AddHandler
axTest1.OnDoor,
AddressOf
AxTest1_OnDoor
171.
AddHandler
axTest1.OnWriteCard,
AddressOf
AxTest1_OnWriteCard
172.
AddHandler
axTest1.OnEmptyCard,
AddressOf
AxTest1_OnEmptyCard
173.
AddHandler
axTest1.OnHIDNum,
AddressOf
AxTest1_OnHIDNum
174.
175.
End
If
176.
Else
177.
axTest1.GetLastError(idwErrorCode2)
178.
MsgBox(
"ไม่พบ ไดร์เวอร์,ErrorCode="
& idwErrorCode2, MsgBoxStyle.Exclamation,
"Error"
)
179.
End
If
180.
Cursor = Cursors.
Default
181.
182.
End
Sub
183.
184.
185.
#End Region
186.
187.
188.
189.
190.
191.
#Region "RealTime Events"
192.
193.
Private
Sub
AxTest1_OnFinger()
194.
inboxshow.Items.Add(
"<<--มีการ สแกนลายนิ้วมือ-->>"
)
195.
End
Sub
196.
197.
198.
Private
Sub
AxTest1_OnVerify(
ByVal
iUserID
As
Integer
)
199.
inboxshow.Items.Add(
"กำลังตรวจสอบลายนิ้วมือ..."
)
200.
If
iUserID <> -1
Then
201.
inboxshow.Items.Add(
"ลายนิ้วมือ ถูกต้อง"
)
202.
203.
Else
204.
inboxshow.Items.Add(
"ลายนิ้วมือผิดพลาดหรือไม่มีข้อมูลในระบบ ครับ...!"
)
205.
End
If
206.
End
Sub
207.
208.
Private
Sub
AxTest1_OnAttTransactionEx(
ByVal
sEnrollNumber
As
String
,
ByVal
iIsInValid
As
Integer
,
ByVal
iAttState
As
Integer
,
ByVal
iVerifyMethod
As
Integer
, _
209.
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
)
210.
211.
inboxshow.Items.Clear()
212.
Dim
objConn
As
New
MySqlConnection
213.
Dim
objCmd
As
New
MySqlCommand
214.
Dim
strConnString, strSQL
As
String
215.
216.
strConnString =
"Server=www.ohotime.com;User Id=ohotime; Password=mit260914; Database=ohotime_pepo; Pooling=false"
217.
objConn.ConnectionString = strConnString
218.
objConn.Open()
219.
220.
Dim
intNumRows
As
Integer
221.
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 &
"')"
222.
objCmd =
New
MySqlCommand(strSQL, objConn)
223.
intNumRows = objCmd.ExecuteScalar()
224.
225.
objConn.Close()
226.
objConn =
Nothing
227.
228.
229.
inboxshow.Items.Add(
"บันทึกข้อมูลเรียบร้อยครับ...!"
)
230.
inboxshow.Items.Add(
"รายละเอียด ดังนี้"
)
231.
inboxshow.Items.Add(
"รหัส ID : "
& sEnrollNumber)
232.
233.
inboxshow.Items.Add(
"สถานะ : "
& iAttState.ToString())
234.
235.
236.
inboxshow.Items.Add(
"วัน/เวลา : "
& iYear.ToString() &
"-"
& iMonth.ToString() &
"-"
& iDay.ToString() &
" "
& iHour.ToString() &
":"
& iMinute.ToString() &
":"
& iSecond.ToString())
237.
238.
239.
240.
End
Sub
241.
242.
Private
Sub
AxTest1_OnFingerFeature(
ByVal
iScore
As
Integer
)
243.
If
iScore < 0
Then
244.
inboxshow.Items.Add(
"The quality of your fingerprint is poor"
)
245.
Else
246.
inboxshow.Items.Add(
"RTEvent OnFingerFeature Has been Triggered...Score:"
& iScore.ToString())
247.
End
If
248.
End
Sub
249.
250.
Private
Sub
AxTest1_OnDeleteTemplate(
ByVal
iEnrollNumber
As
Integer
,
ByVal
iFingerIndex
As
Integer
)
251.
inboxshow.Items.Add(
"RTEvent OnDeleteTemplate Has been Triggered..."
)
252.
inboxshow.Items.Add(
"...UserID="
& iEnrollNumber.ToString() &
" FingerIndex="
& iFingerIndex.ToString())
253.
End
Sub
254.
255.
Private
Sub
AxTest1_OnNewUser(
ByVal
iEnrollNumber
As
Integer
)
256.
inboxshow.Items.Add(
"RTEvent OnNewUser Has been Triggered..."
)
257.
inboxshow.Items.Add(
"...NewUserID="
& iEnrollNumber.ToString())
258.
End
Sub
259.
260.
Private
Sub
AxTest1_OnHIDNum(
ByVal
iCardNumber
As
Integer
)
261.
inboxshow.Items.Add(
"RTEvent OnHIDNum Has been Triggered..."
)
262.
inboxshow.Items.Add(
"...Cardnumber="
& iCardNumber.ToString())
263.
End
Sub
264.
265.
Private
Sub
AxTest1_OnEnrollFingerEx(
ByVal
sEnrollNumber
As
String
,
ByVal
iFingerIndex
As
Integer
,
ByVal
iActionResult
As
Integer
,
ByVal
iTemplateLength
As
Integer
)
266.
If
iActionResult = 0
Then
267.
inboxshow.Items.Add(
"RTEvent OnEnrollFigerEx Has been Triggered...."
)
268.
inboxshow.Items.Add(
".....UserID: "
& sEnrollNumber &
" Index: "
& iFingerIndex.ToString() &
" tmpLen: "
& iTemplateLength.ToString())
269.
Else
270.
inboxshow.Items.Add(
"RTEvent OnEnrollFigerEx Has been Triggered Error,actionResult="
+ iActionResult.ToString())
271.
End
If
272.
End
Sub
273.
274.
Private
Sub
AxTest1_OnAlarm(
ByVal
iAlarmType
As
Integer
,
ByVal
iEnrollNumber
As
Integer
,
ByVal
iVerified
As
Integer
)
275.
inboxshow.Items.Add(
"RTEvnet OnAlarm Has been Triggered..."
)
276.
inboxshow.Items.Add(
"...alarmType="
& iAlarmType.ToString())
277.
inboxshow.Items.Add(
"...enrollNumber="
& iEnrollNumber.ToString())
278.
inboxshow.Items.Add(
"...verified="
& iVerified.ToString())
279.
End
Sub
280.
281.
Private
Sub
AxTest1_OnDoor(
ByVal
iEventType
As
Integer
)
282.
inboxshow.Items.Add(
"RTEvent Ondoor Has been Triggered..."
)
283.
inboxshow.Items.Add(
"...EventType="
& iEventType.ToString())
284.
End
Sub
285.
286.
Private
Sub
AxTest1_OnEmptyCard(
ByVal
iActionResult
As
Integer
)
287.
inboxshow.Items.Add(
"RTEvent OnEmptyCard Has been Triggered..."
)
288.
If
iActionResult = 0
Then
289.
inboxshow.Items.Add(
"...Empty Mifare Card OK"
)
290.
Else
291.
inboxshow.Items.Add(
"...Empty Failed"
)
292.
End
If
293.
End
Sub
294.
295.
Private
Sub
AxTest1_OnWriteCard(
ByVal
iEnrollNumber
As
Integer
,
ByVal
iActionResult
As
Integer
,
ByVal
iLength
As
Integer
)
296.
inboxshow.Items.Add(
"RTEvent OnWriteCard Has been Triggered..."
)
297.
If
iActionResult = 0
Then
298.
inboxshow.Items.Add(
"...Write Mifare Card OK"
)
299.
inboxshow.Items.Add(
"...EnrollNumber="
& iEnrollNumber.ToString())
300.
inboxshow.Items.Add(
"...TmpLength="
& iLength.ToString())
301.
Else
302.
inboxshow.Items.Add(
"...Write Failed"
)
303.
End
If
304.
End
Sub
305.
#End Region
306.
End
Class