LevelSettingSubjectServices.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using Bowin.Common.Linq.Entity;
  2. using EMIS.Entities;
  3. using EMIS.ViewModel;
  4. using EMIS.ViewModel.ExamManage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using Bowin.Common.Linq;
  10. using System.Text;
  11. using EMIS.DataLogic.ExamManage;
  12. using EMIS.DataLogic.SystemDAL;
  13. using EMIS.ViewModel.SystemView;
  14. namespace EMIS.CommonLogic.ExamManage
  15. {
  16. public class LevelSettingSubjectServices: BaseServices, ILevelSettingSubjectServices
  17. {
  18. public LevelSettingSubjectDAL levelSettingSubjectDAL { get; set; }
  19. public DictionaryDAL dictionaryDAL { get; set; }
  20. public IGridResultSet<LevelSettingView> GetLevelSettingViewGrid(ConfiguretView examinationSubjectView, Guid? examinationTypeID, Guid? examinationProjectID, int pageIndex, int pageSize)
  21. {
  22. Expression<Func<EX_ExaminationProject, bool>> erexp = x => true;
  23. if (examinationTypeID.HasValue)
  24. {
  25. erexp = erexp.And(x => x.ExaminationTypeID == examinationTypeID);
  26. }
  27. if (examinationProjectID.HasValue)
  28. {
  29. erexp = erexp.And(x => x.ExaminationProjectID == examinationProjectID);
  30. }
  31. var query = levelSettingSubjectDAL.GetLevelSettingView(erexp);
  32. if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute))
  33. query = query.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue);
  34. return query.OrderBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.LevelName).ToGridResultSet<LevelSettingView>(pageIndex, pageSize);
  35. }
  36. public LevelSettingView GetLevelSettingView(Guid? levelSettingID)
  37. {
  38. var query = levelSettingSubjectDAL.GetLevelSettingSubjectView(levelSettingID);
  39. return query;
  40. }
  41. public void Edit(LevelSettingView levelSettingView, List<LevelSettingSubjectView> levelSettingSubjectViewList)
  42. {
  43. try
  44. {
  45. List<ER_LevelSettingSubject> levelSettingSubjectList = new List<ER_LevelSettingSubject>();
  46. if (!levelSettingView.LevelSettingID.HasValue || levelSettingView.LevelSettingID == Guid.Empty)
  47. {
  48. ER_LevelSetting levelSetting = new ER_LevelSetting();
  49. levelSetting.LevelSettingID = Guid.NewGuid();
  50. levelSetting.ExaminationProjectID = levelSettingView.ExaminationProjectID;
  51. levelSetting.LevelName = levelSettingView.LevelName;
  52. levelSetting.IsPassed = levelSettingView.IsPassedEdit;
  53. levelSetting.IsPassLine = levelSettingView.IsPassLineEdit;
  54. SetNewStatus(levelSetting);
  55. foreach (var levelSettingSubjectView in levelSettingSubjectViewList)
  56. {
  57. ER_LevelSettingSubject levelSettingSubject = new ER_LevelSettingSubject();
  58. levelSettingSubject.LevelSettingSubjectID = Guid.NewGuid();
  59. levelSettingSubject.LevelSettingID = levelSetting.LevelSettingID;
  60. levelSettingSubject.ExaminationSubjectID = levelSettingSubjectView.ExaminationSubjectID;
  61. levelSettingSubject.PassScore = levelSettingSubjectView.PassScore;
  62. SetNewStatus(levelSettingSubject);
  63. levelSettingSubjectList.Add(levelSettingSubject);
  64. //UnitOfWork.Add(levelSettingSubject);
  65. }
  66. UnitOfWork.Add(levelSetting);
  67. UnitOfWork.BulkInsert(levelSettingSubjectList);
  68. UnitOfWork.Commit();
  69. }
  70. else
  71. {
  72. var levelSetting = levelSettingSubjectDAL.levelSettingRepository.GetList(x => x.LevelSettingID == levelSettingView.LevelSettingID).FirstOrDefault();
  73. if (levelSetting == null)
  74. {
  75. throw new Exception("您要修改的记录已被删除或不存在");
  76. }
  77. levelSetting.ExaminationProjectID = levelSettingView.ExaminationProjectID;
  78. levelSetting.LevelName = levelSettingView.LevelName;
  79. levelSetting.IsPassed = levelSettingView.IsPassedEdit;
  80. levelSetting.IsPassLine = levelSettingView.IsPassLineEdit;
  81. SetModifyStatus(levelSetting);
  82. if (levelSettingSubjectViewList.Count > 0)
  83. {
  84. UnitOfWork.Delete<ER_LevelSettingSubject>(x => x.LevelSettingID == levelSetting.LevelSettingID);
  85. foreach (var levelSettingSubjectView in levelSettingSubjectViewList)
  86. {
  87. ER_LevelSettingSubject levelSettingSubject = new ER_LevelSettingSubject();
  88. levelSettingSubject.LevelSettingSubjectID = Guid.NewGuid();
  89. levelSettingSubject.LevelSettingID = levelSetting.LevelSettingID;
  90. levelSettingSubject.ExaminationSubjectID = levelSettingSubjectView.ExaminationSubjectID;
  91. levelSettingSubject.PassScore = levelSettingSubjectView.PassScore;
  92. SetNewStatus(levelSettingSubject);
  93. levelSettingSubjectList.Add(levelSettingSubject);
  94. //UnitOfWork.Add(levelSettingSubject);
  95. }
  96. }
  97. UnitOfWork.BulkInsert(levelSettingSubjectList);
  98. UnitOfWork.Commit();
  99. }
  100. }
  101. catch (Exception)
  102. {
  103. throw;
  104. }
  105. }
  106. public void Delete(List<Guid?> LevelSettingIDList)
  107. {
  108. try
  109. {
  110. var ProjectScoreList = levelSettingSubjectDAL.projectScoreRepository.GetList(x => LevelSettingIDList.Contains(x.LevelSettingID));
  111. if (ProjectScoreList.Count() > 0)
  112. {
  113. throw new Exception("选中的设置有已被使用的记录不能删除");
  114. }
  115. UnitOfWork.Delete<ER_LevelSettingSubject>(x => LevelSettingIDList.Contains(x.LevelSettingID));
  116. UnitOfWork.Delete<ER_LevelSetting>(x => LevelSettingIDList.Contains(x.LevelSettingID));
  117. }
  118. catch (Exception)
  119. {
  120. throw;
  121. }
  122. }
  123. public IGridResultSet<LevelSettingSubjectView> GetLevelSettingSubjectViewGridByID(Guid? levelSettingID, int pageIndex, int pageSize)
  124. {
  125. var query = levelSettingSubjectDAL.GetLevelSettingSubjectViewByLevelID(levelSettingID);
  126. return query.OrderBy(x => x.ExaminationSubjectID).ToGridResultSet<LevelSettingSubjectView>(pageIndex, pageSize);
  127. }
  128. public IGridResultSet<DictionaryItemView> GetExaminationSubjectDicSelect(Guid? examinationProjectID, int pageIndex, int pageSize)
  129. {
  130. var examinationSubjectIDList = levelSettingSubjectDAL.examinationProjectSubjectRepository.Entities.Where(x => x.ExaminationProjectID == examinationProjectID).Select(x => x.ExaminationSubjectID).ToList();
  131. var query = dictionaryDAL.GetDictionaryItemQuery("EX_ExaminationSubject").Where(x => examinationSubjectIDList.Contains(x.Value));
  132. return query.OrderBy(x => x.OrderNo).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
  133. }
  134. public IGridResultSet<DictionaryItemView> GetLevelSettingSubjectViewGridByProjectID(ConfiguretView configuretView, Guid? examinationProjectID, int pageIndex, int pageSize)
  135. {
  136. var LevelSettingSubjectList = levelSettingSubjectDAL.GetLevelSettingSubjectViewByProjectID(examinationProjectID).ToList();
  137. List<int?> subjectIDList = LevelSettingSubjectList.Select(x => x.ExaminationSubjectID).ToList();
  138. var query = from a in levelSettingSubjectDAL.dictionaryItemRepository.GetList(x => x.DictionaryCode == "EX_ExaminationSubject" && subjectIDList.Contains(x.Value))
  139. select new DictionaryItemView
  140. {
  141. DictionaryItemID = a.DictionaryItemID,
  142. DictionaryCode = a.DictionaryCode,
  143. Code = a.Code,
  144. DictionaryName = a.Sys_Dictionary.Name,
  145. Value = a.Value,
  146. IsEditable = a.IsEditable.Value,
  147. IsVisible = a.RecordStatus > 0,
  148. Name = a.Name,
  149. OrderNo = a.OrderNo,
  150. RecordStatus = a.RecordStatus,
  151. };
  152. return query.OrderBy(x => x.Value).ToGridResultSet<DictionaryItemView>(pageIndex, pageSize);
  153. }
  154. }
  155. }