InSchoolSettingServices.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Transactions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.StudentManage.StudentStatistics;
  12. using EMIS.DataLogic.StudentManage.StudentStatistics;
  13. namespace EMIS.CommonLogic.StudentManage.StudentStatistics
  14. {
  15. public class InSchoolSettingServices : BaseServices, IInSchoolSettingServices
  16. {
  17. public InSchoolSettingDAL InSchoolSettingDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的在校设定信息InSchoolSettingView
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="inSchoolStatusID"></param>
  23. /// <param name="isSelected"></param>
  24. /// <param name="isDisplayID"></param>
  25. /// <param name="pageIndex"></param>
  26. /// <param name="pageSize"></param>
  27. /// <returns></returns>
  28. public IGridResultSet<InSchoolSettingView> GetInSchoolSettingViewGrid(ConfiguretView configuretView, int? inSchoolStatusID, int? isSelected, int? isDisplayID, int pageIndex, int pageSize)
  29. {
  30. Expression<Func<Sys_DictionaryItem, bool>> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name);
  31. Expression<Func<CF_InSchoolSetting, bool>> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. var query = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting);
  33. if (inSchoolStatusID.HasValue)
  34. {
  35. query = query.Where(x => x.InSchoolStatusID == inSchoolStatusID);
  36. }
  37. if (isSelected.HasValue)
  38. {
  39. if (isSelected == (int)CF_GeneralPurpose.IsYes)
  40. {
  41. query = query.Where(x => x.IsSelected == true);
  42. }
  43. if (isSelected == (int)CF_GeneralPurpose.IsNo)
  44. {
  45. query = query.Where(x => x.IsSelected != true);
  46. }
  47. }
  48. if (isDisplayID.HasValue)
  49. {
  50. if (isDisplayID == (int)CF_GeneralPurpose.IsYes)
  51. {
  52. query = query.Where(x => x.IsDisplay == true);
  53. }
  54. if (isDisplayID == (int)CF_GeneralPurpose.IsNo)
  55. {
  56. query = query.Where(x => x.IsDisplay != true);
  57. }
  58. }
  59. //查询条件
  60. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  61. {
  62. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  63. }
  64. return query.OrderBy(x => x.InSchoolStatusID).ToGridResultSet<InSchoolSettingView>(pageIndex, pageSize);
  65. }
  66. /// <summary>
  67. /// 查询对应的在校设定信息List
  68. /// </summary>
  69. /// <param name="configuretView"></param>
  70. /// <param name="inSchoolStatusID"></param>
  71. /// <param name="isSelected"></param>
  72. /// <param name="isDisplayID"></param>
  73. /// <returns></returns>
  74. public IList<InSchoolSettingView> GetInSchoolSettingViewList(ConfiguretView configuretView, int? inSchoolStatusID, int? isSelected, int? isDisplayID)
  75. {
  76. Expression<Func<Sys_DictionaryItem, bool>> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name);
  77. Expression<Func<CF_InSchoolSetting, bool>> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  78. var query = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting);
  79. if (inSchoolStatusID.HasValue)
  80. {
  81. query = query.Where(x => x.InSchoolStatusID == inSchoolStatusID);
  82. }
  83. if (isSelected.HasValue)
  84. {
  85. if (isSelected == (int)CF_GeneralPurpose.IsYes)
  86. {
  87. query = query.Where(x => x.IsSelected == true);
  88. }
  89. if (isSelected == (int)CF_GeneralPurpose.IsNo)
  90. {
  91. query = query.Where(x => x.IsSelected != true);
  92. }
  93. }
  94. if (isDisplayID.HasValue)
  95. {
  96. if (isDisplayID == (int)CF_GeneralPurpose.IsYes)
  97. {
  98. query = query.Where(x => x.IsDisplay == true);
  99. }
  100. if (isDisplayID == (int)CF_GeneralPurpose.IsNo)
  101. {
  102. query = query.Where(x => x.IsDisplay != true);
  103. }
  104. }
  105. //查询条件
  106. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  107. {
  108. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  109. }
  110. return query.OrderBy(x => x.InSchoolStatusID).ToList();
  111. }
  112. /// <summary>
  113. /// 查询对应的在校设定中状态List
  114. /// </summary>
  115. /// <param name="isSelected"></param>
  116. /// <returns></returns>
  117. public List<int?> GetInschoolStatusList(bool? isSelected)
  118. {
  119. Expression<Func<Sys_DictionaryItem, bool>> expInschoolStatus = (x => x.DictionaryCode == typeof(CF_InschoolStatus).Name);
  120. Expression<Func<CF_InSchoolSetting, bool>> expInSchoolSetting = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  121. var inSchoolSettingViewList = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(expInschoolStatus, expInSchoolSetting);
  122. var inSchoolStatusIDList = inSchoolSettingViewList.Where(x => x.IsSelected == isSelected).Select(x => x.InSchoolStatusID).ToList();
  123. return inSchoolStatusIDList;
  124. }
  125. /// <summary>
  126. /// 查询对应的在校设定信息InSchoolSettingView(根据在校设定ID)
  127. /// </summary>
  128. /// <param name="inSchoolSettingID"></param>
  129. /// <returns></returns>
  130. public InSchoolSettingView GetInSchoolSettingView(Guid? inSchoolSettingID)
  131. {
  132. try
  133. {
  134. var inSchoolSettingView = InSchoolSettingDAL.GetInSchoolSettingViewQueryable(x => x.InSchoolSettingID == inSchoolSettingID).SingleOrDefault();
  135. return inSchoolSettingView;
  136. }
  137. catch (Exception ex)
  138. {
  139. throw new Exception(ex.Message);
  140. }
  141. }
  142. /// <summary>
  143. /// 设置(新增、修改、删除)
  144. /// </summary>
  145. /// <param name="inSchoolSettingViewList"></param>
  146. public void InSchoolSettingEdit(IEnumerable<InSchoolSettingView> inSchoolSettingViewList)
  147. {
  148. try
  149. {
  150. var inSchoolSettingInList = new List<CF_InSchoolSetting>();
  151. var inSchoolSettingUpList = new List<CF_InSchoolSetting>();
  152. var inschoolStatusList = InSchoolSettingDAL.DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_InschoolStatus).Name).ToList();
  153. var inschoolStatusIDList = inschoolStatusList.Select(x => x.Value).ToList();
  154. var inSchoolSettingList = InSchoolSettingDAL.InSchoolSettingRepository.GetList(x => true);
  155. var inSchoolSettingIDDelList = inSchoolSettingList.Where(x => !inschoolStatusIDList.Contains(x.InSchoolStatusID)).Select(x => x.InSchoolSettingID).ToList();
  156. foreach (var inSchoolSettingView in inSchoolSettingViewList)
  157. {
  158. if (inSchoolSettingView.InSchoolSettingID == null || inSchoolSettingView.InSchoolSettingID == Guid.Empty)
  159. {
  160. var inSchoolSetting = inSchoolSettingList.Where(x => x.InSchoolStatusID == inSchoolSettingView.InSchoolStatusID).SingleOrDefault();
  161. if (inSchoolSetting != null)
  162. {
  163. inSchoolSettingIDDelList.Add(inSchoolSetting.InSchoolSettingID);
  164. }
  165. var newInSchoolSetting = new CF_InSchoolSetting();
  166. newInSchoolSetting.InSchoolSettingID = Guid.NewGuid();
  167. newInSchoolSetting.InSchoolStatusID = inSchoolSettingView.InSchoolStatusID;
  168. newInSchoolSetting.IsSelected = inSchoolSettingView.IsSelected == null ? false : inSchoolSettingView.IsSelected;
  169. SetNewStatus(newInSchoolSetting);
  170. inSchoolSettingInList.Add(newInSchoolSetting);
  171. }
  172. else
  173. {
  174. var inSchoolSetting = inSchoolSettingList.SingleOrDefault(x => x.InSchoolSettingID == inSchoolSettingView.InSchoolSettingID);
  175. inSchoolSetting.IsSelected = inSchoolSettingView.IsSelected == null ? false : inSchoolSettingView.IsSelected;
  176. SetModifyStatus(inSchoolSetting);
  177. inSchoolSettingUpList.Add(inSchoolSetting);
  178. }
  179. }
  180. using (TransactionScope ts = new TransactionScope())
  181. {
  182. UnitOfWork.Delete<CF_InSchoolSetting>(x => inSchoolSettingIDDelList.Contains(x.InSchoolSettingID));
  183. UnitOfWork.BulkInsert<CF_InSchoolSetting>(inSchoolSettingInList);
  184. if (inSchoolSettingUpList != null && inSchoolSettingUpList.Count() > 0)
  185. {
  186. UnitOfWork.BatchUpdate<CF_InSchoolSetting>(inSchoolSettingUpList);
  187. }
  188. ts.Complete();
  189. }
  190. }
  191. catch (Exception ex)
  192. {
  193. throw new Exception(ex.Message);
  194. }
  195. }
  196. }
  197. }