ExamineApplyDAL.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.ExaminationApply;
  9. using EMIS.DataLogic.Common.Students;
  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 StudentAccountRepository StudentAccountRepository { get; set; }
  17. public ExaminationProjectRepository examinationProjectRepository { get; set; }
  18. public ExaminationTypeRepository examinationTypeRepository { get; set; }
  19. public ExaminationProjectFeeRepository examinationProjectFeeRepository { get; set; }
  20. public ExaminationProjectFeeTypeRepository examinationProjectFeeTypeRepository { get; set; }
  21. public ExaminationRegistrationRepository examinationRegistrationRepository { get; set; }
  22. public ExaminationProjectCountLimitRepository examinationProjectCountLimitRepository { get; set; }
  23. public ExaminationProjectCollegeControlRepository examinationProjectCollegeControlRepository { get; set; }
  24. public ExaminationBatchProjectPersonControlRepository examinationBatchProjectPersonControlRepository { get; set; }
  25. public ExaminationBatchProjectControlRepository examinationBatchProjectControlRepository { get; set; }
  26. public ExaminationBatchProjectRepository examinationBatchProjectRepository { get; set; }
  27. public ExaminationBatchRepository examinationBatchRepository { get; set; }
  28. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  29. public ClassmajorRepository ClassRepository { get; set; }
  30. public GrademajorRepository GradeRepository { get; set; }
  31. public CollegeRepository CollegeRepository { get; set; }
  32. public FacultymajorRepository FacultymajorRepository { get; set; }
  33. public SchoolyearRepository schoolyearRepository { get; set; }
  34. public ProjectScoreRepository projectScoreRepository { get; set; }
  35. public LevelSettingRepository levelSettingRepository { get; set; }
  36. public StudentsDAL studentsDAL { get; set; }
  37. public IList<ExaminationApplyView> GetExaminationSubjectList(Guid UserID)
  38. {
  39. var currentSchoolyear = schoolyearRepository.Entities.Where(x => x.IsCurrent == true).FirstOrDefault();
  40. var query = from epr in examinationProjectRepository.Entities
  41. from ebpr in examinationBatchProjectRepository.Entities.Where(x => x.ExaminationProjectID == epr.ExaminationProjectID)
  42. from ebp in examinationBatchRepository.Entities.Where(x => x.ExaminationBatchID == ebpr.ExaminationBatchID)
  43. from sch in schoolyearRepository.Entities.Where(x => x.SchoolyearID == ebp.SchoolyearID)
  44. from err in examinationRegistrationRepository.Entities.Where(x => x.ExaminationBatchProjectID == ebpr.ExaminationBatchProjectID && x.UserID == UserID && x.RecordStatus != (int)EX_ExaminationRegistrationStatus.Refunded).DefaultIfEmpty()
  45. from etr in examinationTypeRepository.Entities.Where(x => x.ExaminationTypeID == epr.ExaminationTypeID)
  46. from stu in StudentRepository.Entities.Where(x => x.UserID == UserID)
  47. from cla in ClassRepository.Entities.Where(x => x.ClassmajorID == stu.ClassmajorID)
  48. from gra in GradeRepository.Entities.Where(x => x.GrademajorID == cla.GrademajorID)
  49. //from school in schoolyearRepository.Entities.Where(x => x.Years == gra.SchoolyearID && x.SchoolcodeID == gra.SchoolcodeID)
  50. from fac in FacultymajorRepository.Entities.Where(x => x.FacultymajorID == gra.FacultymajorID)
  51. //from col in CollegeRepository.Entities.Where(x => x.CollegeID == fac.CollegeID)
  52. //门数控制(考试类型控制),若该学生已报考门数大于控制门数,则得到不为空的结果(不可以报名);如果已报考门数小于控制门数,或者没有设置门数控制,则得到为空的结果(可以报名)
  53. from epcl in examinationProjectCountLimitRepository.Entities.Where(x => x.ExaminationTypeID == epr.ExaminationTypeID && x.StandardID == fac.StandardID
  54. && x.SchoolyearNumID == ((currentSchoolyear.Value - gra.CF_Schoolyear.Value - (currentSchoolyear.SchoolcodeID == gra.SchoolcodeID ? 0 : 1)) / 2 + 1)
  55. && x.SubjectCountLimit <= stu.EX_ExaminationRegistration.Count()).DefaultIfEmpty()
  56. //from epccr in examinationProjectCollegeControlRepository.Entities.Where(x => x.ExaminationProjectID == epr.ExaminationProjectID && x.StandardID == fac.StandardID)
  57. from ebpcr in examinationBatchProjectControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == ebpr.ExaminationBatchProjectID && (x.StandardID == fac.StandardID || x.StandardID == null)
  58. && (x.CollegeID == fac.CollegeID || x.CollegeID == null) && (x.SchoolyearID == gra.SchoolyearID || x.SchoolyearID == null)).DefaultIfEmpty()
  59. //from err in examinationRegistrationRepository.Entities.Where(x => x.UserID == UserID && x.ExaminationBatchProjectID == ebpr.ExaminationBatchProjectID)
  60. from ebppcr in examinationBatchProjectPersonControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == ebpr.ExaminationBatchProjectID && x.UserID == UserID).DefaultIfEmpty()
  61. where (epcl.ExaminationSubjectCountLimitID == null && err.ExaminationRegistrationID == null && ebpcr.ExaminationBatchProjectControlID != null)
  62. || (epcl.ExaminationSubjectCountLimitID == null && err.ExaminationRegistrationID == null && ebppcr.ExaminationProjectFeeID != null)
  63. //批次项目控制不为空或者个人报名控制不为空
  64. select new ExaminationApplyView
  65. {
  66. SchoolYearID = ebp.SchoolyearID,
  67. SchoolYearCode = sch.Code,
  68. ExaminationProjectID = epr.ExaminationProjectID,
  69. ExaminationBatchProjectID = ebpr.ExaminationBatchProjectID,
  70. ExaminationTypeID = etr.ExaminationTypeID,
  71. ExaminationTypeName = etr.Name,
  72. ExaminationLevelID = epr.ExaminationLevelID,
  73. ExaminationProjectName = epr.Name,
  74. StartDate = ebppcr.ExaminationBatchProjectPersonControlID != null ? ebppcr.StartDate : ebpr.StartDate,
  75. EndDate = ebppcr.ExaminationBatchProjectPersonControlID != null ? ebppcr.EndDate : ebpr.EndDate,
  76. SimulateTime = ebpr.SimulateTime,
  77. MaxRegistCount = ebpr.MaxRegistCount,
  78. Remark = ebpr.Remark,
  79. RegisterNum = ebpr.EX_ExaminationRegistration.Count(),
  80. ExaminationProjectFeeID = ebppcr.ExaminationProjectFeeID == null ? ebpcr.ExaminationProjectFeeID : ebppcr.ExaminationProjectFeeID,
  81. ExaminationProjectFeeName = ebppcr.ExaminationProjectFeeID == null ? ebpcr.EX_ExaminationProjectFee.Name : ebppcr.EX_ExaminationProjectFee.Name,
  82. TakeCourseTime = ebpr.TakeCourseTime,
  83. Training = ebpr.Training,
  84. BatchRemark = ebp.Remark,
  85. };
  86. return query.Distinct().ToList();
  87. }
  88. public IList<ExaminationRegisView> GetExaminationRegisterList(Guid UserID)
  89. {
  90. var currentSchoolyear = schoolyearRepository.Entities.Where(x => x.IsCurrent == true).FirstOrDefault();
  91. var query = from err in examinationRegistrationRepository.Entities.Where(x => x.UserID == UserID)
  92. from stu in StudentRepository.Entities.Where(x => x.UserID == err.UserID)
  93. from ebpr in examinationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == err.ExaminationBatchProjectID)
  94. from ebp in examinationBatchRepository.Entities.Where(x => x.ExaminationBatchID == ebpr.ExaminationBatchID)
  95. from epr in examinationProjectRepository.Entities.Where(x => x.ExaminationProjectID == ebpr.ExaminationProjectID)
  96. from sch in schoolyearRepository.Entities.Where(x => x.SchoolyearID == ebp.SchoolyearID)
  97. from epftr in examinationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == err.ExaminationProjectFeeTypeID)
  98. from epfr in examinationProjectFeeRepository.Entities.Where(x => x.ExaminationProjectFeeID == epftr.ExaminationProjectFeeID)
  99. from feeTypedic in DictionaryItemRepository.Entities.Where(x => x.DictionaryCode == typeof(EX_ExaminationProjectFeeType).Name && x.Value == epftr.FeeTypeID)
  100. from ebppcr in examinationBatchProjectPersonControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == ebpr.ExaminationBatchProjectID && x.UserID == UserID).DefaultIfEmpty()
  101. select new ExaminationRegisView
  102. {
  103. ExaminationRegistrationID = err.ExaminationRegistrationID,
  104. ExaminationProjectID = epr.ExaminationProjectID,
  105. ExaminationProjectName = epr.Name,
  106. SchoolYearID = sch.SchoolyearID,
  107. SchoolYearCode = sch.Code,
  108. StartDate = ebppcr.ExaminationBatchProjectPersonControlID != null ? ebppcr.StartDate : ebpr.StartDate,
  109. EndDate = ebppcr.ExaminationBatchProjectPersonControlID != null ? ebppcr.EndDate : ebpr.EndDate,
  110. CertificatesType = stu.CertificatesType,
  111. IDNumber = stu.IDNumber,
  112. FeeTypeID = epftr.FeeTypeID,
  113. Fee = epftr.Fee,
  114. ExaminationProjectFeeTypeID = err.ExaminationProjectFeeTypeID,
  115. RecordStatus = err.RecordStatus,
  116. Remark = ebpr.Remark,
  117. BatchRemark = ebp.Remark
  118. };
  119. return query.ToList();
  120. }
  121. public StudentListView GetRegisterViewByExaminationBatchProjectID(Guid? examinationBatchProjectID, Guid? userID)
  122. {
  123. //var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
  124. var student = studentsDAL.GetStudentQueryable(x => x.UserID == userID, x => true, x => true).FirstOrDefault();
  125. var query = from ebpr in examinationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == examinationBatchProjectID)
  126. from ebr in examinationBatchRepository.Entities.Where(x => x.ExaminationBatchID == ebpr.ExaminationBatchID)
  127. from epr in examinationProjectRepository.Entities.Where(x => x.ExaminationProjectID == ebpr.ExaminationProjectID)
  128. from ebpcr in examinationBatchProjectControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == examinationBatchProjectID && (x.SchoolyearID == student.Years || x.SchoolyearID == null) && (x.StandardID == student.StandardID || x.StandardID == null)).DefaultIfEmpty()
  129. from ebppcr in examinationBatchProjectPersonControlRepository.Entities.Where(x => x.ExaminationBatchProjectID == examinationBatchProjectID && x.UserID == userID).DefaultIfEmpty()
  130. select new StudentListView
  131. {
  132. ExaminationBatchProjectID = ebpr.ExaminationBatchProjectID,
  133. SchoolyearID = ebr.SchoolyearID,
  134. SchoolyearCode = ebr.CF_Schoolyear.Code,
  135. ExaminationBatchID = ebr.ExaminationBatchID,
  136. ExaminationBatchName = ebr.Name,
  137. ExaminationProjectID = epr.ExaminationProjectID,
  138. ExaminationProjectName = epr.Name,
  139. ExaminationTypeID = epr.ExaminationTypeID,
  140. ExaminationTypeName = epr.EX_ExaminationType.Name,
  141. StartDate = ebppcr.ExaminationBatchProjectPersonControlID != null ? ebppcr.StartDate : ebpr.StartDate,
  142. EndDate = ebppcr.ExaminationBatchProjectPersonControlID != null ? ebppcr.EndDate : ebpr.EndDate,
  143. Remark = ebpr.Remark,
  144. ExaminationProjectFeeID = ebppcr.ExaminationProjectFeeID == null ? ebpcr.ExaminationProjectFeeID : ebppcr.ExaminationProjectFeeID,
  145. ExaminationProjectFeeName = ebppcr.ExaminationProjectFeeID == null ? ebpcr.EX_ExaminationProjectFee.Name : ebppcr.EX_ExaminationProjectFee.Name
  146. //RegistView = registView,
  147. };
  148. return query.FirstOrDefault();
  149. }
  150. public List<bool?> GetPreposeProjectIsPass(Guid? preposeProjectID, Guid? userID)
  151. {
  152. var query = from epr in examinationProjectRepository.Entities.Where(x => x.ExaminationProjectID == preposeProjectID)
  153. from psr in projectScoreRepository.Entities.Where(x => x.ExaminationProjectID == epr.ExaminationProjectID && x.UserID == userID)
  154. from lsr in levelSettingRepository.Entities.Where(x => x.LevelSettingID == psr.LevelSettingID)
  155. select new
  156. {
  157. ExaminationProjectID = epr.ExaminationProjectID,
  158. ProjectScoreID = psr.ProjectScoreID,
  159. LevelSettingID = lsr.LevelSettingID,
  160. IsPassed = lsr.IsPassed,
  161. };
  162. return query.Select(x => x.IsPassed).ToList();
  163. }
  164. public List<FeeTypeByProjectFeeView> GetFeeTypeByProjectFeeView(Expression<Func<EMIS.Entities.EX_ExaminationProjectFeeType, bool>> epftexp)
  165. {
  166. var query = from epftr in examinationProjectFeeTypeRepository.Entities.Where(epftexp)
  167. from dic in DictionaryItemRepository.Entities.Where(x => x.DictionaryCode == "EX_ExaminationProjectFeeType" && x.Value == epftr.FeeTypeID)
  168. //group dic by epftr.ExaminationProjectFeeID
  169. //into gdic
  170. select new FeeTypeByProjectFeeView
  171. {
  172. ExaminationProjectFeeTypeID = epftr.ExaminationProjectFeeTypeID,
  173. ExaminationProjectFeeID = epftr.ExaminationProjectFeeID,
  174. ExaminationProjectID = epftr.EX_ExaminationProjectFee.ExaminationProjectID,
  175. FeeTypeID = epftr.FeeTypeID,
  176. FeeTypeName = dic.Name + "(" + epftr.Fee + ")",
  177. IsResit = epftr.IsResit,
  178. //String.Join("/n",gdic.Select(x => x.Name).ToArray()),
  179. };
  180. return query.Distinct().ToList();
  181. }
  182. }
  183. }