OpenControlSettingServices.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.SelectCourse;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using Bowin.Common.Linq.Entity;
  9. using Bowin.Common.Linq;
  10. using EMIS.ViewModel.SelectCourse;
  11. using EMIS.ViewModel;
  12. namespace EMIS.CommonLogic.SelectCourse
  13. {
  14. public class OpenControlSettingServices : BaseServices, IOpenControlSettingServices
  15. {
  16. public OpenControlSettingDAL OpenControlSettingDAL { get; set; }
  17. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SelectCourse.SelectCourseOpenControlSettingView>
  18. GetOpenControlSettingViewList(ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? campusID, Guid? collegeID,
  19. int? yearID, int? standardID, int pageIndex, int pageSize)
  20. {
  21. Expression<Func<EM_SelectCourseOpenControlSetting, bool>> openControlSettingExp = (x => true);
  22. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolYearExp = (x => true);
  23. Expression<Func<CF_Grademajor, bool>> gradeMajorExp = (x => true);
  24. if (schoolYearID.HasValue)
  25. {
  26. openControlSettingExp = openControlSettingExp.And(x => x.SchoolyearID == schoolYearID.Value);
  27. }
  28. if (campusID.HasValue)
  29. {
  30. gradeMajorExp = gradeMajorExp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID.Value);
  31. }
  32. if (collegeID.HasValue)
  33. {
  34. gradeMajorExp = gradeMajorExp.And(x => x.CF_Facultymajor.CollegeID == collegeID.Value);
  35. }
  36. if (yearID.HasValue)
  37. {
  38. gradeMajorExp = gradeMajorExp.And(x => x.GradeID == yearID.Value);
  39. }
  40. if (standardID.HasValue)
  41. {
  42. gradeMajorExp = gradeMajorExp.And(x => x.CF_Facultymajor.StandardID == standardID.Value);
  43. }
  44. IQueryable<ViewModel.SelectCourse.SelectCourseOpenControlSettingView> q =
  45. OpenControlSettingDAL.GetOpenControlSettingView(openControlSettingExp, schoolYearExp, gradeMajorExp)
  46. .OrderByDescending(x => x.SchoolyearCode);
  47. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  48. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  49. return this.GetQueryByDataRangeByCollege(q).ToGridResultSet(pageIndex, pageSize);
  50. }
  51. public IList<ViewModel.SelectCourse.SelectCourseOpenControlSettingView> GetOpenControlSettingViewList(
  52. ViewModel.ConfiguretView configuretView, Guid? schoolYearID, Guid? campusID, Guid? collegeID, int? yearID, int? standardID)
  53. {
  54. Expression<Func<EM_SelectCourseOpenControlSetting, bool>> openControlSettingExp = (x => true);
  55. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolYearExp = (x => true);
  56. Expression<Func<CF_Grademajor, bool>> gradeMajorExp = (x => true);
  57. if (schoolYearID.HasValue)
  58. {
  59. openControlSettingExp = openControlSettingExp.And(x => x.SchoolyearID == schoolYearID.Value);
  60. }
  61. if (campusID.HasValue)
  62. {
  63. gradeMajorExp = gradeMajorExp.And(x => x.CF_Facultymajor.CF_College.CampusID == campusID.Value);
  64. }
  65. if (collegeID.HasValue)
  66. {
  67. gradeMajorExp = gradeMajorExp.And(x => x.CF_Facultymajor.CollegeID == collegeID.Value);
  68. }
  69. if (yearID.HasValue)
  70. {
  71. gradeMajorExp = gradeMajorExp.And(x => x.GradeID == yearID.Value);
  72. }
  73. if (standardID.HasValue)
  74. {
  75. gradeMajorExp = gradeMajorExp.And(x => x.CF_Facultymajor.StandardID == standardID.Value);
  76. }
  77. IQueryable<ViewModel.SelectCourse.SelectCourseOpenControlSettingView> q =
  78. OpenControlSettingDAL.GetOpenControlSettingView(openControlSettingExp, schoolYearExp, gradeMajorExp)
  79. .OrderByDescending(x => x.SchoolyearCode);
  80. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  81. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  82. return this.GetQueryByDataRangeByCollege(q).ToList();
  83. }
  84. public ViewModel.SelectCourse.SelectCourseOpenControlSettingView GetOpenControlSettingViewInfo(Guid? openControlSettingID)
  85. {
  86. return OpenControlSettingDAL.GetOpenControlSettingView((x => x.SelectCourseOpenControlSettingID == openControlSettingID),
  87. (x => true), (x => true)).FirstOrDefault();
  88. }
  89. public void Save(ViewModel.SelectCourse.SelectCourseOpenControlSettingView openControlSetting)
  90. {
  91. var openControlSettingEntity = OpenControlSettingDAL.SelectCourseOpenControlSettingRepository
  92. .GetSingle(x => x.SelectCourseOpenControlSettingID == openControlSetting.SelectCourseOpenControlSettingID);
  93. if (openControlSettingEntity != null)
  94. {
  95. openControlSettingEntity.SchoolyearID = openControlSetting.SchoolyearID;
  96. openControlSettingEntity.GrademajorID = openControlSetting.GrademajorID;
  97. openControlSettingEntity.StartTime = openControlSetting.StartTime;
  98. openControlSettingEntity.EndTime = openControlSetting.EndTime;
  99. openControlSettingEntity.MaxSelectCount = openControlSetting.MaxSelectCount;
  100. openControlSettingEntity.MinSelectCount = openControlSetting.MinSelectCount;
  101. openControlSettingEntity.MaxCredit = openControlSetting.MaxCredit;
  102. openControlSettingEntity.MinCredit = openControlSetting.MinCredit;
  103. openControlSettingEntity.Remark = openControlSetting.Remark;
  104. this.SetModifyStatus(openControlSettingEntity);
  105. }
  106. else
  107. {
  108. openControlSettingEntity = new EM_SelectCourseOpenControlSetting();
  109. openControlSettingEntity.SelectCourseOpenControlSettingID = Guid.NewGuid();
  110. openControlSettingEntity.SchoolyearID = openControlSetting.SchoolyearID;
  111. openControlSettingEntity.GrademajorID = openControlSetting.GrademajorID;
  112. openControlSettingEntity.StartTime = openControlSetting.StartTime;
  113. openControlSettingEntity.EndTime = openControlSetting.EndTime;
  114. openControlSettingEntity.MaxSelectCount = openControlSetting.MaxSelectCount;
  115. openControlSettingEntity.MinSelectCount = openControlSetting.MinSelectCount;
  116. openControlSettingEntity.MaxCredit = openControlSetting.MaxCredit;
  117. openControlSettingEntity.MinCredit = openControlSetting.MinCredit;
  118. openControlSettingEntity.Remark = openControlSetting.Remark;
  119. this.SetNewStatus(openControlSettingEntity);
  120. UnitOfWork.Add(openControlSettingEntity);
  121. }
  122. var valid = OpenControlSettingDAL.SelectCourseOpenControlSettingRepository
  123. .GetSingle(x => x.SchoolyearID == openControlSetting.SchoolyearID &&
  124. x.GrademajorID == openControlSetting.GrademajorID &&
  125. x.SelectCourseOpenControlSettingID != openControlSettingEntity.SelectCourseOpenControlSettingID);
  126. if (valid != null)
  127. throw new Exception("已存在相同的学年学期和年级专业,请核查。");
  128. UnitOfWork.Commit();
  129. }
  130. public void Delete(IList<Guid?> openControlSettingIDList)
  131. {
  132. if (openControlSettingIDList.Count > 0)
  133. {
  134. UnitOfWork.Delete<EM_SelectCourseOpenControlSetting>(x => openControlSettingIDList.Contains(x.SelectCourseOpenControlSettingID));
  135. }
  136. }
  137. /// <summary>
  138. /// 任选控制
  139. /// </summary>
  140. /// <param name="openControlView"></param>
  141. /// <param name="SchoolyearID"></param>
  142. /// <param name="GradeYear"></param>
  143. /// <param name="pageIndex"></param>
  144. /// <param name="pageSize"></param>
  145. /// <returns></returns>
  146. public IGridResultSet<FreeSelectionCouseControlView> GetFreeSelectionCouseControlViewGrid(ViewModel.ConfiguretView openControlView, Guid? SchoolyearID,
  147. int? GradeYear, int pageIndex, int pageSize)
  148. {
  149. Expression<Func<EM_FreeSelectionCourseGradeYearSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  150. if (SchoolyearID.HasValue)
  151. {
  152. exp = exp.And(x => x.SchoolyearID == SchoolyearID);
  153. }
  154. if (GradeYear.HasValue)
  155. {
  156. exp = exp.And(x => x.GradeYear == GradeYear);
  157. }
  158. var q = OpenControlSettingDAL.GetFreeSelectionCouseControlView(exp);
  159. if (!string.IsNullOrEmpty(openControlView.ConditionValue) && !string.IsNullOrEmpty(openControlView.Attribute))
  160. q = q.DynamicWhere(openControlView.Attribute, openControlView.Condition, openControlView.ConditionValue);
  161. return q.OrderBy(x => x.SchoolyearCode).ThenBy(x => x.GradeYear).ToGridResultSet<FreeSelectionCouseControlView>(pageIndex, pageSize);
  162. }
  163. /// <summary>
  164. /// 任选控制
  165. /// </summary>
  166. /// <param name="openControlView"></param>
  167. /// <param name="SchoolyearID"></param>
  168. /// <param name="GradeYear"></param>
  169. /// <returns></returns>
  170. public IList<FreeSelectionCouseControlView> GetFreeSelectionCouseControlList(ViewModel.ConfiguretView openControlView, Guid? SchoolyearID, int? GradeYear)
  171. {
  172. Expression<Func<EM_FreeSelectionCourseGradeYearSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  173. if (SchoolyearID.HasValue)
  174. {
  175. exp = exp.And(x => x.SchoolyearID == SchoolyearID);
  176. }
  177. if (GradeYear.HasValue)
  178. {
  179. exp = exp.And(x => x.GradeYear == GradeYear);
  180. }
  181. var q = OpenControlSettingDAL.GetFreeSelectionCouseControlView(exp);
  182. if (!string.IsNullOrEmpty(openControlView.ConditionValue) && !string.IsNullOrEmpty(openControlView.Attribute))
  183. q = q.DynamicWhere(openControlView.Attribute, openControlView.Condition, openControlView.ConditionValue);
  184. return q.OrderBy(x => x.SchoolyearCode).ThenBy(x => x.GradeYear).ToList();
  185. }
  186. /// <summary>
  187. /// 任选控制
  188. /// </summary>
  189. /// <param name="freeSelectionCouseControlID"></param>
  190. /// <returns></returns>
  191. public ViewModel.SelectCourse.FreeSelectionCouseControlView GetFreeSelectionCouseControlSettingViewInfo(Guid? freeSelectionCouseControlID)
  192. {
  193. return OpenControlSettingDAL.GetFreeSelectionCouseControlView((x => x.FreeSelectionCourseGradeYearSettingID == freeSelectionCouseControlID)).FirstOrDefault();
  194. }
  195. /// <summary>
  196. /// 任选控制
  197. /// </summary>
  198. /// <param name="openControlSetting"></param>
  199. public void FreeSelectionCouseControlSave(ViewModel.SelectCourse.FreeSelectionCouseControlView openControlSetting)
  200. {
  201. var openControlSettingEntity = OpenControlSettingDAL.FreeSelectionCourseGradeYearSettingRepository
  202. .GetSingle(x => x.FreeSelectionCourseGradeYearSettingID == openControlSetting.FreeSelectionCourseGradeYearSettingID);
  203. if (openControlSettingEntity != null)
  204. {
  205. openControlSettingEntity.SchoolyearID = openControlSetting.SchoolyearID;
  206. openControlSettingEntity.GradeYear = openControlSetting.GradeYear;
  207. openControlSettingEntity.StartTime = openControlSetting.StartTime;
  208. openControlSettingEntity.EndTime = openControlSetting.EndTime;
  209. openControlSettingEntity.MaxSelectCount = openControlSetting.MaxSelectCount;
  210. openControlSettingEntity.MinSelectCount = openControlSetting.MinSelectCount;
  211. openControlSettingEntity.MaxCredit = openControlSetting.MaxCredit;
  212. openControlSettingEntity.MinCredit = openControlSetting.MinCredit;
  213. openControlSettingEntity.Remark = openControlSetting.Remark;
  214. this.SetModifyStatus(openControlSettingEntity);
  215. }
  216. else
  217. {
  218. openControlSettingEntity = new EM_FreeSelectionCourseGradeYearSetting();
  219. openControlSettingEntity.FreeSelectionCourseGradeYearSettingID = Guid.NewGuid();
  220. openControlSettingEntity.SchoolyearID = openControlSetting.SchoolyearID;
  221. openControlSettingEntity.GradeYear = openControlSetting.GradeYear;
  222. openControlSettingEntity.StartTime = openControlSetting.StartTime;
  223. openControlSettingEntity.EndTime = openControlSetting.EndTime;
  224. openControlSettingEntity.MaxSelectCount = openControlSetting.MaxSelectCount;
  225. openControlSettingEntity.MinSelectCount = openControlSetting.MinSelectCount;
  226. openControlSettingEntity.MaxCredit = openControlSetting.MaxCredit;
  227. openControlSettingEntity.MinCredit = openControlSetting.MinCredit;
  228. openControlSettingEntity.Remark = openControlSetting.Remark;
  229. this.SetNewStatus(openControlSettingEntity);
  230. UnitOfWork.Add(openControlSettingEntity);
  231. }
  232. var valid = OpenControlSettingDAL.FreeSelectionCourseGradeYearSettingRepository
  233. .GetSingle(x => x.SchoolyearID == openControlSetting.SchoolyearID &&
  234. x.GradeYear == openControlSetting.GradeYear &&
  235. x.FreeSelectionCourseGradeYearSettingID != openControlSettingEntity.FreeSelectionCourseGradeYearSettingID);
  236. if (valid != null)
  237. throw new Exception("已存在相同的学年学期和年级,请核查。");
  238. UnitOfWork.Commit();
  239. }
  240. /// <summary>
  241. /// 任选控制
  242. /// </summary>
  243. /// <param name="openControlSettingIDList"></param>
  244. public void FreeSelectionCouseControlDelete(IList<Guid?> openControlSettingIDList)
  245. {
  246. if (openControlSettingIDList.Count > 0)
  247. {
  248. UnitOfWork.Delete<EM_FreeSelectionCourseGradeYearSetting>(x => openControlSettingIDList.Contains(x.FreeSelectionCourseGradeYearSettingID));
  249. }
  250. }
  251. }
  252. }