ClassroomScheduleDAL.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using EMIS.DataLogic.Repositories;
  7. using EMIS.ViewModel;
  8. using EMIS.Entities;
  9. using System.Linq.Expressions;
  10. using EMIS.ViewModel.EducationSchedule;
  11. using EMIS.Utility;
  12. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  13. using EMIS.DataLogic.UniversityManage.ClassroomManage;
  14. namespace EMIS.DataLogic.EducationSchedule
  15. {
  16. public class ClassroomScheduleDAL
  17. {
  18. public Lazy<ClassroomDAL> ClassroomDAL { get; set; }
  19. public ClassroomRepository ClassroomRepository { get; set; }
  20. public CoursesTimeRepository CoursesTimeRepository { get; set; }
  21. public ClassroomReserveRepository ClassroomReserveRepository { get; set; }
  22. public ClassroomScheduleSettingRepository ClassroomScheduleSettingRepository { get; set; }
  23. public ClassroomExcessiveUseRepository ClassroomExcessiveUseRepository { get; set; }
  24. public ClassroomExcessiveUseSchedulingRepository ClassroomExcessiveUseSchedulingRepository { get; set; }
  25. public ClassroomExcessiveUseSchedulingWeekNumRepository ClassroomExcessiveUseSchedulingWeekNumRepository { get; set; }
  26. public CollegeClassroomRepository CollegeClassroomRepository { get; set; }
  27. public EducationSchedulingRepository EducationSchedulingRepository { get; set; }
  28. public IQueryable<ClassroomView> GetAvailableClassroom()
  29. {
  30. var sql = (from c in ClassroomDAL.Value.GetClassroomViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  31. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  32. && x.IsReserved == true)
  33. on c.ClassroomID equals cr.ClassroomID into dcr
  34. from ecr in dcr.DefaultIfEmpty()
  35. where ecr.ClassroomReserveID == null
  36. select c);
  37. return sql;
  38. }
  39. public IQueryable<ClassroomView> GetAvailableClassroom(Guid collegeID, Guid schoolYearID, IList<int?> schedulingWeekList,
  40. int weekday, Guid courseTimeID, int? studentNum, int? classroomTypeID = null)
  41. {
  42. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsAvailable == true);
  43. if (classroomTypeID.HasValue)
  44. {
  45. exp = exp.And(x => x.CF_ClassroomType.Any(w => w.ClassroomType == classroomTypeID));
  46. }
  47. var sql = (from c in ClassroomDAL.Value.GetClassroomViewQueryable(exp)
  48. join cc in CollegeClassroomRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE) on c.ClassroomID equals cc.ClassroomID
  49. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  50. on new { c.ClassroomID, IsReserved = (bool?)true } equals new { cr.ClassroomID, cr.IsReserved } into dcr
  51. from ecr in dcr.DefaultIfEmpty()
  52. join css in ClassroomScheduleSettingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsOnWork == false)
  53. on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID }
  54. equals new { css.ClassroomID, css.Weekday, css.CoursesTimeID } into dcss
  55. from ecss in dcss.DefaultIfEmpty()
  56. join es in
  57. (
  58. from es in EducationSchedulingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  59. from eswn in es.ES_EducationSchedulingWeekNum
  60. where schedulingWeekList.Contains(eswn.WeekNum)
  61. select es
  62. ) on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  63. equals new { es.ClassroomID, es.Weekday, es.CoursesTimeID, es.SchoolyearID } into des
  64. from ees in des.DefaultIfEmpty()
  65. join ceu in
  66. (
  67. from ceu in ClassroomExcessiveUseRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  68. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  69. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  70. where schedulingWeekList.Contains(ceusw.WeekNum)
  71. select new { ceu.ClassroomID, ceus.Weekday, ceus.CoursesTimeID, ceu.SchoolyearID }
  72. ) on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  73. equals new { ceu.ClassroomID, ceu.Weekday, ceu.CoursesTimeID, ceu.SchoolyearID } into dceu
  74. from eceu in dceu.DefaultIfEmpty()
  75. where cc.CollegeID == collegeID
  76. && ((c.Totalseating ?? 0) == 0 || studentNum == null || c.Totalseating >= studentNum)
  77. && ecr.ClassroomReserveID == null
  78. && (ecss.ClassroomScheduleSettingID == null)
  79. && (c.IsConcurrentUse == true || (ees.EducationSchedulingID == null && eceu.ClassroomID == null))
  80. group c by c.ClassroomID into g
  81. select g.FirstOrDefault()
  82. );
  83. return sql;
  84. }
  85. public IQueryable<ClassroomView> GetAvailableClassroom(Guid schoolYearID, IList<int?> schedulingWeekList,
  86. int weekday, Guid courseTimeID, int? studentNum, int? classroomTypeID = null)
  87. {
  88. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsAvailable == true);
  89. if (classroomTypeID.HasValue)
  90. {
  91. exp = exp.And(x => x.CF_ClassroomType.Any(w => w.ClassroomType == classroomTypeID));
  92. }
  93. var sql = (from c in ClassroomDAL.Value.GetClassroomViewQueryable(exp)
  94. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  95. on new { c.ClassroomID, IsReserved = (bool?)true } equals new { cr.ClassroomID, cr.IsReserved } into dcr
  96. from ecr in dcr.DefaultIfEmpty()
  97. join css in ClassroomScheduleSettingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsOnWork == false)
  98. on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID }
  99. equals new { css.ClassroomID, css.Weekday, css.CoursesTimeID } into dcss
  100. from ecss in dcss.DefaultIfEmpty()
  101. join es in
  102. (
  103. from es in EducationSchedulingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  104. from eswn in es.ES_EducationSchedulingWeekNum
  105. where schedulingWeekList.Contains(eswn.WeekNum)
  106. select es
  107. ) on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  108. equals new { es.ClassroomID, es.Weekday, es.CoursesTimeID, es.SchoolyearID } into des
  109. from ees in des.DefaultIfEmpty()
  110. join ceu in
  111. (
  112. from ceu in ClassroomExcessiveUseRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  113. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  114. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  115. where schedulingWeekList.Contains(ceusw.WeekNum)
  116. select new { ceu.ClassroomID, ceus.Weekday, ceus.CoursesTimeID, ceu.SchoolyearID }
  117. ) on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  118. equals new { ceu.ClassroomID, ceu.Weekday, ceu.CoursesTimeID, ceu.SchoolyearID } into dceu
  119. from eceu in dceu.DefaultIfEmpty()
  120. where ((c.Totalseating ?? 0) == 0 || studentNum == null || c.Totalseating >= studentNum)
  121. && ecr.ClassroomReserveID == null
  122. && ecss.ClassroomScheduleSettingID == null
  123. && (c.IsConcurrentUse == true || (ees.EducationSchedulingID == null && eceu.ClassroomID == null))
  124. group c by c.ClassroomID into g
  125. select g.FirstOrDefault()
  126. );
  127. return sql;
  128. }
  129. public IQueryable<ClassroomView> GetAvailableClassroom(Guid collegeID, int? studentNum, Expression<Func<CF_Classroom, bool>> exp, int? classroomTypeID = null)
  130. {
  131. exp = exp.And(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsAvailable == true);
  132. if (classroomTypeID.HasValue)
  133. {
  134. exp = exp.And(x => x.CF_ClassroomType.Any(w => w.ClassroomType == classroomTypeID));
  135. }
  136. var classroomQuery = ClassroomDAL.Value.GetClassroomViewQueryable(exp);
  137. if (!Const.LOCAL_SETTING_ISCLOSESCHEDULINGMANAGE)
  138. {
  139. classroomQuery = (from c in classroomQuery
  140. join cc in CollegeClassroomRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE) on c.ClassroomID equals cc.ClassroomID
  141. where cc.CollegeID == collegeID
  142. select c);
  143. }
  144. var sql = (from c in classroomQuery
  145. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  146. on new { c.ClassroomID, IsReserved = (bool?)true } equals new { cr.ClassroomID, cr.IsReserved } into dcr
  147. from ecr in dcr.DefaultIfEmpty()
  148. where ((c.Totalseating ?? 0) == 0 || studentNum == null || c.Totalseating >= studentNum)
  149. && ecr.ClassroomReserveID == null
  150. group c by c.ClassroomID into g
  151. select g.FirstOrDefault()
  152. );
  153. return sql;
  154. }
  155. public IQueryable<ClassroomView> GetAvailableClassroomForAdjustment(Guid schoolYearID, IList<int?> schedulingWeekList,
  156. int weekday, Guid courseTimeID, Guid curEducationSchedulingID, int? studentNum, int? classroomTypeID = null)
  157. {
  158. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsAvailable == true);
  159. if (classroomTypeID.HasValue)
  160. {
  161. exp = exp.And(x => x.CF_ClassroomType.Any(w => w.ClassroomType == classroomTypeID));
  162. }
  163. var sql = (from c in ClassroomDAL.Value.GetClassroomViewQueryable(exp)
  164. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  165. on new { c.ClassroomID, IsReserved = (bool?)true } equals new { cr.ClassroomID, cr.IsReserved } into dcr
  166. from ecr in dcr.DefaultIfEmpty()
  167. join css in ClassroomScheduleSettingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsOnWork == false)
  168. on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID }
  169. equals new { css.ClassroomID, css.Weekday, css.CoursesTimeID } into dcss
  170. from ecss in dcss.DefaultIfEmpty()
  171. join es in
  172. (
  173. from es in EducationSchedulingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  174. from eswn in es.ES_EducationSchedulingWeekNum
  175. where schedulingWeekList.Contains(eswn.WeekNum)
  176. && es.EducationSchedulingID != curEducationSchedulingID
  177. select es
  178. ) on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  179. equals new { es.ClassroomID, es.Weekday, es.CoursesTimeID, es.SchoolyearID } into des
  180. from ees in des.DefaultIfEmpty()
  181. join ceu in
  182. (
  183. from ceu in ClassroomExcessiveUseRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  184. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  185. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  186. where schedulingWeekList.Contains(ceusw.WeekNum)
  187. select new { ceu.ClassroomID, ceus.Weekday, ceus.CoursesTimeID, ceu.SchoolyearID }
  188. ) on new { c.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  189. equals new { ceu.ClassroomID, ceu.Weekday, ceu.CoursesTimeID, ceu.SchoolyearID } into dceu
  190. from eceu in dceu.DefaultIfEmpty()
  191. where ((c.Totalseating ?? 0) == 0 || studentNum == null || c.Totalseating >= studentNum)
  192. && ecr.ClassroomReserveID == null
  193. && (ecss.ClassroomScheduleSettingID == null)
  194. && (c.IsConcurrentUse == true || (ees.EducationSchedulingID == null && eceu.ClassroomID == null))
  195. group c by c.ClassroomID into g
  196. select g.FirstOrDefault()
  197. );
  198. return sql;
  199. }
  200. public IQueryable<ClassroomView> GetAvailableClassroomForAdjustmentNew(Guid schoolYearID, IList<int?> schedulingWeekList,
  201. int weekday, Guid courseTimeID, Guid curEducationSchedulingID, int? studentNum, int? classroomTypeID = null)
  202. {
  203. Expression<Func<CF_Classroom, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsAvailable == true);
  204. if (classroomTypeID.HasValue)
  205. {
  206. exp = exp.And(x => x.CF_ClassroomType.Any(w => w.ClassroomType == classroomTypeID));
  207. }
  208. var sql = from a in
  209. (from clar in ClassroomRepository.GetList(exp)
  210. join cr in ClassroomReserveRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  211. on new { ClassroomID = clar.ClassroomID, IsReserved = (bool?)true } equals new { ClassroomID = cr.ClassroomID.Value, cr.IsReserved } into dcr
  212. from ecr in dcr.DefaultIfEmpty()
  213. join css in ClassroomScheduleSettingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.IsOnWork == false)
  214. on new { ClassroomID = clar.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID }
  215. equals new { ClassroomID = css.ClassroomID.Value, css.Weekday, css.CoursesTimeID } into dcss
  216. from ecss in dcss.DefaultIfEmpty()
  217. join es in
  218. (
  219. from es in EducationSchedulingRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  220. from eswn in es.ES_EducationSchedulingWeekNum
  221. where schedulingWeekList.Contains(eswn.WeekNum)
  222. && es.EducationSchedulingID != curEducationSchedulingID
  223. select es
  224. ) on new { ClassroomID = clar.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  225. equals new { ClassroomID = es.ClassroomID.Value, es.Weekday, es.CoursesTimeID, es.SchoolyearID } into des
  226. from ees in des.DefaultIfEmpty()
  227. join ceu in
  228. (
  229. from ceu in ClassroomExcessiveUseRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  230. from ceus in ceu.ES_ClassroomExcessiveUseScheduling
  231. from ceusw in ceus.ES_ClassroomExcessiveUseSchedulingWeekNum
  232. where schedulingWeekList.Contains(ceusw.WeekNum)
  233. select new { ceu.ClassroomID, ceus.Weekday, ceus.CoursesTimeID, ceu.SchoolyearID }
  234. ) on new { ClassroomID = clar.ClassroomID, Weekday = (int?)weekday, CoursesTimeID = (Guid?)courseTimeID, SchoolyearID = (Guid?)schoolYearID }
  235. equals new { ClassroomID = ceu.ClassroomID.Value, ceu.Weekday, ceu.CoursesTimeID, ceu.SchoolyearID } into dceu
  236. from eceu in dceu.DefaultIfEmpty()
  237. where ((clar.Totalseating ?? 0) == 0 || studentNum == null || clar.Totalseating >= studentNum)
  238. && ecr.ClassroomReserveID == null
  239. && (ecss.ClassroomScheduleSettingID == null)
  240. && (clar.IsConcurrentUse == true || (ees.EducationSchedulingID == null && eceu.ClassroomID == null))
  241. group clar by clar.ClassroomID into g
  242. select g.FirstOrDefault())
  243. join clag in ClassroomRepository.Entities
  244. on a.ClassroomID equals clag.ClassroomID
  245. join re in ClassroomReserveRepository.Entities
  246. on a.ClassroomID equals re.ClassroomID into tempre
  247. from crre in tempre.DefaultIfEmpty()
  248. join cc in
  249. (
  250. from cc in CollegeClassroomRepository.Entities
  251. group cc by cc.ClassroomID into gcr
  252. select new
  253. {
  254. ClassroomID = gcr.Key,
  255. ScheduleCollegeCount = gcr.Count()
  256. }
  257. )
  258. on a.ClassroomID equals cc.ClassroomID into tempcc
  259. from colcr in tempcc.DefaultIfEmpty()
  260. select new ClassroomView
  261. {
  262. ClassroomID = clag.ClassroomID,
  263. Code = clag.Code,
  264. Name = clag.Name,
  265. BuildingsInfoID = clag.BuildingsInfoID,
  266. BuildingsInfoCode = clag.CF_BuildingsInfo.Code,
  267. BuildingsInfoName = clag.CF_BuildingsInfo.Name,
  268. CampusID = clag.CF_BuildingsInfo.CampusID,
  269. CampusCode = clag.CF_BuildingsInfo.CF_Campus.No,
  270. CampusName = clag.CF_BuildingsInfo.CF_Campus.Name,
  271. CollegeID = clag.CollegeID,
  272. CollegeCode = clag.CF_College.No,
  273. CollegeName = clag.CF_College.Name,
  274. UnitCategoryID = clag.CF_College.CF_CollegeProfile.UnitCategoryID,
  275. CollegeCampusID = clag.CF_College.CampusID,
  276. CollegeCampusCode = clag.CF_College.CF_Campus.No,
  277. CollegeCampusName = clag.CF_College.CF_Campus.Name,
  278. //CF_ClassroomType = clag.CF_ClassroomType,
  279. //ClassroomTypeIDList = clag.CF_ClassroomType.Select(x => x.ClassroomType).ToList(),
  280. LayoutTypeID = clag.LayoutTypeID,
  281. RoomUseID = clag.RoomUseID,
  282. FloorLevel = clag.FloorLevel,
  283. Acreage = clag.Acreage,
  284. RowCout = clag.RowCout,
  285. ColumnCount = clag.ColumnCount,
  286. Totalseating = clag.Totalseating,
  287. Effectiveseating = clag.Effectiveseating,
  288. Examinationseating = clag.Examinationseating,
  289. IsWrittenExam = clag.IsWrittenExam ?? false,
  290. IsMachinetest = clag.IsMachinetest ?? false,
  291. IsConcurrentUse = clag.IsConcurrentUse ?? false,
  292. IsReserve = crre.IsReserved == true ? true : false,
  293. IsAvailable = clag.IsAvailable ?? false,
  294. ScheduleCollegeCount = colcr.ScheduleCollegeCount == null ? 0 : colcr.ScheduleCollegeCount,
  295. Remark = clag.Remark,
  296. RecordStatus = clag.RecordStatus,
  297. CreateUserID = clag.CreateUserID,
  298. CreateTime = clag.CreateTime,
  299. ModifyUserID = clag.ModifyUserID,
  300. ModifyTime = clag.ModifyTime
  301. };
  302. return sql;
  303. }
  304. }
  305. }