コード例 #1
0
 private void mnu_SyncTime_Click(object sender, EventArgs e)
 {
     TreeNode node = deviceTree1.SelectedNode;
     DeviceInfo device = node.Tag as DeviceInfo;
     if (device == null) return;
     ZKFingerKeeper keeper = new ZKFingerKeeper(device);
     FrmProcessing frm = new FrmProcessing();
     Action action = delegate()
     {
         frm.ShowProgress("正在连接考勤机...", 0);
         keeper.Connect();
         if (keeper.IsConnected)
         {
             try
             {
                 keeper.SetTime(DateTime.Now);
             }
             catch (ThreadAbortException)
             {
             }
             catch (Exception ex)
             {
                 LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
             }
             finally
             {
                 keeper.EnableDevice(true);
                 keeper.Disconnect();
                 frm.ShowProgress(string.Empty, 1);
             }
         }
         else
         {
             frm.ShowProgress("连接设备失败", 1);
         }
     };
     Thread t = new Thread(new ThreadStart(action));
     t.Start();
     frm.ShowDialog();
 }
コード例 #2
0
 private void mnu_UploadAll_Click(object sender, EventArgs e)
 {
     TreeNode node = deviceTree1.SelectedNode;
     DeviceInfo device = node.Tag as DeviceInfo;
     if (device == null) return;
     ZKFingerKeeper keeper = new ZKFingerKeeper(device);
     FrmProcessing frm = new FrmProcessing();
     Action action = delegate()
     {
         frm.ShowProgress("正在连接考勤机...", 0);
         keeper.Connect();
         if (keeper.IsConnected)
         {
             try
             {
                 keeper.EnableDevice(false);
                 //清空控制器
                 frm.ShowProgress("正在清空设备...", 0);
                 keeper.ClearData(ClearDataFlag.UserInfo);
                 keeper.ClearData(ClearDataFlag.FPTemplate);
                 frm.ShowProgress("清空设备成功", 0.1m);
                 keeper.SetTime(DateTime.Now);
                 decimal count = 0;
                 frm.ShowProgress("开始上传人员...", 0);
                 List<Staff> staff = (new StaffBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(null).QueryObjects;
                 List<StaffBioTemplate> templates = (new StaffBLL(AppSettings.CurrentSetting.ConnectUri)).GetBioTemplates(null).QueryObjects;
                 for (int i = 0; i < staff.Count; i++)
                 {
                     keeper.SetUserInfo(staff[i]);
                     List<StaffBioTemplate> temp = templates.Where(item => item.StaffID == staff[i].ID).ToList();
                     if (temp != null && temp.Count > 0)
                     {
                         foreach (StaffBioTemplate template in temp)
                         {
                             keeper.SetUserTemplate(template);
                         }
                     }
                     count++;
                     frm.ShowProgress(string.Format("上传人员 {0}", staff[i].Name), count / staff.Count);
                 }
                 keeper.RefreshData();
             }
             catch (ThreadAbortException)
             {
             }
             catch (Exception ex)
             {
                 LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
             }
             finally
             {
                 keeper.EnableDevice(true);
                 keeper.Disconnect();
                 frm.ShowProgress(string.Empty, 1);
             }
         }
         else
         {
             frm.ShowProgress("连接设备失败", 1);
         }
     };
     Thread t = new Thread(new ThreadStart(action));
     t.Start();
     frm.ShowDialog();
 }