TimeSegmentServices.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.Entities;
  9. using EMIS.DataLogic.ExaminationManage;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.ExaminationManage;
  12. using Bowin.Common.Exceptions;
  13. namespace EMIS.CommonLogic.ExaminationManage
  14. {
  15. public class TimeSegmentServices : BaseServices, ITimeSegmentServices
  16. {
  17. public TimeSegmentDAL TimeSegmentDAL { get; set; }
  18. public IGridResultSet<TimeSegmentView> GetTimeSegmentViewList(ConfiguretView timeSegmentConditionView, int pageIndex, int pageSize)
  19. {
  20. Expression<Func<EX_TimeSegment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  21. var query = TimeSegmentDAL.GetTimeSegmentView(exp);
  22. if (!string.IsNullOrEmpty(timeSegmentConditionView.ConditionValue) && !string.IsNullOrEmpty(timeSegmentConditionView.Attribute))
  23. query = query.DynamicWhere(timeSegmentConditionView.Attribute, timeSegmentConditionView.Condition, timeSegmentConditionView.ConditionValue);
  24. query = query.OrderByDescending(x => x.ExaminationDate).ThenByDescending(x => x.StartTime).ThenByDescending(x => x.EndTime);
  25. return query.ToGridResultSet<TimeSegmentView>(pageIndex, pageSize);
  26. }
  27. public List<TimeSegmentView> GetTimeSegmentViewList(bool? isForResit = null)
  28. {
  29. Expression<Func<EX_TimeSegment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  30. if (isForResit.HasValue)
  31. {
  32. exp = exp.And(x => x.IsForResit == isForResit);
  33. }
  34. var query = TimeSegmentDAL.GetTimeSegmentView(exp);
  35. query = query.OrderByDescending(x => x.ExaminationDate).OrderByDescending(x => x.StartTime).OrderByDescending(x => x.EndTime);
  36. return query.ToList();
  37. }
  38. /// <summary>
  39. /// 获取考试时间信息
  40. /// </summary>
  41. /// <param name="timeSegmentID">考试时间ID</param>
  42. /// <returns></returns>
  43. public TimeSegmentView GetTimeSegmentView(Guid? timeSegmentID)
  44. {
  45. var query = TimeSegmentDAL.GetTimeSegmentView(x => x.TimeSegmentID == timeSegmentID);
  46. return query.FirstOrDefault();
  47. }
  48. /// <summary>
  49. /// 保存
  50. /// </summary>
  51. /// <param name="coursematerial">课程资料实体</param>
  52. /// <returns></returns>
  53. public void SaveTimeSegment(TimeSegmentView timeSegmentView)
  54. {
  55. EX_TimeSegment timeSegment = new EX_TimeSegment();
  56. if (timeSegmentView.TimeSegmentID == null || timeSegmentView.TimeSegmentID == Guid.Empty)
  57. {
  58. if (timeSegmentView.ExaminationDate < DateTime.Now)
  59. {
  60. throw new Exception("考试日期应大于系统当前日期。");
  61. }
  62. timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.ExaminationDate == timeSegmentView.ExaminationDate
  63. && x.StartTime == timeSegmentView.StartTime && x.EndTime == timeSegmentView.EndTime);
  64. if (timeSegment != null)
  65. {
  66. if (timeSegment.IsForResit == timeSegmentView.IsForResit)
  67. {
  68. throw new Exception("已有相同的考试时间设置,请勿重复设置。");
  69. }
  70. else
  71. {
  72. throw new Exception("正常考试时间不能和补考考试时间重复,否则协调教室资源会很困难,请调整时间后再保存。");
  73. }
  74. }
  75. timeSegment = new EX_TimeSegment();
  76. timeSegment.TimeSegmentID = Guid.NewGuid();
  77. SetNewStatus(timeSegment);
  78. UnitOfWork.Add(timeSegment);
  79. }
  80. else
  81. {
  82. timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.TimeSegmentID != timeSegmentView.TimeSegmentID
  83. && x.ExaminationDate == timeSegmentView.ExaminationDate
  84. && x.StartTime == timeSegmentView.StartTime && x.EndTime == timeSegmentView.EndTime);
  85. if (timeSegment != null)
  86. {
  87. if (timeSegment.IsForResit == timeSegmentView.IsForResit)
  88. {
  89. throw new Exception("已有相同的考试时间设置,请勿重复设置。");
  90. }
  91. else
  92. {
  93. throw new Exception("正常考试时间不能和补考考试时间重复,否则协调教室资源会很困难,请调整时间后再保存。");
  94. }
  95. }
  96. timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.TimeSegmentID == timeSegmentView.TimeSegmentID);
  97. if (timeSegment == null)
  98. {
  99. throw new Exception("未能找到需要修改的数据,数据可能已被其他用户更改。");
  100. }
  101. SetModifyStatus(timeSegment);
  102. }
  103. timeSegment.IsForResit = timeSegmentView.IsForResit;
  104. timeSegment.ExaminationDate = timeSegmentView.ExaminationDate;
  105. timeSegment.StartTime = timeSegmentView.StartTime;
  106. timeSegment.EndTime = timeSegmentView.EndTime;
  107. UnitOfWork.Commit();
  108. }
  109. public void Delete(IList<Guid?> timeSegmentIDList)
  110. {
  111. if (timeSegmentIDList.Count > 0)
  112. {
  113. UnitOfWork.Delete<EX_TimeSegment>(x => timeSegmentIDList.Contains(x.TimeSegmentID));
  114. }
  115. }
  116. }
  117. }