using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.Common.CalendarManage; using EMIS.ViewModel; using EMIS.ViewModel.CalendarManage; using EMIS.Entities; namespace EMIS.CommonLogic.CalendarManage { public class ArrangementServices : BaseServices, IArrangementServices { public ArrangementDAL ArrangementDAL { get; set; } public List GetArrangementViewList(ViewModel.ConfiguretView configuretView) { var query = ArrangementDAL.GetArrangementView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); return query.OrderBy(x => x.Weekday).ThenBy(x => x.StartTimes).ToList(); } /// /// 周工作时间安排表 /// /// public IGridResultSet GetArrangementViewGrid() { var resultSet = ArrangementDAL.GetArrangementViewQueryable().OrderBy(x => x.StartTimes).ToGridResultSet(); return resultSet; } /// /// 新增周工作时间 /// /// public void ArrangementAdd(List listArrangement) { try { var courseTimeIDList = listArrangement.Select(x => x.CoursesTimeID).ToList(); var courseTimeList = ArrangementDAL.coursesTimeRepository.GetList(x => courseTimeIDList.Contains(x.CoursesTimeID), (y => y.CF_Arrangements)); foreach (var arrangementView in listArrangement) { EM_CoursesTime coursesTime = courseTimeList.Where(x => x.CoursesTimeID == arrangementView.CoursesTimeID) .FirstOrDefault(); if (coursesTime != null) { UnitOfWork.Remove(x => x.CoursesTimeID == coursesTime.CoursesTimeID); bool? IsOnWork = false; for (int i = 0; i < 7; i++) { if (i == (int)DayOfWeek.Monday) IsOnWork = arrangementView.MondayIsOnWork; if (i == (int)DayOfWeek.Tuesday) IsOnWork = arrangementView.TuesdayIsOnWork; if (i == (int)DayOfWeek.Wednesday) IsOnWork = arrangementView.WednesdayIsOnWork; if (i == (int)DayOfWeek.Thursday) IsOnWork = arrangementView.ThursdayIsOnWork; if (i == (int)DayOfWeek.Friday) IsOnWork = arrangementView.FridayIsOnWork; if (i == (int)DayOfWeek.Saturday) IsOnWork = arrangementView.SaturdayIsOnWork; if (i == (int)DayOfWeek.Sunday) IsOnWork = arrangementView.SundayIsOnWork; CF_Arrangements arrangements = new CF_Arrangements(); arrangements.ArrangementsID = Guid.NewGuid(); arrangements.CoursesTimeID = coursesTime.CoursesTimeID; arrangements.Weekday = i; arrangements.IsOnWork = IsOnWork; SetNewStatus(arrangements); UnitOfWork.Add(arrangements); } } } UnitOfWork.Commit(); } catch (Exception) { throw; } } public bool IsOnWork(int weekday, Guid courseTimeID) { var isOnWork = ArrangementDAL.ArrangementsRepository.GetList(x => x.Weekday == weekday && x.CoursesTimeID == courseTimeID && x.IsOnWork == true); return isOnWork.Count() > 0; } } }