本文参考手册:《TFT 系列脱机通讯开发包开发手册》
主要内容:
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 = new CZKEMClass(); 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 int dwVerifyMode; 25 int dwInOutMode; 26 int dwYear;//刷卡时间 27 int dwMonth; 28 int dwDay; 29 int dwHour; 30 int dwMinute; 31 int dwSecond; 32 string verifyMode = ""; 33 string privilege = ""; 34 string enabled = ""; 35 #endregion
1-2、连接考勤机
1 #region 考勤机功能:连接 2 private void btnConnect_Click(object sender, EventArgs e) 3 { 4 if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")//考勤机的IP地址与端口 5 { 6 MessageBox.Show("IP and Port cannot be null", "Error"); 7 return; 8 } 9 int idwErrorCode = 0; 10 11 Cursor = Cursors.WaitCursor; 12 if (btnConnect.Text == "DisConnect") 13 { 14 axCZKEM1.Disconnect(); 15 bIsConnected = false; 16 btnConnect.Text = "Connect"; 17 lblState.Text = "Current State:DisConnected"; 18 Cursor = Cursors.Default; 19 return; 20 } 21 22 bIsConnected = axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text)); 23 if (bIsConnected == true) 24 { 25 btnConnect.Text = "DisConnect"; 26 btnConnect.Refresh(); 27 lblState.Text = "Current State:Connected"; 28 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. 29 axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all) 30 } 31 else 32 { 33 axCZKEM1.GetLastError(ref idwErrorCode); 34 MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error"); 35 } 36 Cursor = Cursors.Default; 37 } 38 #endregion
1-3、配置定时任务
(这里定时任务用到的是System.Timers.Timer,我在使用过程中遇到一个问题:开启定时任务创建一个线程后调用atimer.Stop()无法关闭,只有关闭整个应用程序才会结束这个线程。如果知道怎么解决的朋友还请告知^ ^~)
1 #region 定时任务配置 2 public void Timing_Task() 3 { 4 atimer.Enabled = true; 5 atimer.Interval = 60000; //执行间隔时间,单位为毫秒; 这里实际间隔为1分钟 6 atimer.Elapsed += new System.Timers.ElapsedEventHandler(getLogData); 7 } 8 public void Timing_Task_Star() 9 { 10 atimer.Enabled = true; 11 atimer.Start(); 12 } 13 public