Esempio n. 1
0
        private void tmrAutoGenerateResult_Tick(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;
            MyTime   mt = AppSettings.CurrentSetting.AutoGenerateTime;

            if (mt != null && mt.Hour == dt.Hour && mt.Minute == dt.Minute)
            {
                if (!_HasGenerateResult)
                {
                    _HasGenerateResult = true;
                    List <string> readers = GetAttendanceReaders();
                    if (readers == null || readers.Count == 0)
                    {
                        MessageBox.Show("还未指定考勤点");
                        return;
                    }
                    LJH.GeneralLibrary.LOG.FileLog.Log("自动生成考勤结果", "开始生成考勤结果......");
                    DatetimeRange dr     = new DatetimeRange(dt.Date.AddDays(-1), dt.Date.AddSeconds(-1)); //前一天的时间范围
                    List <Staff>  staffs = (new StaffBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(null).QueryObjects;
                    CreateAttendanceResults(staffs, dr, readers);
                }
            }
            else
            {
                _HasGenerateResult = false;
            }
        }
Esempio n. 2
0
        private bool CreateAttendanceResult(Staff staff, DatetimeRange dr, List <string> readers)
        {
            ShiftArrangeSearchCondition con1 = new ShiftArrangeSearchCondition();

            con1.StaffID   = staff.ID;
            con1.ShiftDate = dr;
            List <ShiftArrange> sas = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con1).QueryObjects;

            TASheetSearchCondition con2 = new TASheetSearchCondition();

            con2.StaffID = staff.ID;
            List <TASheet> sheets = (new TASheetBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con2).QueryObjects;

            AttendanceLogSearchCondition con3 = new AttendanceLogSearchCondition();

            con3.Staff = new List <int>();
            con3.Staff.Add(staff.ID);
            con3.Readers           = readers;
            con3.ReadDateTime      = dr;
            con3.ContainManualLogs = true;
            List <AttendanceLog> records = (new AttendanceLogBLL(AppSettings.CurrentSetting.ConnectUri)).GetItems(con3).QueryObjects;

            List <AttendanceResult> results = (new AttendanceAnalyst()).Analist(staff, sas, records, sheets, dr);
            CommandResult           ret     = (new AttendanceResultBLL(AppSettings.CurrentSetting.ConnectUri)).Add(staff.ID, dr, results);

            return(ret.Result == ResultCode.Successful);
        }
        /// <summary>
        /// 增加考勤结果,此用户在此时间段内的所以考勤结果都清除,再写入新结果
        /// </summary>
        /// <param name="staffID"></param>
        /// <param name="range"></param>
        /// <param name="arranges"></param>
        /// <returns></returns>
        public CommandResult Add(int staffID, DatetimeRange range, List <AttendanceResult> arranges)
        {
            IAttendanceResultProvider            provider = ProviderFactory.Create <IAttendanceResultProvider>(_RepoUri);
            StaffAttendanceResultSearchCondition con      = new StaffAttendanceResultSearchCondition();

            con.Staff = new List <int>();
            con.Staff.Add(staffID);
            con.ShiftDate = range;
            List <AttendanceResult> items = provider.GetItems(con).QueryObjects;
            IUnitWork unitWork            = ProviderFactory.Create <IUnitWork>(_RepoUri);

            foreach (AttendanceResult item in items)
            {
                provider.Delete(item, unitWork);
            }
            if (arranges != null && arranges.Count > 0)
            {
                foreach (AttendanceResult item in arranges)
                {
                    if (item.AbsentItems != null && item.AbsentItems.Count > 0)
                    {
                        item.AbsentItems.ForEach(it => it.ResultID = item.ID);
                    }
                    provider.Insert(item, unitWork);
                }
            }
            return(unitWork.Commit());
        }
Esempio n. 4
0
        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("自动生成考勤结果", "自动生成考勤结果完成");
            }
        }
Esempio n. 5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (dtEnd.Value < dtBegin.Value)
            {
                MessageBox.Show("\"复制到\" 里面的结束时间小于开始时间");
                return;
            }
            DatetimeRange       dr    = new DatetimeRange(dtBegin.Value, dtEnd.Value);
            List <ShiftArrange> items = GetShiftArranges();
            CommandResult       ret   = (new ShiftArrangeBLL(AppSettings.CurrentSetting.ConnectUri)).ShiftArrange(Staff.ID, dr, items);

            if (ret.Result == ResultCode.Successful)
            {
                ShiftArranges     = items;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(ret.Message);
            }
        }
Esempio n. 6
0
        public CommandResult ShiftArrange(int staffID, DatetimeRange range, List <ShiftArrange> arranges)
        {
            IShiftArrangeProvider       provider = ProviderFactory.Create <IShiftArrangeProvider>(_RepoUri);
            ShiftArrangeSearchCondition con      = new ShiftArrangeSearchCondition();

            con.StaffID   = staffID;
            con.ShiftDate = range;
            List <ShiftArrange> items    = provider.GetItems(con).QueryObjects;
            IUnitWork           unitWork = ProviderFactory.Create <IUnitWork>(_RepoUri);

            foreach (ShiftArrange item in items)
            {
                provider.Delete(item, unitWork);
            }
            if (arranges != null && arranges.Count > 0)
            {
                foreach (ShiftArrange item in arranges)
                {
                    provider.Insert(item, unitWork);
                }
            }
            return(unitWork.Commit());
        }
        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();
        }
Esempio n. 9
0
        /// <summary>
        /// 获取机器上的考勤记录
        /// </summary>
        /// <param name="range">考勤记录的日期时间范围,为null表示获取所有记录</param>
        /// <returns></returns>
        public List <AttendanceLog> GetAttendanceLogs(DatetimeRange range)
        {
            int idwErrorCode          = 0;
            List <AttendanceLog> logs = new List <AttendanceLog>();

            try
            {
                axCZKEM1.EnableDevice(iMachineNumber, false);    //disable the device
                if (axCZKEM1.ReadGeneralLogData(iMachineNumber)) //read all the attendance records to the memory
                {
                    int idwTMachineNumber = 0;
                    int idwEnrollNumber   = 0;
                    int idwEMachineNumber = 0;
                    int idwVerifyMode     = 0;
                    int idwInOutMode      = 0;
                    int idwYear           = 0;
                    int idwMonth          = 0;
                    int idwDay            = 0;
                    int idwHour           = 0;
                    int idwMinute         = 0;
                    while (axCZKEM1.GetGeneralLogData(iMachineNumber, ref idwTMachineNumber, ref idwEnrollNumber,
                                                      ref idwEMachineNumber, ref idwVerifyMode, ref idwInOutMode, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute))//get records from the memory
                    {
                        DateTime dt = new DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, 0);
                        if (range == null || range.Contain(dt))
                        {
                            AttendanceLog log = new AttendanceLog()
                            {
                                StaffID      = idwEnrollNumber,
                                StaffName    = string.Empty,
                                ReaderID     = Parameter.ID,
                                ReaderName   = Parameter.Name,
                                ReadDateTime = dt,
                            };
                            logs.Add(log);
                        }
                    }
                }
                else
                {
                    axCZKEM1.GetLastError(ref idwErrorCode);

                    if (idwErrorCode != 0)
                    {
                        LJH.GeneralLibrary.LOG.FileLog.Log(Parameter.Name, "获取考勤记录失败,ErrorCode=" + idwErrorCode.ToString());
                    }
                    else
                    {
                        LJH.GeneralLibrary.LOG.FileLog.Log(Parameter.Name, "无考勤记录,ErrorCode=" + idwErrorCode.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device
            }
            return(logs);
        }