ProjectScoreDAL.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using EMIS.DataLogic.Repositories;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel.ScoreManage;
  9. namespace EMIS.DataLogic.ScoreManage
  10. {
  11. public class ProjectScoreDAL
  12. {
  13. public ProjectScoreRepository ProjectScoreRepository { get; set; }
  14. public SchoolyearRepository SchoolyearRepository { get; set; }
  15. public UserRepository UserRepository { get; set; }
  16. public StudentRepository StudentRepository { get; set; }
  17. public ClassmajorRepository ClassmajorRepository { get; set; }
  18. public GrademajorRepository GrademajorRepository { get; set; }
  19. public FacultymajorRepository FacultymajorRepository { get; set; }
  20. public CollegeRepository CollegeRepository { get; set; }
  21. public ExaminationProjectRepository ExaminationProjectRepository { get; set; }
  22. public ExaminationTypeRepository ExaminationTypeRepository { get; set; }
  23. public LevelSettingRepository LevelSettingRepository { get; set; }
  24. public TrainingClassRepository TrainingClassRepository { get; set; }
  25. public ExaminationBatchProjectRepository ExaminationBatchProjectRepository { get; set; }
  26. public ExaminationBatchRepository ExaminationBatchRepository { get; set; }
  27. public ExaminationScoreRepository ExaminationScoreRepository { get; set; }
  28. public CertisfierDistributeRepository CertisfierDistributeRepository { get; set; }
  29. public IQueryable<ProjectScoreView> GetProjectScoreViewQueryable(Expression<Func<ER_ProjectScore, bool>> exp,
  30. Expression<Func<EX_ExaminationProject, bool>> projectExp, Expression<Func<CF_Facultymajor, bool>> facultExp,
  31. Expression<Func<CF_Grademajor, bool>> grademajorExp, Expression<Func<CF_Classmajor, bool>> classmajorExp)
  32. {
  33. var sql = (from score in ProjectScoreRepository.GetList(exp)
  34. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == score.SchoolyearID)
  35. from user in UserRepository.Entities.Where(x => x.UserID == score.UserID)
  36. from student in StudentRepository.Entities.Where(x => x.UserID == user.UserID)
  37. from classmajor in ClassmajorRepository.Entities.Where(classmajorExp).Where(x => x.ClassmajorID == student.ClassmajorID)
  38. from grade in GrademajorRepository.Entities.Where(grademajorExp).Where(x => x.GrademajorID == classmajor.GrademajorID)
  39. from faculty in FacultymajorRepository.Entities.Where(facultExp).Where(x => x.FacultymajorID == grade.FacultymajorID)
  40. from college in CollegeRepository.Entities.Where(x => x.CollegeID == faculty.CollegeID)
  41. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == score.ExaminationProjectID)
  42. from type in ExaminationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  43. from level in LevelSettingRepository.Entities.Where(x => x.LevelSettingID == score.LevelSettingID)
  44. from train in (
  45. from train1 in TrainingClassRepository.Entities
  46. from student1 in train1.CF_Student
  47. from batchProject1 in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == train1.ExaminationBatchProjectID)
  48. from batch1 in ExaminationBatchRepository.Entities.Where(x => x.ExaminationBatchID == batchProject1.ExaminationBatchID)
  49. from schoolyear1 in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch1.SchoolyearID)
  50. where batchProject1.ExaminationProjectID == project.ExaminationProjectID && student1.UserID == score.UserID
  51. orderby new { schoolyear1.Code, batch1.CreateTime, TrainCreateTime = train1.CreateTime }
  52. select train1
  53. ).Take(1).DefaultIfEmpty()
  54. select new ProjectScoreView
  55. {
  56. ProjectScoreID = score.ProjectScoreID,
  57. SchoolyearID = score.SchoolyearID,
  58. SchoolyearCode = schoolyear.Code,
  59. UserID = score.UserID,
  60. UserName = user.Name,
  61. CertificatesType = student.CertificatesType,
  62. IDNumber = student.IDNumber,
  63. CollegeID = faculty.CollegeID,
  64. CollegeName = college.Name,
  65. Year = grade.SchoolyearID,
  66. StandardID = faculty.StandardID,
  67. ClassmajorID = student.ClassmajorID,
  68. ClassmajorName = classmajor.Name,
  69. ExaminationTypeID = project.ExaminationTypeID,
  70. ExaminationTypeName = type.Name,
  71. ExaminationProjectID = score.ExaminationProjectID,
  72. ExaminationProjectName = project.Name,
  73. LevelSettingID = score.LevelSettingID,
  74. LevelName = level.LevelName,
  75. TrainingClassID = train.TrainingClassID,
  76. TrainingClassName = train.Name
  77. });
  78. return sql;
  79. }
  80. public IQueryable<ProjectScoreGenerateScoreView> GetAllExaminationScoreViewByBatchStudent(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  81. Expression<Func<EX_ExaminationProject, bool>> projectExp)
  82. {
  83. var sql = (from batch in ExaminationBatchRepository.GetList(batchExp)
  84. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == batch.ExaminationBatchID)
  85. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  86. from curScore in ExaminationScoreRepository.Entities.Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID)
  87. from user in UserRepository.Entities.Where(x => x.UserID == curScore.UserID)
  88. from allScore in (
  89. from score1 in ExaminationScoreRepository.Entities
  90. from batchProject1 in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == score1.ExaminationBatchProjectID)
  91. from batch1 in ExaminationBatchRepository.Entities.Where(x => x.ExaminationBatchID == batchProject1.ExaminationBatchID)
  92. select new { Score = score1, ProjectID = batchProject1.ExaminationProjectID, UserID = score1.UserID, BatchStartDate = batch1.StartDate }
  93. ).Where(x => x.ProjectID == project.ExaminationProjectID && x.UserID == curScore.UserID)
  94. select new ProjectScoreGenerateScoreView
  95. {
  96. ExaminationScoreID = allScore.Score.ExaminationScoreID,
  97. ExaminationProjectID = project.ExaminationProjectID,
  98. ExaminationSubjectID = allScore.Score.ExaminationSubjectID,
  99. UserID = user.UserID,
  100. Score = allScore.Score.Score,
  101. IsResit = allScore.Score.IsResit,
  102. Expire = allScore.Score.Expire,
  103. BatchStartDate = allScore.BatchStartDate,
  104. ExaminationBatchProjectID = batchProject.ExaminationBatchProjectID,
  105. SchoolYearID = batch.SchoolyearID,
  106. });
  107. return sql;
  108. }
  109. public IQueryable<ProjectScoreGenerateScoreView> GetExaminationScoreViewByBatchStudent(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  110. Expression<Func<EX_ExaminationProject, bool>> projectExp)
  111. {
  112. var nowTime = DateTime.Today;
  113. var sql = (from batch in ExaminationBatchRepository.GetList(batchExp)
  114. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == batch.ExaminationBatchID)
  115. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  116. from score in ExaminationScoreRepository.Entities.Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID)
  117. from user in UserRepository.Entities.Where(x => x.UserID == score.UserID)
  118. select new ProjectScoreGenerateScoreView
  119. {
  120. ExaminationScoreID = score.ExaminationScoreID,
  121. ExaminationProjectID = project.ExaminationProjectID,
  122. ExaminationSubjectID = score.ExaminationSubjectID,
  123. UserID = user.UserID,
  124. Score = score.Score,
  125. IsResit = score.IsResit,
  126. Expire = score.Expire,
  127. BatchStartDate = batch.StartDate
  128. });
  129. return sql;
  130. }
  131. public IQueryable<ProjectScoreDetailView> GetProjectScoreDetailViewQueryable(Expression<Func<ER_ProjectScore, bool>> exp)
  132. {
  133. var sql = (from score in ProjectScoreRepository.GetList(exp)
  134. from batch in ExaminationBatchRepository.Entities
  135. .Where(x => x.SchoolyearID == score.SchoolyearID)
  136. from batchProject in ExaminationBatchProjectRepository.Entities
  137. .Where(x => x.ExaminationBatchID == batch.ExaminationBatchID
  138. && x.ExaminationProjectID == score.ExaminationProjectID)
  139. from examScore in ExaminationScoreRepository.Entities
  140. .Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID
  141. && x.UserID == score.UserID)
  142. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == score.SchoolyearID)
  143. select new ProjectScoreDetailView
  144. {
  145. ExaminationScoreID = examScore.ExaminationScoreID,
  146. ExaminationSubjectID = examScore.ExaminationSubjectID,
  147. Score = examScore.Score,
  148. CreateTime = examScore.CreateTime,
  149. SchoolyearID = schoolyear.SchoolyearID,
  150. SchoolyearCode = schoolyear.Code,
  151. ExaminationBatchID = batch.ExaminationBatchID,
  152. ExaminationBatchName = batch.Name
  153. });
  154. return sql;
  155. }
  156. }
  157. }