ExaminationSubjectDAL.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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.ExaminationApply;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. namespace EMIS.DataLogic.ExaminationApply
  10. {
  11. public class ExaminationSubjectDAL
  12. {
  13. public ExaminationSubjectRepository ExaminationSubjectRepository { get; set; }
  14. public StudentRepository StudentRepository { get; set; }
  15. public ExaminationRegistrationRepository ExaminationRegistrationRepository { get; set; }
  16. public SchoolyearRepository SchoolyearRepository { get; set; }
  17. public ClassmajorRepository classmajorRepository { get; set; }
  18. public GrademajorRepository grademajorRepository { get; set; }
  19. public StudentRepository studentRepository { get; set; }
  20. public IQueryable<ExaminationSubjectView> GetExaminationSubjectView(Expression<Func<EX_ExaminationSubject, bool>> examinationSubjectExpression)
  21. {
  22. var q = (from es in ExaminationSubjectRepository.GetList(examinationSubjectExpression)
  23. join pes in ExaminationSubjectRepository.Entities on es.PreposeSubjectID equals pes.ExaminationSubjectID into dpes
  24. from epes in dpes.DefaultIfEmpty()
  25. orderby es.Name
  26. select new ExaminationSubjectView
  27. {
  28. ExaminationSubjectID = es.ExaminationSubjectID,
  29. ExaminationTypeID = es.ExaminationTypeID,
  30. ExaminationTypeName = es.EX_ExaminationType.Name,
  31. SchoolyearID = es.SchoolyearID,
  32. SchoolyearCode = es.CF_Schoolyear.Code,
  33. ExaminationFormID = es.ExaminationFormID,
  34. ExaminationFormsID=es.ExaminationFormID,
  35. Name = es.Name,
  36. PreposeSubjectID = es.PreposeSubjectID,
  37. PreposeSubjectName = epes.Name,
  38. PreposeScoreLimit = es.PreposeScoreLimit,
  39. ExaminationDate = es.ExaminationDate,
  40. PeopleNumLimit = es.PeopleNumLimit,
  41. Cost = es.Cost,
  42. Remark = es.Remark,
  43. RecordStatus = es.RecordStatus,
  44. CreateUserID = es.CreateUserID,
  45. CreateTime = es.CreateTime,
  46. ModifyUserID = es.ModifyUserID,
  47. ModifyTime = es.ModifyTime
  48. });
  49. return q;
  50. }
  51. public IQueryable<ExaminationSubjectView> GetExaminationSubjectView1(Expression<Func<EX_ExaminationSubject, bool>> examinationSubjectExpression)
  52. {
  53. var q = (from es in ExaminationSubjectRepository.GetList(examinationSubjectExpression).Select(x=>x.Name).Distinct()
  54. //orderby es.Name
  55. select new ExaminationSubjectView
  56. {
  57. Name = es
  58. });
  59. return q;
  60. }
  61. public IQueryable<StudentListView> GetRegistedListView(Expression<Func<EX_ExaminationSubject, bool>> exp,
  62. Expression<Func<CF_Student, bool>> studentExp, Expression<Func<EX_ExaminationRegistration, bool>> exr)
  63. {
  64. var q = (from es in ExaminationSubjectRepository.GetList(exp)
  65. join er in ExaminationRegistrationRepository.GetList(exr) on es.ExaminationSubjectID equals er.ExaminationSubjectID
  66. join year in SchoolyearRepository.Entities on er.ExaminationSchoolyearID equals year.SchoolyearID//换成考试学年学期
  67. join s in StudentRepository.GetList(studentExp) on er.UserID equals s.UserID
  68. group s by new
  69. {
  70. er.ExaminationRegistrationID,
  71. s.UserID,
  72. StudentNo = s.Sys_User.LoginID,
  73. Name = s.Sys_User.Name,
  74. s.SexID,
  75. s.ClassmajorID,
  76. ClassmajorNo = s.CF_Classmajor.No,
  77. ClassmajorName = s.CF_Classmajor.Name,
  78. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  79. CollegeName = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  80. SubjectName = es.Name,
  81. er.CertificatesType,
  82. er.IDNumber,
  83. //exSchoolyearID = er.ExaminationSchoolyearID,
  84. SchoolyearCode = year.Code,
  85. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID,
  86. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem,
  87. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  88. s.CF_Classmajor.CF_Grademajor.GradeID,
  89. StartSchoolyearValue = (s.CF_Classmajor.CF_Grademajor.GradeID.Value * 2) - 1 + (s.CF_Classmajor.CF_Grademajor.SemesterID.Value - 1),
  90. EndSchoolyearValue = es.CF_Schoolyear.Value,
  91. PhotoUrl = s.PhotoUrl,
  92. CardNo = s.CF_StudentAccount.CardNo,
  93. Cost = es.Cost,
  94. IsPay = er.IsPay,
  95. SchoolyearIDGuid = year.SchoolyearID,
  96. ExaminationSubjectID = es.ExaminationSubjectID,
  97. } into g
  98. select new StudentListView
  99. {
  100. ExaminationRegistrationID = g.Key.ExaminationRegistrationID,
  101. CardNo = g.Key.CardNo,
  102. UserID = g.Key.UserID,
  103. StudentNo = g.Key.StudentNo,
  104. Name = g.Key.Name,
  105. Sex = g.Key.SexID,
  106. ClassmajorID = g.Key.ClassmajorID,
  107. ClassmajorNo = g.Key.ClassmajorNo,
  108. ClassmajorName = g.Key.ClassmajorName,
  109. CollegeID = g.Key.CollegeID,
  110. CollegeName = g.Key.CollegeName,
  111. SubjectName = g.Key.SubjectName,
  112. CertificatesType = g.Key.CertificatesType,
  113. IDNumber = g.Key.IDNumber,
  114. EducationID = g.Key.EducationID,
  115. LearnSystem = g.Key.LearnSystem,
  116. StandardID = g.Key.StandardID,
  117. Year = g.Key.GradeID,
  118. SchoolyearNumID = (int?)Math.Ceiling((decimal)(g.Key.EndSchoolyearValue - g.Key.StartSchoolyearValue + 1) / 2),
  119. PhotoUrl = g.Key.PhotoUrl,
  120. RegistedCount = g.Count(),
  121. SchoolyearCode = g.Key.SchoolyearCode,
  122. Cost = g.Key.Cost,
  123. IsPay = g.Key.IsPay == true ? "是" : "否",
  124. SchoolyearID = g.Key.SchoolyearIDGuid,
  125. ExaminationSubjectID = g.Key.ExaminationSubjectID,
  126. }
  127. );
  128. return q;
  129. }
  130. public IQueryable<StudentListView> GetRegistedStudentListView(Expression<Func<EX_ExaminationSubject, bool>> exp,
  131. Expression<Func<CF_Student, bool>> studentExp,
  132. Expression<Func<EX_ExaminationRegistration, bool>> exr)
  133. {
  134. var q = (from es in ExaminationSubjectRepository.GetList(exp)
  135. join er in ExaminationRegistrationRepository.GetList(exr) on es.ExaminationSubjectID equals er.ExaminationSubjectID
  136. join year in SchoolyearRepository.Entities on er.ExaminationSchoolyearID equals year.SchoolyearID//换成考试学年学期
  137. join s in StudentRepository.GetList(studentExp) on er.UserID equals s.UserID
  138. group s by new
  139. {
  140. er.ExaminationRegistrationID,
  141. s.UserID,
  142. StudentNo = s.Sys_User.LoginID,
  143. Name = s.Sys_User.Name,
  144. s.SexID,
  145. s.ClassmajorID,
  146. ClassmajorNo = s.CF_Classmajor.No,
  147. ClassmajorName = s.CF_Classmajor.Name,
  148. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  149. CollegeName = s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  150. SubjectName = es.Name,
  151. er.CertificatesType,
  152. er.IDNumber,
  153. SchoolyearIDGuid = er.SchoolyearID,
  154. SchoolyearCode = year.Code,
  155. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.EducationID,
  156. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.LearnSystem,
  157. s.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  158. s.CF_Classmajor.CF_Grademajor.GradeID,
  159. StartSchoolyearValue = (s.CF_Classmajor.CF_Grademajor.GradeID.Value * 2) - 1 + (s.CF_Classmajor.CF_Grademajor.SemesterID.Value - 1),
  160. EndSchoolyearValue = es.CF_Schoolyear.Value,
  161. PhotoUrl = s.PhotoUrl,
  162. CardNo = s.CF_StudentAccount.CardNo,
  163. Cost = es.Cost,
  164. IsPay = er.IsPay,
  165. ExaminationSchoolyearID = year.SchoolyearID,
  166. ExaminationSubjectID = es.ExaminationSubjectID,
  167. } into g
  168. select new StudentListView
  169. {
  170. ExaminationRegistrationID=g.Key.ExaminationRegistrationID,
  171. CardNo = g.Key.CardNo,
  172. UserID = g.Key.UserID,
  173. StudentNo = g.Key.StudentNo,
  174. Name = g.Key.Name,
  175. Sex = g.Key.SexID,
  176. ClassmajorID = g.Key.ClassmajorID,
  177. ClassmajorNo = g.Key.ClassmajorNo,
  178. ClassmajorName = g.Key.ClassmajorName,
  179. CollegeID = g.Key.CollegeID,
  180. CollegeName = g.Key.CollegeName,
  181. SubjectName = g.Key.SubjectName,
  182. CertificatesType = g.Key.CertificatesType,
  183. IDNumber = g.Key.IDNumber,
  184. EducationID = g.Key.EducationID,
  185. LearnSystem = g.Key.LearnSystem,
  186. StandardID = g.Key.StandardID,
  187. Year = g.Key.GradeID,
  188. SchoolyearNumID = (int?)Math.Ceiling((decimal)(g.Key.EndSchoolyearValue - g.Key.StartSchoolyearValue + 1) / 2),
  189. PhotoUrl = g.Key.PhotoUrl,
  190. RegistedCount = g.Count(),
  191. SchoolyearCode = g.Key.SchoolyearCode,
  192. Cost = g.Key.Cost,
  193. IsPay = g.Key.IsPay == true ? "是":"否",
  194. SchoolyearID = g.Key.SchoolyearIDGuid,
  195. ExaminationSchoolyearID = g.Key.ExaminationSchoolyearID,
  196. ExaminationSubjectID = g.Key.ExaminationSubjectID,
  197. }
  198. );
  199. return q;
  200. }
  201. public IQueryable<ExaminationClassStudentStatisticsView> GetRegistedClassStudentStatisticsListView(Expression<Func<EX_ExaminationRegistration, bool>> exp,
  202. Expression<Func<CF_Student, bool>> studentExp)
  203. {
  204. //var q = (from es in ExaminationSubjectRepository.GetList(exp)
  205. // from er in es.EX_ExaminationRegistration.GroupBy(x => new { x.ExaminationSubjectID,x.UserID}).Select(x=>x.FirstOrDefault())
  206. // join s in StudentRepository.GetList(studentExp) on er.UserID equals s.UserID
  207. // group s by new
  208. // {
  209. // SubjectID = es.ExaminationSubjectID,
  210. // SubjectName = es.Name,
  211. // s.ClassmajorID,
  212. // ClassmajorName = s.CF_Classmajor.Name,
  213. // SchoolyearCode = es.CF_Schoolyear.Code,
  214. // s.CF_Classmajor.CF_Grademajor.GrademajorID,
  215. // GrademajorName = s.CF_Classmajor.CF_Grademajor.Name,
  216. // s.CF_Classmajor.CF_Grademajor.SchoolyearID,
  217. // es.Cost,
  218. // } into g
  219. // select new ExaminationClassStudentStatisticsView
  220. // {
  221. // SubjectID=g.Key.SubjectID,
  222. // SubjectName = g.Key.SubjectName,
  223. // ClassmajorID = g.Key.ClassmajorID,
  224. // ClassmajorName = g.Key.ClassmajorName,
  225. // GrademajorName = g.Key.GrademajorName,
  226. // Year = g.Key.SchoolyearID,
  227. // StudentCount = g.Count(),
  228. // SchoolyearCode = g.Key.SchoolyearCode,
  229. // Cost = g.Key.Cost,
  230. // }
  231. // );
  232. var query = from er in ExaminationRegistrationRepository.GetList(exp)
  233. join ss in SchoolyearRepository.Entities
  234. on er.SchoolyearID equals ss.SchoolyearID
  235. join esch in SchoolyearRepository.Entities
  236. on er.ExaminationSchoolyearID equals esch.SchoolyearID
  237. join stu in studentRepository.GetList(studentExp)
  238. on er.UserID equals stu.UserID
  239. join cla in classmajorRepository.Entities
  240. on stu.ClassmajorID equals cla.ClassmajorID
  241. join gra in grademajorRepository.Entities
  242. on cla.GrademajorID equals gra.GrademajorID
  243. group er by new
  244. {
  245. SchoolyearID = ss.SchoolyearID,
  246. SchoolyearCode = ss.Code,
  247. ExaminationSchoolyearID = esch.SchoolyearID,
  248. ExaminationSchoolyearCode = esch.Code,
  249. stu.ClassmajorID,
  250. ClassName = cla.Name,
  251. cla.GrademajorID,
  252. GrademajorName = gra.Name,
  253. er.ExaminationSubjectID,
  254. SubjectName = er.EX_ExaminationSubject.Name,
  255. Year = gra.GradeID,
  256. er.EX_ExaminationSubject.Cost,
  257. } into g
  258. select new ExaminationClassStudentStatisticsView
  259. {
  260. SubjectID = g.Key.ExaminationSubjectID,
  261. SubjectName = g.Key.SubjectName,
  262. ClassmajorID = g.Key.ClassmajorID,
  263. ClassmajorName = g.Key.ClassName,
  264. GrademajorID = g.Key.GrademajorID,
  265. GrademajorName = g.Key.GrademajorName,
  266. SchoolyearID = g.Key.SchoolyearID,
  267. Year = g.Key.Year,
  268. SchoolyearCode = g.Key.SchoolyearCode,
  269. ExaminationSchoolyearID = g.Key.ExaminationSchoolyearID,
  270. ExaminationSchoolyearCode = g.Key.ExaminationSchoolyearCode,
  271. Cost = g.Key.Cost,
  272. StudentCount = g.Count(),
  273. };
  274. return query;
  275. }
  276. //public IQueryable<ExaminationClassStudentStatisticsView> GetRegistedClassStudentStatisticsListView(Expression<Func<EX_ExaminationSubject, bool>> exp,
  277. // Expression<Func<CF_Student, bool>> studentExp)
  278. //{
  279. // var q = (from es in ExaminationSubjectRepository.GetList(exp)
  280. // from er in es.EX_ExaminationRegistration
  281. // join s in StudentRepository.GetList(studentExp) on er.UserID equals s.UserID
  282. // group s by new
  283. // {
  284. // SubjectID=es.ExaminationSubjectID,
  285. // SubjectName = es.Name,
  286. // s.ClassmajorID,
  287. // ClassmajorName = s.CF_Classmajor.Name,
  288. // SchoolyearCode = es.CF_Schoolyear.Code,
  289. // s.CF_Classmajor.CF_Grademajor.GrademajorID,
  290. // GrademajorName=s.CF_Classmajor.CF_Grademajor.Name,
  291. // s.CF_Classmajor.CF_Grademajor.SchoolyearID,
  292. // es.Cost,
  293. // } into g
  294. // select new ExaminationClassStudentStatisticsView
  295. // {
  296. // SubjectName = g.Key.SubjectName,
  297. // ClassmajorID = g.Key.ClassmajorID,
  298. // ClassmajorName = g.Key.ClassmajorName,
  299. // GrademajorName=g.Key.GrademajorName,
  300. // Year = g.Key.SchoolyearID,
  301. // StudentCount = g.Count(),
  302. // SchoolyearCode = g.Key.SchoolyearCode,
  303. // Cost=g.Key.Cost,
  304. // }
  305. // );
  306. // return q;
  307. //}
  308. public IQueryable<EX_ExaminationRegistration> GetExaminationRegistrationByID(Expression<Func<EX_ExaminationRegistration,bool>> exp)
  309. {
  310. var query = from ex in ExaminationRegistrationRepository.GetList(exp)
  311. select new EX_ExaminationRegistration
  312. {
  313. ExaminationRegistrationID = ex.ExaminationRegistrationID,
  314. ExaminationSubjectID = ex.ExaminationSubjectID,
  315. SchoolyearID = ex.SchoolyearID,
  316. UserID = ex.UserID,
  317. CertificatesType = ex.CertificatesType,
  318. IDNumber = ex.IDNumber,
  319. IsPay = ex.IsPay
  320. };
  321. return query;
  322. }
  323. }
  324. }