GraduationSchoolYearServices.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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.GraduationManage.GraduationSetting;
  11. using EMIS.CommonLogic.SystemServices;
  12. using EMIS.ViewModel.GraduationManage.GraduationSetting;
  13. namespace EMIS.CommonLogic.GraduationManage.GraduationSetting
  14. {
  15. public class GraduationSchoolYearServices: BaseServices, IGraduationSchoolYearServices
  16. {
  17. public GraduationSchoolYearDAL GraduationSchoolYearDAL { get; set; }
  18. public Lazy<IParameterServices> ParameterServices { get; set; }
  19. /// <summary>
  20. /// 查询毕业学期信息View
  21. /// </summary>
  22. /// <param name="configuretView"></param>
  23. /// <param name="years"></param>
  24. /// <param name="schoolcodeID"></param>
  25. /// <param name="isCurrent"></param>
  26. /// <param name="isEnable"></param>
  27. /// <param name="pageIndex"></param>
  28. /// <param name="pageSize"></param>
  29. /// <returns></returns>
  30. public IGridResultSet<GraduationSchoolYearView> GetGradSchoolYearViewGrid(ConfiguretView configuretView, int? years,
  31. int? schoolcodeID, int? isCurrent, int? isEnable, int pageIndex, int pageSize)
  32. {
  33. //查询设置的毕业学期Value
  34. var graduatingSemesterID = ParameterServices.Value.GetParameterValue<Guid>(CF_ParameterType.GraduationSchoolyear);
  35. //毕业学期设置信息
  36. Expression<Func<ER_GraduateSchoolyear, bool>> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  37. var query = GraduationSchoolYearDAL.GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID);
  38. if (years.HasValue)
  39. {
  40. query = query.Where(x => x.Years == years);
  41. }
  42. if (schoolcodeID.HasValue)
  43. {
  44. query = query.Where(x => x.SchoolcodeID == schoolcodeID);
  45. }
  46. if (isCurrent.HasValue)
  47. {
  48. if (isCurrent == 1)
  49. {
  50. query = query.Where(x => x.IsCurrent == true);
  51. }
  52. if (isCurrent == 0)
  53. {
  54. query = query.Where(x => x.IsCurrent != true);
  55. }
  56. }
  57. if (isEnable.HasValue)
  58. {
  59. if (isEnable == 1)
  60. {
  61. query = query.Where(x => x.IsEnable == true);
  62. }
  63. if (isEnable == 0)
  64. {
  65. query = query.Where(x => x.IsEnable != true);
  66. }
  67. }
  68. //查询条件
  69. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  70. {
  71. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  72. }
  73. return query.OrderByDescending(x => x.IsEnable)
  74. .ThenByDescending(x => x.GraduatingSemesterValue)
  75. .ToGridResultSet<GraduationSchoolYearView>(pageIndex, pageSize);
  76. }
  77. /// <summary>
  78. /// 查询毕业学期信息List
  79. /// </summary>
  80. /// <param name="configuretView"></param>
  81. /// <param name="years"></param>
  82. /// <param name="schoolcodeID"></param>
  83. /// <param name="isCurrent"></param>
  84. /// <param name="isEnable"></param>
  85. /// <returns></returns>
  86. public IList<GraduationSchoolYearView> GetGradSchoolYearViewList(ConfiguretView configuretView, int? years,
  87. int? schoolcodeID, int? isCurrent, int? isEnable)
  88. {
  89. //查询设置的毕业学期Value
  90. var graduatingSemesterID = ParameterServices.Value.GetParameterValue<Guid>(CF_ParameterType.GraduationSchoolyear);
  91. //毕业学期设置信息
  92. Expression<Func<ER_GraduateSchoolyear, bool>> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  93. var query = GraduationSchoolYearDAL.GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID);
  94. if (years.HasValue)
  95. {
  96. query = query.Where(x => x.Years == years);
  97. }
  98. if (schoolcodeID.HasValue)
  99. {
  100. query = query.Where(x => x.SchoolcodeID == schoolcodeID);
  101. }
  102. if (isCurrent.HasValue)
  103. {
  104. if (isCurrent == 1)
  105. {
  106. query = query.Where(x => x.IsCurrent == true);
  107. }
  108. if (isCurrent == 0)
  109. {
  110. query = query.Where(x => x.IsCurrent != true);
  111. }
  112. }
  113. if (isEnable.HasValue)
  114. {
  115. if (isEnable == 1)
  116. {
  117. query = query.Where(x => x.IsEnable == true);
  118. }
  119. if (isEnable == 0)
  120. {
  121. query = query.Where(x => x.IsEnable != true);
  122. }
  123. }
  124. //查询条件
  125. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  126. {
  127. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  128. }
  129. return query.OrderByDescending(x => x.IsEnable)
  130. .ThenByDescending(x => x.GraduatingSemesterValue)
  131. .ToList();
  132. }
  133. /// <summary>
  134. /// 查询对应的毕业学期信息View(根据毕业学期设置信息ID)
  135. /// </summary>
  136. /// <param name="graduationSchoolYearSettingID"></param>
  137. /// <returns></returns>
  138. public GraduationSchoolYearView GetGradSchoolYearView(Guid? graduationSchoolYearSettingID)
  139. {
  140. try
  141. {
  142. //查询设置的毕业学期Value
  143. var graduatingSemesterID = ParameterServices.Value.GetParameterValue<Guid>(CF_ParameterType.GraduationSchoolyear);
  144. //毕业学期设置信息
  145. Expression<Func<ER_GraduateSchoolyear, bool>> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  146. expGraduateSchoolyear = expGraduateSchoolyear.And(x => x.GraduateSchoolyearID == graduationSchoolYearSettingID);
  147. var query = GraduationSchoolYearDAL.GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID)
  148. .SingleOrDefault();
  149. return query;
  150. }
  151. catch (Exception ex)
  152. {
  153. throw new Exception(ex.Message);
  154. }
  155. }
  156. /// <summary>
  157. /// 编辑(新增、修改,业务主键:毕业学期设置信息ID)
  158. /// 判断启用状态(只有一种启用状态)
  159. /// </summary>
  160. /// <param name="graduationSchoolYearView"></param>
  161. public void GraduationSchoolYearEdit(GraduationSchoolYearView graduationSchoolYearView)
  162. {
  163. try
  164. {
  165. //查询数据库进行验证
  166. var gradSchoolYearVerification = GraduationSchoolYearDAL.GraduateSchoolyearRepository
  167. .GetList(x => x.GraduateSchoolyearID != graduationSchoolYearView.GraduationSchoolYearSettingID
  168. && x.SchoolyearID == graduationSchoolYearView.GraduatingSemesterID)
  169. .SingleOrDefault();
  170. if (gradSchoolYearVerification == null)
  171. {
  172. //数据有误验证
  173. if (graduationSchoolYearView.GraduationSchoolYearSettingID != Guid.Empty)
  174. {
  175. var gradSchoolYear = GraduationSchoolYearDAL.GraduateSchoolyearRepository
  176. .GetList(x => x.SchoolyearID == graduationSchoolYearView.GraduatingSemesterID)
  177. .SingleOrDefault();
  178. if (gradSchoolYear == null)
  179. {
  180. throw new Exception("数据有误,请核查。");
  181. }
  182. else
  183. {
  184. //表示修改
  185. //查询设置的毕业学期Value
  186. var graduatingSemesterID = ParameterServices.Value.GetParameterValue<Guid>(CF_ParameterType.GraduationSchoolyear);
  187. if (graduationSchoolYearView.GraduatingSemesterID == graduatingSemesterID)
  188. {
  189. if (!graduationSchoolYearView.IsEnable)
  190. {
  191. ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, null);
  192. }
  193. }
  194. else
  195. {
  196. //设置对应的毕业学期
  197. if (graduationSchoolYearView.IsEnable)
  198. {
  199. ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, graduationSchoolYearView.GraduatingSemesterID.Value);
  200. }
  201. }
  202. gradSchoolYear.GraduateDate = graduationSchoolYearView.GraduateDate;
  203. SetModifyStatus(gradSchoolYear);
  204. }
  205. }
  206. else
  207. {
  208. //表示新增
  209. //设置对应的毕业学期
  210. if (graduationSchoolYearView.IsEnable)
  211. {
  212. ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, graduationSchoolYearView.GraduatingSemesterID.Value);
  213. }
  214. ER_GraduateSchoolyear newGraduateSchoolyear = new ER_GraduateSchoolyear();
  215. newGraduateSchoolyear.GraduateSchoolyearID = Guid.NewGuid();
  216. newGraduateSchoolyear.SchoolyearID = graduationSchoolYearView.GraduatingSemesterID;
  217. newGraduateSchoolyear.GraduateDate = graduationSchoolYearView.GraduateDate;
  218. SetNewStatus(newGraduateSchoolyear);
  219. UnitOfWork.Add(newGraduateSchoolyear);
  220. }
  221. }
  222. else
  223. {
  224. throw new Exception("已存在相同的毕业学期信息,请核查。");
  225. }
  226. //事务提交
  227. UnitOfWork.Commit();
  228. }
  229. catch (Exception ex)
  230. {
  231. throw new Exception(ex.Message);
  232. }
  233. }
  234. /// <summary>
  235. /// 删除(注:需对设置的毕业学期进行处理)
  236. /// </summary>
  237. /// <param name="graduationSchoolYearSettingIDs"></param>
  238. /// <returns></returns>
  239. public bool GraduationSchoolYearDelete(List<Guid?> graduationSchoolYearSettingIDs)
  240. {
  241. try
  242. {
  243. //查询设置的毕业学期Value
  244. var graduatingSemesterID = ParameterServices.Value.GetParameterValue<Guid>(CF_ParameterType.GraduationSchoolyear);
  245. //毕业学期设置信息
  246. Expression<Func<ER_GraduateSchoolyear, bool>> expGraduateSchoolyear = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  247. expGraduateSchoolyear = expGraduateSchoolyear.And(x => graduationSchoolYearSettingIDs.Contains(x.GraduateSchoolyearID));
  248. var gradSchoolYearViewList = GraduationSchoolYearDAL
  249. .GetGraduationSchoolYearViewQueryable(expGraduateSchoolyear, graduatingSemesterID).ToList();
  250. foreach (var gradSchoolYearView in gradSchoolYearViewList)
  251. {
  252. if (gradSchoolYearView.IsEnable)
  253. {
  254. ParameterServices.Value.SaveTo(CF_ParameterType.GraduationSchoolyear, null);
  255. }
  256. }
  257. UnitOfWork.Delete<ER_GraduateSchoolyear>(x => graduationSchoolYearSettingIDs.Contains(x.GraduateSchoolyearID));
  258. UnitOfWork.Commit();
  259. return true;
  260. }
  261. catch (Exception ex)
  262. {
  263. throw new Exception(ex.Message);
  264. }
  265. }
  266. }
  267. }