本文参考手册:《TFT 系列脱机通讯开发包开发手册》
业务需求:
1、定时同步考勤机的刷卡记录到数据库
2、推送人员信息到考勤机
主要内容:
1、定时同步考勤记录到数据库
2、用户信息、指纹操作
3、考勤记录批量操作
正文
1、定时任务
1-1、定义全局变量
1 #region 窗体变量
2 string USERID = "";//同步到数据库的参数
3 string CHARGE_TIME = "";//同步到数据库的参数
4 string VERIFYMODE = "";//同步到数据库的参数
5 string WORKCODE = "";//同步到数据库的参数
6 string PASSWORD = "";//同步到数据库的参数
7 string PRIVILEGE = "";//同步到数据库的参数
8 string ENABLE = "";//同步到数据库的参数
9 System.Timers.Timer atimer = new System.Timers.Timer(); //定时任务
10 #endregion
11
12 #region 考勤机变量
13 public CZKEMClass axCZKEM1 = newCZKEMClass();14 private bool bIsConnected = false;15 private int iMachineNumber = 1;16
17 string sdwEnrollNumber = "";//用户ID
18 string sName = "";//姓名
19 string sPassword = "";//密码
20 int iPrivilege = 0;21 bool bEnabled = false;22 string sCardnumber = "";//卡号
23 int dwWorkCode = 0;24 intdwVerifyMode;25 intdwInOutMode;26 int dwYear;//刷卡时间
27 intdwMonth;28 intdwDay;29 intdwHour;30 intdwMinute;31 intdwSecond;32 string verifyMode = "";33 string privilege = "";34 string enabled = "";35 #endregion
View Code
1-2、连接考勤机
1 #region 考勤机功能:打开连接
2 private voidconnectZK()3 {4 //若IP、端口号为空则不能连接
5 if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")6 {7 WriteLog.Write("WARN", txtIP.Text, "打开连接时IP或端口不能为空");8 return;9 }10 //若状态为已连接则先关闭连接
11 if (bIsConnected == true)12 {13 disconnectZK();14 }15 //连接机器
16 int idwErrorCode = 0;17 Cursor =Cursors.WaitCursor;18 bIsConnected =axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text));19 if (bIsConnected == true)20 {21 lblState.Text = "Current State:Connected";22 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.
23 axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
24 WriteLog.Write("INFO", txtIP.Text, "连接成功。");25 }26 else
27 {28 axCZKEM1.GetLastError(refidwErrorCode);29 WriteLog.Write("WARN", txtIP.Text, "连接失败。ErrorCode=" +idwErrorCode.ToString());30 }31 Cursor =Cursors.Default;32 }33 #endregion
34
35 #region 考勤机功能:关闭连接
36 private voiddisconnectZK()37 {38 if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")39 {40 WriteLog.Write("WARN", txtIP.Text, "关闭连接时IP或端口不能为空");41 return;42 }43
44 Cursor =Cursors.WaitCursor;45 if(bIsConnected)46 {47 axCZKEM1.Disconnect();48 bIsConnected = false;49 lblState.Text = "Current State:DisConnected";50 WriteLog.W