static int CalcDueShowDays(DateTime firstDayOfMonth) { int days = 0; if (DUE_SHOW_DAYS_MAP.ContainsKey(firstDayOfMonth)) { return(DUE_SHOW_DAYS_MAP[firstDayOfMonth]); } int month = firstDayOfMonth.Month; DateTime nextDay = firstDayOfMonth; do { // skip the dayoff if (!WorkdayUtil.IsWorkday(nextDay)) { nextDay = nextDay.AddDays(1); continue; } days++; nextDay = nextDay.AddDays(1); } while (nextDay.Month == month); DUE_SHOW_DAYS_MAP[firstDayOfMonth] = days; return(days); }
public void GetNextInfo(AttendanceInfo nextInfo) { // assert there is no weekend days in the list if (!WorkdayUtil.IsWorkday(nextInfo.Date)) { Debug.Assert(false, "there is weekend in the list"); } // filter out the absent days if (nextInfo.State != AttendanceState.Absent) { return; } // first node if (this.AbsentDays == 0) { this.Reset(nextInfo); this.AbsentDays++; return; } // date is not continous, reset the points if ((nextInfo.Date.DayOfWeek == DayOfWeek.Monday) && (nextInfo.Date.DayOfYear - this.PreNode.Date.DayOfYear > 3)) { if (this.PreState == AttendanceState.Dimission) { // change to absent this.NextState = AttendanceState.Absent; this.NextNode = nextInfo; } else { this.Reset(nextInfo); } return; } if ((nextInfo.Date.DayOfWeek != DayOfWeek.Monday) && (nextInfo.Date.DayOfYear - this.PreNode.Date.DayOfYear > 1)) { if (this.PreState == AttendanceState.Dimission) { // change to absent this.NextState = AttendanceState.Absent; this.NextNode = nextInfo; } else { this.Reset(nextInfo); } return; } // change state to left if ((++this.AbsentDays > MAX_ABSENT_DAYS) && (this.PreState == AttendanceState.Absent)) { this.NextState = AttendanceState.Dimission; this.NextNode = nextInfo; } this.PreNode = nextInfo; }
static void SetAttendanceState(AttendanceInfo todayInfo, AttendanceInfo yesterdayInfo) { // skip the dayoff (weekend and holiday) if (!WorkdayUtil.IsWorkday(todayInfo.Date)) { todayInfo.State = AttendanceState.PaidLeave; Trace.WriteLine("skip weekend: " + todayInfo.Date.ToShortDateString()); return; } // assure the same person if ((yesterdayInfo != null) && (yesterdayInfo.Name != todayInfo.Name)) { Trace.WriteLine("name changed"); yesterdayInfo = null; } // assure the date is contiguous if ((yesterdayInfo != null) && (todayInfo.Date.DayOfYear - yesterdayInfo.Date.DayOfYear != 1)) { Trace.WriteLine("date is not contiguous"); yesterdayInfo = null; } // leave (no pay) if (!string.IsNullOrWhiteSpace(todayInfo.ExceptionComments) && (todayInfo.ExceptionComments == "请假")) { todayInfo.State = AttendanceState.Leave; return; } // additional record (no fine) if (!string.IsNullOrWhiteSpace(todayInfo.ExceptionComments) && (todayInfo.ExceptionComments == "补录异常")) { todayInfo.State = AttendanceState.AdditionalRecord; return; } // addiional record (fined) // to do ... // absent case if (!todayInfo.IsValid) { todayInfo.State = AttendanceState.Absent; return; } if (todayInfo.WorkTime.Hours < 4) { todayInfo.State = AttendanceState.Absent; Trace.WriteLine("worktime less than 4 hours"); return; } // late case if ((todayInfo.WorkTime.Hours < 9) || (todayInfo.ArriveTime.Hour > 10)) { if (yesterdayInfo == null) { todayInfo.State = AttendanceState.Late; return; } if (yesterdayInfo.WorkTime.Hours + todayInfo.WorkTime.Hours < 18) { todayInfo.State = AttendanceState.Late; return; } Trace.WriteLine("yesterday leave too late."); } // the nomral case todayInfo.State = AttendanceState.Normal; }