CoursesTimeServices.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.CalendarManage;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.CalendarManage;
  11. using EMIS.DataLogic.EducationSchedule;
  12. namespace EMIS.CommonLogic.CalendarManage
  13. {
  14. public class CoursesTimeServices : BaseServices, ICoursesTimeServices
  15. {
  16. public CoursesTimeDAL coursesTimeDAL { get; set; }
  17. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  18. public EducationSchedulingDAL educationSchedulingDAL { get; set; }
  19. /// <summary>
  20. /// 查询课程时间信息
  21. /// </summary>
  22. /// <param name="configuretView">查询条件实体</param>
  23. /// <param name="timesSegment">时间段</param>
  24. /// <param name="pageIndex">页码</param>
  25. /// <param name="pageSize">显示页数</param>
  26. /// <returns></returns>
  27. public IGridResultSet<CoursesTimeView> GetCoursesTimeViewGrid(ConfiguretView configuretView, int? timesSegment, int pageIndex, int pageSize)
  28. {
  29. var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  30. if (timesSegment.HasValue && timesSegment != -1)
  31. query = query.Where(x => x.TimesSegment == timesSegment);
  32. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  33. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToGridResultSet<CoursesTimeView>(pageIndex, pageSize);
  34. return query.OrderBy(x => x.StartTimes).ToGridResultSet<CoursesTimeView>(pageIndex, pageSize);
  35. }
  36. /// <summary>
  37. /// 查询课程时间信息
  38. /// </summary>
  39. /// <param name="configuretView">查询条件实体</param>
  40. /// <param name="timesSegment">时间段</param>
  41. /// <returns></returns>
  42. public List<CoursesTimeView> GetCoursesTimeViewList(ConfiguretView configuretView, int? timesSegment)
  43. {
  44. var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  45. if (timesSegment.HasValue && timesSegment != -1)
  46. query = query.Where(x => x.TimesSegment == timesSegment);
  47. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  48. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList();
  49. return query.OrderBy(x => x.StartTimes).ToList();
  50. }
  51. /// <summary>
  52. /// 查询课程时间信息
  53. /// </summary>
  54. /// <param name="configuretView">查询条件实体</param>
  55. /// <param name="timesSegment">时间段</param>
  56. /// <returns></returns>
  57. public List<CoursesTimeView> GetCoursesTimeViewFutureList(List<Guid?> educationSchedulingWeekNumIDList, int? weekNum, int? weekday)
  58. {
  59. var weekNumList = educationSchedulingDAL.EducationSchedulingWeekNumRepository.GetList(x =>
  60. educationSchedulingWeekNumIDList.Contains(x.EducationSchedulingWeekNumID),
  61. (x => x.ES_EducationScheduling.EM_CoursesTime)).ToList();
  62. var currentSchoolyear = this.SchoolYearServices.Value.GetCurrentSchoolYear();
  63. var query = coursesTimeDAL.GetCoursesTimeQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  64. List<Guid?> usedCourseeTimeIDList = new List<Guid?>();
  65. var result = query.OrderBy(x => x.StartTimes).ToList();
  66. result = result.Where(x => !this.SchoolYearServices.Value.IsTimePassed(currentSchoolyear, weekNum, weekday, x.StartHour, x.StartMinutes))
  67. .ToList();
  68. return result;
  69. }
  70. /// <summary>
  71. /// 获取课程时间信息
  72. /// </summary>
  73. /// <param name="coursesTimeID">主键ID</param>
  74. /// <returns></returns>
  75. public EM_CoursesTime GetCoursesTime(Guid? coursesTimeID)
  76. {
  77. //查询条件
  78. Expression<Func<EM_CoursesTime, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  79. expression = (x => x.CoursesTimeID == coursesTimeID);
  80. return coursesTimeDAL.coursesTimeRepository.GetSingle(expression);
  81. }
  82. /// <summary>
  83. /// 获取下一堂课程时间信息
  84. /// </summary>
  85. /// <param name="coursesTimeID">主键ID</param>
  86. /// <returns></returns>
  87. public CoursesTimeView GetNextCoursesTime(Guid? coursesTimeID)
  88. {
  89. //查询条件
  90. Expression<Func<EM_CoursesTime, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  91. expression = (x => x.CoursesTimeID == coursesTimeID);
  92. return coursesTimeDAL.GetNextCoursesTimeQueryable(expression).FirstOrDefault();
  93. }
  94. /// <summary>
  95. /// 获取课程时间信息
  96. /// </summary>
  97. /// <param name="coursesTimeID">主键ID</param>
  98. /// <returns></returns>
  99. public CoursesTimeView GetCoursesTimeView(Guid? coursesTimeID)
  100. {
  101. CoursesTimeView coursesTimeView = new CoursesTimeView();
  102. if (coursesTimeID.HasValue)
  103. coursesTimeView = coursesTimeDAL.GetCoursesTimeQueryable(x => true).Where(x => x.CoursesTimeID == coursesTimeID).FirstOrDefault();
  104. return coursesTimeView;
  105. }
  106. /// <summary>
  107. /// 添加
  108. /// </summary>
  109. /// <param name="coursesTime">实体</param>
  110. /// <returns></returns>
  111. public bool CoursesTimeAdd(CoursesTimeView coursesTimeView)
  112. {
  113. try
  114. {
  115. if (this.coursesTimeDAL.coursesTimeRepository
  116. .GetList(x => x.EndTimes >= coursesTimeView.StartTimes && x.StartTimes <= coursesTimeView.EndTimes
  117. && x.RecordStatus > (int)SYS_STATUS.UNUSABLE).Count() > 0)
  118. {
  119. throw new Exception("节次已存在,请重新输入!");
  120. }
  121. EM_CoursesTime coursesTime = new EM_CoursesTime();
  122. coursesTime.CoursesTimeID = Guid.NewGuid();
  123. coursesTime.StartTimes = coursesTimeView.StartTimes.Value;
  124. coursesTime.EndTimes = coursesTimeView.EndTimes.Value;
  125. coursesTime.TimesSegment = coursesTimeView.TimesSegment.Value;
  126. coursesTime.StartHour = coursesTimeView.StartHour.Value;
  127. coursesTime.StartMinutes = coursesTimeView.StartMinutes.Value;
  128. coursesTime.EndHour = coursesTimeView.EndHour.Value;
  129. coursesTime.EndMinutes = coursesTimeView.EndMinutes.Value;
  130. this.SetNewStatus(coursesTime);
  131. UnitOfWork.Add(coursesTime);
  132. UnitOfWork.Commit();
  133. return true;
  134. }
  135. catch (Exception)
  136. {
  137. throw;
  138. }
  139. }
  140. /// <summary>
  141. /// 修改
  142. /// </summary>
  143. /// <param name="coursesTime">实体</param>
  144. /// <returns></returns>
  145. public bool CoursesTimeUpdate(CoursesTimeView coursesTimeView)
  146. {
  147. try
  148. {
  149. if (this.coursesTimeDAL.coursesTimeRepository
  150. .GetList(x => x.EndTimes >= coursesTimeView.StartTimes && x.StartTimes <= coursesTimeView.EndTimes
  151. && x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  152. && x.CoursesTimeID != coursesTimeView.CoursesTimeID).Count() > 0)
  153. {
  154. throw new Exception("节次已存在,请重新输入!");
  155. }
  156. EM_CoursesTime coursesTime = GetCoursesTime(coursesTimeView.CoursesTimeID);
  157. if (coursesTime == null)
  158. {
  159. throw new Exception("保存失败,未能找到相对应的数据!");
  160. }
  161. coursesTime.StartTimes = coursesTimeView.StartTimes.Value;
  162. coursesTime.EndTimes = coursesTimeView.EndTimes.Value;
  163. coursesTime.TimesSegment = coursesTimeView.TimesSegment.Value;
  164. coursesTime.StartHour = coursesTimeView.StartHour.Value;
  165. coursesTime.StartMinutes = coursesTimeView.StartMinutes.Value;
  166. coursesTime.EndHour = coursesTimeView.EndHour.Value;
  167. coursesTime.EndMinutes = coursesTimeView.EndMinutes.Value;
  168. this.SetModifyStatus(coursesTime);
  169. UnitOfWork.Update(coursesTime);
  170. UnitOfWork.Commit();
  171. return true;
  172. }
  173. catch (Exception)
  174. {
  175. throw;
  176. }
  177. }
  178. /// <summary>
  179. /// 删除
  180. /// </summary>
  181. /// <param name="coursesTimeIDs"></param>
  182. /// <returns></returns>
  183. public bool CoursesTimeDelete(List<Guid> coursesTimeIDs)
  184. {
  185. try
  186. {
  187. UnitOfWork.Update<EM_CoursesTime>((x => new EM_CoursesTime { RecordStatus = (int)SYS_STATUS.UNUSABLE }), x => coursesTimeIDs.Contains(x.CoursesTimeID));
  188. return true;
  189. }
  190. catch (Exception)
  191. {
  192. throw;
  193. }
  194. }
  195. }
  196. }