Beispiel #1
0
 private void CalLeaveEarly()
 {
     if (this.OffDutyTime != null && this.NewEndTime != null && this.OffDutyTime.Value < this.NewEndTime)
     {
         TimeSpan ts  = new TimeSpan(this.NewEndTime.Ticks - this.OffDutyTime.Value.Ticks);
         int      min = (int)Math.Floor(ts.TotalMinutes);
         this.LeaveEarly = min > this.AllowLeaveEarlyTime ? min : 0; //大于允许早退时间才算早退
         if (this.LeaveEarly > 0 && AttendanceRules.Current != null)
         {
             if (AttendanceRules.Current.MinLeaveEarly != null && AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute > 0 && AttendanceRules.Current.MinLeaveEarly >= this.LeaveEarly)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID       = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.LeaveEarly) + "计缺勤",
                         Duration = Present > AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute ? AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute : Present,
                     };
                     this.AbsentItems.Add(ai);
                     Present -= AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute;
                     if (Present < 0)
                     {
                         Present = 0;
                     }
                 }
             }
             if (AttendanceRules.Current.LeaveEarlyAsAbsent != null && this.LeaveEarly > AttendanceRules.Current.LeaveEarlyAsAbsent)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID       = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.LeaveEarly) + "计缺勤",
                         Duration = this.Present,
                     };
                     this.AbsentItems.Add(ai);
                     this.Present = 0;
                 }
             }
         }
     }
 }
Beispiel #2
0
 private void CalLate()
 {
     if (this.OnDutyTime != null && this.NewStartTime != null && this.OnDutyTime.Value > this.NewStartTime)
     {
         TimeSpan ts  = new TimeSpan(this.OnDutyTime.Value.Ticks - this.NewStartTime.Ticks);
         int      min = (int)Math.Floor(ts.TotalMinutes);
         this.Belate = min > this.AllowLateTime ? min : 0; //大于允许迟到时间才算迟到
         if (this.Belate > 0 && AttendanceRules.Current != null)
         {
             if (AttendanceRules.Current.MinLate != null && AttendanceRules.Current.MinLateAsAbsentMinute > 0 && AttendanceRules.Current.MinLate >= this.Belate)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID       = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.Late) + "计缺勤",
                         Duration = Present > AttendanceRules.Current.MinLateAsAbsentMinute ? AttendanceRules.Current.MinLateAsAbsentMinute : Present,
                     };
                     this.AbsentItems.Add(ai);
                     Present -= AttendanceRules.Current.MinLateAsAbsentMinute;
                     if (Present < 0)
                     {
                         Present = 0;
                     }
                 }
             }
             if (AttendanceRules.Current.LateAsAbsent != null && this.Belate > AttendanceRules.Current.LateAsAbsent)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID       = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.Late) + "计缺勤",
                         Duration = this.Present,
                     };
                     this.AbsentItems.Add(ai);
                     this.Present = 0;
                 }
             }
         }
     }
 }
        private void ExcludeTASheet(List <AttendanceResult> timezones, TASheet sheet, DatetimeRange range)
        {
            List <AttendanceResult> items = new List <AttendanceResult>();

            if (!range.Contain(sheet.StartDate) && !range.Contain(sheet.EndDate))
            {
                return;
            }
            DateTime dt = sheet.StartDate;

            while (dt <= sheet.EndDate && range.Contain(dt))
            {
                if (sheet.Items != null && sheet.Items.Count > 0)
                {
                    foreach (TASheetItem item in sheet.Items)
                    {
                        DateTime dt1 = dt.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second);
                        DateTime dt2 = dt.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second);
                        if (item.NextDay)
                        {
                            dt2 = dt2.AddDays(1);
                        }
                        DatetimeRange           dr  = new DatetimeRange(dt1, dt2);
                        List <AttendanceResult> sts = timezones.Where(it => it.ShiftDate == dt).ToList();
                        if (sts != null && sts.Count > 0)
                        {
                            foreach (AttendanceResult st in sts)
                            {
                                DatetimeRange drItem = new DatetimeRange(st.NewStartTime, st.NewEndTime);
                                if (dr.Contain(drItem))
                                {
                                    if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                                    {
                                        st.Present = 0;
                                    }
                                    st.Category      = sheet.CategoryID;
                                    st.LogWhenArrive = false;
                                    st.LogWhenLeave  = false;
                                    AbsentItem ai = new AbsentItem()
                                    {
                                        ID       = Guid.NewGuid(),
                                        Category = sheet.CategoryID,
                                        Duration = st.ShiftTime
                                    };
                                    st.AbsentItems.Add(ai);
                                }
                                else if (drItem.Contain(dr))
                                {
                                    if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                                    {
                                        st.Present -= dr.TotalMinutes;
                                    }
                                    if (drItem.Begin == dr.Begin)
                                    {
                                        st.NewStartTime = dr.End;
                                    }
                                    if (drItem.End == dr.End)
                                    {
                                        st.NewEndTime = dr.Begin;
                                    }
                                    AbsentItem ai = new AbsentItem()
                                    {
                                        ID       = Guid.NewGuid(),
                                        Category = sheet.CategoryID,
                                        Duration = dr.TotalMinutes
                                    };
                                    st.AbsentItems.Add(ai);
                                }
                                else if (drItem.Contain(dr.Begin))
                                {
                                    DatetimeRange drTemp = new DatetimeRange(dr.Begin, drItem.End);
                                    if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                                    {
                                        st.Present -= drTemp.TotalMinutes;
                                    }
                                    st.NewEndTime = dr.Begin;
                                    AbsentItem ai = new AbsentItem()
                                    {
                                        ID       = Guid.NewGuid(),
                                        Category = sheet.CategoryID,
                                        Duration = drTemp.TotalMinutes
                                    };
                                    st.AbsentItems.Add(ai);
                                }
                                else if (drItem.Contain(dr.End))
                                {
                                    DatetimeRange drTemp = new DatetimeRange(drItem.Begin, dr.End);
                                    if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                                    {
                                        st.Present -= drTemp.TotalMinutes;
                                    }
                                    st.NewStartTime = dr.End;
                                    AbsentItem ai = new AbsentItem()
                                    {
                                        ID       = Guid.NewGuid(),
                                        Category = sheet.CategoryID,
                                        Duration = drTemp.TotalMinutes
                                    };
                                    st.AbsentItems.Add(ai);
                                }
                            }
                        }
                    }
                }
                dt = dt.AddDays(1);
            }
            if (items.Count > 0)
            {
                timezones.AddRange(items);
            }
        }
 private void ExcludeTASheet(List<AttendanceResult> timezones, TASheet sheet, DatetimeRange range)
 {
     List<AttendanceResult> items = new List<AttendanceResult>();
     if (!range.Contain(sheet.StartDate) && !range.Contain(sheet.EndDate)) return;
     DateTime dt = sheet.StartDate;
     while (dt <= sheet.EndDate && range.Contain(dt))
     {
         if (sheet.Items != null && sheet.Items.Count > 0)
         {
             foreach (TASheetItem item in sheet.Items)
             {
                 DateTime dt1 = dt.AddHours(item.StartTime.Hour).AddMinutes(item.StartTime.Minute).AddSeconds(item.StartTime.Second);
                 DateTime dt2 = dt.AddHours(item.EndTime.Hour).AddMinutes(item.EndTime.Minute).AddSeconds(item.EndTime.Second);
                 if (item.NextDay) dt2 = dt2.AddDays(1);
                 DatetimeRange dr = new DatetimeRange(dt1, dt2);
                 List<AttendanceResult> sts = timezones.Where(it => it.ShiftDate == dt).ToList();
                 if (sts != null && sts.Count > 0)
                 {
                     foreach (AttendanceResult st in sts)
                     {
                         DatetimeRange drItem = new DatetimeRange(st.NewStartTime, st.NewEndTime);
                         if (dr.Contain(drItem))
                         {
                             if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                             {
                                 st.Present = 0;
                             }
                             st.Category = sheet.CategoryID;
                             st.LogWhenArrive = false;
                             st.LogWhenLeave = false;
                             AbsentItem ai = new AbsentItem()
                             {
                                 ID=Guid.NewGuid (),
                                 Category = sheet.CategoryID,
                                 Duration = st.ShiftTime
                             };
                             st.AbsentItems.Add(ai);
                         }
                         else if (drItem.Contain(dr))
                         {
                             if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                             {
                                 st.Present -= dr.TotalMinutes;
                             }
                             if (drItem.Begin == dr.Begin) st.NewStartTime = dr.End;
                             if (drItem.End == dr.End) st.NewEndTime = dr.Begin;
                             AbsentItem ai = new AbsentItem()
                             {
                                 ID=Guid.NewGuid (),
                                 Category = sheet.CategoryID,
                                 Duration = dr.TotalMinutes
                             };
                             st.AbsentItems.Add(ai);
                         }
                         else if (drItem.Contain(dr.Begin))
                         {
                             DatetimeRange drTemp = new DatetimeRange(dr.Begin, drItem.End);
                             if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                             {
                                 st.Present -= drTemp.TotalMinutes;
                             }
                             st.NewEndTime = dr.Begin;
                             AbsentItem ai = new AbsentItem()
                             {
                                 ID=Guid.NewGuid (),
                                 Category = sheet.CategoryID,
                                 Duration = drTemp.TotalMinutes
                             };
                             st.AbsentItems.Add(ai);
                         }
                         else if (drItem.Contain(dr.End))
                         {
                             DatetimeRange drTemp = new DatetimeRange(drItem.Begin, dr.End);
                             if (!(sheet.SheetType == "C" && AttendanceRules.Current != null && AttendanceRules.Current.ShiftTimeIncludeWaiChu))
                             {
                                 st.Present -= drTemp.TotalMinutes;
                             }
                             st.NewStartTime = dr.End;
                             AbsentItem ai = new AbsentItem()
                             {
                                 ID=Guid .NewGuid (),
                                 Category = sheet.CategoryID,
                                 Duration = drTemp.TotalMinutes
                             };
                             st.AbsentItems.Add(ai);
                         }
                     }
                 }
             }
         }
         dt = dt.AddDays(1);
     }
     if (items.Count > 0) timezones.AddRange(items);
 }
 private void CalLeaveEarly()
 {
     if (this.OffDutyTime != null && this.NewEndTime != null && this.OffDutyTime.Value < this.NewEndTime)
     {
         TimeSpan ts = new TimeSpan(this.NewEndTime.Ticks - this.OffDutyTime.Value.Ticks);
         int min = (int)Math.Floor(ts.TotalMinutes);
         this.LeaveEarly = min > this.AllowLeaveEarlyTime ? min : 0; //大于允许早退时间才算早退
         if (this.LeaveEarly > 0 && AttendanceRules.Current != null)
         {
             if (AttendanceRules.Current.MinLeaveEarly != null && AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute > 0 && AttendanceRules.Current.MinLeaveEarly >= this.LeaveEarly)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.LeaveEarly) + "计缺勤",
                         Duration = Present > AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute ? AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute : Present,
                     };
                     this.AbsentItems.Add(ai);
                     Present -= AttendanceRules.Current.MinLeaveEarlyAsAbsentMinute;
                     if (Present < 0) Present = 0;
                 }
             }
             if (AttendanceRules.Current.LeaveEarlyAsAbsent != null && this.LeaveEarly > AttendanceRules.Current.LeaveEarlyAsAbsent)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.LeaveEarly) + "计缺勤",
                         Duration = this.Present,
                     };
                     this.AbsentItems.Add(ai);
                     this.Present = 0;
                 }
             }
         }
     }
 }
 private void CalLate()
 {
     if (this.OnDutyTime != null && this.NewStartTime != null && this.OnDutyTime.Value > this.NewStartTime)
     {
         TimeSpan ts = new TimeSpan(this.OnDutyTime.Value.Ticks - this.NewStartTime.Ticks);
         int min = (int)Math.Floor(ts.TotalMinutes);
         this.Belate = min > this.AllowLateTime ? min : 0; //大于允许迟到时间才算迟到
         if (this.Belate > 0 && AttendanceRules.Current != null)
         {
             if (AttendanceRules.Current.MinLate != null && AttendanceRules.Current.MinLateAsAbsentMinute > 0 && AttendanceRules.Current.MinLate >= this.Belate)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID=Guid .NewGuid (),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.Late) + "计缺勤",
                         Duration = Present > AttendanceRules.Current.MinLateAsAbsentMinute ? AttendanceRules.Current.MinLateAsAbsentMinute : Present,
                     };
                     this.AbsentItems.Add(ai);
                     Present -= AttendanceRules.Current.MinLateAsAbsentMinute;
                     if (Present < 0) Present = 0;
                 }
             }
             if (AttendanceRules.Current.LateAsAbsent != null && this.Belate > AttendanceRules.Current.LateAsAbsent)
             {
                 if (Present > 0)
                 {
                     AbsentItem ai = new AbsentItem()
                     {
                         ID = Guid.NewGuid(),
                         Category = AttendanceResultDescription.GetDescription(AttendanceResultCode.Late) + "计缺勤",
                         Duration = this.Present,
                     };
                     this.AbsentItems.Add(ai);
                     this.Present = 0;
                 }
             }
         }
     }
 }