private static Dictionary <string, int> GetHoliday() { IHolidayContract _holidayContract = EntityContract._holidayContract; Dictionary <string, int> dic = _holidayContract.GetHoliday(); return(dic); }
private int GetWorkDay(DateTime date, WorkTime workTime) { string strDateIndex = date.ToString("yyyy/MM/01"); DateTime dateIndex = DateTime.Parse(strDateIndex); int index = DateTime.DaysInMonth(date.Year, date.Month); int workDay = 0; string[] arrWeeks = workTime.WorkWeek.Split(","); Dictionary <string, int> dic = new Dictionary <string, int>(); if (workTime.IsVacations == true) { dic = _holidayContract.GetHoliday(); } StringBuilder sbWeekDay = new StringBuilder(); StringBuilder sbCurrentDate = new StringBuilder(); while (true) { if (index <= 0) { break; } else { sbWeekDay.Append(dateIndex.DayOfWeek.ToString("d")); sbCurrentDate.Append(dateIndex.ToString("yyyyMMdd")); if (dic != null) { int count = dic.Where(x => x.Key == sbCurrentDate.ToString() && x.Value == (int)WorkDateFlag.WorkDay).Count(); if (count > 0) { workDay += 1; } } else { if (arrWeeks.Contains(sbWeekDay.ToString())) { workDay += 1; } } } dateIndex.AddDays(1); index -= 1; sbWeekDay.Clear(); sbCurrentDate.Clear(); } return(workDay); }
private Dictionary <string, int> GetHoliday() { Dictionary <string, int> dic = _holidayContract.GetHoliday(); return(dic); }
private List <M_DepartAtten> GetAttens(int departmentId, DateTime startDate, DateTime endDate, int currentAdminId = 0) { int adminId = AuthorityHelper.OperatorId ?? 0; List <M_DepartAtten> listEntity = new List <M_DepartAtten>(); int count = startDate.CompareTo(endDate); int days = 0; if (count > 0) { return(listEntity); } else { TimeSpan timeSpan = endDate - startDate; days = timeSpan.Days + 1; List <int> listAdminId = new List <int>(); List <Administrator> admins = new List <Administrator>(); List <Administrator> listAdmin = _administratorContract.Administrators.Where(x => x.IsDeleted == false && x.IsEnabled == true).ToList(); if (currentAdminId == 0) { #region 获取部门下的员工 List <Administrator> entities = listAdmin.Where(x => x.DepartmentId == departmentId).ToList(); if (entities != null && entities.Count() > 0) { listAdminId = listAdmin.Select(x => x.Id).ToList(); admins.AddRange(entities); } if (admins.Count == 0) { return(listEntity); } #endregion } else { listAdminId.Add(currentAdminId); Administrator admin = listAdmin.FirstOrDefault(x => x.Id == currentAdminId); admins.Add(admin); } int index = 0; Dictionary <string, int> dic = _holidayContract.GetHoliday(); List <Attendance> listAtten = _attendanceContract.Attendances.Where(x => x.IsDeleted == false && x.IsEnabled == true && listAdminId.Contains(x.AdminId) && startDate.CompareTo(x.AttendanceTime) <= 0 && endDate.CompareTo(x.AttendanceTime) >= 0).ToList(); StringBuilder sbContent = new StringBuilder(); while (true) { if (index == days) { break; } else { DateTime currentDate = startDate.AddDays(index); foreach (Administrator admin in admins) { M_DepartAtten mEntity = new M_DepartAtten() { AttenTime = currentDate, RealName = admin.Member.RealName, }; WorkTime workTime = new WorkTime(); if (admin.WorkTime != null && admin.WorkTime.IsEnabled == true) { workTime = admin.WorkTime; } else if (admin.JobPosition != null) { workTime = admin.JobPosition.WorkTime; } Attendance atten = listAtten.FirstOrDefault(x => x.AdminId == admin.Id && x.AttendanceTime.Year == currentDate.Year && x.AttendanceTime.Month == currentDate.Month && x.AttendanceTime.Day == currentDate.Day); if (atten == null) { bool isWork = OfficeHelper.IsWorkDay(currentDate, workTime, dic); if (isWork == true) { mEntity.AttenType = "缺勤"; } else { bool isOverTime = IsOverTime(currentDate, admin.Id); if (isOverTime == true) { mEntity.AttenType = "未加班(申请加班)"; } } } else { #region 逻辑判断 if (atten.IsLate == -1) { sbContent.Append("迟到,"); } else if (atten.IsLate == 1) { sbContent.Append("迟到补卡,"); } if (atten.IsLeaveEarly == -1) { sbContent.Append("早退,"); } else if (atten.IsLeaveEarly == 1) { sbContent.Append("早退补卡,"); } if (atten.IsNoSignOut == -1) { sbContent.Append("未签到"); } else if (atten.IsNoSignOut == 1) { sbContent.Append("未签到补卡,"); } if (atten.IsAbsence == -1) { if (atten.AbsenceType == (int)AttendanceFlag.AmAbsence) { sbContent.Append("上午缺勤,"); } else if (atten.AbsenceType == (int)AttendanceFlag.PmAbsence) { sbContent.Append("下午缺勤,"); } else { sbContent.Append("缺勤,"); } } else if (atten.IsAbsence == 1) { sbContent.Append("缺勤补卡,"); } if (atten.FieldId != null) { if (atten.FieldType == (int)AttendanceFlag.AmField) { sbContent.Append("上午外勤,"); } else if (atten.FieldType == (int)AttendanceFlag.PmField) { sbContent.Append("下午外勤,"); } else { sbContent.Append("外勤,"); } } if (atten.LeaveInfoId != null) { if (atten.FieldType == (int)AttendanceFlag.AmLeave) { sbContent.Append("上午请教,"); } else if (atten.FieldType == (int)AttendanceFlag.PmLeave) { sbContent.Append("下午请假,"); } else { sbContent.Append("请假,"); } } #endregion mEntity.AttenType = sbContent.ToString(); mEntity.StartTime = atten.AmStartTime; mEntity.EndTime = atten.PmEndTime; } listEntity.Add(mEntity); sbContent.Clear(); } index++; } } } return(listEntity); }
/// <summary> /// 初始化打卡界面 /// </summary> /// <returns></returns> public ActionResult Registration() { Dictionary <string, int> dic = _holidayContract.GetHoliday(); string strStartTime = ""; string strEndTime = ""; string strLoginInTime = string.Empty; string strLoginOutTime = string.Empty; int adminId = AuthorityHelper.OperatorId ?? 0; //初始值默认不能签到和签退的 bool enableLoginIn = false; bool enableLoginOut = false; bool Isatten = false; var admin = _administratorContract.Administrators.FirstOrDefault(x => x.Id == adminId); if (dic == null && dic.Count == 0) { strStartTime = "请添加公休假"; strEndTime = "请添加公休假"; } else { OperationResult oper = _administratorContract.GetWorkTime(adminId); if (oper.ResultType == OperationResultType.Success) { WorkTime workTime = oper.Data as WorkTime; DateTime nowTime = DateTime.Now; Attendance atten = _attendanceContract.Attendances.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == adminId) .FirstOrDefault(x => nowTime.Year == x.AttendanceTime.Year && nowTime.Month == x.AttendanceTime.Month && nowTime.Day == x.AttendanceTime.Day); bool isWork = IsWorkDay(nowTime, workTime, dic); string strNotice = "弹性时间"; //提示上下班时间 if (!admin.IsPersonalTime) { strStartTime = workTime.IsFlexibleWork == true ? strNotice : workTime.AmStartTime; strEndTime = workTime.IsFlexibleWork == true ? strNotice : workTime.PmEndTime; } else { var _wd = _workTimeDetaileContract.WorkTimeDetailes.FirstOrDefault(x => x.WorkTimeId == admin.WorkTimeId && x.Year == nowTime.Year && x.Month == nowTime.Month && x.WorkDay == nowTime.Day); if (_wd != null) { if (_wd.WorkTimeType != 2) { strStartTime = workTime.IsFlexibleWork == true ? strNotice : _wd.AmStartTime; strEndTime = workTime.IsFlexibleWork == true ? strNotice : _wd.PmEndTime; } else { isWork = false; } } } if (isWork) { enableLoginIn = true; enableLoginOut = true; } else { isWork = IsOverTime(nowTime, adminId); if (isWork == true) { enableLoginIn = true; enableLoginOut = true; } } if (atten != null) { enableLoginIn = false; Isatten = true; strLoginInTime = atten.AmStartTime; strLoginOutTime = atten.PmEndTime; if (atten.LeaveInfoId != null) { enableLoginIn = true; enableLoginOut = true; enableLoginIn = true; } if (atten.FieldId != null) { enableLoginIn = true; enableLoginOut = true; enableLoginIn = true; } } } } ViewBag.EnableLoginIn = enableLoginIn; ViewBag.EnableLoginOut = enableLoginOut; ViewBag.LoginInTime = strLoginInTime; ViewBag.LoginOutTime = strLoginOutTime; ViewBag.StartTime = strStartTime; ViewBag.EndTime = strEndTime; return(PartialView()); }