public CommandResult Update(AttendanceResult info) { AttendanceResult org = ProviderFactory.Create<IAttendanceResultProvider>(_RepoUri).GetByID(info.ID).QueryObject; if (org != null) { return ProviderFactory.Create<IAttendanceResultProvider>(_RepoUri).Update(info, org); } else { return new CommandResult(ResultCode.NoRecord, ResultCodeDecription.GetDescription(ResultCode.NoRecord)); } }
private string AbsentItemsDescr(AttendanceResult sar) { if (sar.AbsentItems != null && sar.AbsentItems.Count > 0) { string temp = string.Empty; for (int i = 0; i < sar.AbsentItems.Count; i++) { if (i > 0) temp += ","; AttendanceDuration dur = AttendanceRules.Current.GetDuarationFrom(sar.AbsentItems[i].Duration, true); temp += string.Format("{0} {1} {2}", sar.AbsentItems[i].Category, dur.Value, dur.Unit); } return temp; } return null; }
private List <AttendanceResult> CreateAttendanceResult(Staff staff, DateTime shiftDate, TASheet sheet) { List <AttendanceResult> items = new List <AttendanceResult>(); if (sheet.Items != null && sheet.Items.Count > 0) { foreach (TASheetItem item in sheet.Items) { DateTime dt1 = shiftDate.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second); DateTime dt2 = shiftDate.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second); if (dt1 > dt2) { dt2 = dt2.AddDays(1); //跨天 } AttendanceResult st = new AttendanceResult(); st.ID = Guid.NewGuid(); st.StaffID = staff.ID; st.StaffName = staff.Name; st.ShiftDate = shiftDate; st.Category = sheet.CategoryID; st.StartTime = dt1; st.NewStartTime = dt1; st.EndTime = dt2; st.NewEndTime = dt2; if (AttendanceRules.Current != null) { st.EarlyestTime = st.NewStartTime.AddMinutes(-(int)AttendanceRules.Current.BeforeOTStartTime); st.LatestTime = st.NewEndTime.AddMinutes((int)AttendanceRules.Current.AfterOTEndTime); } else { st.EarlyestTime = st.NewStartTime.AddMinutes(-30); st.LatestTime = st.NewEndTime.AddMinutes(30); } st.ShiftTime = item.Duration; st.Present = item.Duration; st.AbsentItems = new List <AbsentItem>(); st.LogWhenArrive = true; st.LogWhenLeave = true; st.EnableLate = true; st.EnableLeaveEarly = true; st.EnableAbsent = true; items.Add(st); } } return(items); }
private List <AttendanceResult> CreateAttendanceResult(Staff staff, ShiftArrange item) { List <AttendanceResult> items = new List <AttendanceResult>(); if (item.Shift != null && item.Shift.Items != null && item.Shift.Items.Count > 0) { foreach (ShiftItem si in item.Shift.Items) { AttendanceResult st = new AttendanceResult(); st.ID = Guid.NewGuid(); st.StaffID = staff.ID; st.StaffName = staff.Name; st.ShiftDate = item.ShiftDate; st.ShiftID = item.ShiftID; st.ShiftName = item.Shift.Name; MyTime mt = si.StartTime; st.StartTime = item.ShiftDate.AddHours(mt.Hour).AddMinutes(mt.Minute).AddSeconds(mt.Second); st.NewStartTime = st.StartTime; st.LogWhenArrive = si.LogAtStart; mt = si.EndTime; st.EndTime = item.ShiftDate.AddHours(mt.Hour).AddMinutes(mt.Minute).AddSeconds(mt.Second); if (si.NextDay) { st.EndTime = st.EndTime.AddDays(1); } st.NewEndTime = st.EndTime; st.LogWhenLeave = si.LogAtEnd; st.ShiftTime = si.Duration; //设置班次时段的上班时间 st.Present = si.Duration; st.EarlyestTime = st.NewStartTime.AddMinutes((int)-si.BeforeStartTime); st.LatestTime = st.NewEndTime.AddMinutes((int)si.AfterEndTime); st.AllowLateTime = si.AllowLateTime; st.AllowLeaveEarlyTime = si.AllowLeaveEarlyTime; st.AbsentItems = new List <AbsentItem>(); st.LogWhenArrive = true; st.LogWhenLeave = true; st.EnableLate = true; st.EnableLeaveEarly = true; st.EnableAbsent = true; items.Add(st); } } return(items); }
private void AttachAttendanceReocrds(List <AttendanceResult> timezones, List <AttendanceLog> ars) { for (int i = 0; i < timezones.Count; i++) { AttendanceResult item = timezones[i]; AttendanceLog record = null; //上班时间 if (item.LogWhenArrive) { DateTime dt1 = item.EarlyestTime; //最早上班时间 //获取上班打卡时间,如果之前有已经计算好的时间段,则当前时间段的上班时间需要从上一个时间段的刷卡时间后开始算起, //并要注意上班时间不能小于上一班次的下班时间 if (i > 0) { AttendanceResult stPre = timezones[i - 1]; if (stPre.NewEndTime >= dt1) { dt1 = stPre.NewEndTime.AddMilliseconds(1); } if (stPre.OffDutyTime != null && stPre.OffDutyTime.Value >= dt1) { dt1 = stPre.OffDutyTime.Value.AddMilliseconds(1); } } record = (from it in ars where it.ReadDateTime >= dt1 && it.ReadDateTime < item.NewEndTime orderby it.ReadDateTime ascending select it).FirstOrDefault(); if (record != null) { item.OnDutyTime = record.ReadDateTime; DateTime dtTemp = record.ReadDateTime; if (AttendanceRules.Current != null) { if (!string.IsNullOrEmpty(item.ShiftID)) { dtTemp = dtTemp.AddMinutes(AttendanceRules.Current.MinShiftMinute); } else { dtTemp = dtTemp.AddMinutes(AttendanceRules.Current.MinOTMinute); } } else { dtTemp = dtTemp.AddMinutes(1); } ars.RemoveAll(it => it.ReadDateTime <= dtTemp); //去掉所有前面的读卡记录,下面计算时会越来越快 } } else { item.OnDutyTime = item.NewStartTime; //如果上班不需要刷卡,则上班时间设置成应上班时间 } if (item.LogWhenLeave) { //获取下班时间 DateTime dt2 = item.LatestTime; if (i < timezones.Count - 1) { AttendanceResult stNext = timezones[i + 1]; if (dt2 >= stNext.NewStartTime) { dt2 = stNext.NewStartTime.AddMilliseconds(-1); } List <AttendanceLog> items = (from it in ars where it.ReadDateTime >= item.NewEndTime && it.ReadDateTime <= dt2 orderby it.ReadDateTime descending select it).ToList(); if (items.Count == 1) { item.OffDutyTime = items[0].ReadDateTime; } if (items.Count > 1) //如果有多条记录,则下班时间计算到最长,保留最后一条用作下一个班次的上班时间就可以了。 { if (items[0].ReadDateTime >= stNext.EarlyestTime) { item.OffDutyTime = items[1].ReadDateTime; } else { item.OffDutyTime = items[0].ReadDateTime; } ars.RemoveAll(it => it.ReadDateTime <= item.OffDutyTime); //去掉所有前面的读卡记录,下面计算时会越来越快 } } if (item.OffDutyTime == null) { record = (from it in ars where it.ReadDateTime > item.NewStartTime && it.ReadDateTime <= dt2 orderby it.ReadDateTime descending select it).FirstOrDefault(); if (record != null) { item.OffDutyTime = record.ReadDateTime; ars.RemoveAll(it => it.ReadDateTime <= item.OffDutyTime);//去掉所有前面的读卡记录,下面计算时会越来越快 } } } else { item.OffDutyTime = item.NewEndTime; //如果下班不需要刷卡,则下班时间为应下班时间 } } }
public CommandResult Delete(AttendanceResult info) { return ProviderFactory.Create<IAttendanceResultProvider>(_RepoUri).Delete(info); }
private List<AttendanceResult> CreateAttendanceResult(Staff staff, DateTime shiftDate, TASheet sheet) { List<AttendanceResult> items = new List<AttendanceResult>(); if (sheet.Items != null && sheet.Items.Count > 0) { foreach (TASheetItem item in sheet.Items) { DateTime dt1 = shiftDate.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second); DateTime dt2 = shiftDate.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second); if (dt1 > dt2) dt2 = dt2.AddDays(1); //跨天 AttendanceResult st = new AttendanceResult(); st.ID = Guid.NewGuid(); st.StaffID = staff.ID; st.StaffName = staff.Name; st.ShiftDate = shiftDate; st.Category = sheet.CategoryID; st.StartTime = dt1; st.NewStartTime = dt1; st.EndTime = dt2; st.NewEndTime = dt2; if (AttendanceRules.Current != null) { st.EarlyestTime = st.NewStartTime.AddMinutes(-(int)AttendanceRules.Current.BeforeOTStartTime); st.LatestTime = st.NewEndTime.AddMinutes((int)AttendanceRules.Current.AfterOTEndTime); } else { st.EarlyestTime = st.NewStartTime.AddMinutes(-30); st.LatestTime = st.NewEndTime.AddMinutes(30); } st.ShiftTime = item.Duration; st.Present = item.Duration; st.AbsentItems = new List<AbsentItem>(); st.LogWhenArrive = true; st.LogWhenLeave = true; st.EnableLate = true; st.EnableLeaveEarly = true; st.EnableAbsent = true; items.Add(st); } } return items; }
private List<AttendanceResult> CreateAttendanceResult(Staff staff, ShiftArrange item) { List<AttendanceResult> items = new List<AttendanceResult>(); if (item.Shift != null && item.Shift.Items != null && item.Shift.Items.Count > 0) { foreach (ShiftItem si in item.Shift.Items) { AttendanceResult st = new AttendanceResult(); st.ID = Guid.NewGuid(); st.StaffID = staff.ID; st.StaffName = staff.Name; st.ShiftDate = item.ShiftDate; st.ShiftID = item.ShiftID; st.ShiftName = item.Shift.Name; MyTime mt = si.StartTime; st.StartTime = item.ShiftDate.AddHours(mt.Hour).AddMinutes(mt.Minute).AddSeconds(mt.Second); st.NewStartTime = st.StartTime; st.LogWhenArrive = si.LogAtStart; mt = si.EndTime; st.EndTime = item.ShiftDate.AddHours(mt.Hour).AddMinutes(mt.Minute).AddSeconds(mt.Second); if (si.NextDay) st.EndTime = st.EndTime.AddDays(1); st.NewEndTime = st.EndTime; st.LogWhenLeave = si.LogAtEnd; st.ShiftTime = si.Duration; //设置班次时段的上班时间 st.Present = si.Duration; st.EarlyestTime = st.NewStartTime.AddMinutes((int)-si.BeforeStartTime); st.LatestTime = st.NewEndTime.AddMinutes((int)si.AfterEndTime); st.AllowLateTime = si.AllowLateTime; st.AllowLeaveEarlyTime = si.AllowLeaveEarlyTime; st.AbsentItems = new List<AbsentItem>(); st.LogWhenArrive = true; st.LogWhenLeave = true; st.EnableLate = true; st.EnableLeaveEarly = true; st.EnableAbsent = true; items.Add(st); } } return items; }