ExaminationScoreDAL.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using EMIS.DataLogic.Repositories;
  2. using EMIS.Entities;
  3. using EMIS.ViewModel;
  4. using EMIS.ViewModel.ScoreManage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using System.Text;
  10. namespace EMIS.DataLogic.ScoreManage
  11. {
  12. public class ExaminationScoreDAL
  13. {
  14. public ExaminationScoreRepository examinationScoreRepository { get; set; }
  15. public ExaminationBatchProjectRepository examinationBatchProjectRepository { get; set; }
  16. public ExaminationBatchRepository examinationBatchRepository { get; set; }
  17. public ExaminationProjectRepository examinationProjectRepository { get; set; }
  18. public ExaminationProjectSubjectRepository examinationProjectSubjectRepository { get; set; }
  19. public ExaminationTypeRepository examinationTypeRepository { get; set; }
  20. public UserRepository userRepository { get; set; }
  21. public StudentRepository studentRepository { get; set; }
  22. public ClassmajorRepository classmajorRepository { get; set; }
  23. public GrademajorRepository grademajorRepository { get; set; }
  24. public FacultymajorRepository facultymajorRepository { get; set; }
  25. public CollegeRepository collegeRepository { get; set; }
  26. public SchoolyearRepository schoolyearRepository { get; set; }
  27. public ResitRepository resitRepository { get; set; }
  28. public ProjectScoreRepository projectScoreRepository { get; set; }
  29. public IQueryable<ExaminationScoreView> GetExaminationScoreView(Expression<Func<ER_ExaminationScore, bool>> esexp, Expression<Func<EX_ExaminationBatchProject, bool>> ebrexp,
  30. Expression<Func<EX_ExaminationBatch, bool>> ebexp, Expression<Func<EX_ExaminationProject, bool>> epexp, Expression<Func<CF_Classmajor, bool>> claexp,
  31. Expression<Func<CF_Grademajor, bool>> graexp, Expression<Func<CF_Facultymajor, bool>> facexp, Expression<Func<CF_College, bool>> colexp)
  32. {
  33. var query = from esr in examinationScoreRepository.Entities.Where(esexp)
  34. from ebpr in examinationBatchProjectRepository.Entities.Where(ebrexp).Where(x => x.ExaminationBatchProjectID == esr.ExaminationBatchProjectID)
  35. from ebr in examinationBatchRepository.Entities.Where(ebexp).Where(x => x.ExaminationBatchID == ebpr.ExaminationBatchID)
  36. from sch in schoolyearRepository.Entities.Where(x => x.SchoolyearID == ebr.SchoolyearID)
  37. from epr in examinationProjectRepository.Entities.Where(epexp).Where(x => x.ExaminationProjectID == ebpr.ExaminationProjectID)
  38. from etr in examinationTypeRepository.Entities.Where(x => x.ExaminationTypeID == epr.ExaminationTypeID)
  39. from us in userRepository.Entities.Where(x => x.UserID == esr.UserID)
  40. from stu in studentRepository.Entities.Where(x => x.UserID == esr.UserID)
  41. from cla in classmajorRepository.Entities.Where(claexp).Where(x => x.ClassmajorID == stu.ClassmajorID)
  42. from gra in grademajorRepository.Entities.Where(graexp).Where(x => x.GrademajorID == cla.GrademajorID)
  43. from fac in facultymajorRepository.Entities.Where(facexp).Where(x => x.FacultymajorID == gra.FacultymajorID)
  44. from col in collegeRepository.Entities.Where(colexp).Where(x => x.CollegeID == fac.CollegeID)
  45. select new ExaminationScoreView
  46. {
  47. ExaminationScoreID = esr.ExaminationScoreID,
  48. ExaminationBatchProjectID = esr.ExaminationBatchProjectID,
  49. SchoolyearID = ebr.SchoolyearID,
  50. SchoolyearCode = sch.Code,
  51. ExaminationBatchID = ebpr.ExaminationBatchID,
  52. ExaminationBatchName = ebr.Name,
  53. ExaminationTypeID = epr.ExaminationTypeID,
  54. ExaminationTypeName = etr.Name,
  55. ExaminationProjectID = epr.ExaminationProjectID,
  56. ExaminationProjectName = epr.Name,
  57. ExaminationSubjectID = esr.ExaminationSubjectID,
  58. CollegeID = col.CollegeID,
  59. CollegeName = col.Name,
  60. SchoolyearNumID = gra.SchoolyearID,
  61. StandardID = fac.StandardID,
  62. ClassmajorID = cla.ClassmajorID,
  63. ClassmajorName = cla.Name,
  64. StudentNo = stu.StudentCardNo,
  65. UserID = us.UserID,
  66. UserIDForIDNumber = us.UserID,
  67. UserName = us.Name,
  68. CertificatesType = stu.CertificatesType,
  69. IDNumber = stu.IDNumber,
  70. Score = esr.Score,
  71. Expire = esr.Expire,
  72. CampusID = col.CampusID,
  73. Remark = esr.Remark,
  74. CreateTime = esr.CreateTime,
  75. SchoolAreaID = gra.SchoolAreaID,
  76. };
  77. return query;
  78. }
  79. public IQueryable<ER_ProjectScore> GetProjectScoreByExaminationScore(Expression<Func<ER_ExaminationScore, bool>> exp)
  80. {
  81. var today = DateTime.Today;
  82. var sql = (from score in examinationScoreRepository.GetList(exp)
  83. from batchProject in examinationBatchProjectRepository.Entities.Where(x => score.ExaminationBatchProjectID == x.ExaminationBatchProjectID)
  84. from projectScore in projectScoreRepository.Entities.Where(x => batchProject.ExaminationProjectID == x.ExaminationProjectID && x.UserID == score.UserID)
  85. where score.Expire == null || score.Expire >= today
  86. select projectScore);
  87. return sql;
  88. }
  89. public IQueryable<ExaminationScoreView> GetExaminationScoreViewForProjectScore(Expression<Func<ER_ProjectScore, bool>> exp)
  90. {
  91. var curDate = DateTime.Today;
  92. var query = (
  93. from projectScore in projectScoreRepository.GetList(exp)
  94. from subject in examinationProjectSubjectRepository.Entities.Where(x => x.ExaminationProjectID == projectScore.ExaminationProjectID)
  95. from score in (
  96. from batchProject in examinationBatchProjectRepository.Entities.Where(x => x.ExaminationProjectID == projectScore.ExaminationProjectID)
  97. from score in examinationScoreRepository.Entities.Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID
  98. && x.UserID == projectScore.UserID && x.ExaminationSubjectID == subject.ExaminationSubjectID
  99. && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  100. from batch in examinationBatchRepository.Entities.Where(x => x.ExaminationBatchID == batchProject.ExaminationBatchID)
  101. from schoolyear in schoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  102. from project in examinationProjectRepository.Entities.Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  103. from type in examinationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  104. from user in userRepository.Entities.Where(x => x.UserID == score.UserID)
  105. from student in studentRepository.Entities.Where(x => x.UserID == score.UserID)
  106. from classmajor in classmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  107. from grade in grademajorRepository.Entities.Where(x => x.GrademajorID == classmajor.GrademajorID)
  108. from faculty in facultymajorRepository.Entities.Where(x => x.FacultymajorID == grade.FacultymajorID)
  109. from college in collegeRepository.Entities.Where(x => x.CollegeID == faculty.CollegeID)
  110. where !score.Expire.HasValue || score.Expire >= curDate
  111. orderby score.Score descending
  112. select new ExaminationScoreView
  113. {
  114. ExaminationScoreID = score.ExaminationScoreID,
  115. ExaminationBatchProjectID = score.ExaminationBatchProjectID,
  116. SchoolyearID = batch.SchoolyearID,
  117. SchoolyearCode = schoolyear.Code,
  118. ExaminationBatchID = batchProject.ExaminationBatchID,
  119. ExaminationBatchName = batch.Name,
  120. ExaminationTypeID = project.ExaminationTypeID,
  121. ExaminationTypeName = type.Name,
  122. ExaminationProjectID = project.ExaminationProjectID,
  123. ExaminationProjectName = project.Name,
  124. ExaminationSubjectID = score.ExaminationSubjectID,
  125. CollegeID = college.CollegeID,
  126. CollegeName = college.Name,
  127. SchoolyearNumID = grade.SchoolyearID,
  128. StandardID = faculty.StandardID,
  129. ClassmajorID = classmajor.ClassmajorID,
  130. ClassmajorName = classmajor.Name,
  131. StudentNo = student.StudentCardNo,
  132. UserID = user.UserID,
  133. UserIDForIDNumber = user.UserID,
  134. UserName = user.Name,
  135. CertificatesType = student.CertificatesType,
  136. IDNumber = student.IDNumber,
  137. Score = score.Score,
  138. Expire = score.Expire,
  139. CampusID = college.CampusID,
  140. Remark = score.Remark,
  141. CreateTime = score.CreateTime,
  142. SchoolAreaID = grade.SchoolAreaID,
  143. }
  144. ).Take(1)
  145. select score
  146. );
  147. return query;
  148. }
  149. }
  150. }