Dim s As String
vars("txt") = "c:\data\KQ-" & Format(Date.Today,"yyyyMMdd") & ".txt"
s = "开始:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,vbcrlf & s & vbcrlf, True)
Dim axCZKEM1 As New zkemkeeper.CZKEM
Dim sdwEnrollNumber As String = ""
Dim sName As String = ""
Dim sPassword As String = ""
Dim iPrivilege As Integer
Dim bEnabled As Boolean = False
Dim idwVerifyMode As Integer
Dim idwInOutMode As Integer
Dim idwYear As Integer
Dim idwMonth As Integer
Dim idwDay As Integer
Dim idwHour As Integer
Dim idwMinute As Integer
Dim idwSecond As Integer
Dim idwWorkcode As Integer
Dim dr,nr As DataRow
For Each r As Row In Tables("机器").Rows
Dim iMachineNumber As Integer = r("机器号")
Dim bIsConnected = axCZKEM1.Connect_Net(r("IP"), "4370")
s = iMachineNumber & "号机连接:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
If bIsConnected = True Then
r("状态") = "连接成功"
r("时间") = Date.now
r.save
AxCZKEM1.EnableDevice(iMachineNumber, False) 'disable the device
If AxCZKEM1.ReadAllUserID(iMachineNumber) Then
s = iMachineNumber & "号机读取人员数据到内存:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
While AxCZKEM1.SSR_GetAllUserInfo(iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled) = True 'get all the users' information from the memory
If sName.length = 4 Then
sName = sName.Substring(0,2)
Else
If sName.length = 6 Then
sName = sName.Substring(0,3)
End If
End If
dr = DataTables("人员").Find("编号 = '" & sdwEnrollNumber & "'")
If dr Is Nothing Then
nr = DataTables("人员").AddNew()
nr("编号") = sdwEnrollNumber
nr("姓名") = sName
nr("密码") = sPassword
nr("权限") = iPrivilege
nr("启用") = bEnabled
nr.save
Else
If dr("姓名") <> sName Then
dr("姓名") = sName
End If
End If
End While
s = iMachineNumber & "号机逐条读取人员数据:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
End If
If AxCZKEM1.ReadGeneralLogData(iMachineNumber) Then 'read all the attendance records to the memory
s = iMachineNumber & "号机读取考勤数据到内存:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
DataTables("采集数据").StopRedraw
While AxCZKEM1.SSR_GetGeneralLogData(iMachineNumber,sdwEnrollNumber, idwVerifyMode, idwInOutMode, idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond, idwWorkcode)
dr = DataTables("采集数据").Find("编号 = '" & sdwEnrollNumber & "' and 时间 = '" & idwYear.ToString() & "-" & idwMonth.ToString() & "-" & idwDay.ToString() & " " & idwHour.ToString() & ":" & idwMinute.ToString() & ":" & idwSecond.ToString() & "'")
If dr Is Nothing Then
nr = DataTables("采集数据").AddNew()
nr("编号") = sdwEnrollNumber
nr("方式") = idwVerifyMode.ToString()
nr("机器") = iMachineNumber
nr("IP") = r("IP")
nr("Y") = idwYear.ToString()
nr("M") = idwMonth.ToString()
nr("D") = idwDay.ToString()
nr("T") = idwHour.ToString() & ":" & idwMinute.ToString() & ":" & idwSecond.ToString()
nr("时间") = idwYear.ToString() & "-" & idwMonth.ToString() & "-" & idwDay.ToString() & " " & idwHour.ToString() & ":" & idwMinute.ToString() & ":" & idwSecond.ToString()
nr.save
End If
End While
s = iMachineNumber & "号机逐条读取考勤数据:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
DataTables("采集数据").ResumeRedraw
End If
AxCZKEM1.EnableDevice(iMachineNumber, True)
Else
r("状态") = "连接失败"
r("时间") = Date.now
r.Save
End If
s = iMachineNumber & "号机结束:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
Next
s = "结束:" & Format(Date.now,"yyyy-MM-dd HH:mm:ss:fff")
Filesys.WriteAllText(vars("txt") ,s & vbcrlf, True)
加入事件记录以后,得到的记录如下:
开始:2019-01-08 08:10:27:041
1号机连接:2019-01-08 08:10:27:263
1号机读取人员数据到内存:2019-01-08 08:10:27:438
1号机逐条读取人员数据:2019-01-08 08:10:27:444
1号机读取考勤数据到内存:2019-01-08 08:10:28:826
1号机逐条读取考勤数据:2019-01-08 08:10:29:562
1号机结束:2019-01-08 08:10:29:581
2号机连接:2019-01-08 08:10:34:958
2号机读取人员数据到内存:2019-01-08 08:10:36:295
2号机逐条读取人员数据:2019-01-08 08:10:36:303
2号机读取考勤数据到内存:2019-01-08 08:10:46:586