TypeSettingServices.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using Bowin.Common.Linq.Entity;
  7. using EMIS.DataLogic.SelectCourse;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. namespace EMIS.CommonLogic.SelectCourse
  11. {
  12. public class TypeSettingServices : BaseServices, ITypeSettingServices
  13. {
  14. public TypeSettingDAL TypeSettingDAL { get; set; }
  15. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SelectCourse.SelectCourseTypeSettingView> GetTypeSettingViewList(
  16. ViewModel.ConfiguretView configuretView, Guid? schoolYearID, int? selectCourseTypeID, int? recordStatus,
  17. int pageIndex, int pageSize)
  18. {
  19. Expression<Func<EM_SelectCourseTypeSetting, bool>> typeSettingExp = (x => true);
  20. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolYearExp = (x => true);
  21. if (schoolYearID.HasValue)
  22. {
  23. typeSettingExp = typeSettingExp.And(x => x.SchoolyearID == schoolYearID.Value);
  24. }
  25. if (selectCourseTypeID.HasValue)
  26. {
  27. typeSettingExp = typeSettingExp.And(x => x.SelectCourseTypeID == selectCourseTypeID.Value);
  28. }
  29. if (recordStatus.HasValue)
  30. {
  31. typeSettingExp = typeSettingExp.And(x => x.RecordStatus == recordStatus.Value);
  32. }
  33. IQueryable<ViewModel.SelectCourse.SelectCourseTypeSettingView> q = TypeSettingDAL.GetTypeSettingView(typeSettingExp, schoolYearExp)
  34. .OrderByDescending(x => x.SchoolyearCode);
  35. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  36. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  37. return q.ToGridResultSet(pageIndex, pageSize);
  38. }
  39. public IList<ViewModel.SelectCourse.SelectCourseTypeSettingView> GetTypeSettingViewList(ViewModel.ConfiguretView configuretView,
  40. Guid? schoolYearID, int? selectCourseTypeID, int? recordStatus)
  41. {
  42. Expression<Func<EM_SelectCourseTypeSetting, bool>> typeSettingExp = (x => true);
  43. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolYearExp = (x => true);
  44. if (schoolYearID.HasValue)
  45. {
  46. typeSettingExp = typeSettingExp.And(x => x.SchoolyearID == schoolYearID.Value);
  47. }
  48. if (selectCourseTypeID.HasValue)
  49. {
  50. typeSettingExp = typeSettingExp.And(x => x.SelectCourseTypeID == selectCourseTypeID.Value);
  51. }
  52. if (recordStatus.HasValue)
  53. {
  54. typeSettingExp = typeSettingExp.And(x => x.RecordStatus == recordStatus.Value);
  55. }
  56. IQueryable<ViewModel.SelectCourse.SelectCourseTypeSettingView> q = TypeSettingDAL.GetTypeSettingView(typeSettingExp, schoolYearExp)
  57. .OrderByDescending(x => x.SchoolyearCode);
  58. if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
  59. q = q.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  60. return q.ToList();
  61. }
  62. public ViewModel.SelectCourse.SelectCourseTypeSettingView GetTypeSettingViewInfo(Guid? typeSettingID)
  63. {
  64. return TypeSettingDAL.GetTypeSettingView((x => x.SelectCourseTypeSettingID == typeSettingID), (x => true)).FirstOrDefault();
  65. }
  66. public void Save(ViewModel.SelectCourse.SelectCourseTypeSettingView typeSetting)
  67. {
  68. var dupSettingList = TypeSettingDAL.SelectCourseTypeSettingRepository
  69. .GetList(x => x.SchoolyearID == typeSetting.SchoolyearID
  70. && x.SelectCourseTypeID == typeSetting.SelectCourseTypeID
  71. && x.EndTime >= typeSetting.StartTime && x.StartTime <= typeSetting.EndTime
  72. && x.SelectCourseTypeSettingID != typeSetting.SelectCourseTypeSettingID).ToList();
  73. var typeSettingEntity = TypeSettingDAL.SelectCourseTypeSettingRepository
  74. .GetSingle(x => x.SelectCourseTypeSettingID == typeSetting.SelectCourseTypeSettingID);
  75. if (typeSettingEntity != null)
  76. {
  77. if (dupSettingList.Count > 0)
  78. {
  79. throw new Exception("在同一学年学期的有效时间内存在重复的类型设定,不能保存。");
  80. }
  81. typeSettingEntity.SchoolyearID = typeSetting.SchoolyearID;
  82. typeSettingEntity.SelectCourseTypeID = typeSetting.SelectCourseTypeID;
  83. typeSettingEntity.StartTime = typeSetting.StartTime;
  84. typeSettingEntity.EndTime = typeSetting.EndTime;
  85. typeSettingEntity.MaxSelectCount = typeSetting.MaxSelectCount;
  86. typeSettingEntity.MinSelectCount = typeSetting.MinSelectCount;
  87. typeSettingEntity.MaxCredit = typeSetting.MaxCredit;
  88. typeSettingEntity.MinCredit = typeSetting.MinCredit;
  89. typeSettingEntity.Remark = typeSetting.Remark;
  90. this.SetModifyStatus(typeSettingEntity);
  91. }
  92. else
  93. {
  94. if (dupSettingList.Count > 0)
  95. {
  96. throw new Exception("在同一学年学期的有效时间内存在重复的类型设定,不能添加。");
  97. }
  98. typeSettingEntity = new EM_SelectCourseTypeSetting();
  99. typeSettingEntity.SelectCourseTypeSettingID = Guid.NewGuid();
  100. typeSettingEntity.SchoolyearID = typeSetting.SchoolyearID;
  101. typeSettingEntity.SelectCourseTypeID = typeSetting.SelectCourseTypeID;
  102. typeSettingEntity.StartTime = typeSetting.StartTime;
  103. typeSettingEntity.EndTime = typeSetting.EndTime;
  104. typeSettingEntity.MaxSelectCount = typeSetting.MaxSelectCount;
  105. typeSettingEntity.MinSelectCount = typeSetting.MinSelectCount;
  106. typeSettingEntity.MaxCredit = typeSetting.MaxCredit;
  107. typeSettingEntity.MinCredit = typeSetting.MinCredit;
  108. typeSettingEntity.Remark = typeSetting.Remark;
  109. this.SetNewStatus(typeSettingEntity);
  110. UnitOfWork.Add(typeSettingEntity);
  111. }
  112. UnitOfWork.Commit();
  113. }
  114. public void Delete(IList<Guid?> typeSettingIDList)
  115. {
  116. if (typeSettingIDList.Count > 0)
  117. {
  118. UnitOfWork.Delete<EM_SelectCourseTypeSetting>(x => typeSettingIDList.Contains(x.SelectCourseTypeSettingID));
  119. }
  120. }
  121. }
  122. }