/// <summary> /// 设置时间范围 /// </summary> /// <param name="beginDate"></param> /// <param name="endDate"></param> public void SetDate(DateTime beginDate, DateTime endDate) { BeginDate = beginDate; EndDate = endDate; for (DateTime d = beginDate; d <= endDate.AddDays(1); d = d.AddDays(1)) { var emp = new EmpCheckDay(Emp, d) { DeptName = DeptName, DayType = GetDayType(d), }; if (Shifts.Count > 0) { emp.EmpShift = Shifts[0]; } EmpChecks.Add(emp); } //连接上下天 EmpChecks.ForEach(p => { p.PreCheckDay = EmpChecks.SingleOrDefault(d => d.CheckDate == p.CheckDate.AddDays(-1)); p.AfterCheckDay = EmpChecks.SingleOrDefault(d => d.CheckDate == p.CheckDate.AddDays(1)); }); }
/// <summary> /// 更改班次 /// </summary> /// <param name="ecd"></param> /// <param name="newShift"></param> public void ChangeShift(EmpCheckDay ecd, Shift ns) { DateTime bd, ed; var newShift = ns; if (ecd.EmpShift.BeginTime != newShift.BeginTime || ecd.EmpShift.EndTime != newShift.EndTime) { if (ecd.DayType == DayType.假日) { newShift = new Shift(); } if (ecd.AfterCheckDay != null && ecd.AfterCheckDay.DayType == DayType.假日) { bd = ecd.CheckDate.Add(newShift.BeginTime); ed = ecd.CheckDate.Add(new TimeSpan(23, 59, 59)); } else { bd = ecd.CheckDate.Add(newShift.BeginTime); ed = ecd.CheckDate.Add(newShift.EndTime); } ecd.RawChecks = Checks.Where(p => p.CHECKTIME >= bd && p.CHECKTIME <= ed).ToList(); ecd.Checks = ecd.RawChecks; RemoveDuplicate(ecd); } ecd.EmpShift = newShift; }
/// <summary> /// 一次打卡处理,首未打卡区域少于15分钟视为一次打卡 /// </summary> /// <param name="ed"></param> private void OneCheckSet(EmpCheckDay ed) { if (ed.Checks.Count > 0 && (ed.LTS - ed.FTS).TotalMinutes < 15) { if (OneCheckBuildOneDay) { //一次打卡生成全天 ed.FTS = ed.FTS < ed.EmpShift.AmCheckIn ? ed.FTS : ed.EmpShift.AmCheckIn; ed.LTS = ed.LTS > ed.EmpShift.PmCheckOut ? ed.LTS : ed.EmpShift.PmCheckOut; } else { //生成0.5天 if (ed.FTS <= ed.EmpShift.PmCheckIn) { ed.FTS = ed.FTS < ed.EmpShift.AmCheckIn ? ed.FTS : ed.EmpShift.AmCheckIn; ed.LTS = ed.LTS > ed.EmpShift.AmcheckOut ? ed.LTS : ed.EmpShift.AmcheckOut; } else { ed.FTS = ed.FTS < ed.EmpShift.PmCheckIn ? ed.FTS : ed.EmpShift.PmCheckIn; ed.LTS = ed.LTS > ed.EmpShift.PmCheckOut ? ed.LTS : ed.EmpShift.PmCheckOut; } } } }
/// <summary> /// 未打卡处理 /// </summary> /// <param name="ed"></param> private void NoCheckSet(EmpCheckDay ed) { if (ed.Checks.Count == 0 && NoCheckAlwaysBuild) { ed.FTS = ed.EmpShift.AmCheckIn; ed.LTS = ed.EmpShift.PmCheckOut; } }
/// <summary> /// 生成全部考勤 /// </summary> /// <param name="ed"></param> private void BuildAllChecSet(EmpCheckDay ed) { if (BuildAllCheck) { ed.FTS = ed.EmpShift.AmCheckIn; ed.LTS = ed.EmpShift.OTCheckOut; } }
/// <summary> /// 删除毫秒 /// </summary> /// <param name="ed"></param> private void RemoveMillsecond(EmpCheckDay ed) { ed.NewChecks.ForEach(p => { var ml = p.CHECKTIME.Millisecond; if (ml > 0) { p.CHECKTIME = p.CHECKTIME.AddMilliseconds(-ml); } }); }
/// <summary> /// 去重 /// </summary> /// <param name="ecd"></param> public void RemoveDuplicate(EmpCheckDay ecd) { if (ecd.PreCheckDay != null && ecd.PreCheckDay.RawChecks.Count > 0) { ecd.PreCheckDay.RawChecks.ForEach(p => { if (ecd.RawChecks.Contains(p)) { ecd.RawChecks.Remove(p); } }); } }
private void Button1_Click(object sender, EventArgs e) { if (dayDgv.SelectedRows.Count > 0) { EmpCheckDay cr = (EmpCheckDay)dayDgv.SelectedRows[0].DataBoundItem; DayCheckEdit dce = new DayCheckEdit(); dce.EditChecks(cr); dayDgv.Refresh(); } else { MessageBox.Show("请选择考勤数据"); } }
private void Button3_Click(object sender, EventArgs e) { if (dayDgv.SelectedRows.Count > 0) { foreach (DataGridViewRow p in dayDgv.SelectedRows) { EmpCheckDay cd = (EmpCheckDay)p.DataBoundItem; cd.NewChecks.Clear(); } dayDgv.Refresh(); } else { MessageBox.Show("请选择考勤数据"); } }
public void EditChecks(EmpCheckDay ecd) { Ecd = ecd; cHECKINOUTBindingSource.DataSource = Ecd.NewChecks; this.ShowDialog(); }
/// <summary> /// 生成当天全部考勤 /// </summary> /// <param name="ed"></param> private void BuildUserCheckInOut(EmpCheckDay ed) { if (IsHollyDayNotWork && ed.DayType == DayType.假日) { return; } if (ed.Checks.Count > 0 || NoCheckAlwaysBuild) { var shift = ed.EmpShift; //生成全部考勤 if (Am) { bool amIn = false; //amIn if (ed.FTS <= shift.AmCheckIn) { ed.AmIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = GetInTime(ed.CheckDate, ed.FTS, ed.EmpShift.AmCheckIn), Memoinfo = ed.EmpShift.ID }; ed.NewChecks.Add(ed.AmIn); amIn = true; } else if (ed.FTS < shift.AmcheckOut) { ed.NewChecks.Add(ed.AmIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = ed.CheckDate.AddSeconds(Get1T60Rand()) + ed.FTS, Memoinfo = ed.EmpShift.ID }); amIn = true; } //inOut if (ed.LTS >= shift.AmcheckOut && amIn) { ed.NewChecks.Add(ed.AmOut = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = GetOutTime(ed.CheckDate, ed.LTS, ed.EmpShift.AmcheckOut), Memoinfo = ed.EmpShift.ID }); } else if (amIn) { ed.NewChecks.Add(ed.AmOut = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = ed.CheckDate.AddSeconds(1) + ed.LTS, Memoinfo = ed.EmpShift.ID }); } } if (Pm) { //pmIn bool pmIn = false; if (ed.FTS <= shift.PmCheckIn && ed.LTS >= shift.PmCheckIn) { ed.NewChecks.Add(ed.PmIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = GetInTime(ed.CheckDate, ed.FTS, ed.EmpShift.PmCheckIn), Memoinfo = ed.EmpShift.ID }); pmIn = true; } else if (ed.FTS < shift.PmCheckOut && ed.FTS > shift.PmCheckIn) { ed.NewChecks.Add(ed.PmIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = ed.CheckDate.AddSeconds(Get1T60Rand()) + ed.FTS, Memoinfo = ed.EmpShift.ID }); pmIn = true; } //pmOut if (ed.LTS >= shift.PmCheckOut && pmIn) { ed.NewChecks.Add(ed.PmIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = GetOutTime(ed.CheckDate, ed.LTS, ed.EmpShift.PmCheckOut), Memoinfo = ed.EmpShift.ID }); } else if (ed.LTS >= shift.PmCheckIn && pmIn) { ed.NewChecks.Add(ed.PmIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = ed.CheckDate.AddSeconds(1) + ed.LTS, Memoinfo = ed.EmpShift.ID }); } } if (Ot) { //otIn bool otIn = false; if (ed.FTS <= shift.OTCheckIn && ed.LTS > shift.OTCheckIn.Add(new TimeSpan(0, 30, 0))) { ed.NewChecks.Add(ed.OtIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = GetInTime(ed.CheckDate, ed.FTS, ed.EmpShift.OTCheckIn), Memoinfo = ed.EmpShift.ID }); otIn = true; } else if (ed.FTS < shift.OTCheckOut && ed.FTS > shift.OTCheckIn) { ed.NewChecks.Add(ed.OtIn = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = ed.CheckDate.AddSeconds(Get1T60Rand()) + ed.FTS, Memoinfo = ed.EmpShift.ID }); otIn = true; } //otOut if (ed.LTS >= shift.OTCheckOut && otIn) { ed.NewChecks.Add(ed.OtOut = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = GetOutTime(ed.CheckDate, ed.LTS, ed.EmpShift.OTCheckOut), Memoinfo = ed.EmpShift.ID }); } else if (ed.LTS > shift.OTCheckIn && otIn) { ed.NewChecks.Add(ed.OtOut = new CHECKINOUT { USERID = ed.Emp.USERID, CHECKTIME = ed.CheckDate.AddSeconds(Get1T60Rand()) + ed.LTS, Memoinfo = ed.EmpShift.ID }); } } } }