RetakeOpenControlServices.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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.ViewModel.RetakeManage;
  9. using EMIS.ViewModel;
  10. using EMIS.Entities;
  11. using EMIS.DataLogic.RetakeManage;
  12. using EMIS.CommonLogic.SystemServices;
  13. using EMIS.CommonLogic.CalendarManage;
  14. namespace EMIS.CommonLogic.RetakeManage
  15. {
  16. public class RetakeOpenControlServices : BaseServices, IRetakeOpenControlServices
  17. {
  18. public RetakeOpenControlDAL RetakeOpenControlDAL { get; set; }
  19. public Lazy<IParameterServices> ParameterServices { get; set; }
  20. public Lazy<ISchoolYearServices> ISchoolYearServices { get; set; }
  21. /// <summary>
  22. /// 查询重修控制信息View
  23. /// </summary>
  24. /// <param name="openControlConditionView"></param>
  25. /// <param name="schoolyearID"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<RetakeOpenControlView> GetRetakeOpenControlViewList(ConfiguretView openControlConditionView, Guid? schoolyearID, int pageIndex, int pageSize)
  30. {
  31. Expression<Func<ER_RetakeOpenControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. if (schoolyearID.HasValue)
  33. {
  34. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  35. }
  36. var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(exp);
  37. if (!string.IsNullOrEmpty(openControlConditionView.ConditionValue) && !string.IsNullOrEmpty(openControlConditionView.Attribute))
  38. {
  39. query = query.DynamicWhere(openControlConditionView.Attribute, openControlConditionView.Condition, openControlConditionView.ConditionValue);
  40. }
  41. query = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.StartDate);
  42. return query.ToGridResultSet<RetakeOpenControlView>(pageIndex, pageSize);
  43. }
  44. /// <summary>
  45. /// 查询重修控制信息List
  46. /// </summary>
  47. /// <param name="openControlConditionView"></param>
  48. /// <param name="schoolyearID"></param>
  49. /// <returns></returns>
  50. public List<RetakeOpenControlView> GetRetakeOpenControlViewList(ConfiguretView openControlConditionView, Guid? schoolyearID)
  51. {
  52. Expression<Func<ER_RetakeOpenControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  53. if (schoolyearID.HasValue)
  54. {
  55. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  56. }
  57. var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(exp);
  58. if (!string.IsNullOrEmpty(openControlConditionView.ConditionValue) && !string.IsNullOrEmpty(openControlConditionView.Attribute))
  59. {
  60. query = query.DynamicWhere(openControlConditionView.Attribute, openControlConditionView.Condition, openControlConditionView.ConditionValue);
  61. }
  62. query = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.StartDate);
  63. return query.ToList();
  64. }
  65. /// <summary>
  66. /// 查询对应的重修控制信息
  67. /// </summary>
  68. /// <param name="retakeOpenControlID"></param>
  69. /// <returns></returns>
  70. public RetakeOpenControlView GetRetakeOpenControlView(Guid? retakeOpenControlID)
  71. {
  72. var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(x => x.RetakeOpenControlID == retakeOpenControlID);
  73. return query.FirstOrDefault();
  74. }
  75. /// <summary>
  76. /// 查询对应的重修控制信息(根据重修学年学期)
  77. /// </summary>
  78. /// <param name="schoolyearID"></param>
  79. /// <returns></returns>
  80. public RetakeOpenControlView GetRetakeOpenControlViewBySchoolyearID(Guid? schoolyearID)
  81. {
  82. var query = RetakeOpenControlDAL.GetRetakeOpenControlViewQuery(x => x.SchoolyearID == schoolyearID);
  83. return query.SingleOrDefault();
  84. }
  85. /// <summary>
  86. /// 重修控制编辑(新增、修改)
  87. /// </summary>
  88. /// <param name="retakeOpenControlView"></param>
  89. public void RetakeOpenControlEdit(RetakeOpenControlView retakeOpenControlView)
  90. {
  91. try
  92. {
  93. ER_RetakeOpenControl openControl = new ER_RetakeOpenControl();
  94. if (retakeOpenControlView.RetakeOpenControlID == null || retakeOpenControlView.RetakeOpenControlID == Guid.Empty)
  95. {
  96. openControl = RetakeOpenControlDAL.RetakeOpenControlRepository
  97. .GetSingle(x => x.SchoolyearID == retakeOpenControlView.SchoolyearID);
  98. if (openControl != null)
  99. {
  100. throw new Exception("已存在相同学年学期的重修控制信息。");
  101. }
  102. openControl = new ER_RetakeOpenControl();
  103. openControl.RetakeOpenControlID = Guid.NewGuid();
  104. openControl.SchoolyearID = retakeOpenControlView.SchoolyearID;
  105. openControl.StartDate = retakeOpenControlView.StartDate;
  106. openControl.EndDate = retakeOpenControlView.EndDate;
  107. SetNewStatus(openControl);
  108. UnitOfWork.Add(openControl);
  109. }
  110. else
  111. {
  112. openControl = RetakeOpenControlDAL.RetakeOpenControlRepository
  113. .GetSingle(x => x.RetakeOpenControlID != retakeOpenControlView.RetakeOpenControlID
  114. && x.SchoolyearID == retakeOpenControlView.SchoolyearID);
  115. if (openControl != null)
  116. {
  117. throw new Exception("已存在相同学年学期的重修控制信息。");
  118. }
  119. openControl = RetakeOpenControlDAL.RetakeOpenControlRepository
  120. .GetSingle(x => x.RetakeOpenControlID == retakeOpenControlView.RetakeOpenControlID);
  121. if (openControl == null)
  122. {
  123. throw new Exception("数据有误,请核查。");
  124. }
  125. openControl.SchoolyearID = retakeOpenControlView.SchoolyearID;
  126. openControl.StartDate = retakeOpenControlView.StartDate;
  127. openControl.EndDate = retakeOpenControlView.EndDate;
  128. SetModifyStatus(openControl);
  129. }
  130. UnitOfWork.Commit();
  131. }
  132. catch (Exception ex)
  133. {
  134. throw new Exception(ex.Message);
  135. }
  136. }
  137. /// <summary>
  138. /// 重修控制删除
  139. /// </summary>
  140. /// <param name="openControlIDList"></param>
  141. public void RetakeOpenControlDelete(IList<Guid?> openControlIDList)
  142. {
  143. try
  144. {
  145. if (openControlIDList.Count > 0)
  146. {
  147. UnitOfWork.Delete<ER_RetakeOpenControl>(x => openControlIDList.Contains(x.RetakeOpenControlID));
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. throw new Exception(ex.Message);
  153. }
  154. }
  155. /// <summary>
  156. /// 查询重修学年学期对应的重修控制信息(根据对应重修学年学期查询)
  157. /// </summary>
  158. /// <param name="schoolyearID"></param>
  159. /// <returns></returns>
  160. public ER_RetakeOpenControl GetRetakeOpenControl(Guid? schoolyearID)
  161. {
  162. try
  163. {
  164. Expression<Func<ER_RetakeOpenControl, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  165. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  166. var query = RetakeOpenControlDAL.RetakeOpenControlRepository.GetSingle(exp);
  167. return query;
  168. }
  169. catch (Exception ex)
  170. {
  171. throw new Exception(ex.Message);
  172. }
  173. }
  174. /// <summary>
  175. /// 查询重修学年学期对应的重修开放控制信息
  176. /// </summary>
  177. /// <param name="schoolyearID"></param>
  178. /// <returns></returns>
  179. public string GetRetakeApplyDateTime(Guid? schoolyearID)
  180. {
  181. var retakeOpenControl = GetRetakeOpenControl(schoolyearID);
  182. if (retakeOpenControl == null)
  183. {
  184. return "未开放";
  185. }
  186. else
  187. {
  188. if (retakeOpenControl.StartDate > DateTime.Now)
  189. {
  190. return Convert.ToDateTime(retakeOpenControl.StartDate).ToString("yyyy-MM-dd hh:mm:ss")
  191. + " 至 " + Convert.ToDateTime(retakeOpenControl.EndDate).ToString("yyyy-MM-dd hh:mm:ss")
  192. + " (即将开始)";
  193. }
  194. else if (retakeOpenControl.EndDate < DateTime.Now)
  195. {
  196. return Convert.ToDateTime(retakeOpenControl.StartDate).ToString("yyyy-MM-dd hh:mm:ss")
  197. + " 至 " + Convert.ToDateTime(retakeOpenControl.EndDate).ToString("yyyy-MM-dd hh:mm:ss")
  198. + " (报名结束)";
  199. }
  200. else
  201. {
  202. return Convert.ToDateTime(retakeOpenControl.StartDate).ToString("yyyy-MM-dd hh:mm:ss")
  203. + " 至 " + Convert.ToDateTime(retakeOpenControl.EndDate).ToString("yyyy-MM-dd hh:mm:ss")
  204. + " (开始报名)";
  205. }
  206. }
  207. }
  208. }
  209. }