using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.CalendarManage; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.ViewModel.CalendarManage; namespace EMIS.CommonLogic.CalendarManage { public class CoursesTimeServices : BaseServices, ICoursesTimeServices { public CoursesTimeDAL coursesTimeDAL { get; set; } public Lazy SchoolYearServices { get; set; } /// /// 查询课程时间信息 /// /// 查询条件实体 /// 时间段 /// 页码 /// 显示页数 /// public IGridResultSet GetCoursesTimeViewGrid(ConfiguretView configuretView, int? timesSegment, int pageIndex, int pageSize) { var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (timesSegment.HasValue && timesSegment != -1) query = query.Where(x => x.TimesSegment == timesSegment); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); return query.OrderBy(x => x.StartTimes).ToGridResultSet(pageIndex, pageSize); } /// /// 查询课程时间信息 /// /// 查询条件实体 /// 时间段 /// public List GetCoursesTimeViewList(ConfiguretView configuretView, int? timesSegment) { var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (timesSegment.HasValue && timesSegment != -1) query = query.Where(x => x.TimesSegment == timesSegment); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList(); return query.OrderBy(x => x.StartTimes).ToList(); } /// /// 查询课程时间信息 /// /// 查询条件实体 /// 时间段 /// public List GetCoursesTimeViewFutureList(int? weekNum, int? weekday) { var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear(); var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var result = query.OrderBy(x => x.StartTimes).ToList(); result = result.Where(x => !this.SchoolYearServices.Value.IsTimePassed(currentSchoolyear, weekNum, weekday, x.StartHour, x.StartMinutes)) .ToList(); return result; } /// /// 获取课程时间信息 /// /// 主键ID /// public EM_CoursesTime GetCoursesTime(Guid? coursesTimeID) { //查询条件 Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.CoursesTimeID == coursesTimeID); return coursesTimeDAL.coursesTimeRepository.GetSingle(expression); } /// /// 获取下一堂课程时间信息 /// /// 主键ID /// public CoursesTimeView GetNextCoursesTime(Guid? coursesTimeID) { //查询条件 Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.CoursesTimeID == coursesTimeID); return coursesTimeDAL.GetNextCoursesTimeQueryable(expression).FirstOrDefault(); } /// /// 获取课程时间信息 /// /// 主键ID /// public CoursesTimeView GetCoursesTimeView(Guid? coursesTimeID) { CoursesTimeView coursesTimeView = new CoursesTimeView(); if (coursesTimeID.HasValue) coursesTimeView = coursesTimeDAL.GetCoursesTimeQueryable(x => true).Where(x => x.CoursesTimeID == coursesTimeID).FirstOrDefault(); return coursesTimeView; } /// /// 添加 /// /// 实体 /// public bool CoursesTimeAdd(CoursesTimeView coursesTimeView) { try { if (this.coursesTimeDAL.coursesTimeRepository .GetList(x => x.EndTimes >= coursesTimeView.StartTimes && x.StartTimes <= coursesTimeView.EndTimes && x.RecordStatus > (int)SYS_STATUS.UNUSABLE).Count() > 0) { throw new Exception("节次已存在,请重新输入!"); } EM_CoursesTime coursesTime = new EM_CoursesTime(); coursesTime.CoursesTimeID = Guid.NewGuid(); coursesTime.StartTimes = coursesTimeView.StartTimes.Value; coursesTime.EndTimes = coursesTimeView.EndTimes.Value; coursesTime.TimesSegment = coursesTimeView.TimesSegment.Value; coursesTime.StartHour = coursesTimeView.StartHour.Value; coursesTime.StartMinutes = coursesTimeView.StartMinutes.Value; coursesTime.EndHour = coursesTimeView.EndHour.Value; coursesTime.EndMinutes = coursesTimeView.EndMinutes.Value; this.SetNewStatus(coursesTime); UnitOfWork.Add(coursesTime); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 修改 /// /// 实体 /// public bool CoursesTimeUpdate(CoursesTimeView coursesTimeView) { try { if (this.coursesTimeDAL.coursesTimeRepository .GetList(x => x.EndTimes >= coursesTimeView.StartTimes && x.StartTimes <= coursesTimeView.EndTimes && x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.CoursesTimeID != coursesTimeView.CoursesTimeID).Count() > 0) { throw new Exception("节次已存在,请重新输入!"); } EM_CoursesTime coursesTime = GetCoursesTime(coursesTimeView.CoursesTimeID); if (coursesTime == null) { throw new Exception("保存失败,未能找到相对应的数据!"); } coursesTime.StartTimes = coursesTimeView.StartTimes.Value; coursesTime.EndTimes = coursesTimeView.EndTimes.Value; coursesTime.TimesSegment = coursesTimeView.TimesSegment.Value; coursesTime.StartHour = coursesTimeView.StartHour.Value; coursesTime.StartMinutes = coursesTimeView.StartMinutes.Value; coursesTime.EndHour = coursesTimeView.EndHour.Value; coursesTime.EndMinutes = coursesTimeView.EndMinutes.Value; this.SetModifyStatus(coursesTime); UnitOfWork.Update(coursesTime); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 删除 /// /// /// public bool CoursesTimeDelete(List coursesTimeIDs) { try { UnitOfWork.Update((x => new EM_CoursesTime { RecordStatus = (int)SYS_STATUS.UNUSABLE }), x => coursesTimeIDs.Contains(x.CoursesTimeID)); return true; } catch (Exception) { throw; } } } }