SubjectCountLimitServices.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.ExaminationApply;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.ExaminationApply;
  12. namespace EMIS.CommonLogic.ExaminationApply
  13. {
  14. public class SubjectCountLimitServices : BaseServices, ISubjectCountLimitServices
  15. {
  16. public SubjectCountLimitDAL SubjectCountLimitDAL { get; set; }
  17. public Bowin.Common.Linq.Entity.IGridResultSet<SubjectCountLimitView> GetSubjectCountLimitViewList(ViewModel.ConfiguretView subjectCountLimitView,
  18. Guid? examinationTypeID, Guid? facultymajorID, int? yearNum, int pageIndex, int pageSize)
  19. {
  20. Expression<Func<EX_ExaminationSubjectCountLimit, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  21. if (examinationTypeID.HasValue)
  22. {
  23. exp = exp.And(x => x.ExaminationTypeID == examinationTypeID);
  24. }
  25. if (facultymajorID.HasValue)
  26. {
  27. exp = exp.And(x => x.FacultymajorID == facultymajorID);
  28. }
  29. if (yearNum.HasValue)
  30. {
  31. exp = exp.And(x => x.Years == yearNum);
  32. }
  33. var q = SubjectCountLimitDAL.GetSubjectCountLimitView(exp);
  34. if (!string.IsNullOrEmpty(subjectCountLimitView.ConditionValue) && !string.IsNullOrEmpty(subjectCountLimitView.Attribute))
  35. q = q.DynamicWhere(subjectCountLimitView.Attribute, subjectCountLimitView.Condition, subjectCountLimitView.ConditionValue);
  36. return GetQueryByDataRangeByCollege(q).OrderBy(x => x.ExaminationTypeName).ThenBy(x => x.FacultymajorName).ToGridResultSet<SubjectCountLimitView>(pageIndex, pageSize);
  37. }
  38. public IList<ViewModel.ExaminationApply.SubjectCountLimitView> GetSubjectCountLimitViewList(ViewModel.ConfiguretView subjectCountLimitView, Guid? examinationTypeID, Guid? facultymajorID)
  39. {
  40. Expression<Func<EX_ExaminationSubjectCountLimit, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  41. if (examinationTypeID.HasValue)
  42. {
  43. exp = exp.And(x => x.ExaminationTypeID == examinationTypeID);
  44. }
  45. if (facultymajorID.HasValue)
  46. {
  47. exp = exp.And(x => x.FacultymajorID == facultymajorID);
  48. }
  49. var q = SubjectCountLimitDAL.GetSubjectCountLimitView(exp);
  50. if (!string.IsNullOrEmpty(subjectCountLimitView.ConditionValue) && !string.IsNullOrEmpty(subjectCountLimitView.Attribute))
  51. q = q.DynamicWhere(subjectCountLimitView.Attribute, subjectCountLimitView.Condition, subjectCountLimitView.ConditionValue);
  52. return GetQueryByDataRangeByCollege(q).OrderBy(x => x.ExaminationTypeName).ThenBy(x => x.FacultymajorName).ToList();
  53. }
  54. public ViewModel.ExaminationApply.SubjectCountLimitView GetSubjectCountLimitViewInfo(Guid? subjectCountLimitID)
  55. {
  56. return SubjectCountLimitDAL.GetSubjectCountLimitView(x => x.ExaminationSubjectCountLimitID == subjectCountLimitID).FirstOrDefault();
  57. }
  58. public void Save(ViewModel.ExaminationApply.SubjectCountLimitView subjectCountLimitView)
  59. {
  60. var subjectCountLimitEntity = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.GetSingle(x => x.ExaminationSubjectCountLimitID == subjectCountLimitView.ExaminationSubjectCountLimitID);
  61. var RepeatSubjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.GetSingle(x =>
  62. x.ExaminationTypeID == subjectCountLimitView.ExaminationTypeID &&
  63. x.FacultymajorID == subjectCountLimitView.FacultymajorID && x.Years == subjectCountLimitView.Years);
  64. if (subjectCountLimitEntity != null)
  65. {
  66. if (RepeatSubjectCountLimit != null && subjectCountLimitEntity.ExaminationSubjectCountLimitID != RepeatSubjectCountLimit.ExaminationSubjectCountLimitID)
  67. { //门数限定,判断考试类型、院系专业、年级数不能重复
  68. throw new Exception("已存在相同的考试类型、院系专业、年级数,请核查");
  69. }
  70. subjectCountLimitEntity.ExaminationTypeID = subjectCountLimitView.ExaminationTypeID;
  71. subjectCountLimitEntity.FacultymajorID = subjectCountLimitView.FacultymajorID;
  72. subjectCountLimitEntity.Years = subjectCountLimitView.Years;
  73. subjectCountLimitEntity.SubjectCountLimit = subjectCountLimitView.SubjectCountLimit;
  74. this.SetModifyStatus(subjectCountLimitEntity);
  75. }
  76. else
  77. {
  78. if (RepeatSubjectCountLimit != null)
  79. { //门数限定,判断考试类型、院系专业、年级数不能重复
  80. throw new Exception("已存在相同的考试类型、院系专业、年级数,请核查");
  81. }
  82. subjectCountLimitEntity = new EX_ExaminationSubjectCountLimit();
  83. subjectCountLimitEntity.ExaminationSubjectCountLimitID = Guid.NewGuid();
  84. subjectCountLimitEntity.ExaminationTypeID = subjectCountLimitView.ExaminationTypeID;
  85. subjectCountLimitEntity.FacultymajorID = subjectCountLimitView.FacultymajorID;
  86. subjectCountLimitEntity.Years = subjectCountLimitView.Years;
  87. subjectCountLimitEntity.SubjectCountLimit = subjectCountLimitView.SubjectCountLimit;
  88. this.SetNewStatus(subjectCountLimitEntity);
  89. UnitOfWork.Add(subjectCountLimitEntity);
  90. }
  91. UnitOfWork.Commit();
  92. }
  93. public void Delete(IList<Guid?> subjectCountLimitID)
  94. {
  95. if (subjectCountLimitID.Count > 0)
  96. {
  97. UnitOfWork.Delete<EX_ExaminationSubjectCountLimit>(x => subjectCountLimitID.Contains(x.ExaminationSubjectCountLimitID));
  98. }
  99. }
  100. /// <summary>
  101. /// 批量修改前,验证门数限定表的院系专业、学年数、考试类型是否重复
  102. /// </summary>
  103. /// <param name="examinationType">考试类型</param>
  104. /// <param name="facultymajorIDs">院系专业</param>
  105. /// <param name="years">学年数</param>
  106. /// <returns></returns>
  107. public string[] Validation(Guid? examinationType,List<Guid?> facultymajorIDs,List<int?> years)
  108. {
  109. try
  110. {
  111. for (int i = 0; i < facultymajorIDs.Count; i++)
  112. {
  113. Guid a = facultymajorIDs[0].Value;
  114. int b = years[0].Value;
  115. //var SubjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.Entities.Where(x =>
  116. // x.ExaminationTypeID == examinationType.Value && x.FacultymajorID == facultymajorIDs[0].Value &&
  117. // x.Years == years[0].Value).FirstOrDefault();
  118. var SubjectCountLimit = SubjectCountLimitDAL.GetSubjectCountLimitView(x =>
  119. x.ExaminationTypeID == examinationType.Value && x.FacultymajorID == a &&
  120. x.Years == b).FirstOrDefault();
  121. if (SubjectCountLimit != null)
  122. return new[] { "false", "专业【"+SubjectCountLimit.FacultymajorName + "】第" + SubjectCountLimit.Years + "学年的【" + SubjectCountLimit.ExaminationTypeName + "】考试类型数据已存在。" };
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. return new[] { "false", ex.Message };
  128. }
  129. return new[] { "true", "成功" };
  130. }
  131. }
  132. }