CoursesTimeServices.cs 8.8 KB

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