EducationSchedulingAdjustmentDAL.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.EducationSchedule;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. namespace EMIS.DataLogic.EducationSchedule
  10. {
  11. public class EducationSchedulingAdjustmentDAL
  12. {
  13. public CourseProcessRepository CourseProcessRepository { get; set; }
  14. public EducationSchedulingAdjustmentRepository EducationSchedulingAdjustmentRepository { get; set; }
  15. public EducationSchedulingAdjustmentTeacherRepository EducationSchedulingAdjustmentTeacherRepository { get; set; }
  16. public EducationSchedulingAdjustmentToTeacherRepository EducationSchedulingAdjustmentToTeacherRepository { get; set; }
  17. public EducationSchedulingRepository EducationSchedulingRepository { get; set; }
  18. public EducationMissionClassRepository EducationMissionClassRepository { get; set; }
  19. public EducationMissionRepository EducationMissionRepository { get; set; }
  20. public CoursematerialRepository CoursematerialRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public StaffRepository StaffRepository { get; set; }
  23. public UserRepository UserRepository { get; set; }
  24. public CollegeRepository CollegeRepository { get; set; }
  25. public CoursesTimeRepository CoursesTimeRepository { get; set; }
  26. public ClassroomRepository ClassroomRepository { get; set; }
  27. public IQueryable<ScheduleAdjustmentView> GetScheduleAdjustmentViewQueryable(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp,
  28. Expression<Func<EM_EducationMission, bool>> missionExp,
  29. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp,
  30. Expression<Func<CF_Staff, bool>> staffExp)
  31. {
  32. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  33. join missionClass in EducationMissionClassRepository.Entities.Where(missionClassExp)
  34. on adjustment.EducationMissionClassID equals missionClass.EducationMissionClassID
  35. join mission in EducationMissionRepository.Entities.Where(missionExp)
  36. on missionClass.EducationMissionID equals mission.EducationMissionID
  37. join schoolyear in SchoolyearRepository.Entities on mission.SchoolyearID equals schoolyear.SchoolyearID
  38. join course in CoursematerialRepository.Entities on missionClass.CoursematerialID equals course.CoursematerialID
  39. join teacher in StaffRepository.Entities.Where(staffExp) on adjustment.UserID equals teacher.UserID
  40. join user in UserRepository.Entities on teacher.UserID equals user.UserID
  41. join college in CollegeRepository.Entities on teacher.CollegeID equals college.CollegeID
  42. join courseTime in CoursesTimeRepository.Entities on adjustment.CoursesTimeID equals courseTime.CoursesTimeID
  43. join classroom in ClassroomRepository.Entities on adjustment.ClassroomID equals classroom.ClassroomID
  44. join touser in UserRepository.Entities on adjustment.ToUserID equals touser.UserID into dtouser
  45. from touser in dtouser.DefaultIfEmpty()
  46. join tocourseTime in CoursesTimeRepository.Entities on adjustment.ToCoursesTimeID equals tocourseTime.CoursesTimeID
  47. join toclassroom in ClassroomRepository.Entities on adjustment.ToClassroomID equals toclassroom.ClassroomID
  48. from applyUser in UserRepository.Entities.Where(x => adjustment.ApplyUserID == x.UserID).DefaultIfEmpty()
  49. from createUser in UserRepository.Entities.Where(x => adjustment.CreateUserID == x.UserID).DefaultIfEmpty()
  50. select new ScheduleAdjustmentView
  51. {
  52. EducationSchedulingAdjustmentID = adjustment.EducationSchedulingAdjustmentID,
  53. SchoolyearID = mission.SchoolyearID,
  54. SchoolyearCode = schoolyear.Code,
  55. EducationMissionClassName = missionClass.Name,
  56. CourseCode = course.CourseCode,
  57. CourseName = course.CourseName,
  58. DepartmentID = teacher.DepartmentID,
  59. CollegeID = teacher.CollegeID,
  60. CollegeNo = college.No,
  61. CollegeName = college.Name,
  62. UserID = adjustment.UserID,
  63. UserName = user.Name,
  64. WeekNum = adjustment.WeekNum,
  65. Weekday = adjustment.Weekday,
  66. CoursesTimeID = adjustment.CoursesTimeID,
  67. StartTimes = courseTime.StartTimes,
  68. EndTimes = courseTime.EndTimes,
  69. ClassroomID = adjustment.ClassroomID,
  70. ClassroomName = classroom.Name,
  71. ToUserID = adjustment.ToUserID,
  72. ToUserName = touser.Name,
  73. ToWeekNum = adjustment.ToWeekNum,
  74. ToWeekday = adjustment.ToWeekday,
  75. ToCoursesTimeID = adjustment.ToCoursesTimeID,
  76. ToStartTimes = tocourseTime.StartTimes,
  77. ToEndTimes = tocourseTime.EndTimes,
  78. ToClassroomID = adjustment.ToClassroomID,
  79. ToClassroomName = toclassroom.Name,
  80. ApplyUserID = adjustment.ApplyUserID,
  81. ApplyUserName = applyUser.Name,
  82. ApplyTime = adjustment.ApplyTime,
  83. CreateUserID = adjustment.CreateUserID,
  84. CreateTime = adjustment.CreateTime,
  85. CreateUserName = createUser.Name,
  86. RecordStatus = adjustment.RecordStatus
  87. });
  88. return sql;
  89. }
  90. public IQueryable<ScheduleAdjustmentEditView> GetScheduleAdjustmentEditViewQueryable(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp,
  91. Expression<Func<EM_EducationMission, bool>> missionExp,
  92. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp,
  93. Expression<Func<CF_Staff, bool>> staffExp)
  94. {
  95. var curDate = DateTime.Today;
  96. var curSchoolyear = SchoolyearRepository.GetSingle(x => x.IsCurrent == true);
  97. var firstWeek = curSchoolyear.FirstWeek.AddDays(1 - (int)curSchoolyear.FirstWeek.DayOfWeek);
  98. var nowWeekNum = (curDate.Subtract(firstWeek).Days + 7) / 7;
  99. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  100. join missionClass in EducationMissionClassRepository.Entities.Where(missionClassExp)
  101. on adjustment.EducationMissionClassID equals missionClass.EducationMissionClassID
  102. join mission in EducationMissionRepository.Entities.Where(missionExp)
  103. on missionClass.EducationMissionID equals mission.EducationMissionID
  104. join schoolyear in SchoolyearRepository.Entities on mission.SchoolyearID equals schoolyear.SchoolyearID
  105. join course in CoursematerialRepository.Entities on missionClass.CoursematerialID equals course.CoursematerialID
  106. join teacher in StaffRepository.Entities.Where(staffExp) on adjustment.UserID equals teacher.UserID
  107. join user in UserRepository.Entities on teacher.UserID equals user.UserID
  108. join college in CollegeRepository.Entities on teacher.CollegeID equals college.CollegeID
  109. join courseTime in CoursesTimeRepository.Entities on adjustment.CoursesTimeID equals courseTime.CoursesTimeID
  110. join classroom in ClassroomRepository.Entities on adjustment.ClassroomID equals classroom.ClassroomID
  111. join touser in UserRepository.Entities on adjustment.ToUserID equals touser.UserID into dtouser
  112. from touser in dtouser.DefaultIfEmpty()
  113. join tocourseTime in CoursesTimeRepository.Entities on adjustment.ToCoursesTimeID equals tocourseTime.CoursesTimeID
  114. join toclassroom in ClassroomRepository.Entities on adjustment.ToClassroomID equals toclassroom.ClassroomID
  115. select new ScheduleAdjustmentEditView
  116. {
  117. EducationSchedulingAdjustmentID = adjustment.EducationSchedulingAdjustmentID,
  118. EducationMissionClassID = missionClass.EducationMissionClassID,
  119. SchoolyearID = mission.SchoolyearID,
  120. EducationMissionClassName = missionClass.Name,
  121. CoursematerialID = missionClass.CoursematerialID,
  122. CourseCode = course.CourseCode,
  123. CourseName = course.CourseName,
  124. EducationMissionClassStartWeekNum = (nowWeekNum > 1) ? nowWeekNum : 1,
  125. EducationMissionClassEndWeekNum = schoolyear.WeeksNum,
  126. UserID = adjustment.UserID,
  127. UserName = user.Name,
  128. WeekNum = adjustment.WeekNum,
  129. Weekday = adjustment.Weekday,
  130. TimesSegment = courseTime.TimesSegment,
  131. CoursesTimeID = adjustment.CoursesTimeID,
  132. StartHour = courseTime.StartHour,
  133. StartMinutes = courseTime.StartMinutes,
  134. EndHour = courseTime.EndHour,
  135. EndMinutes = courseTime.EndMinutes,
  136. ToWeekNum = adjustment.ToWeekNum,
  137. ToWeekday = adjustment.ToWeekday,
  138. ToCoursesTimeID = adjustment.ToCoursesTimeID,
  139. ClassroomTypeID = adjustment.ClassroomTypeID,
  140. ToClassroomTypeID = adjustment.ToClassroomTypeID,
  141. CollegeName = college.Name,
  142. ClassroomID = adjustment.ClassroomID,
  143. ClassroomName = classroom.Name,
  144. ToClassroomID = adjustment.ToClassroomID,
  145. ToUserID = adjustment.ToUserID
  146. });
  147. return sql;
  148. }
  149. public IQueryable<ScheduleAdjustmentTeacherView> GetEducationSchedulingAdjustmentTeacherQueryable(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp,
  150. Expression<Func<EM_EducationMission, bool>> missionExp,
  151. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp,
  152. Expression<Func<CF_Staff, bool>> staffExp)
  153. {
  154. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  155. join missionClass in EducationMissionClassRepository.Entities.Where(missionClassExp)
  156. on adjustment.EducationMissionClassID equals missionClass.EducationMissionClassID
  157. join mission in EducationMissionRepository.Entities.Where(missionExp)
  158. on missionClass.EducationMissionID equals mission.EducationMissionID
  159. join teacher in StaffRepository.Entities.Where(staffExp) on adjustment.UserID equals teacher.UserID
  160. join teacherList in EducationSchedulingAdjustmentTeacherRepository.Entities
  161. on adjustment.EducationSchedulingAdjustmentID equals teacherList.EducationSchedulingAdjustmentID
  162. join user in UserRepository.Entities on teacherList.UserID equals user.UserID
  163. select new ScheduleAdjustmentTeacherView
  164. {
  165. EducationSchedulingAdjustmentID = adjustment.EducationSchedulingAdjustmentID,
  166. UserID = user.UserID,
  167. LoginID = user.LoginID,
  168. Name = user.Name,
  169. TeachingMethod = teacherList.TeachingMethod
  170. });
  171. return sql;
  172. }
  173. public IQueryable<ScheduleAdjustmentTeacherView> GetEducationSchedulingAdjustmentToTeacherQueryable(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp,
  174. Expression<Func<EM_EducationMission, bool>> missionExp,
  175. Expression<Func<EM_EducationMissionClass, bool>> missionClassExp,
  176. Expression<Func<CF_Staff, bool>> staffExp)
  177. {
  178. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  179. join missionClass in EducationMissionClassRepository.Entities.Where(missionClassExp)
  180. on adjustment.EducationMissionClassID equals missionClass.EducationMissionClassID
  181. join mission in EducationMissionRepository.Entities.Where(missionExp)
  182. on missionClass.EducationMissionID equals mission.EducationMissionID
  183. join teacher in StaffRepository.Entities.Where(staffExp) on adjustment.UserID equals teacher.UserID
  184. join teacherList in EducationSchedulingAdjustmentToTeacherRepository.Entities
  185. on adjustment.EducationSchedulingAdjustmentID equals teacherList.EducationSchedulingAdjustmentID
  186. join user in UserRepository.Entities on teacherList.UserID equals user.UserID
  187. select new ScheduleAdjustmentTeacherView
  188. {
  189. EducationSchedulingAdjustmentID = adjustment.EducationSchedulingAdjustmentID,
  190. UserID = user.UserID,
  191. LoginID = user.LoginID,
  192. Name = user.Name,
  193. TeachingMethod = teacherList.TeachingMethod
  194. });
  195. return sql;
  196. }
  197. public IQueryable<ES_EducationScheduling> GetEducationSchedulingQueryableByAdjustment(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp)
  198. {
  199. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  200. from scheduling in EducationSchedulingRepository.Entities.Where(x => x.Weekday == adjustment.Weekday
  201. && x.CoursesTimeID == adjustment.CoursesTimeID
  202. && x.EM_EducationSchedulingClass.EducationMissionClassID == adjustment.EducationMissionClassID
  203. && x.ES_EducationSchedulingTeacher.Any(w => w.UserID == adjustment.UserID)
  204. && x.ES_EducationSchedulingWeekNum.Any(w => adjustment.WeekNum == w.WeekNum))
  205. group scheduling by scheduling.EducationSchedulingID into g
  206. select g.FirstOrDefault());
  207. return sql;
  208. }
  209. public IQueryable<ES_EducationScheduling> GetNewEducationSchedulingQueryableByAdjustment(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp)
  210. {
  211. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  212. from scheduling in EducationSchedulingRepository.Entities.Where(x => x.Weekday == adjustment.ToWeekday
  213. && x.CoursesTimeID == adjustment.ToCoursesTimeID
  214. && x.EM_EducationSchedulingClass.EducationMissionClassID == adjustment.EducationMissionClassID
  215. && x.ES_EducationSchedulingTeacher.Any(w => w.UserID == adjustment.ToUserID)
  216. && x.ES_EducationSchedulingWeekNum.Any(w => adjustment.ToWeekNum == w.WeekNum))
  217. group scheduling by scheduling.EducationSchedulingID into g
  218. select g.FirstOrDefault());
  219. return sql;
  220. }
  221. public IQueryable<ES_EducationSchedulingWeekNum> GetEducationSchedulingWeekNumQueryableByAdjustment(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp)
  222. {
  223. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  224. from scheduling in EducationSchedulingRepository.Entities.Where(x => x.Weekday == adjustment.Weekday
  225. && x.CoursesTimeID == adjustment.CoursesTimeID
  226. && x.EM_EducationSchedulingClass.EducationMissionClassID == adjustment.EducationMissionClassID
  227. && x.ES_EducationSchedulingTeacher.Any(w => w.UserID == adjustment.UserID)
  228. && x.ES_EducationSchedulingWeekNum.Any(w => adjustment.WeekNum == w.WeekNum))
  229. from weekNum in scheduling.ES_EducationSchedulingWeekNum
  230. group weekNum by weekNum.EducationSchedulingWeekNumID into g
  231. select g.FirstOrDefault());
  232. return sql;
  233. }
  234. public IQueryable<ES_EducationSchedulingWeekNum> GetNewEducationSchedulingWeekNumQueryableByAdjustment(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp)
  235. {
  236. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  237. from scheduling in EducationSchedulingRepository.Entities.Where(x => x.Weekday == adjustment.ToWeekday
  238. && x.CoursesTimeID == adjustment.ToCoursesTimeID
  239. && x.EM_EducationSchedulingClass.EducationMissionClassID == adjustment.EducationMissionClassID
  240. && x.ES_EducationSchedulingTeacher.Any(w => w.UserID == adjustment.ToUserID)
  241. && x.ES_EducationSchedulingWeekNum.Any(w => adjustment.ToWeekNum == w.WeekNum))
  242. from weekNum in scheduling.ES_EducationSchedulingWeekNum
  243. group weekNum by weekNum.EducationSchedulingWeekNumID into g
  244. select g.FirstOrDefault());
  245. return sql;
  246. }
  247. public IQueryable<ES_EducationSchedulingTeacher> GetEducationSchedulingTeacherQueryableByAdjustment(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp)
  248. {
  249. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  250. from scheduling in EducationSchedulingRepository.Entities.Where(x => x.Weekday == adjustment.Weekday
  251. && x.CoursesTimeID == adjustment.CoursesTimeID
  252. && x.EM_EducationSchedulingClass.EducationMissionClassID == adjustment.EducationMissionClassID
  253. && x.ES_EducationSchedulingTeacher.Any(w => w.UserID == adjustment.UserID)
  254. && x.ES_EducationSchedulingWeekNum.Any(w => adjustment.WeekNum == w.WeekNum))
  255. from teacher in scheduling.ES_EducationSchedulingTeacher
  256. group teacher by teacher.EducationSchedulingTeacherID into g
  257. select g.FirstOrDefault());
  258. return sql;
  259. }
  260. public IQueryable<ES_EducationSchedulingTeacher> GetNewEducationSchedulingTeacherQueryableByAdjustment(Expression<Func<ES_EducationSchedulingAdjustment, bool>> exp)
  261. {
  262. var sql = (from adjustment in EducationSchedulingAdjustmentRepository.GetList(exp)
  263. from scheduling in EducationSchedulingRepository.Entities.Where(x => x.Weekday == adjustment.ToWeekday
  264. && x.CoursesTimeID == adjustment.ToCoursesTimeID
  265. && x.EM_EducationSchedulingClass.EducationMissionClassID == adjustment.EducationMissionClassID
  266. && x.ES_EducationSchedulingTeacher.Any(w => w.UserID == adjustment.ToUserID)
  267. && x.ES_EducationSchedulingWeekNum.Any(w => adjustment.ToWeekNum == w.WeekNum))
  268. from teacher in scheduling.ES_EducationSchedulingTeacher
  269. group teacher by teacher.EducationSchedulingTeacherID into g
  270. select g.FirstOrDefault());
  271. return sql;
  272. }
  273. }
  274. }