Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (setting == null)
            {
                setting           = new Maticsoft.Model.SMT_ATTEN_SETTING();
                setting.ID        = -1;
                setting.DUTY_TYPE = 0;
            }
            setting.DUTY_ON_TIME1    = dtiOnDuty.Value.TimeOfDay;
            setting.DUTY_OFF_TIME1   = dtiOffDuty.Value.TimeOfDay;
            setting.DUTY_ON_EARLIEST = dtiEarliestTime.Value.TimeOfDay;
            setting.DUTY_LATE_MIN    = iiLateMin.Value;
            setting.DUTY_LATE_MAX    = iiLateMax.Value;
            setting.DUTY_LEAVE_MIN   = iiLeaveMin.Value;
            setting.DUTY_LEAVE_MAX   = iiLeaveMax.Value;
            if (cboLatePunish.SelectedIndex == 0)
            {
                setting.DUTY_LATE_PUNISH = 0;
            }
            else if (cboLatePunish.SelectedIndex == 2)
            {
                setting.DUTY_LATE_PUNISH = 1;
            }
            else
            {
                setting.DUTY_LATE_PUNISH = 0.5M;
            }

            if (cboLeavePunish.SelectedIndex == 0)
            {
                setting.DUTY_LEAVE_PUNISH = 0;
            }
            else if (cboLeavePunish.SelectedIndex == 2)
            {
                setting.DUTY_LEAVE_PUNISH = 1;
            }
            else
            {
                setting.DUTY_LEAVE_PUNISH = 0.5M;
            }

            setting.DUTY_ONLY_ON = cbOnlyOn.Checked;


            if (cbSatSetting0.Checked)
            {
                setting.DUTY_SAT_TYPE = 0;
            }
            else if (cbSatSetting1.Checked)
            {
                setting.DUTY_SAT_TYPE = 1;
            }
            else
            {
                setting.DUTY_SAT_TYPE = 2;
            }

            if (cbSunSetting0.Checked)
            {
                setting.DUTY_SUN_TYPE = 0;
            }
            else if (cbSunSetting1.Checked)
            {
                setting.DUTY_SUN_TYPE = 1;
            }
            else
            {
                setting.DUTY_SUN_TYPE = 2;
            }
            CtrlWaiting waiting = new CtrlWaiting("正在保存...", () =>
            {
                try
                {
                    Maticsoft.BLL.SMT_ATTEN_SETTING settingBll = new Maticsoft.BLL.SMT_ATTEN_SETTING();
                    if (setting.ID == -1)
                    {
                        settingBll.Add(setting);
                        SmtLog.Info("设置", "设置考勤正常班");
                    }
                    else
                    {
                        settingBll.Update(setting);
                        SmtLog.Info("设置", "更新考勤正常班");
                    }
                    WinInfoHelper.ShowInfoWindow(this, "保存成功。");
                }
                catch (System.Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "保存设置异常!" + ex.Message);
                    log.Error("保存正常班设置异常:" + ex.Message, ex);
                }
            });

            waiting.Show(this);
        }
Example #2
0
        private void AttenSetting_Load(object sender, EventArgs e)
        {
            cboLatePunish.SelectedIndex  = 1;
            cboLeavePunish.SelectedIndex = 1;
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    Maticsoft.BLL.SMT_ATTEN_SETTING settingBll = new Maticsoft.BLL.SMT_ATTEN_SETTING();
                    var settings = settingBll.GetModelList("DUTY_TYPE=0");//查找正常班
                    if (settings.Count == 0)
                    {
                        WinInfoHelper.ShowInfoWindow(this, "无正常班设置!");
                        return;
                    }
                    setting = settings[0];
                    this.Invoke(new Action(() =>
                    {
                        DateTime now          = DateTime.Now.Date;
                        dtiOnDuty.Value       = now + setting.DUTY_ON_TIME1;
                        dtiOffDuty.Value      = now + setting.DUTY_OFF_TIME1;
                        dtiEarliestTime.Value = now + setting.DUTY_ON_EARLIEST;
                        iiLateMin.Value       = setting.DUTY_LATE_MIN;
                        iiLateMax.Value       = setting.DUTY_LATE_MAX;
                        iiLeaveMin.Value      = setting.DUTY_LEAVE_MIN;
                        iiLeaveMax.Value      = setting.DUTY_LEAVE_MAX;
                        if (setting.DUTY_LATE_PUNISH == 0)
                        {
                            cboLatePunish.SelectedIndex = 0;
                        }
                        else if (setting.DUTY_LATE_PUNISH == 1)
                        {
                            cboLatePunish.SelectedIndex = 2;
                        }
                        else
                        {
                            cboLatePunish.SelectedIndex = 1;
                        }

                        if (setting.DUTY_LEAVE_PUNISH == 0)
                        {
                            cboLeavePunish.SelectedIndex = 0;
                        }
                        else if (setting.DUTY_LEAVE_PUNISH == 1)
                        {
                            cboLeavePunish.SelectedIndex = 2;
                        }
                        else
                        {
                            cboLeavePunish.SelectedIndex = 1;
                        }
                        cbOnlyOn.Checked = setting.DUTY_ONLY_ON;

                        if (setting.DUTY_SAT_TYPE == 0)
                        {
                            cbSatSetting0.Checked = true;
                        }
                        else if (setting.DUTY_SAT_TYPE == 1)
                        {
                            cbSatSetting1.Checked = true;
                        }
                        else
                        {
                            cbSatSetting2.Checked = true;
                        }

                        if (setting.DUTY_SUN_TYPE == 0)
                        {
                            cbSunSetting0.Checked = true;
                        }
                        else if (setting.DUTY_SUN_TYPE == 1)
                        {
                            cbSunSetting1.Checked = true;
                        }
                        else
                        {
                            cbSunSetting2.Checked = true;
                        }
                    }));
                }
                catch (Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "读取正常班设置异常!");
                    log.Error("读取考勤设置异常:", ex);
                }
            });

            waiting.Show(this);
        }
Example #3
0
        private void StartCreateReport()
        {
            DateTime dtStart = dtpStart.Value.Date;
            DateTime dtEnd   = dtpEnd.Value.Date;

            CtrlWaiting waiting = new CtrlWaiting("正在生成...", () =>
            {
                try
                {
                    Maticsoft.BLL.SMT_ATTEN_SETTING settingBll = new Maticsoft.BLL.SMT_ATTEN_SETTING();
                    var settings = settingBll.GetModelList("DUTY_TYPE=0");//查找正常班
                    if (settings.Count == 0)
                    {
                        WinInfoHelper.ShowInfoWindow(this, "生成报表中断:无正常班设置,请设置正常班!");
                        return;
                    }

                    DateTime dt = dtStart;
                    Maticsoft.Model.SMT_ATTEN_SETTING setting = settings[0];
                    Maticsoft.BLL.SMT_ATTEN_REPORT reportBll  = new Maticsoft.BLL.SMT_ATTEN_REPORT();

                    while (dt <= dtEnd)
                    {
                        bool isweekend  = false;
                        int weekendType = 0;
                        if (dt.DayOfWeek == DayOfWeek.Saturday)
                        {
                            isweekend   = true;
                            weekendType = setting.DUTY_SAT_TYPE;
                        }
                        else if (dt.DayOfWeek == DayOfWeek.Sunday)
                        {
                            isweekend   = true;
                            weekendType = setting.DUTY_SUN_TYPE;
                        }
                        if (isweekend && weekendType == 1)//全天上班
                        {
                            isweekend = false;
                        }
                        else if (isweekend && weekendType == 0)//全天休息
                        {
                            Maticsoft.DBUtility.DbHelperSQL.ExecuteSql("delete from SMT_ATTEN_REPORT where ATTEN_DATE='" + dt.ToString("yyyy-MM-dd") + "'");
                            goto End;//直接结束
                        }
                        DateTime earliest = dt.Date + setting.DUTY_ON_EARLIEST;
                        DateTime ontime1  = dt.Date + setting.DUTY_ON_TIME1;
                        DateTime offtime1 = dt.Date + setting.DUTY_OFF_TIME1;

                        string sql          = string.Format("select t.RECORD_DATE,t.STAFF_ID from SMT_CARD_RECORDS t where t.RECORD_REASON='Swipe' and t.STAFF_ID>=0 and t.RECORD_DATE>='{0} 00:00:00' and t.RECORD_DATE<'{1} 00:00:00' and t.STAFF_ID in (select ssi.ID from SMT_STAFF_INFO ssi where ssi.IS_DELETE=0)", dt.ToString("yyyy-MM-dd"), dt.AddDays(1).ToString("yyyy-MM-dd"));
                        DataTable dateTable = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0];

                        List <Record> records = new List <Record>();
                        foreach (DataRow item in dateTable.Rows)
                        {
                            Record record     = new Record();
                            record.StaffId    = (decimal)item[1];
                            record.RecordTime = (DateTime)item[0];
                            records.Add(record);
                        }
                        var g = records.GroupBy(m => m.StaffId);
                        List <decimal> staffIds = new List <decimal>();
                        foreach (var list in g)
                        {
                            List <Record> l = list.ToList();//获取一个职员当天的刷卡记录
                            staffIds.Add(l[0].StaffId);

                            Maticsoft.Model.SMT_ATTEN_REPORT report = new Maticsoft.Model.SMT_ATTEN_REPORT();
                            report.ATTEN_DATE        = dt.Date;
                            report.STAFF_ID          = l[0].StaffId;
                            report.ATTEN_SWIPE_TIMES = setting.DUTY_SWING_TIMES;

                            #region  班计算
                            List <Record> onRecords = l.FindAll(m => m.RecordTime >= earliest && m.RecordTime <= ontime1.AddMinutes(setting.DUTY_LATE_MAX));
                            if (onRecords.Count == 0)//上班未打卡,算旷工
                            {
                                report.ATTEN_ON_STATE      = "旷工(上班)";
                                report.ATTEN_AWAY_DAY      = setting.DUTY_LATE_PUNISH;
                                report.ATTEN_UNSWIPE_TIMES = 1;
                            }
                            else
                            {
                                DateTime minDate     = onRecords.Min(m => m.RecordTime);
                                report.ATTEN_ON_TIME = minDate.TimeOfDay;
                                if (minDate <= ontime1.AddMinutes(setting.DUTY_LATE_MIN))//正常上班
                                {
                                    report.ATTEN_ON_STATE = "正常";
                                }
                                else /* if (minDate<=ontime1.AddMinutes(setting.DUTY_LATE_MAX))*///迟到
                                {
                                    report.ATTEN_ON_STATE = "迟到";
                                    report.ATTEN_LATE_MIN = (int)(minDate - ontime1).TotalMinutes;
                                }
                            }
                            #endregion

                            #region  班计算
                            if (!setting.DUTY_ONLY_ON || !isweekend)
                            {
                                onRecords = l.FindAll(m => m.RecordTime >= offtime1.AddMinutes(-setting.DUTY_LEAVE_MAX));
                                if (onRecords.Count == 0)//下班未打卡,算旷工
                                {
                                    report.ATTEN_OFF_STATE = "旷工(下班)";
                                    if (report.ATTEN_AWAY_DAY == null)
                                    {
                                        report.ATTEN_AWAY_DAY = 0;
                                    }
                                    report.ATTEN_AWAY_DAY += setting.DUTY_LATE_PUNISH;
                                    if (report.ATTEN_UNSWIPE_TIMES == null)
                                    {
                                        report.ATTEN_UNSWIPE_TIMES = 0;
                                    }
                                    report.ATTEN_UNSWIPE_TIMES += 1;
                                }
                                else
                                {
                                    DateTime maxDate      = onRecords.Max(m => m.RecordTime);
                                    report.ATTEN_OFF_TIME = maxDate.TimeOfDay;
                                    if (maxDate < offtime1.AddMinutes(-setting.DUTY_LEAVE_MIN))//早退
                                    {
                                        report.ATTEN_OFF_STATE = "早退";
                                        report.ATTEN_LEAVE_MIN = (int)(offtime1 - maxDate).TotalMinutes;
                                    }
                                    else if (maxDate < offtime1.AddMinutes(setting.DUTY_EXTRA_MIN))
                                    {
                                        report.ATTEN_OFF_STATE = "正常";
                                    }
                                    else
                                    {
                                        report.ATTEN_OFF_STATE = "加班";
                                        report.ATTEN_EXTRA_MIN = (int)(maxDate - offtime1).TotalMinutes;
                                    }
                                }
                            }
                            #endregion

                            var exist = reportBll.GetModelList("ATTEN_DATE='" + dt.Date.ToString("yyyy-MM-dd 00:00:00") + "' and  STAFF_ID=" + report.STAFF_ID);
                            if (exist.Count > 0)
                            {
                                report.ID = exist[0].ID;
                                reportBll.Update(report);
                            }
                            else
                            {
                                reportBll.Add(report);
                            }
                        }
                        sql = "select ID from SMT_STAFF_INFO where IS_DELETE=0 ";
                        if (staffIds.Count > 0)
                        {
                            sql += " and Id not in (" + string.Join(",", staffIds.ToArray()) + ")";
                        }
                        DataTable staffTables = Maticsoft.DBUtility.DbHelperSQL.Query(sql).Tables[0];
                        foreach (DataRow sid in staffTables.Rows)
                        {
                            Maticsoft.Model.SMT_ATTEN_REPORT report = new Maticsoft.Model.SMT_ATTEN_REPORT();
                            report.ATTEN_DATE        = dt.Date;
                            report.STAFF_ID          = (decimal)sid[0];
                            report.ATTEN_SWIPE_TIMES = setting.DUTY_SWING_TIMES;
                            report.ATTEN_ON_STATE    = "旷工";
                            if (isweekend)
                            {
                                report.ATTEN_AWAY_DAY = 0.5M;
                            }
                            else
                            {
                                report.ATTEN_AWAY_DAY  = 1M;
                                report.ATTEN_OFF_STATE = "旷工";
                            }

                            report.ATTEN_UNSWIPE_TIMES = setting.DUTY_SWING_TIMES;
                            var exist = reportBll.GetModelList("ATTEN_DATE='" + dt.Date.ToString("yyyy-MM-dd 00:00:00") + "' and  STAFF_ID=" + report.STAFF_ID);
                            if (exist.Count > 0)
                            {
                                report.ID = exist[0].ID;
                                reportBll.Update(report);
                            }
                            else
                            {
                                reportBll.Add(report);
                            }
                        }

                        End:
                        dt = dt.AddDays(1);
                    }
                    WinInfoHelper.ShowInfoWindow(this, "生成报表结束!");
                }
                catch (Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "生成报表异常:" + ex.Message);
                    log.Error("生成报表异常:" + ex.Message, ex);
                }
            });

            waiting.Show(this);
        }