001.
Option
Explicit
002.
Dim
ItemIDOld
As
String
003.
Dim
StateClick
As
String
004.
Dim
ItemUserId
As
String
005.
Dim
ItemUserName
As
String
006.
Dim
ItemUserPic
As
String
007.
008.
009.
Private
Sub
lockctrl()
010.
txtid.Locked =
True
011.
txtname.Locked =
True
012.
Picture1.Visible =
True
013.
Picture2.Visible =
True
014.
Picture3.Visible =
True
015.
Picture4.Visible =
False
016.
Picture5.Visible =
False
017.
txtid.BackColor = &H80000000
018.
txtname.BackColor = &H80000000
019.
cmdpic.Enabled =
False
020.
cmddeletepic.Enabled =
False
021.
mfg.Enabled =
True
022.
End
Sub
023.
024.
025.
Private
Sub
UnLockCtrl()
026.
txtid.Locked =
False
027.
txtname.Locked =
False
028.
Picture1.Visible =
False
029.
Picture2.Visible =
False
030.
Picture3.Visible =
False
031.
Picture4.Visible =
True
032.
Picture5.Visible =
True
033.
cmdpic.Enabled =
True
034.
cmddeletepic.Enabled =
True
035.
txtid.BackColor = &HFFFFFF
036.
txtname.BackColor = &HFFFFFF
037.
mfg.Enabled =
False
038.
End
Sub
039.
040.
Private
Sub
cmdAdd_Click()
041.
If
frmScan.ZKFPEngX1.Active =
True
Then
042.
txtid.SetFocus
043.
txtid.Text =
""
044.
txtname.Text =
""
045.
StateClick =
"Add"
046.
UnLockCtrl
047.
StatusAdd = 1
048.
ItemUserPic =
""
049.
ItemFinger =
""
050.
Img.Picture = LoadPicture(ItemUserPic)
051.
052.
frmScan.ZKFPEngX1.BeginEnroll
053.
StatusBar.Caption =
"เริ่มเก็บลายนิ้วมือ"
054.
Else
055.
MsgBox
"เกิดข้อผิดพลาดในการเชื่อมต่อ ไม่สามารถเพิ่มผู้ใช้งานได้!"
, vbOKOnly + vbCritical,
"เกิดข้อผิดพลาด"
056.
End
If
057.
End
Sub
058.
059.
Private
Sub
cmdCancel_Click()
060.
lockctrl
061.
StatusAdd = 0
062.
End
Sub
063.
064.
Private
Sub
cmdDelete_Click()
065.
If
txtid.Text <>
""
Then
066.
DeleteUser txtid.Text
067.
Else
068.
MsgBox
"กรุณาคลิก เลือกรายการที่จะ DELETE ก่อน ! "
, vbOKOnly + vbInformation,
"พบข้อผิดพลาด"
069.
End
If
070.
End
Sub
071.
072.
073.
Private
Sub
DeleteUser(tmpID
As
String
)
074.
On
Error
GoTo
PictureNotFound
075.
Dim
comUpdate
As
New
ADODB.Command
076.
Dim
sqlUpdate
As
String
077.
078.
Conn.BeginTrans
079.
With
comUpdate
080.
.ActiveConnection = Conn
081.
.CommandType = adCmdText
082.
End
With
083.
084.
sqlUpdate =
"DELETE * FROM us_userinfo"
085.
sqlUpdate = sqlUpdate &
" Where (code='"
& tmpID &
"')"
086.
087.
With
comUpdate
088.
.CommandText = sqlUpdate
089.
.Execute
090.
End
With
091.
092.
If
MsgBox(
"คุณต้อง DELETE พนักงานชื่อ "
& txtname.Text &
" ใช่หรือไม่?"
, vbYesNo + vbQuestion,
"คำยืนยัน"
) = vbYes
Then
093.
Conn.CommitTrans
094.
095.
DisplayUser mfg
096.
With
mfg
097.
ItemUserId = (.TextMatrix(1, 0))
098.
ItemUserName = (.TextMatrix(1, 1))
099.
ItemUserPic = (.TextMatrix(1, 2))
100.
ItemFinger = (.TextMatrix(1, 3))
101.
End
With
102.
txtid.Text = ItemUserId
103.
txtname.Text = ItemUserName
104.
If
ItemUserPic =
""
Then
105.
Img.Picture = LoadPicture(ItemPathNoPic)
106.
Else
107.
Img.Picture = LoadPicture(ItemUserPic)
108.
End
If
109.
Else
110.
Conn.RollbackTrans
111.
End
If
112.
113.
PictureNotFound:
114.
If
(Err.Number = 76)
Or
(Err.Number = 53)
Or
(Err.Number = 481)
Then
115.
ItemUserPic =
""
116.
Img.Picture = LoadPicture(ItemUserPic)
117.
Exit
Sub
118.
End
If
119.
End
Sub
120.
121.
122.
Public
Sub
DisplayUser(mfgName
As
MSHFlexGrid)
123.
Dim
sqlSelect
As
String
124.
Dim
rsSelect
As
New
ADODB.Recordset
125.
Dim
i
As
Integer
126.
127.
sqlSelect =
"SELECT * FROM us_userinfo ORDER BY code"
128.
129.
With
rsSelect
130.
If
.State = adStateOpen
Then
.Close
131.
.ActiveConnection = Conn
132.
.CursorType = adOpenForwardOnly
133.
.CursorLocation = adUseClient
134.
.Open sqlSelect
135.
If
.RecordCount <> 0
Then
136.
ClearGrid mfgName
137.
With
mfgName
138.
For
i = 1
To
rsSelect.RecordCount
139.
.TextMatrix(i, 0) = rsSelect.Fields(
"code"
).Value
140.
.TextMatrix(i, 1) = rsSelect.Fields(
"name"
).Value
141.
If
rsSelect.Fields(
"pic"
).Value <>
""
Then
142.
.TextMatrix(i, 2) = rsSelect.Fields(
"pic"
).Value
143.
Else
144.
.TextMatrix(i, 2) =
""
145.
End
If
146.
If
rsSelect.Fields(
"fpstring"
).Value <>
""
Then
147.
.TextMatrix(i, 3) = rsSelect.Fields(
"fpstring"
).Value
148.
Else
149.
.TextMatrix(i, 3) =
""
150.
End
If
151.
rsSelect.MoveNext
152.
.Rows = .Rows + 1
153.
If
.Rows > rsSelect.RecordCount
Then
154.
.Rows = rsSelect.RecordCount + 1
155.
End
If
156.
Next
157.
End
With
158.
Else
159.
ClearGrid mfgName
160.
End
If
161.
Setmfg mfgName
162.
End
With
163.
rsSelect.Close
164.
Set
rsSelect =
Nothing
165.
End
Sub
166.
167.
168.
Private
Sub
cmddeletepic_Click()
169.
ItemUserPic =
""
170.
Img.Picture = LoadPicture(ItemUserPic)
171.
End
Sub
172.
173.
Private
Sub
cmdEdit_Click()
174.
If
frmScan.ZKFPEngX1.Active =
True
Then
175.
StatusAdd = 1
176.
If
txtid.Text <>
""
Then
177.
Call
UnLockCtrl
178.
ItemIDOld = txtid.Text
179.
StateClick =
"Edit"
180.
frmScan.ZKFPEngX1.BeginEnroll
181.
StatusBar.Caption =
"เริ่มเก็บลายนิ้วมือ"
182.
Else
183.
MsgBox
"กรุณาคลิก รายการที่จะ EDIT ก่อน ! "
, vbOKOnly + vbInformation,
"พบข้อผิดพลาด"
184.
End
If
185.
Else
186.
MsgBox
"เกิดข้อผิดพลาดในการเชื่อมต่อ ไม่สามารถแก้ไขผู้ใช้งานได้!"
, vbOKOnly + vbCritical,
"เกิดข้อผิดพลาด"
187.
End
If
188.
End
Sub
189.
190.
Private
Sub
cmdpic_Click()
191.
On
Error
GoTo
PictureNotFound
192.
With
cdlBrowse
193.
.DialogTitle =
"เลือกรูปภาพ"
194.
.CancelError =
False
195.
.Action = 1
196.
ItemUserPic = .Filename
197.
End
With
198.
199.
If
ItemUserPic <>
""
Then
200.
Img.Picture = LoadPicture(ItemUserPic)
201.
End
If
202.
203.
PictureNotFound:
204.
If
(Err.Number = 76)
Or
(Err.Number = 53)
Or
(Err.Number = 481)
Then
205.
ItemUserPic =
""
206.
Img.Picture = LoadPicture(ItemUserPic)
207.
Exit
Sub
208.
End
If
209.
End
Sub
210.
211.
Private
Sub
cmdSave_Click()
212.
If
StateClick =
"Edit"
Then
213.
214.
Call
UpdateData
215.
Else
216.
217.
Call
AddData
218.
End
If
219.
End
Sub
220.
221.
Private
Sub
Form_Load()
222.
On
Error
GoTo
PictureNotFound
223.
If
frmScan.ZKFPEngX1.Active =
True
Then
224.
FMatchType = 0
225.
DisplayUser mfg
226.
lockctrl
227.
If
frmScan.ZKFPEngX1.Active =
True
Then
228.
StatusBar.Caption =
"เชื่อมต่อสำเร็จ"
229.
Else
230.
StatusBar.Caption =
"การเชื่อมต่อ เกิดข้อผิดพลาด"
231.
End
If
232.
233.
With
mfg
234.
ItemUserId = (.TextMatrix(1, 0))
235.
ItemUserName = (.TextMatrix(1, 1))
236.
ItemUserPic = (.TextMatrix(1, 2))
237.
ItemFinger = (.TextMatrix(1, 3))
238.
End
With
239.
txtid.Text = ItemUserId
240.
txtname.Text = ItemUserName
241.
If
ItemUserPic =
""
Then
242.
Img.Picture = LoadPicture(ItemPathNoPic)
243.
Else
244.
Img.Picture = LoadPicture(ItemUserPic)
245.
End
If
246.
Else
247.
MsgBox
"เกิดข้อผิดพลาดในการเชื่อมต่อ กรุณาปิดโปรแกรมแล้วเรียกใช้อีกครั้ง!"
, vbOKOnly + vbCritical,
"เกิดข้อผิดพลาด"
248.
Exit
Sub
249.
End
If
250.
251.
PictureNotFound:
252.
If
(Err.Number = 76)
Or
(Err.Number = 53)
Or
(Err.Number = 481)
Then
253.
ItemUserPic =
""
254.
Img.Picture = LoadPicture(ItemUserPic)
255.
Exit
Sub
256.
End
If
257.
End
Sub
258.
259.
Private
Sub
UpdateData()
260.
On
Error
GoTo
DuplicateERROR
261.
Dim
comUpdate
As
New
ADODB.Command
262.
Dim
sqlUpdate
As
String
263.
Dim
tmpSex
As
String
264.
265.
If
Trim(txtid.Text) =
""
Then
266.
MsgBox
"กรุณาระบุรหัสพนักงานก่อนครับ !!!"
, vbOKOnly + vbInformation,
"ผลการตรวจสอบ"
267.
txtid.SetFocus
268.
Exit
Sub
269.
End
If
270.
271.
If
Trim(txtname.Text) =
""
Then
272.
MsgBox
"กรุณาระบุชื่อพนักงานก่อนครับ ! "
, vbOKOnly + vbCritical,
"พบข้อผิดพลาด"
273.
txtname.SetFocus
274.
Exit
Sub
275.
End
If
276.
277.
If
(Trim(ItemFinger) =
""
)
Then
278.
MsgBox
"กรุณากำหนดลายนิ้วมือก่อนครับ !!!"
, vbOKOnly + vbInformation,
"ผลการตรวจสอบ"
279.
Exit
Sub
280.
End
If
281.
282.
Conn.BeginTrans
283.
With
comUpdate
284.
.ActiveConnection = Conn
285.
.CommandType = adCmdText
286.
End
With
287.
288.
sqlUpdate =
"UPDATE us_userinfo"
289.
sqlUpdate = sqlUpdate &
" SET code='"
& txtid.Text &
"',name='"
& txtname.Text &
"',"
290.
sqlUpdate = sqlUpdate &
" pic='"
& ItemUserPic &
"',fpstring='"
& ItemFinger &
"'"
291.
sqlUpdate = sqlUpdate &
" Where (code='"
& ItemIDOld &
"')"
292.
293.
With
comUpdate
294.
.CommandText = sqlUpdate
295.
.Execute
296.
End
With
297.
298.
If
MsgBox(
"คุณต้องการแก้ไขข้อมูลของพนักงานชื่อ "
& txtname.Text &
" ใช่หรือไม่?"
, vbYesNo + vbQuestion,
"คำยืนยัน"
) = vbYes
Then
299.
Conn.CommitTrans
300.
ItemIDOld =
""
301.
StatusBar.Caption =
""
302.
303.
DisplayUser mfg
304.
lockctrl
305.
306.
frmScan.ZKFPEngX1.AddRegTemplateStrToFPCacheDB fpcHandle, FingerCount, ItemFinger
307.
ReDim
Preserve
FFingerCode(FingerCount + 1)
308.
ReDim
Preserve
FFingerNames(FingerCount + 1)
309.
ReDim
Preserve
FFingerPic(FingerCount + 1)
310.
FFingerCode(FingerCount) = txtid.Text
311.
FFingerNames(FingerCount) = txtname.Text
312.
FFingerPic(FingerCount) = ItemUserPic
313.
FingerCount = FingerCount + 1
314.
Else
315.
Conn.RollbackTrans
316.
lockctrl
317.
End
If
318.
StatusAdd = 0
319.
DuplicateERROR:
320.
If
Err.Number = -2147467259
Then
321.
MsgBox
"คุณกำหนดรหัสซ้ำ !"
, vbOKOnly + vbCritical,
"เกิดข้อผิดพลาด"
322.
Conn.RollbackTrans
323.
txtid.SetFocus
324.
End
If
325.
End
Sub
326.
327.
Private
Sub
AddData()
328.
On
Error
GoTo
DuplicateERROR
329.
Dim
comUpdate
As
New
ADODB.Command
330.
Dim
sqlUpdate
As
String
331.
Dim
tmpSex
As
String
332.
333.
If
Trim(txtid.Text) =
""
Then
334.
MsgBox
"กรุณาระบุรหัสพนักงานก่อนครับ !!!"
, vbOKOnly + vbInformation,
"ผลการตรวจสอบ"
335.
txtid.SetFocus
336.
Exit
Sub
337.
End
If
338.
339.
If
Trim(txtname.Text) =
""
Then
340.
MsgBox
"กรุณาระบุชื่อพนักงานก่อนครับ ! "
, vbOKOnly + vbCritical,
"พบข้อผิดพลาด"
341.
txtname.SetFocus
342.
Exit
Sub
343.
End
If
344.
345.
If
(Trim(ItemFinger) =
""
)
Then
346.
MsgBox
"กรุณากำหนดลายนิ้วมือก่อนครับ !!!"
, vbOKOnly + vbInformation,
"ผลการตรวจสอบ"
347.
Exit
Sub
348.
End
If
349.
350.
351.
Conn.BeginTrans
352.
sqlUpdate =
"INSERT INTO us_userinfo(code,name,pic,fpstring) "
353.
sqlUpdate = sqlUpdate &
" VALUES('"
& txtid.Text &
"','"
& txtname.Text &
"','"
& ItemUserPic &
"','"
& ItemFinger &
"')"
354.
355.
With
comUpdate
356.
.ActiveConnection = Conn
357.
.CommandType = adCmdText
358.
.CommandText = sqlUpdate
359.
.Execute
360.
End
With
361.
362.
If
MsgBox(
"คุณต้องการเพิ่มพนักงานใหม่ชื่อ "
& txtname.Text &
" ใช่หรือไม่?"
, vbYesNo + vbQuestion,
"คำยืนยัน"
) = vbYes
Then
363.
Conn.CommitTrans
364.
365.
StatusBar.Caption =
""
366.
DisplayUser mfg
367.
lockctrl
368.
369.
frmScan.ZKFPEngX1.AddRegTemplateStrToFPCacheDB fpcHandle, FingerCount, ItemFinger
370.
ReDim
Preserve
FFingerCode(FingerCount + 1)
371.
ReDim
Preserve
FFingerNames(FingerCount + 1)
372.
ReDim
Preserve
FFingerPic(FingerCount + 1)
373.
FFingerCode(FingerCount) = txtid.Text
374.
FFingerNames(FingerCount) = txtname.Text
375.
FFingerPic(FingerCount) = ItemUserPic
376.
FingerCount = FingerCount + 1
377.
Else
378.
Conn.RollbackTrans
379.
lockctrl
380.
End
If
381.
StatusAdd = 0
382.
DuplicateERROR:
383.
If
Err.Number = -2147467259
Then
384.
MsgBox
"คุณกำหนดรหัสซ้ำ !"
, vbOKOnly + vbCritical,
"เกิดข้อผิดพลาด"
385.
Conn.RollbackTrans
386.
txtid.SetFocus
387.
End
If
388.
End
Sub
389.
390.
391.
Public
Sub
Setmfg(mfgName
As
MSHFlexGrid)
392.
Dim
i
As
Integer
393.
With
mfgName
394.
.ColWidth(0) = 1200
395.
.ColWidth(1) = 1800
396.
.ColWidth(2) = 0
397.
.ColWidth(3) = 0
398.
399.
.TextMatrix(0, 0) =
"รหัสพนักงาน"
400.
.TextMatrix(0, 1) =
"ชื่อ-สกุล"
401.
.TextMatrix(0, 2) =
"ลิ้งรูปภาพ"
402.
.TextMatrix(0, 3) =
"ลายนิ้ว"
403.
End
With
404.
With
mfgName
405.
For
i = 0
To
2
406.
.FixedAlignment(i) = flexAlignLeftCenter
407.
.ColAlignment(0) = flexAlignCenterCenter
408.
.ColAlignment(1) = flexAlignLeftCenter
409.
Next
410.
End
With
411.
End
Sub
412.
413.
Public
Sub
ClearGrid(mfgName
As
MSHFlexGrid)
414.
Dim
i
As
Integer
415.
With
mfgName
416.
For
i = 1
To
.Rows - 2
417.
If
.Rows > 2
Then
418.
.Rows = .Rows - 1
419.
End
If
420.
Next
421.
.Clear
422.
End
With
423.
End
Sub
424.
425.
Private
Sub
Form_Unload(Cancel
As
Integer
)
426.
StatusAdd = 0
427.
FMatchType = 2
428.
End
Sub
429.
430.
Private
Sub
mfg_Click()
431.
On
Error
GoTo
PictureNotFound
432.
With
mfg
433.
ItemUserId = (.TextMatrix(.Row, 0))
434.
ItemUserName = (.TextMatrix(.Row, 1))
435.
ItemUserPic = (.TextMatrix(.Row, 2))
436.
ItemFinger = (.TextMatrix(.Row, 3))
437.
End
With
438.
txtid.Text = ItemUserId
439.
txtname.Text = ItemUserName
440.
If
ItemUserPic =
""
Then
441.
Img.Picture = LoadPicture(ItemPathNoPic)
442.
Else
443.
Img.Picture = LoadPicture(ItemUserPic)
444.
End
If
445.
446.
PictureNotFound:
447.
If
(Err.Number = 76)
Or
(Err.Number = 53)
Or
(Err.Number = 481)
Then
448.
ItemUserPic =
""
449.
Img.Picture = LoadPicture(ItemUserPic)
450.
Exit
Sub
451.
End
If
452.
End
Sub
453.
454.
Private
Sub
mfg_KeyDown(KeyCode
As
Integer
, Shift
As
Integer
)
455.
On
Error
GoTo
PictureNotFound
456.
With
mfg
457.
ItemUserId = (.TextMatrix(.Row, 0))
458.
ItemUserName = (.TextMatrix(.Row, 1))
459.
ItemUserPic = (.TextMatrix(.Row, 2))
460.
ItemFinger = (.TextMatrix(.Row, 3))
461.
End
With
462.
txtid.Text = ItemUserId
463.
txtname.Text = ItemUserName
464.
If
ItemUserPic =
""
Then
465.
Img.Picture = LoadPicture(ItemPathNoPic)
466.
Else
467.
Img.Picture = LoadPicture(ItemUserPic)
468.
End
If
469.
470.
PictureNotFound:
471.
If
(Err.Number = 76)
Or
(Err.Number = 53)
Or
(Err.Number = 481)
Then
472.
ItemUserPic =
""
473.
Img.Picture = LoadPicture(ItemUserPic)
474.
Exit
Sub
475.
End
If
476.
End
Sub