ClassroomExcessiveUseDAL.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 EMIS.DataLogic.Repositories;
  8. using EMIS.ViewModel.EducationSchedule;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.ExaminationManage;
  12. namespace EMIS.DataLogic.EducationSchedule
  13. {
  14. public class ClassroomExcessiveUseDAL
  15. {
  16. public ClassroomExcessiveUseRepository ClassroomExcessiveUseRepository { get; set; }
  17. public ClassroomExcessiveUseSchedulingRepository ClassroomExcessiveUseSchedulingRepository { get; set; }
  18. public ClassroomExcessiveUseSchedulingWeekNumRepository ClassroomExcessiveUseSchedulingWeekNumRepository { get; set; }
  19. public ClassroomRepository ClassroomRepository { get; set; }
  20. public CollegeRepository CollegeRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. public CoursesTimeRepository CoursesTimeRepository { get; set; }
  24. public ClassroomReserveRepository ClassroomReserveRepository { get; set; }
  25. public EducationSchedulingRepository EducationSchedulingRepository { get; set; }
  26. public ExaminationRoomLayoutRepository ExaminationRoomLayoutRepository { get; set; }
  27. public ExaminationPlanRepository ExaminationPlanRepository { get; set; }
  28. public IQueryable<ClassroomExcessiveUseView> GetClassroomExcessiveUseViewQueryable(Expression<Func<ES_ClassroomExcessiveUse, bool>> exp,
  29. Expression<Func<CF_Classroom, bool>> classroomExp)
  30. {
  31. var sql = (from classroomUse in ClassroomExcessiveUseRepository.GetList(exp)
  32. join schoolyear in SchoolyearRepository.Entities on classroomUse.SchoolyearID equals schoolyear.SchoolyearID
  33. join classroom in ClassroomRepository.Entities.Where(classroomExp) on classroomUse.ClassroomID equals classroom.ClassroomID
  34. join college in CollegeRepository.Entities on classroomUse.CollegeID equals college.CollegeID into dcollege
  35. from college in dcollege.DefaultIfEmpty()
  36. join user in UserRepository.Entities on classroomUse.UserID equals user.UserID into duser
  37. from user in duser.DefaultIfEmpty()
  38. join cre in UserRepository.Entities on classroomUse.CreateUserID equals cre.UserID into dcre
  39. from cre in dcre.DefaultIfEmpty()
  40. select new ClassroomExcessiveUseView
  41. {
  42. ClassroomExcessiveUseID = classroomUse.ClassroomExcessiveUseID,
  43. ClassroomID = classroom.ClassroomID,
  44. ClassroomName = classroom.Name,
  45. SchoolyearID = classroomUse.SchoolyearID,
  46. SchoolyearCode = schoolyear.Code,
  47. CollegeID = college.CollegeID,
  48. CollegeName = college.Name,
  49. UserID = classroomUse.UserID,
  50. UserName = user.Name,
  51. Content = classroomUse.Content,
  52. CreateUserID = cre.UserID,
  53. CreateUserName = cre.Name,
  54. CreateTime = classroomUse.CreateTime
  55. });
  56. return sql;
  57. }
  58. public IQueryable<ClassroomExcessiveUseSchedulingView> GetClassroomExcessiveUseSchedulingViewQueryable(Expression<Func<ES_ClassroomExcessiveUse, bool>> exp,
  59. Expression<Func<CF_Classroom, bool>> classroomExp)
  60. {
  61. var sql = (from classroomUse in ClassroomExcessiveUseRepository.GetList(exp)
  62. join classroom in ClassroomRepository.Entities.Where(classroomExp) on classroomUse.ClassroomID equals classroom.ClassroomID
  63. join scheduling in ClassroomExcessiveUseSchedulingRepository.Entities on classroomUse.ClassroomExcessiveUseID equals scheduling.ClassroomExcessiveUseID
  64. join courseTime in CoursesTimeRepository.Entities on scheduling.CoursesTimeID equals courseTime.CoursesTimeID
  65. select new ClassroomExcessiveUseSchedulingView
  66. {
  67. ClassroomExcessiveUseSchedulingID = scheduling.ClassroomExcessiveUseSchedulingID,
  68. ClassroomExcessiveUseID = classroomUse.ClassroomExcessiveUseID,
  69. CollegeID = classroomUse.CollegeID,
  70. Weekday = scheduling.Weekday,
  71. CoursesTimeID = scheduling.CoursesTimeID,
  72. StartTimes = courseTime.StartTimes,
  73. EndTimes = courseTime.EndTimes,
  74. StartHour = courseTime.StartHour,
  75. StartMinute = courseTime.StartMinutes,
  76. EndHour = courseTime.EndHour,
  77. EndMinute = courseTime.EndMinutes,
  78. WeekNumList = scheduling.ES_ClassroomExcessiveUseSchedulingWeekNum.Select(x => x.WeekNum)
  79. });
  80. return sql;
  81. }
  82. public IQueryable<ClassroomExcessiveUseWeekNumView> GetClassroomExcessiveUseWeekNumViewQueryable(Expression<Func<ES_ClassroomExcessiveUse, bool>> exp,
  83. Expression<Func<CF_Classroom, bool>> classroomExp)
  84. {
  85. var sql = (from classroomUse in ClassroomExcessiveUseRepository.GetList(exp)
  86. join schoolyear in SchoolyearRepository.Entities on classroomUse.SchoolyearID equals schoolyear.SchoolyearID
  87. join classroom in ClassroomRepository.Entities.Where(classroomExp) on classroomUse.ClassroomID equals classroom.ClassroomID
  88. join scheduling in ClassroomExcessiveUseSchedulingRepository.Entities on classroomUse.ClassroomExcessiveUseID equals scheduling.ClassroomExcessiveUseID
  89. join weekNum in ClassroomExcessiveUseSchedulingWeekNumRepository.Entities on scheduling.ClassroomExcessiveUseSchedulingID equals weekNum.ClassroomExcessiveUseSchedulingID
  90. select new ClassroomExcessiveUseWeekNumView
  91. {
  92. ClassroomExcessiveUseSchedulingWeekNumID = weekNum.ClassroomExcessiveUseSchedulingWeekNumID,
  93. ClassroomExcessiveUseSchedulingID = scheduling.ClassroomExcessiveUseSchedulingID,
  94. ClassroomExcessiveUseID = classroomUse.ClassroomExcessiveUseID,
  95. ClassroomID = classroomUse.ClassroomID,
  96. ClassroomName = classroom.Name,
  97. SchoolyearID = classroomUse.SchoolyearID,
  98. SchoolyearCode = schoolyear.Code,
  99. CollegeID = classroomUse.CollegeID,
  100. WeekNum = weekNum.WeekNum,
  101. Weekday = scheduling.Weekday,
  102. CoursesTimeID = scheduling.CoursesTimeID
  103. });
  104. return sql;
  105. }
  106. public IQueryable<CF_Classroom> GetAvailableClassroom(Guid schoolYearID, IList<int?> schedulingWeekList,
  107. int weekday, Guid courseTimeID, Guid classroomID, Guid? classroomExcessiveUseID = null)
  108. {
  109. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsAvailable == true
  110. && x.ClassroomID == classroomID);
  111. Expression<Func<ES_ClassroomExcessiveUse, bool>> excessiveUseExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  112. if (classroomExcessiveUseID.HasValue)
  113. {
  114. excessiveUseExp = excessiveUseExp.And(x => x.ClassroomExcessiveUseID != classroomExcessiveUseID);
  115. }
  116. var sql = (from c in this.ClassroomRepository.GetList(exp)
  117. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  118. on new { ClassroomID = (Guid?)c.ClassroomID, IsReserved = (bool?)true } equals new { cr.ClassroomID, cr.IsReserved } into dcr
  119. from ecr in dcr.DefaultIfEmpty()
  120. join es in
  121. (
  122. from es in EducationSchedulingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  123. from eswn in es.ES_EducationSchedulingWeekNum
  124. where schedulingWeekList.Contains(eswn.WeekNum)
  125. select es
  126. ) on new { ClassroomID = (Guid?)c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  127. equals new { es.ClassroomID, es.Weekday, es.CoursesTimeID, es.SchoolyearID } into des
  128. from ees in des.DefaultIfEmpty()
  129. join ceu in
  130. (
  131. from ceu in ClassroomExcessiveUseRepository.GetList(excessiveUseExp)
  132. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  133. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  134. where schedulingWeekList.Contains(ceusw.WeekNum)
  135. select new { ceu.ClassroomID, ceus.Weekday, ceus.CoursesTimeID, ceu.SchoolyearID }
  136. ) on new { ClassroomID = (Guid?)c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  137. equals new { ceu.ClassroomID, ceu.Weekday, ceu.CoursesTimeID, ceu.SchoolyearID } into dceu
  138. from eceu in dceu.DefaultIfEmpty()
  139. where ecr.ClassroomReserveID == null
  140. && (c.IsConcurrentUse == true || (ees.EducationSchedulingID == null && eceu.ClassroomID == null))
  141. group c by c.ClassroomID into g
  142. select g.FirstOrDefault()
  143. );
  144. return sql;
  145. }
  146. public List<Guid?> GetUsedCourseTime(Guid schoolYearID, IList<int?> schedulingWeekList, int weekday, Guid classroomID)
  147. {
  148. Expression<Func<ES_EducationScheduling, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SchoolyearID == schoolYearID
  149. && x.ClassroomID == classroomID && x.Weekday == weekday);
  150. Expression<Func<ES_ClassroomExcessiveUse, bool>> excessiveUseExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.SchoolyearID == schoolYearID
  151. && x.ClassroomID == classroomID);
  152. var sql = from esa in
  153. (from es in EducationSchedulingRepository.GetList(exp)
  154. from eswn in es.ES_EducationSchedulingWeekNum
  155. where schedulingWeekList.Contains(eswn.WeekNum)
  156. select new { es.ClassroomID, es.CoursesTimeID, es.Weekday, es.SchoolyearID }
  157. ).Concat(
  158. from ceu in ClassroomExcessiveUseRepository.GetList(excessiveUseExp)
  159. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  160. where ceus.Weekday == weekday
  161. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  162. where schedulingWeekList.Contains(ceusw.WeekNum)
  163. select new { ceu.ClassroomID, ceus.CoursesTimeID, ceus.Weekday, ceu.SchoolyearID }
  164. )
  165. select new
  166. {
  167. esa.CoursesTimeID
  168. };
  169. List<Guid?> coursesTimeList = new List<Guid?>();
  170. if (sql != null)
  171. {
  172. coursesTimeList = sql.Select(x => x.CoursesTimeID).ToList();
  173. }
  174. return coursesTimeList;
  175. }
  176. public IQueryable<ClassroomConflictView> GetExaminationPlanViewByClassroom(Guid? schoolyearID, Guid? classroomID)
  177. {
  178. var query = from erl in ExaminationRoomLayoutRepository.GetList(x => x.ClassroomID == classroomID && x.EX_ExaminationPlan.SchoolyearID == schoolyearID && x.EX_ExaminationPlan.RecordStatus == (int)EX_ExaminationPlanStatus.Submitted)
  179. select new ClassroomConflictView
  180. {
  181. ExaminationPlanID = erl.EX_ExaminationPlan.ExaminationPlanID,
  182. ClassroomID = erl.ClassroomID.Value,
  183. ExaminationDate = erl.EX_ExaminationPlan.ExaminationDate,
  184. StartTime = erl.EX_ExaminationPlan.StartTime,
  185. EndTime = erl.EX_ExaminationPlan.EndTime,
  186. };
  187. return query;
  188. }
  189. }
  190. }