private void btnOk_Click(object sender, EventArgs e) { if (CheckInput()) { List<AttendanceLog> logs = GetLogs(); if (logs != null && logs.Count > 0) { FrmProcessing frm = new FrmProcessing(); Action action = delegate() { AttendanceLogBLL bll = new AttendanceLogBLL(AppSettings.CurrentSetting.ConnectUri); int count = logs.Count; int added = 0; foreach (AttendanceLog log in logs) { bll.Add(log); added++; frm.ShowProgress(string.Empty, (decimal)added / count); } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } } this.departmentTreeview1.SelectedStaff = null; MessageBox.Show("补签完成,可以继续补签"); } }
private void btnOk_Click(object sender, EventArgs e) { if (CheckInput()) { List <AttendanceLog> logs = GetLogs(); if (logs != null && logs.Count > 0) { FrmProcessing frm = new FrmProcessing(); Action action = delegate() { AttendanceLogBLL bll = new AttendanceLogBLL(AppSettings.CurrentSetting.ConnectUri); int count = logs.Count; int added = 0; foreach (AttendanceLog log in logs) { bll.Add(log); added++; frm.ShowProgress(string.Empty, (decimal)added / count); } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } } this.departmentTreeview1.SelectedStaff = null; MessageBox.Show("补签完成,可以继续补签"); } }
private void btnOk_Click(object sender, EventArgs e) { if (CheckInput()) { ShiftArrangeBLL bll = new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri); ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition(); con.StaffID = (txtStaff.Tag as Staff).ID; con.ShiftDate = new DatetimeRange(dtBegin.Value, dtEnd.Value); List <ShiftArrange> items = bll.GetItems(con).QueryObjects; List <Staff> copyees = departmentTreeview1.SelectedStaff; FrmProcessing frm = new FrmProcessing(); Action action = delegate() { decimal count = 0; try { foreach (Staff staff in copyees) { List <ShiftArrange> sas = new List <ShiftArrange>(); if (items != null && items.Count > 0) { foreach (ShiftArrange sa in items) { if (staff.HireDate.Date <= sa.ShiftDate.Date) { sa.StaffID = staff.ID; sas.Add(sa); } } } count++; frm.ShowProgress(string.Format("正在复制到 {0}...", staff.Name), count / copyees.Count); if (sas.Count > 0) { CommandResult ret = bll.ShiftArrange(staff.ID, new DatetimeRange(dtBegin.Value, dtEnd.Value), sas); } } } catch (ThreadAbortException) { } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } this.DialogResult = DialogResult.OK; } }
private void btnOk_Click(object sender, EventArgs e) { if (CheckInput()) { ShiftArrangeBLL bll = new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri); ShiftArrangeSearchCondition con = new ShiftArrangeSearchCondition(); con.StaffID = (txtStaff.Tag as Staff).ID; con.ShiftDate = new DatetimeRange(dtBegin.Value, dtEnd.Value); List<ShiftArrange> items = bll.GetItems(con).QueryObjects; List<Staff> copyees = departmentTreeview1.SelectedStaff; FrmProcessing frm = new FrmProcessing(); Action action = delegate() { decimal count = 0; try { foreach (Staff staff in copyees) { List<ShiftArrange> sas = new List<ShiftArrange>(); if (items != null && items.Count > 0) { foreach (ShiftArrange sa in items) { if (staff.HireDate.Date <= sa.ShiftDate.Date) { sa.StaffID = staff.ID; sas.Add(sa); } } } count++; frm.ShowProgress(string.Format("正在复制到 {0}...", staff.Name), count / copyees.Count); if (sas.Count > 0) { CommandResult ret = bll.ShiftArrange(staff.ID, new DatetimeRange(dtBegin.Value, dtEnd.Value), sas); } } } catch (ThreadAbortException) { } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } this.DialogResult = DialogResult.OK; } }
private void CreateAttendanceResults(List <Staff> staffs, DatetimeRange dr, List <string> readers) { FrmProcessing frm = new FrmProcessing(); Action action = delegate() { decimal count = 0; try { foreach (Staff staff in staffs) { try { frm.ShowProgress(string.Format("正在生成考勤结果 {0}...", staff.Name), count / staffs.Count); count++; bool ret = CreateAttendanceResult(staff, dr, readers); if (ret) { frm.ShowProgress(string.Format("生成考勤结果成功 {0}", staff.Name), count / staffs.Count); } else { frm.ShowProgress(string.Format("生成考勤结果失败 {0}", staff.Name), count / staffs.Count); } } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } } catch (ThreadAbortException) { } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); DialogResult sdr = frm.ShowDialog(); if (sdr != DialogResult.OK) { t.Abort(); } else { LJH.GeneralLibrary.LOG.FileLog.Log("自动生成考勤结果", "自动生成考勤结果完成"); } }
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 btnOk_Click(object sender, EventArgs e) { if (txtShiftTemplate.Tag == null) { MessageBox.Show("没有选择模板"); return; } if (this.ucDateTimeInterval1.StartDateTime > this.ucDateTimeInterval1.EndDateTime) { MessageBox.Show("应用的日期不正确,开始时间大于结束时间"); return; } if (this.departmentTreeview1.SelectedStaff == null || this.departmentTreeview1.SelectedStaff.Count == 0) { MessageBox.Show("没有选择人员"); return; } FrmProcessing frm = new FrmProcessing(); DatetimeRange dr = new DatetimeRange(ucDateTimeInterval1.StartDateTime, ucDateTimeInterval1.EndDateTime); List <Staff> staffs = this.departmentTreeview1.SelectedStaff; ShiftTemplate template = txtShiftTemplate.Tag as ShiftTemplate; Action action = delegate() { decimal count = 0; try { foreach (Staff staff in staffs) { try { frm.ShowProgress(string.Format("正在应用模板 {0}...", staff.Name), count / staffs.Count); count++; List <ShiftArrange> items = template.ApplyTemplateTo(staff, dr); CommandResult ret = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).ShiftArrange(staff.ID, dr, items); if (ret.Result == ResultCode.Successful) { frm.ShowProgress(string.Format("应用模板成功 {0}", staff.Name), count / staffs.Count); } else { frm.ShowProgress(string.Format("应用模板失败 {0}", staff.Name), count / staffs.Count); } } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } } catch (ThreadAbortException) { } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } this.DialogResult = DialogResult.OK; }
private void mnu_Reset_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 { frm.ShowProgress("正在重启设备....", 0.2m); keeper.Restart(); } catch (ThreadAbortException) { } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } finally { frm.ShowProgress(string.Empty, 1); } } else { frm.ShowProgress(string.Empty, 1); } }; Thread t = new Thread(new ThreadStart(action)); t.Start(); frm.ShowDialog(); }
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_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(); }
private void btnOk_Click(object sender, EventArgs e) { if (txtShiftTemplate.Tag == null) { MessageBox.Show("没有选择模板"); return; } if (this.ucDateTimeInterval1.StartDateTime > this.ucDateTimeInterval1.EndDateTime) { MessageBox.Show("应用的日期不正确,开始时间大于结束时间"); return; } if (this.departmentTreeview1.SelectedStaff == null || this.departmentTreeview1.SelectedStaff.Count == 0) { MessageBox.Show("没有选择人员"); return; } FrmProcessing frm = new FrmProcessing(); DatetimeRange dr = new DatetimeRange(ucDateTimeInterval1.StartDateTime, ucDateTimeInterval1.EndDateTime); List<Staff> staffs = this.departmentTreeview1.SelectedStaff; ShiftTemplate template = txtShiftTemplate.Tag as ShiftTemplate; Action action = delegate() { decimal count = 0; try { foreach (Staff staff in staffs) { try { frm.ShowProgress(string.Format("正在应用模板 {0}...", staff.Name), count / staffs.Count); count++; List<ShiftArrange> items = template.ApplyTemplateTo(staff, dr); CommandResult ret = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).ShiftArrange(staff.ID, dr, items); if (ret.Result == ResultCode.Successful) { frm.ShowProgress(string.Format("应用模板成功 {0}", staff.Name), count / staffs.Count); } else { frm.ShowProgress(string.Format("应用模板失败 {0}", staff.Name), count / staffs.Count); } } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } } catch (ThreadAbortException) { } }; Thread t = new Thread(new ThreadStart(action)); t.IsBackground = true; t.Start(); if (frm.ShowDialog() != DialogResult.OK) { t.Abort(); } this.DialogResult = DialogResult.OK; }
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_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(); }