ProjectRecordDAL.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.SupervisionManage;
  6. using EMIS.DataLogic.Repositories;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.SupervisionManage
  11. {
  12. public class ProjectRecordDAL
  13. {
  14. public ProjectRecordRepository ProjectRecordRepository { get; set; }
  15. public SupervisionCollegeRepository SupervisionCollegeRepository { get; set; }
  16. public ClassmajorRepository ClassmajorRepository { get; set; }
  17. public CoursematerialRepository CoursematerialRepository { get; set; }
  18. public CoursesTimeRepository CoursesTimeRepository { get; set; }
  19. public UserRepository UserRepository { get; set; }
  20. public StaffRepository StaffRepository { get; set; }
  21. public SchoolyearRepository SchoolyearRepository { get; set; }
  22. public CollegeRepository CollegeRepository { get; set; }
  23. public IQueryable<ProjectRecordView> GetProjectRecordViewQueryable(Expression<Func<SUP_ProjectRecord, bool>> exp, Expression<Func<CF_Staff, bool>> supervisorExp, Guid? UserID, Guid? CollegeID)
  24. {
  25. if (UserID.HasValue)
  26. {
  27. if (CollegeID.HasValue)
  28. {
  29. var sql = (from record in ProjectRecordRepository.GetList(exp)
  30. join schoolyear in SchoolyearRepository.Entities
  31. on record.SchoolyearID equals schoolyear.SchoolyearID
  32. join supcollege in SupervisionCollegeRepository.Entities
  33. on record.SupervisionCollegeID equals supcollege.SupervisionCollegeID
  34. join time in CoursesTimeRepository.Entities
  35. on record.CoursesTimeID equals time.CoursesTimeID
  36. join creator in UserRepository.Entities
  37. on record.CreateUserID equals creator.UserID
  38. from cresta in StaffRepository.Entities.Where(x => x.UserID == creator.UserID).DefaultIfEmpty().Where(supervisorExp)
  39. join staff in StaffRepository.Entities
  40. on record.UserID equals staff.UserID
  41. into dsta
  42. from sta in dsta.DefaultIfEmpty()
  43. where record.SUP_ProjectRecord_CF_Staff.Where(w => w.UserID == UserID).Select(x => x.UserID).ToList().Contains((Guid)UserID)
  44. || record.SUP_ProjectRecord_CF_Staff.Where(w => w.CollegeID == CollegeID).Select(x => x.CollegeID).ToList().Contains((Guid)CollegeID)
  45. select new ProjectRecordView
  46. {
  47. ProjectRecordID = record.ProjectRecordID,
  48. ProjectDate = record.ProjectDate,
  49. Location = record.Location,
  50. SchoolyearID = schoolyear.SchoolyearID,
  51. SchoolyearCode = schoolyear.Code,
  52. CollegeID = cresta.CollegeID,
  53. CoursematerialID = record.CoursematerialID,
  54. TotalScore = record.TotalScore,
  55. CollegeName = cresta.CF_College.Name,
  56. SupervisionCollegeID = record.SupervisionCollegeID,
  57. SupervisionCollegeName = supcollege.Name,
  58. SupervisionTypeID = record.SupervisionTypeID,
  59. Weekday = record.Weekday,
  60. OtherTarget = record.OtherTarget,
  61. UserID = record.UserID,
  62. UserName = sta.Sys_User.Name,
  63. CoursesTimeID = record.CoursesTimeID,
  64. CreateTime = record.CreateTime,
  65. StartTimes = time.StartTimes,
  66. EndTimes = time.EndTimes,
  67. Content = record.Content,
  68. Advise = record.Advise,
  69. CreateUserID = record.CreateUserID,
  70. CreateUserName = creator.Name,
  71. userList = record.SUP_ProjectRecord_CF_Staff.Select(x => x.Sys_User),
  72. ProjectRecordAttachmentList = record.SUP_ProjectRecordAttachment,
  73. });
  74. return sql;
  75. }
  76. else
  77. {
  78. var sql = (from record in ProjectRecordRepository.GetList(exp)
  79. join schoolyear in SchoolyearRepository.Entities
  80. on record.SchoolyearID equals schoolyear.SchoolyearID
  81. join supcollege in SupervisionCollegeRepository.Entities
  82. on record.SupervisionCollegeID equals supcollege.SupervisionCollegeID
  83. join time in CoursesTimeRepository.Entities
  84. on record.CoursesTimeID equals time.CoursesTimeID
  85. join creator in UserRepository.Entities
  86. on record.CreateUserID equals creator.UserID
  87. from cresta in StaffRepository.Entities.Where(x => x.UserID == creator.UserID).DefaultIfEmpty().Where(supervisorExp)
  88. join staff in StaffRepository.Entities
  89. on record.UserID equals staff.UserID
  90. into dsta
  91. from sta in dsta.DefaultIfEmpty()
  92. where record.SUP_ProjectRecord_CF_Staff.Where(w => w.UserID == UserID).Select(x => x.UserID).ToList().Contains((Guid)UserID)
  93. select new ProjectRecordView
  94. {
  95. ProjectRecordID = record.ProjectRecordID,
  96. ProjectDate = record.ProjectDate,
  97. Location = record.Location,
  98. SchoolyearID = schoolyear.SchoolyearID,
  99. SchoolyearCode = schoolyear.Code,
  100. CollegeID = cresta.CollegeID,
  101. CoursematerialID = record.CoursematerialID,
  102. TotalScore = record.TotalScore,
  103. CollegeName = cresta.CF_College.Name,
  104. SupervisionCollegeID = record.SupervisionCollegeID,
  105. SupervisionCollegeName = supcollege.Name,
  106. SupervisionTypeID = record.SupervisionTypeID,
  107. Weekday = record.Weekday,
  108. OtherTarget = record.OtherTarget,
  109. UserID = record.UserID,
  110. UserName = sta.Sys_User.Name,
  111. CoursesTimeID = record.CoursesTimeID,
  112. CreateTime = record.CreateTime,
  113. StartTimes = time.StartTimes,
  114. EndTimes = time.EndTimes,
  115. Content = record.Content,
  116. Advise = record.Advise,
  117. CreateUserID = record.CreateUserID,
  118. CreateUserName = creator.Name,
  119. userList = record.SUP_ProjectRecord_CF_Staff.Select(x => x.Sys_User),
  120. ProjectRecordAttachmentList = record.SUP_ProjectRecordAttachment,
  121. });
  122. return sql;
  123. }
  124. }
  125. else
  126. {
  127. var sql = (from record in ProjectRecordRepository.GetList(exp)
  128. join schoolyear in SchoolyearRepository.Entities
  129. on record.SchoolyearID equals schoolyear.SchoolyearID
  130. join supcollege in SupervisionCollegeRepository.Entities
  131. on record.SupervisionCollegeID equals supcollege.SupervisionCollegeID
  132. join time in CoursesTimeRepository.Entities
  133. on record.CoursesTimeID equals time.CoursesTimeID
  134. join creator in UserRepository.Entities
  135. on record.CreateUserID equals creator.UserID
  136. from cresta in StaffRepository.Entities.Where(x => x.UserID == creator.UserID).DefaultIfEmpty().Where(supervisorExp)
  137. join staff in StaffRepository.Entities
  138. on record.UserID equals staff.UserID
  139. into dsta
  140. from sta in dsta.DefaultIfEmpty()
  141. select new ProjectRecordView
  142. {
  143. ProjectRecordID = record.ProjectRecordID,
  144. ProjectDate = record.ProjectDate,
  145. Location = record.Location,
  146. SchoolyearID = schoolyear.SchoolyearID,
  147. SchoolyearCode = schoolyear.Code,
  148. CollegeID = creator.CF_Staff.CollegeID,
  149. CoursematerialID = record.CoursematerialID,
  150. TotalScore = record.TotalScore,
  151. CollegeName = cresta.CF_College.Name,
  152. SupervisionCollegeID = record.SupervisionCollegeID,
  153. SupervisionCollegeName = supcollege.Name,
  154. SupervisionTypeID = record.SupervisionTypeID,
  155. Weekday = record.Weekday,
  156. OtherTarget = record.OtherTarget,
  157. UserID = record.UserID,
  158. UserName = sta.Sys_User.Name,
  159. CoursesTimeID = record.CoursesTimeID,
  160. CreateTime = record.CreateTime,
  161. StartTimes = time.StartTimes,
  162. EndTimes = time.EndTimes,
  163. Content = record.Content,
  164. Advise = record.Advise,
  165. CreateUserID = record.CreateUserID,
  166. CreateUserName = creator.Name,
  167. userList = record.SUP_ProjectRecord_CF_Staff.Select(x => x.Sys_User),
  168. ProjectRecordAttachmentList = record.SUP_ProjectRecordAttachment,
  169. });
  170. return sql;
  171. }
  172. }
  173. public IQueryable<ProjectRecordTeacherView> GetDefaultTeacherView(Guid? userID)
  174. {
  175. var query = from sta in StaffRepository.GetList(x => x.UserID == userID)
  176. select new ProjectRecordTeacherView
  177. {
  178. //ProjectRecordID = pro.ProjectRecordID,
  179. //TeacherID = staff.UserID,
  180. UserID = sta.UserID,
  181. LoginID = sta.Sys_User.LoginID,
  182. Name = sta.Sys_User.Name,
  183. CollegeID = sta.CF_College.CollegeID,
  184. CollegeName = sta.CF_College.Name,
  185. Sex = sta.SexID,
  186. DepartmentID = sta.DepartmentID,
  187. DepartmentName = sta.CF_Department.Name,
  188. BirthDate = sta.BirthDate,
  189. TeacherType = sta.TeacherTypeID,
  190. IncumbencyState = sta.IncumbencyState,
  191. Title = sta.TitleID,
  192. };
  193. return query;
  194. }
  195. public IQueryable<ProjectRecordTeacherView> GetProjectRecordTeacherView(Guid? projectRecordID)
  196. {
  197. var query = from pro in ProjectRecordRepository.GetList(x => x.ProjectRecordID == projectRecordID)
  198. from staff in pro.SUP_ProjectRecord_CF_Staff
  199. join sta in StaffRepository.Entities
  200. on staff.UserID equals sta.UserID
  201. select new ProjectRecordTeacherView
  202. {
  203. ProjectRecordID = pro.ProjectRecordID,
  204. TeacherID = staff.UserID,
  205. UserID = sta.UserID,
  206. LoginID = sta.Sys_User.LoginID,
  207. Name = sta.Sys_User.Name,
  208. CollegeID = sta.CF_College.CollegeID,
  209. CollegeName = sta.CF_College.Name,
  210. Sex = sta.SexID,
  211. DepartmentID = sta.DepartmentID,
  212. DepartmentName = sta.CF_Department.Name,
  213. BirthDate = sta.BirthDate,
  214. TeacherType = sta.TeacherTypeID,
  215. IncumbencyState = sta.IncumbencyState,
  216. Title = sta.TitleID,
  217. };
  218. return query;
  219. }
  220. public IOrderedQueryable<FileUploadView> GetProjectRecordAttachmentView(Expression<Func<SUP_ProjectRecord, bool>> exp)
  221. {
  222. var tableName = typeof(SUP_ProjectRecordAttachment).Name;
  223. var sql = (from @group in ProjectRecordRepository.GetList(exp)
  224. from attachment in @group.SUP_ProjectRecordAttachment
  225. orderby attachment.CreateTime descending
  226. select new FileUploadView
  227. {
  228. FileID = attachment.ProjectRecordAttachmentID,
  229. FileName = attachment.Name,
  230. FileUrl = attachment.Url,
  231. FormID = attachment.ProjectRecordID,
  232. TableName = tableName
  233. });
  234. return (IOrderedQueryable<FileUploadView>)sql;
  235. }
  236. }
  237. }