private void GetAttendanceLog(DeviceInfo device, bool onlyLatest) { ZKFingerKeeper keeper = new ZKFingerKeeper(device); FrmProcessing frm = new FrmProcessing(); Action action = delegate() { frm.ShowProgress("正在连接考勤机...", 0); keeper.Connect(); if (keeper.IsConnected) { try { //清空控制器 frm.ShowProgress("正在获取考勤记录...", 0); DatetimeRange dr = null; if (onlyLatest && device.LastEventDt != null) { dr = new DatetimeRange(device.LastEventDt.Value.AddSeconds(1), new DateTime(2099, 12, 31)); //从最后那个时间开始获取 } List<AttendanceLog> logs = keeper.GetAttendanceLogs(dr); if (logs == null || logs.Count == 0) { frm.ShowProgress(string.Empty , 1); } else { frm.ShowProgress(string.Format("获取到 {0} 条考勤记录,正在努力保存考勤记录...", logs.Count), 0.99m); AttendanceLogBLL bll = new AttendanceLogBLL(AppSettings.CurrentSetting.ConnectUri); int count = 0; foreach (AttendanceLog log in logs) { count++; frm.ShowProgress(string.Format("正在保存第 {0} 条记录", count), (decimal)count / logs.Count); CommandResult ret = bll.Add(log); } frm.ShowProgress(string.Empty , 1); device.LastEventDt = logs.Max(it => it.ReadDateTime); (new DeviceInfoBLL(AppSettings.CurrentSetting.ConnectUri)).Update(device); } } catch (ThreadAbortException) { } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } finally { keeper.Disconnect(); } } else { frm.ShowProgress("连接设备失败", 1); } }; Thread t = new Thread(new ThreadStart(action)); t.Start(); frm.ShowDialog(); }
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(); }
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(); }