TrainingClassDAL.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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;
  9. using EMIS.ViewModel.EducationManage;
  10. namespace EMIS.DataLogic.EducationManage
  11. {
  12. public class TrainingClassDAL
  13. {
  14. public TrainingClassRepository TrainingClassRepository { get; set; }
  15. public ExaminationBatchProjectRepository ExaminationBatchProjectRepository { get; set; }
  16. public ExaminationBatchRepository ExaminationBatchRepository { get; set; }
  17. public ExaminationProjectRepository ExaminationProjectRepository { get; set; }
  18. public ExaminationTypeRepository ExaminationTypeRepository { get; set; }
  19. public SchoolyearRepository SchoolyearRepository { get; set; }
  20. public ExaminationRegistrationRepository ExaminationRegistrationRepository { get; set; }
  21. public ExaminationProjectFeeTypeRepository ExaminationProjectFeeTypeRepository { get; set; }
  22. public StudentRepository StudentRepository { get; set; }
  23. public StudentContactRepository StudentContactRepository { get; set; }
  24. public UserRepository UserRepository { get; set; }
  25. public ClassmajorRepository ClassmajorRepository { get; set; }
  26. public GrademajorRepository GrademajorRepository { get; set; }
  27. public FacultymajorRepository FacultymajorRepository { get; set; }
  28. public CollegeRepository CollegeRepository { get; set; }
  29. public IQueryable<TrainingClassView> GetTrainingClassViewQueryable(Expression<Func<EM_TrainingClass, bool>> exp,
  30. Expression<Func<EX_ExaminationBatch, bool>> batchExp, Expression<Func<EX_ExaminationProject, bool>> projectExp)
  31. {
  32. var sql = (from train in TrainingClassRepository.GetList(exp)
  33. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == train.ExaminationBatchProjectID)
  34. from batch in ExaminationBatchRepository.Entities.Where(batchExp).Where(x => x.ExaminationBatchID == batchProject.ExaminationBatchID)
  35. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  36. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  37. from type in ExaminationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  38. select new TrainingClassView
  39. {
  40. TrainingClassID = train.TrainingClassID,
  41. SchoolyearID = batch.SchoolyearID,
  42. SchoolyearCode = schoolyear.Code,
  43. ExaminationBatchID = batchProject.ExaminationBatchID,
  44. ExaminationBatchName = batch.Name,
  45. ExaminationBatchCreateTime = batch.CreateTime,
  46. ExaminationTypeID = project.ExaminationTypeID,
  47. ExaminationTypeName = type.Name,
  48. ExaminationProjectID = batchProject.ExaminationProjectID,
  49. ExaminationProjectName = project.Name,
  50. SchoolAreaID = train.SchoolAreaID,
  51. Name = train.Name,
  52. StudentCount = train.CF_Student.Count()
  53. });
  54. return sql;
  55. }
  56. public IQueryable<GenerateTrainingClassView> GetGenerateTrainingClassViewByRegistration(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  57. Expression<Func<EX_ExaminationProject, bool>> projectExp, Expression<Func<CF_Grademajor, bool>> gradeExp)
  58. {
  59. var sql = (from regist in ExaminationRegistrationRepository.Entities
  60. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == regist.ExaminationBatchProjectID)
  61. from batch in ExaminationBatchRepository.Entities.Where(batchExp).Where(x => x.ExaminationBatchID == batchProject.ExaminationBatchID)
  62. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  63. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  64. from feeType in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  65. from student in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  66. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  67. from grade in GrademajorRepository.Entities.Where(gradeExp).Where(x => x.GrademajorID == classmajor.GrademajorID)
  68. from train in student.EM_TrainingClass.Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID).DefaultIfEmpty()
  69. where train.TrainingClassID == null && feeType.IsTrainingFee == true && regist.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid
  70. select new GenerateTrainingClassView
  71. {
  72. SchoolyearID = schoolyear.SchoolyearID,
  73. SchoolyearCode = schoolyear.Code,
  74. ExaminationBatchProjectID = batchProject.ExaminationBatchProjectID,
  75. ExaminationBatchID = batch.ExaminationBatchID,
  76. ExaminationBatchName = batch.Name,
  77. ExaminationProjectID = project.ExaminationProjectID,
  78. ExaminationProjectName = project.Name,
  79. SchoolAreaID = grade.SchoolAreaID,
  80. UserID = student.UserID
  81. }
  82. );
  83. return sql;
  84. }
  85. public IQueryable<TrainingClassStudentView> GetTrainingClassStudentViewQueryable(Expression<Func<EM_TrainingClass, bool>> exp, Expression<Func<CF_Facultymajor, bool>> facultExp,
  86. Expression<Func<CF_Grademajor, bool>> grademajorExp, Expression<Func<CF_Classmajor, bool>> classmajorExp, Expression<Func<Sys_User, bool>> userExp,
  87. Expression<Func<CF_Student, bool>> studentExp)
  88. {
  89. var sql = (from train in TrainingClassRepository.GetList(exp)
  90. from trainstudent in train.CF_Student
  91. from student in StudentRepository.Entities.Where(studentExp).Where(x => x.UserID == trainstudent.UserID)
  92. from contact in StudentContactRepository.Entities.Where(x => x.UserID == student.UserID)
  93. from user in UserRepository.Entities.Where(userExp).Where(x => x.UserID == student.UserID)
  94. from classmajor in ClassmajorRepository.Entities.Where(classmajorExp).Where(x => x.ClassmajorID == student.ClassmajorID)
  95. from grade in GrademajorRepository.Entities.Where(grademajorExp).Where(x => x.GrademajorID == classmajor.GrademajorID)
  96. from faculty in FacultymajorRepository.Entities.Where(facultExp).Where(x => x.FacultymajorID == grade.FacultymajorID)
  97. from college in CollegeRepository.Entities.Where(x => x.CollegeID == faculty.CollegeID)
  98. select new TrainingClassStudentView
  99. {
  100. UserID = student.UserID,
  101. SchoolAreaID = grade.SchoolAreaID,
  102. CollegeID = college.CollegeID,
  103. CollegeName = college.Name,
  104. GrademajorID = grade.GrademajorID,
  105. Year = grade.SchoolyearID,
  106. ClassmajorID = classmajor.ClassmajorID,
  107. ClassmajorName = classmajor.Name,
  108. UserName = user.Name,
  109. Sex = student.Sex,
  110. CertificatesType = student.CertificatesType,
  111. IDNumber = student.IDNumber,
  112. Mobile = contact.Mobile
  113. });
  114. return sql;
  115. }
  116. public IQueryable<TrainingClassExportView> GetTrainingClassExportViewQueryable(Expression<Func<EM_TrainingClass, bool>> exp,
  117. Expression<Func<EX_ExaminationBatch, bool>> batchExp, Expression<Func<EX_ExaminationProject, bool>> projectExp)
  118. {
  119. var sql = (from train in TrainingClassRepository.GetList(exp)
  120. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == train.ExaminationBatchProjectID)
  121. from batch in ExaminationBatchRepository.Entities.Where(batchExp).Where(x => x.ExaminationBatchID == batchProject.ExaminationBatchID)
  122. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  123. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  124. from type in ExaminationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  125. from student in train.CF_Student
  126. from contact in StudentContactRepository.Entities.Where(x => x.UserID == student.UserID)
  127. from user in UserRepository.Entities.Where(x => x.UserID == student.UserID)
  128. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  129. from grade in GrademajorRepository.Entities.Where(x => x.GrademajorID == classmajor.GrademajorID)
  130. select new TrainingClassExportView
  131. {
  132. TrainingClassID = train.TrainingClassID,
  133. SchoolyearID = batch.SchoolyearID,
  134. SchoolyearCode = schoolyear.Code,
  135. ExaminationBatchID = batchProject.ExaminationBatchID,
  136. ExaminationBatchName = batch.Name,
  137. ExaminationBatchCreateTime = batch.CreateTime,
  138. ExaminationTypeID = project.ExaminationTypeID,
  139. ExaminationTypeName = type.Name,
  140. ExaminationProjectID = batchProject.ExaminationProjectID,
  141. ExaminationProjectName = project.Name,
  142. UserID = student.UserID,
  143. GrademajorID = grade.GrademajorID,
  144. Year = grade.SchoolyearID,
  145. ClassmajorID = classmajor.ClassmajorID,
  146. ClassmajorName = classmajor.Name,
  147. UserName = user.Name,
  148. Sex = student.Sex,
  149. CertificatesType = student.CertificatesType,
  150. IDNumber = student.IDNumber,
  151. Mobile = contact.Mobile,
  152. Name = train.Name
  153. });
  154. return sql;
  155. }
  156. public IQueryable<TrainingClassSplitView> GetTrainingClassSplitViewQueryable(Expression<Func<EM_TrainingClass, bool>> exp)
  157. {
  158. var sql = (from train in TrainingClassRepository.GetList(exp)
  159. select new TrainingClassSplitView
  160. {
  161. TrainingClassID = train.TrainingClassID,
  162. Name = train.Name,
  163. StudentCount = train.CF_Student.Count(),
  164. ClassmajorCount = train.CF_Student.Select(x => x.ClassmajorID).Distinct().Count()
  165. });
  166. return sql;
  167. }
  168. }
  169. }