ExamBatchProjectServices.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.Specialtymanage;
  6. using EMIS.Entities;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.ViewModel.Specialtymanage;
  10. using EMIS.ViewModel;
  11. using System.Text.RegularExpressions;
  12. using Bowin.Common.Utility;
  13. using EMIS.ViewModel.Cache;
  14. using EMIS.Utility;
  15. using System.Linq.Expressions;
  16. using EMIS.DataLogic.ExamManage;
  17. namespace EMIS.CommonLogic.ExamManage
  18. {
  19. public class ExamBatchProjectServices : BaseServices, IExamBatchProjectServices
  20. {
  21. public ExaminationBatchDAL ExaminationBatchDAL { get; set; }
  22. public ExamBatchProjectDAL ExamBatchProjectDAL { get; set; }
  23. public ProjectFeeDAL ProjectFeeDAL { get; set; }
  24. public IGridResultSet<EMIS.ViewModel.ExamBatchProjectView> GetBatchProjectListGridView(int pageIndex, int pageSize, params EMIS.ViewModel.ConfiguretView[] configuretViews)
  25. {
  26. //校区信息
  27. System.Linq.Expressions.Expression<Func<EX_ExaminationBatchProject, bool>> expCampus = (x =>true);
  28. var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus);
  29. //查询条件
  30. foreach (var configuretView in configuretViews)
  31. {
  32. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  33. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  34. }
  35. return query
  36. .OrderByDescending(x => x.Schoolyear).ThenBy(x => x.StartDate)
  37. .ThenBy(x => x.ExaminationBatchID).ThenBy(x => x.Name)
  38. .ToGridResultSet<EMIS.ViewModel.ExamBatchProjectView>(pageIndex, pageSize);
  39. }
  40. public IGridResultSet<EMIS.ViewModel.ExaminationApply.ExaminationTypeView> GetExamBatchExamTypeListViewGrid(int pageIndex, int pageSize, params EMIS.ViewModel.ConfiguretView[] configuretViews)
  41. {
  42. System.Linq.Expressions.Expression<Func<EX_ExaminationBatchProject, bool>> expCampus = (x => x.RecordStatus == (int)SYS_STATUS.USABLE);
  43. var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus);
  44. //查询条件
  45. foreach (var configuretView in configuretViews)
  46. {
  47. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  48. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  49. }
  50. var result = query.OrderBy(x => x.ExaminationBatchProjectID).GroupBy(x => new
  51. {
  52. x.ExaminationBatchID,
  53. x.ExaminationTypeID,
  54. x.ExaminationType
  55. }).Select(x => new EMIS.ViewModel.ExaminationApply.ExaminationTypeView()
  56. {
  57. ExaminationBatchID = x.Key.ExaminationBatchID,
  58. ExaminationTypeID = x.Key.ExaminationTypeID.Value,
  59. Name = x.Key.ExaminationType
  60. });
  61. return result
  62. .OrderBy(x => x.ExaminationBatchID)
  63. .ToGridResultSet<EMIS.ViewModel.ExaminationApply.ExaminationTypeView>(pageIndex, pageSize);
  64. }
  65. public IQueryable<EMIS.ViewModel.ExamBatchProjectView> GetBatchProjectList(params EMIS.ViewModel.ConfiguretView[] configuretViews)
  66. {
  67. System.Linq.Expressions.Expression<Func<EX_ExaminationBatchProject, bool>> expCampus = (x => x.RecordStatus == (int)SYS_STATUS.USABLE);
  68. var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus);
  69. //查询条件
  70. foreach (var configuretView in configuretViews)
  71. {
  72. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  73. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  74. }
  75. return query
  76. .OrderBy(x => x.ExaminationBatchID).AsQueryable();
  77. }
  78. public List<ExamBatchProjectView> SelectProjects(Guid ExaminationBatchID, List<Guid?> list)
  79. {
  80. //筛选已经存在的考试
  81. var examlist = ExamBatchProjectDAL.GetBatchProjectList(q => q.ExaminationBatchID == ExaminationBatchID).Select(q => q.ExaminationProjectID).ToArray();
  82. list = list.Where(q => !examlist.Contains(q)).ToList();
  83. var addlist = new List<EX_ExaminationBatchProject>();
  84. var batch = ExaminationBatchDAL.GetBatchList(q => q.ExaminationBatchID == ExaminationBatchID).SingleOrDefault();
  85. list.ForEach(id =>
  86. {
  87. var project = ProjectFeeDAL.ProjectRepository.GetSingle(q => q.ExaminationProjectID == id);
  88. var entity = new EX_ExaminationBatchProject()
  89. {
  90. ExaminationBatchProjectID = Guid.NewGuid(),
  91. ExaminationBatchID = ExaminationBatchID,
  92. ExaminationProjectID = id,
  93. StartDate = batch.StartDate,
  94. EndDate = batch.EndDate,
  95. Remark = project.Remark,
  96. RecordStatus = (int)SYS_STATUS.UNUSABLE
  97. };
  98. this.SetModifyStatus(entity);
  99. addlist.Add(entity);
  100. this.ExamBatchProjectDAL.BatchProjectRepository.UnitOfWork.Add(entity);
  101. });
  102. this.ExamBatchProjectDAL.BatchProjectRepository.UnitOfWork.Commit();
  103. System.Linq.Expressions.Expression<Func<EX_ExaminationBatchProject, bool>> expCampus = (x => x.ExaminationBatchID == ExaminationBatchID && list.Contains(x.ExaminationProjectID));
  104. var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus);
  105. return query.ToList();
  106. }
  107. public EMIS.ViewModel.ExamBatchProjectView GetView(Expression<Func<EX_ExaminationBatchProject, bool>> expCampus)
  108. {
  109. var query = ExamBatchProjectDAL.GetBatchProjectList(expCampus).SingleOrDefault();
  110. return query;
  111. }
  112. public void Edit(ExamBatchProjectView view, IList<ExamBatchProjectView> listData)
  113. {
  114. try
  115. {
  116. var dbBatchProjectList = ExamBatchProjectDAL.BatchProjectRepository.Entities.ToList();
  117. //var entity = ExaminationBatchDAL.BatchRepository.Entities
  118. // .SingleOrDefault(x => x.ExaminationBatchID == view.ExaminationBatchID);
  119. //if (entity == null)
  120. //{
  121. // entity = new EX_ExaminationBatch();
  122. // this.SetNewStatus(entity);
  123. // ExaminationBatchDAL.BatchRepository.UnitOfWork.Add(entity);
  124. //}
  125. List<EX_ExaminationBatchProject> batchProjectList = new List<EX_ExaminationBatchProject>();
  126. foreach (var data in listData)
  127. {
  128. if (dbBatchProjectList.Where(x => x.ExaminationBatchID == view.ExaminationBatchID && x.ExaminationProjectID == data.ExaminationProjectID).Count() > 0)
  129. {
  130. throw new Exception("要添加的项目该批次已存在,请检查后再添加");
  131. }
  132. EX_ExaminationBatchProject item = new EX_ExaminationBatchProject();
  133. item.ExaminationBatchProjectID = Guid.NewGuid();
  134. item.ExaminationBatchID = view.ExaminationBatchID;
  135. item.ExaminationProjectID = data.ExaminationProjectID;
  136. //ExamBatchProjectDAL.BatchProjectRepository.Entities.SingleOrDefault(x => x.ExaminationBatchProjectID == data.ExaminationBatchProjectID);
  137. item.SimulateTime = data.SimulateTime;
  138. item.Training = data.Training;
  139. item.TakeCourseTime = data.TakeCourseTime;
  140. item.MaxRegistCount = data.MaxRegistCount;
  141. item.Remark = data.Remark;
  142. //item.RecordStatus = (int)SYS_STATUS.USABLE;
  143. //item.CreateTime = DateTime.Now;
  144. item.StartDate = view.StartDate;
  145. item.EndDate = view.EndDate;
  146. this.SetNewStatus(item);
  147. batchProjectList.Add(item);
  148. }
  149. UnitOfWork.BulkInsert(batchProjectList);
  150. }
  151. catch (Exception)
  152. {
  153. throw;
  154. }
  155. //ExaminationBatchDAL.BatchRepository.UnitOfWork.Commit();
  156. }
  157. public void Edit(ExamBatchProjectView view)
  158. {
  159. var item = ExamBatchProjectDAL.BatchProjectRepository.Entities
  160. .SingleOrDefault(x => x.ExaminationBatchProjectID == view.ExaminationBatchProjectID);
  161. item.SimulateTime = view.SimulateTime;
  162. item.Training = view.Training;
  163. item.TakeCourseTime = view.TakeCourseTime;
  164. item.MaxRegistCount = view.MaxRegistCount;
  165. item.Remark = view.Remark;
  166. item.StartDate = view.StartDate;
  167. item.EndDate = view.EndDate;
  168. this.SetModifyStatus(item);
  169. ExaminationBatchDAL.BatchRepository.UnitOfWork.Commit();
  170. }
  171. public bool DeleteBatchProject(List<Guid?> ExamBatchProjectIDs)
  172. {
  173. try
  174. {
  175. UnitOfWork.Delete<EX_ExaminationBatchProject>(x => ExamBatchProjectIDs.Contains(x.ExaminationBatchProjectID));
  176. UnitOfWork.Commit();
  177. return true;
  178. }
  179. catch (Exception)
  180. {
  181. throw;
  182. }
  183. }
  184. }
  185. }