using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.DataLogic.ExaminationManage; using EMIS.ViewModel; using EMIS.ViewModel.ExaminationManage; using Bowin.Common.Exceptions; namespace EMIS.CommonLogic.ExaminationManage { public class TimeSegmentServices : BaseServices, ITimeSegmentServices { public TimeSegmentDAL TimeSegmentDAL { get; set; } public IGridResultSet GetTimeSegmentViewList(ConfiguretView timeSegmentConditionView, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = TimeSegmentDAL.GetTimeSegmentView(exp); if (!string.IsNullOrEmpty(timeSegmentConditionView.ConditionValue) && !string.IsNullOrEmpty(timeSegmentConditionView.Attribute)) query = query.DynamicWhere(timeSegmentConditionView.Attribute, timeSegmentConditionView.Condition, timeSegmentConditionView.ConditionValue); query = query.OrderByDescending(x => x.ExaminationDate).ThenByDescending(x => x.StartTime).ThenByDescending(x => x.EndTime); return query.ToGridResultSet(pageIndex, pageSize); } public List GetTimeSegmentViewList(bool? isForResit = null) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (isForResit.HasValue) { exp = exp.And(x => x.IsForResit == isForResit); } var query = TimeSegmentDAL.GetTimeSegmentView(exp); query = query.OrderByDescending(x => x.ExaminationDate).OrderByDescending(x => x.StartTime).OrderByDescending(x => x.EndTime); return query.ToList(); } /// /// 获取考试时间信息 /// /// 考试时间ID /// public TimeSegmentView GetTimeSegmentView(Guid? timeSegmentID) { var query = TimeSegmentDAL.GetTimeSegmentView(x => x.TimeSegmentID == timeSegmentID); return query.FirstOrDefault(); } /// /// 保存 /// /// 课程资料实体 /// public void SaveTimeSegment(TimeSegmentView timeSegmentView) { EX_TimeSegment timeSegment = new EX_TimeSegment(); if (timeSegmentView.TimeSegmentID == null || timeSegmentView.TimeSegmentID == Guid.Empty) { if (timeSegmentView.ExaminationDate < DateTime.Now) { throw new Exception("考试日期应大于系统当前日期。"); } timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.ExaminationDate == timeSegmentView.ExaminationDate && x.StartTime == timeSegmentView.StartTime && x.EndTime == timeSegmentView.EndTime); if (timeSegment != null) { if (timeSegment.IsForResit == timeSegmentView.IsForResit) { throw new Exception("已有相同的考试时间设置,请勿重复设置。"); } else { throw new Exception("正常考试时间不能和补考考试时间重复,否则协调教室资源会很困难,请调整时间后再保存。"); } } timeSegment = new EX_TimeSegment(); timeSegment.TimeSegmentID = Guid.NewGuid(); SetNewStatus(timeSegment); UnitOfWork.Add(timeSegment); } else { timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.TimeSegmentID != timeSegmentView.TimeSegmentID && x.ExaminationDate == timeSegmentView.ExaminationDate && x.StartTime == timeSegmentView.StartTime && x.EndTime == timeSegmentView.EndTime); if (timeSegment != null) { if (timeSegment.IsForResit == timeSegmentView.IsForResit) { throw new Exception("已有相同的考试时间设置,请勿重复设置。"); } else { throw new Exception("正常考试时间不能和补考考试时间重复,否则协调教室资源会很困难,请调整时间后再保存。"); } } timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.TimeSegmentID == timeSegmentView.TimeSegmentID); if (timeSegment == null) { throw new Exception("未能找到需要修改的数据,数据可能已被其他用户更改。"); } SetModifyStatus(timeSegment); } timeSegment.IsForResit = timeSegmentView.IsForResit; timeSegment.ExaminationDate = timeSegmentView.ExaminationDate; timeSegment.StartTime = timeSegmentView.StartTime; timeSegment.EndTime = timeSegmentView.EndTime; UnitOfWork.Commit(); } public void Delete(IList timeSegmentIDList) { if (timeSegmentIDList.Count > 0) { UnitOfWork.Delete(x => timeSegmentIDList.Contains(x.TimeSegmentID)); } } } }