ExaminationSubjectsServices.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.Entities;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.ExaminationApply;
  11. using EMIS.ViewModel.ExaminationApply;
  12. using Bowin.Common.Utility;
  13. using System.Text.RegularExpressions;
  14. namespace EMIS.CommonLogic.ExaminationApply
  15. {
  16. public class ExaminationSubjectsServices : BaseServices, IExaminationSubjectsServices
  17. {
  18. public ExaminationSubjectDAL ExaminationSubjectDAL { get; set; }
  19. public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ExaminationApply.ExaminationSubjectView> GetExaminationSubjectViewList(ViewModel.ConfiguretView examinationSubjectView,
  20. int? examinationFormID, int pageIndex, int pageSize)
  21. {
  22. Expression<Func<EX_ExaminationSubject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  23. if (examinationFormID.HasValue)
  24. {
  25. exp = exp.And(x => x.ExaminationFormID == examinationFormID);
  26. }
  27. var q = ExaminationSubjectDAL.GetExaminationSubjectView(exp);
  28. if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute))
  29. q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue);
  30. return q.OrderBy(x => x.Name).ToGridResultSet<ExaminationSubjectView>(pageIndex, pageSize);
  31. }
  32. public IList<ViewModel.ExaminationApply.ExaminationSubjectView> GetExaminationSubjectViewList(ViewModel.ConfiguretView examinationSubjectView, int? examinationFormID, Guid? examinationSubjectID)
  33. {
  34. Expression<Func<EX_ExaminationSubject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  35. if (examinationFormID.HasValue)
  36. {
  37. exp = exp.And(x => x.ExaminationFormID == examinationFormID);
  38. }
  39. var q = ExaminationSubjectDAL.GetExaminationSubjectView(exp);
  40. if (!string.IsNullOrEmpty(examinationSubjectView.ConditionValue) && !string.IsNullOrEmpty(examinationSubjectView.Attribute))
  41. q = q.DynamicWhere(examinationSubjectView.Attribute, examinationSubjectView.Condition, examinationSubjectView.ConditionValue);
  42. return q.OrderBy(x => x.Name).ToList();
  43. }
  44. public ViewModel.ExaminationApply.ExaminationSubjectView GetExaminationSubjectViewInfo(Guid? examinationSubjectID)
  45. {
  46. return ExaminationSubjectDAL.GetExaminationSubjectView(x => x.ExaminationSubjectID == examinationSubjectID).FirstOrDefault();
  47. }
  48. public void Save(ViewModel.ExaminationApply.ExaminationSubjectView examinationSubjectView)
  49. {
  50. var examinationSubjectEntity = ExaminationSubjectDAL.ExaminationSubjectRepository.GetSingle(x => x.ExaminationSubjectID == examinationSubjectView.ExaminationSubjectID);
  51. //考试科目名字唯一
  52. var RepeatSubject = ExaminationSubjectDAL.ExaminationSubjectRepository.GetSingle(x =>
  53. //x.ExaminationTypeID == examinationSubjectView.ExaminationTypeID &&
  54. //x.ExaminationFormID == examinationSubjectView.ExaminationFormID &&
  55. //x.SchoolyearID == examinationSubjectView.SchoolyearID &&
  56. x.Name == examinationSubjectView.Name);
  57. if (examinationSubjectEntity != null)
  58. {
  59. if (RepeatSubject != null && examinationSubjectEntity.ExaminationSubjectID != RepeatSubject.ExaminationSubjectID)
  60. { //考试科目,判断考试类型、考试类别、学年学期、考试科目名称不能重复
  61. throw new Exception("已存在【" + RepeatSubject.Name + "】考试科目,请核查");
  62. }
  63. examinationSubjectEntity.ExaminationTypeID = examinationSubjectView.ExaminationTypeID;
  64. examinationSubjectEntity.SchoolyearID = examinationSubjectView.SchoolyearID;
  65. examinationSubjectEntity.ExaminationFormID = examinationSubjectView.ExaminationFormsID;
  66. examinationSubjectEntity.Name = examinationSubjectView.Name;
  67. examinationSubjectEntity.PreposeSubjectID = examinationSubjectView.PreposeSubjectID;
  68. examinationSubjectEntity.PreposeScoreLimit = examinationSubjectView.PreposeScoreLimit;
  69. examinationSubjectEntity.ExaminationDate = examinationSubjectView.ExaminationDate;
  70. examinationSubjectEntity.PeopleNumLimit = examinationSubjectView.PeopleNumLimit;
  71. examinationSubjectEntity.Cost = examinationSubjectView.Cost;
  72. examinationSubjectEntity.Remark = examinationSubjectView.Remark;
  73. this.SetModifyStatus(examinationSubjectEntity);
  74. }
  75. else
  76. {
  77. if (RepeatSubject != null)
  78. { //考试科目,判断考试类型、考试类别、学年学期、名称不能重复
  79. throw new Exception("已存在【" + RepeatSubject.Name + "】考试科目,请核查");
  80. }
  81. examinationSubjectEntity = new EX_ExaminationSubject();
  82. examinationSubjectEntity.ExaminationSubjectID = Guid.NewGuid();
  83. examinationSubjectEntity.ExaminationTypeID = examinationSubjectView.ExaminationTypeID;
  84. examinationSubjectEntity.SchoolyearID = examinationSubjectView.SchoolyearID;
  85. examinationSubjectEntity.ExaminationFormID = examinationSubjectView.ExaminationFormsID;
  86. examinationSubjectEntity.Name = examinationSubjectView.Name;
  87. examinationSubjectEntity.PreposeSubjectID = examinationSubjectView.PreposeSubjectID;
  88. examinationSubjectEntity.PreposeScoreLimit = examinationSubjectView.PreposeScoreLimit;
  89. examinationSubjectEntity.ExaminationDate = examinationSubjectView.ExaminationDate;
  90. examinationSubjectEntity.PeopleNumLimit = examinationSubjectView.PeopleNumLimit;
  91. examinationSubjectEntity.Cost = examinationSubjectView.Cost;
  92. examinationSubjectEntity.Remark = examinationSubjectView.Remark;
  93. this.SetNewStatus(examinationSubjectEntity);
  94. UnitOfWork.Add(examinationSubjectEntity);
  95. }
  96. UnitOfWork.Commit();
  97. }
  98. public void Delete(IList<Guid?> examinationSubjectID)
  99. {
  100. if (examinationSubjectID.Count > 0)
  101. {
  102. UnitOfWork.Delete<EX_ExaminationSubject>(x => examinationSubjectID.Contains(x.ExaminationSubjectID));
  103. }
  104. }
  105. public string[] Validation(List<int?> ExaminationFormIDs, List<string> names)
  106. {
  107. try
  108. {
  109. for (int i = 0; i < ExaminationFormIDs.Count; i++)
  110. {int? ExaminationFormID = ExaminationFormIDs[0];
  111. string name = names[0];
  112. //var SubjectCountLimit = SubjectCountLimitDAL.ExaminationSubjectCountLimitRepository.Entities.Where(x =>
  113. // x.ExaminationTypeID == examinationType.Value && x.FacultymajorID == facultymajorIDs[0].Value &&
  114. // x.Years == years[0].Value).FirstOrDefault();
  115. var Subject = ExaminationSubjectDAL.GetExaminationSubjectView(x =>x.ExaminationFormID == ExaminationFormID && x.Name == name).FirstOrDefault();
  116. if (Subject != null)
  117. return new[] { "false", "科目【" + Subject.Name + "】"+ Subject.ExaminationFormName + "的考试性质数据已存在。" };
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. return new[] { "false", ex.Message };
  123. }
  124. return new[] { "true", "成功" };
  125. }
  126. }
  127. }