CertisfierDistributeDAL.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.CerificateManage;
  10. namespace EMIS.DataLogic.CerificateManage
  11. {
  12. public class CertisfierDistributeDAL
  13. {
  14. public CertisfierDistributeRepository DistributeRepository { get; set; }
  15. public ProjectScoreRepository ProjectScoreRepository { get; set; }
  16. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  17. public ExaminationProjectRepository ExaminationProjectRepository { get; set; }
  18. public ExaminationProjectSubjectRepository ExaminationProjectSubjectRepository { get; set; }
  19. public ExaminationBatchProjectRepository ExaminationBatchProjectRepository { get; set; }
  20. public ExaminationScoreRepository ExaminationScoreRepository { get; set; }
  21. public LevelSettingRepository LevelSettingRepository { get; set; }
  22. public ExaminationTypeRepository TypeRepository { get; set; }
  23. public StudentRepository StudentRepository { get; set; }
  24. public ClassmajorRepository ClassmajorRepository { get; set; }
  25. public UserRepository UserRepository { get; set; }
  26. public CollegeRepository CollegeRepository { get; set; }
  27. public GrademajorRepository GrademajorRepository { get; set; }
  28. public FacultymajorRepository FacultymajorRepository { get; set; }
  29. //public IQueryable<EMIS.ViewModel.CerificateView> GetList(Expression<Func<ER_CertisfierDistribute, bool>> expDistribute, Expression<Func<CF_College, bool>> expcol,
  30. // Expression<Func<CF_Grademajor, bool>> expgra, Expression<Func<CF_Classmajor, bool>> expcla, Expression<Func<CF_Facultymajor, bool>> expfac)
  31. //{
  32. // var query = from a in ProjectScoreRepository.Entities
  33. // join b in DistributeRepository.GetList(expDistribute) on new { a.ExaminationProjectID, a.UserID } equals new { b.ExaminationProjectID, b.UserID } into bt
  34. // from br in bt.DefaultIfEmpty()
  35. // join dc in DictionaryItemRepository.Entities
  36. // on new { br.RecordStatus, DictionaryCode = typeof(ER_CertisfierDistributeStatus).Name } equals new { RecordStatus = dc.Value, dc.DictionaryCode } into dct
  37. // from dcr in dct.DefaultIfEmpty()
  38. // join c in StudentRepository.Entities on a.UserID equals c.UserID
  39. // join cl in ClassmajorRepository.Entities.Where(expcla) on c.ClassmajorID equals cl.ClassmajorID
  40. // join gra in GrademajorRepository.Entities.Where(expgra) on cl.GrademajorID equals gra.GrademajorID
  41. // join fac in FacultymajorRepository.Entities.Where(expfac) on gra.FacultymajorID equals fac.FacultymajorID
  42. // join col in CollegeRepository.Entities.Where(expcol) on fac.CollegeID equals col.CollegeID
  43. // where a.ER_LevelSetting.IsPassed == true
  44. // select new EMIS.ViewModel.CerificateView
  45. // {
  46. // CertisfierDistributeID = br.CertisfierDistributeID,
  47. // ProjectScoreID = a.ProjectScoreID,
  48. // Schoolyear = a.CF_Schoolyear.Code,
  49. // SchoolYearCode = a.CF_Schoolyear.SchoolyearID,
  50. // ClassName = cl.Name,
  51. // UserID = a.UserID,
  52. // ProjectName = a.EX_ExaminationProject.Name,
  53. // ExaminationProjectID = a.ExaminationProjectID,
  54. // CollegeID = c.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  55. // UserName = c.Sys_User.Name,
  56. // CertificatesType = c.CertificatesType,
  57. // Sex = c.Sex,
  58. // IDNumber = c.IDNumber,
  59. // ClassmajorName = c.CF_Classmajor.Name,
  60. // ClassmajorID = c.ClassmajorID,
  61. // GrademajorName = c.CF_Classmajor.CF_Grademajor.Name,
  62. // CollegeName = c.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.Name,
  63. // Years = c.CF_Classmajor.CF_Grademajor.SchoolyearID.ToString(),
  64. // StandardID = c.CF_Classmajor.CF_Grademajor.CF_Facultymajor.StandardID,
  65. // Address = br.Address,
  66. // ContactIDNo = br.ContactIDNo,
  67. // ContactNo = br.ContactNo,
  68. // MailContactNo = br.ContactNo,
  69. // //Distributer = br.ContactPerson,
  70. // EntrustDistributer = br.ContactPerson,
  71. // ContactPerson = br.ContactPerson,
  72. // DeliveryNoteNo = br.DeliveryNoteNo,
  73. // Distributer = br.Distributer,
  74. // DistributeTime = br.DistributeTime,
  75. // DistributeTypeID = br.DistributeTypeID,
  76. // No = br.No,
  77. // RecordStatus = br.RecordStatus,
  78. // DistributeStateName = dcr == null ? "制证中" : dcr.Name,
  79. // SchoolAreaID = c.CF_Classmajor.CF_Grademajor.SchoolAreaID,
  80. // SaveNo = br.SaveNo,
  81. // };
  82. // return query;
  83. //}
  84. public IQueryable<EMIS.ViewModel.CerificateView> GetCerificateViewListOnlyGenerated(Expression<Func<ER_CertisfierDistribute, bool>> expDistribute, Expression<Func<CF_College, bool>> expcol,
  85. Expression<Func<CF_Grademajor, bool>> expgra, Expression<Func<CF_Classmajor, bool>> expcla, Expression<Func<CF_Facultymajor, bool>> expfac)
  86. {
  87. var query = from b in DistributeRepository.GetList(expDistribute)
  88. from pro in ExaminationProjectRepository.Entities.Where(x => x.ExaminationProjectID == b.ExaminationProjectID)
  89. from c in StudentRepository.Entities.Where(x => x.UserID == b.UserID)
  90. from cla in ClassmajorRepository.Entities.Where(expcla).Where(x => x.ClassmajorID == c.ClassmajorID)
  91. from gra in GrademajorRepository.Entities.Where(expgra).Where(x => x.GrademajorID == cla.GrademajorID)
  92. from fac in FacultymajorRepository.Entities.Where(expfac).Where(x => x.FacultymajorID == gra.FacultymajorID)
  93. from col in CollegeRepository.Entities.Where(expcol).Where(x => x.CollegeID == fac.CollegeID)
  94. select new EMIS.ViewModel.CerificateView
  95. {
  96. CertisfierDistributeID = b.CertisfierDistributeID,
  97. //ProjectScoreID = a.ProjectScoreID,
  98. Schoolyear = b.CF_Schoolyear.Code,
  99. SchoolYearCode = b.CF_Schoolyear.SchoolyearID,
  100. ClassName = cla.Name,
  101. UserID = b.UserID,
  102. ProjectName = pro.Name,
  103. ExaminationProjectID = b.ExaminationProjectID,
  104. CollegeID = col.CollegeID,
  105. UserName = c.Sys_User.Name,
  106. CertificatesType = c.CertificatesType,
  107. Sex = c.Sex,
  108. IDNumber = c.IDNumber,
  109. ClassmajorName = c.CF_Classmajor.Name,
  110. ClassmajorID = c.ClassmajorID,
  111. GrademajorName = gra.Name,
  112. CollegeName = col.Name,
  113. Years = gra.SchoolyearID.ToString(),
  114. StandardID = fac.StandardID,
  115. Address = b.Address,
  116. ContactIDNo = b.ContactIDNo,
  117. ContactNo = b.ContactNo,
  118. MailContactNo = b.ContactNo,
  119. //Distributer = br.ContactPerson,
  120. EntrustDistributer = b.ContactPerson,
  121. ContactPerson = b.ContactPerson,
  122. DeliveryNoteNo = b.DeliveryNoteNo,
  123. Distributer = b.Distributer,
  124. DistributeTime = b.DistributeTime,
  125. DistributeTypeID = b.DistributeTypeID,
  126. No = b.No,
  127. RecordStatus = b.RecordStatus,
  128. SchoolAreaID = gra.SchoolAreaID,
  129. SaveNo = b.SaveNo,
  130. };
  131. return query;
  132. }
  133. public IQueryable<CertificateMobileView> GetCertificateMobileViewQueryable(Expression<Func<ER_ProjectScore, bool>> exp)
  134. {
  135. var sql = (
  136. from projectScore in ProjectScoreRepository.GetList(exp)
  137. from project in ExaminationProjectRepository.Entities.Where(x => x.ExaminationProjectID == projectScore.ExaminationProjectID)
  138. from level in LevelSettingRepository.Entities.Where(x => x.LevelSettingID == projectScore.LevelSettingID)
  139. from distribute in DistributeRepository.Entities.Where(x => x.ExaminationProjectID == project.ExaminationProjectID && x.UserID == projectScore.UserID)
  140. .DefaultIfEmpty()
  141. select new CertificateMobileView
  142. {
  143. ProjectScoreID = projectScore.ProjectScoreID,
  144. ExaminationProjectID = projectScore.ExaminationProjectID,
  145. ExaminationProjectName = project.Name,
  146. LevelSettingID = projectScore.LevelSettingID,
  147. LevelName = level.LevelName,
  148. IsPassed = level.IsPassed,
  149. CertisfierDistributeID = distribute.CertisfierDistributeID,
  150. DistributeTypeID = distribute.DistributeTypeID,
  151. DistributeStatusID = distribute.RecordStatus,
  152. ContactPerson = distribute.ContactPerson,
  153. ContactNo = distribute.ContactNo,
  154. ContactIDNo = distribute.ContactIDNo,
  155. Address = distribute.Address,
  156. DeliveryNoteNo = distribute.DeliveryNoteNo
  157. }
  158. );
  159. return sql;
  160. }
  161. public IQueryable<CertificateMobileScoreView> GetCertificateMobileScoreViewQueryable(Expression<Func<ER_ProjectScore, bool>> exp)
  162. {
  163. var curDate = DateTime.Today;
  164. var sql = (
  165. from projectScore in ProjectScoreRepository.GetList(exp)
  166. from subject in ExaminationProjectSubjectRepository.Entities.Where(x => x.ExaminationProjectID == projectScore.ExaminationProjectID)
  167. from score in (
  168. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationProjectID == projectScore.ExaminationProjectID)
  169. from score in ExaminationScoreRepository.Entities.Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID
  170. && x.UserID == projectScore.UserID && x.ExaminationSubjectID == subject.ExaminationSubjectID
  171. && x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
  172. where !score.Expire.HasValue || score.Expire >= curDate
  173. orderby score.Score descending
  174. select new { batchProject.ExaminationProjectID, score.ExaminationScoreID, score.ExaminationSubjectID, score.Score }
  175. ).Take(1)
  176. select new CertificateMobileScoreView
  177. {
  178. ExaminationScoreID = score.ExaminationScoreID,
  179. ExaminationProjectID = score.ExaminationProjectID,
  180. ExaminationSubjectID = score.ExaminationSubjectID,
  181. Score = score.Score
  182. }
  183. );
  184. return sql;
  185. }
  186. public IQueryable<ER_CertisfierDistribute> GetCertisfierDistributByProjectScore(Expression<Func<ER_ProjectScore, bool>> exp)
  187. {
  188. var sql = (from score in ProjectScoreRepository.GetList(exp)
  189. from distribute in DistributeRepository.Entities.Where(x => x.ExaminationProjectID == score.ExaminationProjectID && x.UserID == score.UserID)
  190. select distribute);
  191. return sql;
  192. }
  193. }
  194. }