MinorControlServices.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.MinorManage.MinorSetting;
  7. using EMIS.ViewModel;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using Bowin.Common.Linq;
  11. using EMIS.DataLogic.MinorManage.MinorSetting;
  12. namespace EMIS.CommonLogic.MinorManage.MinorSetting
  13. {
  14. public class MinorControlServices : BaseServices, IMinorControlServices
  15. {
  16. public MinorControlDAL minorControlDAL { get; set; }
  17. /// <summary>
  18. /// 获取辅修控制列表
  19. /// </summary>
  20. /// <param name="configuretView"></param>
  21. /// <param name="schoolyearID"></param>
  22. /// <param name="GradeyearID"></param>
  23. /// <param name="collegeID"></param>
  24. /// <param name="pageIndex"></param>
  25. /// <param name="pageSize"></param>
  26. /// <returns></returns>
  27. public IGridResultSet<MinorControlView> GetMinorControlViewList(ConfiguretView configuretView, Guid? schoolyearID, int? GradeyearID, Guid? collegeID, int pageIndex, int pageSize)
  28. {
  29. Expression<Func<ER_MinorControl, bool>> exp = x => true;
  30. if (schoolyearID.HasValue)
  31. {
  32. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  33. }
  34. if (GradeyearID.HasValue)
  35. {
  36. exp = exp.And(x => x.GradeyearID == GradeyearID);
  37. }
  38. if (collegeID.HasValue)
  39. {
  40. exp = exp.And(x => x.CollegeID == collegeID);
  41. }
  42. var query = minorControlDAL.GetMinorControlViewQueryable(exp);
  43. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  44. {
  45. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  46. }
  47. query = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.StartDate);
  48. return query.ToGridResultSet<MinorControlView>(pageIndex, pageSize);
  49. }
  50. /// <summary>
  51. /// 查询对应的辅修控制信息
  52. /// </summary>
  53. /// <param name="retakeOpenControlID"></param>
  54. /// <returns></returns>
  55. public MinorControlView GetMinorControlView(Guid? minorControlID)
  56. {
  57. var query = minorControlDAL.GetMinorControlViewQueryable(x => x.MinorControlID == minorControlID);
  58. return query.FirstOrDefault();
  59. }
  60. /// <summary>
  61. /// 辅修控制编辑(新增、修改)
  62. /// </summary>
  63. /// <param name="retakeOpenControlView"></param>
  64. public void MinorControlEdit(MinorControlView minorControlView)
  65. {
  66. try
  67. {
  68. ER_MinorControl minorControl = new ER_MinorControl();
  69. if (minorControlView.MinorControlID == null || minorControlView.MinorControlID == Guid.Empty)
  70. {
  71. //新增、复制新增
  72. minorControl = minorControlDAL.minorControlRepository
  73. .GetSingle(x => x.SchoolyearID == minorControlView.SchoolyearID && x.CollegeID == minorControlView.CollegeID && x.GradeyearID == minorControlView.GradeYearID);
  74. if (minorControl != null)
  75. {
  76. throw new Exception("院系所下已存在相同学年学期的辅修控制信息");
  77. }
  78. minorControl = new ER_MinorControl();
  79. minorControl.MinorControlID = Guid.NewGuid();
  80. minorControl.SchoolyearID = minorControlView.SchoolyearID;
  81. minorControl.GradeyearID = minorControlView.GradeYearID;
  82. minorControl.CollegeID = minorControlView.CollegeID;
  83. minorControl.StartDate = minorControlView.StartDate;
  84. minorControl.EndDate = minorControlView.EndDate;
  85. SetNewStatus(minorControl);
  86. UnitOfWork.Add(minorControl);
  87. }
  88. else
  89. {
  90. //修改
  91. minorControl = minorControlDAL.minorControlRepository
  92. .GetSingle(x => x.MinorControlID != minorControlView.MinorControlID
  93. && x.SchoolyearID == minorControlView.SchoolyearID && x.CollegeID == minorControlView.CollegeID && x.GradeyearID == minorControlView.GradeYearID);
  94. if (minorControl != null)
  95. {
  96. throw new Exception("院系所下已存在相同学年学期的重修控制信息。");
  97. }
  98. minorControl = minorControlDAL.minorControlRepository
  99. .GetSingle(x => x.MinorControlID == minorControlView.MinorControlID);
  100. if (minorControl == null)
  101. {
  102. throw new Exception("数据有误,请核查。");
  103. }
  104. minorControl.SchoolyearID = minorControlView.SchoolyearID;
  105. minorControl.GradeyearID = minorControlView.GradeYearID;
  106. minorControl.CollegeID = minorControlView.CollegeID;
  107. minorControl.StartDate = minorControlView.StartDate;
  108. minorControl.EndDate = minorControlView.EndDate;
  109. SetModifyStatus(minorControl);
  110. }
  111. UnitOfWork.Commit();
  112. }
  113. catch (Exception ex)
  114. {
  115. throw new Exception(ex.Message);
  116. }
  117. }
  118. /// <summary>
  119. /// 辅修控制删除
  120. /// </summary>
  121. /// <param name="openControlIDList"></param>
  122. public void MinorControlDelete(IList<Guid?> minorControlIDList)
  123. {
  124. try
  125. {
  126. if (minorControlIDList.Count > 0)
  127. {
  128. UnitOfWork.Delete<ER_MinorControl>(x => minorControlIDList.Contains(x.MinorControlID));
  129. }
  130. }
  131. catch (Exception ex)
  132. {
  133. throw new Exception(ex.Message);
  134. }
  135. }
  136. }
  137. }