ExamineApplyDAL.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.Students;
  7. using EMIS.ViewModel;
  8. using EMIS.ViewModel.ScoreManage;
  9. using EMIS.Entities;
  10. using System.Linq.Expressions;
  11. namespace EMIS.DataLogic.StudentSystem.ExamineApply
  12. {
  13. public class ExamineApplyDAL
  14. {
  15. public StudentRepository StudentRepository { get; set; }
  16. public ExaminationSubjectRepository SubjectRepository { get; set; }
  17. public ExaminationOpenControlRepository OpenControlRepository { get; set; }
  18. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  19. public ExaminationRegistrationRepository RegistrationRepository { get; set; }
  20. public ClassmajorRepository ClassRepository { get; set; }
  21. public GrademajorRepository GradeRepository { get; set; }
  22. public SchoolyearRepository SchoolyearRepository { get; set; }
  23. public SchoolyearRepository schoolyearRepository { get; set; }
  24. public ExaminationSubjectCollegeControlRepository examinationSubjectCollegeControlRepository { get; set; }
  25. public LevelScoreRepository levelScoreRepository { get; set; }
  26. public IList<ExaminationApplyView> GetExaminationSubjectList(Guid UserID)
  27. {
  28. var currentSchoolyear=schoolyearRepository.Entities.Where(x=>x.IsCurrent==true).FirstOrDefault();
  29. var query = from subject in SubjectRepository.Entities
  30. //from ex in subject.EX_ExaminationRegistration
  31. join control in OpenControlRepository.Entities on subject.ExaminationSubjectID equals control.ExaminationSubjectID
  32. into tmp from control in tmp.DefaultIfEmpty()
  33. join student in StudentRepository.GetList(x => x.UserID == UserID) on control.StudentType equals student.StudentType
  34. join cla in ClassRepository.Entities on student.ClassmajorID equals cla.ClassmajorID
  35. join grade in GradeRepository.Entities on cla.GrademajorID equals grade.GrademajorID
  36. join schoolyear in SchoolyearRepository.Entities
  37. on new { Years = grade.GradeID, SchoolcodeID = grade.SemesterID }
  38. equals new { Years = (int?)schoolyear.Years, SchoolcodeID = (int?)schoolyear.SchoolcodeID }
  39. where control.SchoolyearNumID==(currentSchoolyear.Value - schoolyear.Value - (currentSchoolyear.SchoolcodeID == grade.SemesterID ? 0 : 1)) / 2 + 1
  40. join esccr in examinationSubjectCollegeControlRepository.Entities
  41. on subject.ExaminationSubjectID equals esccr.ExaminationSubjectID
  42. into gesccr
  43. from fesccr in gesccr.Where(x => x.FacultymajorID == grade.FacultymajorID && (x.SchoolyearNumID == ((currentSchoolyear.Value - schoolyear.Value - (currentSchoolyear.SchoolcodeID == grade.SemesterID ? 0 : 1)) / 2 + 1) || x.SchoolyearNumID == null)).DefaultIfEmpty()
  44. where fesccr.ExaminationSubjectCollegeControlID == null
  45. select new ExaminationApplyView
  46. {
  47. Name = subject.Name,
  48. ExaminationSubjectID = subject.ExaminationSubjectID,
  49. StartDate = control.StartDate,
  50. EndDate = control.EndDate,
  51. ExaminationDate = subject.ExaminationDate,
  52. PeopleNumLimit = subject.PeopleNumLimit,
  53. Cost = subject.Cost,
  54. Remark = subject.Remark,
  55. RegisterNum = subject.EX_ExaminationRegistration.Where(x => x.ExaminationSchoolyearID == subject.SchoolyearID).Count(),//x => x.SchoolyearID == currentSchoolyear.SchoolyearID改为已选人数统计显示报名表考试学年学期和科目表的考试学年学期相同的总人数
  56. BKCS = subject.EX_ExaminationRegistration.Count,
  57. IsRister = subject.EX_ExaminationRegistration.Any(q => q.UserID == UserID && q.SchoolyearID == currentSchoolyear.SchoolyearID),//
  58. };
  59. return query.ToList();
  60. }
  61. public IList<ExaminationRegisView> GetExaminationRegisterList(Guid UserID)
  62. {
  63. var currentSchoolyear = schoolyearRepository.Entities.Where(x => x.IsCurrent == true).FirstOrDefault();
  64. var query = from register in RegistrationRepository.Entities
  65. join student in StudentRepository.Entities on register.UserID equals student.UserID
  66. join subject in SubjectRepository.Entities on register.ExaminationSubjectID equals subject.ExaminationSubjectID
  67. join CertificatesType in DictionaryItemRepository.Entities on new { CourseTypeID = register.CertificatesType, DictionaryCode = typeof(CF_CertificatesType).Name } equals new { CourseTypeID = CertificatesType.Value, CertificatesType.DictionaryCode }
  68. join cla in ClassRepository.Entities on student.ClassmajorID equals cla.ClassmajorID
  69. join grade in GradeRepository.Entities on cla.GrademajorID equals grade.GrademajorID
  70. join schoolyear in SchoolyearRepository.Entities
  71. on new { Years = grade.GradeID, SchoolcodeID = grade.SemesterID }
  72. equals new { Years = (int?)schoolyear.Years, SchoolcodeID = (int?)schoolyear.SchoolcodeID }
  73. join control in OpenControlRepository.Entities on
  74. new { register.ExaminationSubjectID, student.StudentType, SchoolyearNumID = (currentSchoolyear.Value - schoolyear.Value - (currentSchoolyear.SchoolcodeID == grade.SemesterID ? 0 : 1)) / 2 + 1 }
  75. equals new { control.ExaminationSubjectID, control.StudentType, control.SchoolyearNumID } into dcontrol
  76. from econtrol in dcontrol.DefaultIfEmpty()
  77. join sch in schoolyearRepository.Entities
  78. on register.SchoolyearID equals sch.SchoolyearID
  79. join esch in schoolyearRepository.Entities
  80. on register.ExaminationSchoolyearID equals esch.SchoolyearID
  81. where register.UserID == UserID
  82. //&& register.SchoolyearID == currentSchoolyear.SchoolyearID
  83. select new ExaminationRegisView
  84. {
  85. ExaminationRegistrationID=register.ExaminationRegistrationID,
  86. Name = subject.Name,
  87. ExaminationSubjectID = subject.ExaminationSubjectID,
  88. StartDate = econtrol.StartDate,
  89. EndDate = econtrol.EndDate,
  90. ExaminationDate = subject.ExaminationDate,
  91. PeopleNumLimit = subject.PeopleNumLimit,
  92. Cost = subject.Cost,
  93. //Jishu = subject.EX_ExaminationRegistration.Where(x => x.UserID == UserID).Count(),
  94. Remark = subject.Remark,
  95. CertificatesType = CertificatesType.Name,
  96. IDNumber = register.IDNumber,
  97. SchoolYearID = sch.SchoolyearID,
  98. SchoolYearCode = sch.Code,
  99. ExaminationSchoolYearID = esch.SchoolyearID,
  100. ExaminationSchoolYearCode = esch.Code
  101. };
  102. var result = query.Distinct();
  103. return result.ToList();
  104. }
  105. public List<ExaminationApplyView> GetExaminationApplyView(Guid? ExaminationSubjectID)
  106. {
  107. var currentSchoolyear = schoolyearRepository.Entities.Where(x => x.IsCurrent == true).FirstOrDefault();
  108. var query = from subject in SubjectRepository.GetList(x => x.ExaminationSubjectID == ExaminationSubjectID)
  109. //from ex in subject.EX_ExaminationRegistration
  110. join control in OpenControlRepository.Entities on subject.ExaminationSubjectID equals control.ExaminationSubjectID
  111. into tmp
  112. from control in tmp.DefaultIfEmpty()
  113. select new ExaminationApplyView
  114. {
  115. Name = subject.Name,
  116. ExaminationSubjectID = subject.ExaminationSubjectID,
  117. StartDate = control.StartDate,
  118. EndDate = control.EndDate,
  119. ExaminationDate = subject.ExaminationDate,
  120. PeopleNumLimit = subject.PeopleNumLimit,
  121. Cost = subject.Cost,
  122. Remark = subject.Remark,
  123. RegisterNum = subject.EX_ExaminationRegistration.Where(x => x.ExaminationSchoolyearID == subject.SchoolyearID).Count(),//x => x.SchoolyearID == currentSchoolyear.SchoolyearID改为已选人数统计显示报名表考试学年学期和科目表的考试学年学期相同的总人数
  124. BKCS = subject.EX_ExaminationRegistration.Count,
  125. IsRister = subject.EX_ExaminationRegistration.Any(q => q.SchoolyearID == currentSchoolyear.SchoolyearID),
  126. };
  127. return query.ToList();
  128. }
  129. public IQueryable<LevelScoreView> GetLevelScoreViewAndRegisterList(Expression<Func<ER_LevelScore, bool>> lelexp, Expression<Func<EX_ExaminationRegistration, bool>> erexp)
  130. {
  131. var query = from register in RegistrationRepository.GetList(erexp)
  132. join level in levelScoreRepository.GetList(lelexp)
  133. on new { register.ExaminationSubjectID, SchoolyearID = register.ExaminationSchoolyearID } equals new { level.ExaminationSubjectID, SchoolyearID = level.SchoolyearID }
  134. into re
  135. from dre in re.DefaultIfEmpty()
  136. join schoolyear in schoolyearRepository.Entities
  137. on register.SchoolyearID equals schoolyear.SchoolyearID
  138. join stu in StudentRepository.Entities
  139. on register.UserID equals stu.UserID
  140. join subject in SubjectRepository.Entities
  141. on register.ExaminationSubjectID equals subject.ExaminationSubjectID
  142. select new LevelScoreView
  143. {
  144. ExaminationRegistrationID = register.ExaminationRegistrationID,
  145. LevelScoreID = dre.LevelScoreID,
  146. ExaminationSubjectName = subject.Name,
  147. UserName = stu.Sys_User.Name,
  148. UserID = register.UserID,
  149. LoginID = stu.Sys_User.LoginID,
  150. ExaminationDate = subject.ExaminationDate,
  151. ExaminationDateStr = subject.ExaminationDate.ToString(),
  152. SchoolyearID = register.SchoolyearID,
  153. SchoolyearCode = schoolyear.Code,
  154. ScoreNo = dre.ScoreNo,
  155. TotalScore = dre.TotalScore,
  156. //ValidDate = dre.ValidDate,
  157. Remark = dre.Remark,
  158. };
  159. return query;
  160. }
  161. }
  162. }