EvaluationTableServices.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.Data;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. using EMIS.ViewModel.EvaluationManage.EvaluationTable;
  12. using EMIS.DataLogic.EvaluationManage.EvaluationTable;
  13. namespace EMIS.CommonLogic.EvaluationManage.EvaluationTable
  14. {
  15. public class EvaluationTableServices : BaseServices, IEvaluationTableServices
  16. {
  17. public EvaluationTableDAL EvaluationTableDAL { get; set; }
  18. /// <summary>
  19. /// 查询对应的评价表信息View
  20. /// </summary>
  21. /// <param name="configuretView"></param>
  22. /// <param name="evaluationParticipateTypeID"></param>
  23. /// <param name="evaluationTypeID"></param>
  24. /// <param name="isStudent"></param>
  25. /// <param name="isEnabled"></param>
  26. /// <param name="pageIndex"></param>
  27. /// <param name="pageSize"></param>
  28. /// <returns></returns>
  29. public IGridResultSet<EvaluationTableView> GetEvaluationTableViewGrid(ConfiguretView configuretView, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, int? isStudent, int? isEnabled, int pageIndex, int pageSize)
  30. {
  31. Expression<Func<EM_EvaluationTable, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  32. if (evaluationParticipateTypeID.HasValue)
  33. {
  34. exp = exp.And(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
  35. }
  36. if (evaluationTypeID.HasValue)
  37. {
  38. exp = exp.And(x => x.EvaluationIntTypeID == evaluationTypeID);
  39. }
  40. if (isEnabled.HasValue)
  41. {
  42. if (isEnabled.Value == (int)CF_GeneralPurpose.IsYes)
  43. {
  44. exp = exp.And(x => x.IsEnabled == true);
  45. }
  46. if (isEnabled.Value == (int)CF_GeneralPurpose.IsNo)
  47. {
  48. exp = exp.And(x => x.IsEnabled != true);
  49. }
  50. }
  51. var query = EvaluationTableDAL.GetEvaluationTableViewQueryable(exp);
  52. if (isStudent.HasValue)
  53. {
  54. if (isStudent.Value == (int)CF_GeneralPurpose.IsYes)
  55. {
  56. query = query.Where(x => x.IsStudent == true);
  57. }
  58. if (isStudent.Value == (int)CF_GeneralPurpose.IsNo)
  59. {
  60. query = query.Where(x => x.IsStudent != true);
  61. }
  62. }
  63. //查询条件
  64. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  65. {
  66. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  67. }
  68. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<EvaluationTableView>(pageIndex, pageSize);
  69. }
  70. /// <summary>
  71. /// 查询对应的评价表信息List
  72. /// </summary>
  73. /// <param name="configuretView"></param>
  74. /// <param name="evaluationParticipateTypeID"></param>
  75. /// <param name="evaluationTypeID"></param>
  76. /// <param name="isStudent"></param>
  77. /// <param name="isEnabled"></param>
  78. /// <returns></returns>
  79. public IList<EvaluationTableView> GetEvaluationTableViewList(ConfiguretView configuretView, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, int? isStudent, int? isEnabled)
  80. {
  81. Expression<Func<EM_EvaluationTable, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  82. if (evaluationParticipateTypeID.HasValue)
  83. {
  84. exp = exp.And(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
  85. }
  86. if (evaluationTypeID.HasValue)
  87. {
  88. exp = exp.And(x => x.EvaluationIntTypeID == evaluationTypeID);
  89. }
  90. if (isEnabled.HasValue)
  91. {
  92. if (isEnabled.Value == (int)CF_GeneralPurpose.IsYes)
  93. {
  94. exp = exp.And(x => x.IsEnabled == true);
  95. }
  96. if (isEnabled.Value == (int)CF_GeneralPurpose.IsNo)
  97. {
  98. exp = exp.And(x => x.IsEnabled != true);
  99. }
  100. }
  101. var query = EvaluationTableDAL.GetEvaluationTableViewQueryable(exp);
  102. if (isStudent.HasValue)
  103. {
  104. if (isStudent.Value == (int)CF_GeneralPurpose.IsYes)
  105. {
  106. query = query.Where(x => x.IsStudent == true);
  107. }
  108. if (isStudent.Value == (int)CF_GeneralPurpose.IsNo)
  109. {
  110. query = query.Where(x => x.IsStudent != true);
  111. }
  112. }
  113. //查询条件
  114. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  115. {
  116. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  117. }
  118. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  119. }
  120. /// <summary>
  121. /// 查询对应的评价表信息View(启用状态为是或已使用)
  122. /// </summary>
  123. /// <param name="configuretView"></param>
  124. /// <param name="evaluationTableID"></param>
  125. /// <param name="evaluationParticipateTypeID"></param>
  126. /// <param name="evaluationTypeID"></param>
  127. /// <param name="pageIndex"></param>
  128. /// <param name="pageSize"></param>
  129. /// <returns></returns>
  130. public IGridResultSet<EvaluationTableView> GetEnabledAndUseEvaluationTableViewGrid(ConfiguretView configuretView, Guid? evaluationTableID, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID, int pageIndex, int pageSize)
  131. {
  132. Expression<Func<EM_EvaluationTable, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  133. if (evaluationTableID.HasValue)
  134. {
  135. exp = exp.And(x => x.IsEnabled == true || x.EvaluationTableID == evaluationTableID);
  136. }
  137. else
  138. {
  139. exp = exp.And(x => x.IsEnabled == true);
  140. }
  141. if (evaluationParticipateTypeID.HasValue)
  142. {
  143. exp = exp.And(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
  144. }
  145. if (evaluationTypeID.HasValue)
  146. {
  147. exp = exp.And(x => x.EvaluationIntTypeID == evaluationTypeID);
  148. }
  149. var query = EvaluationTableDAL.GetEvaluationTableViewQueryable(exp);
  150. //查询条件
  151. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  152. {
  153. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  154. }
  155. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<EvaluationTableView>(pageIndex, pageSize);
  156. }
  157. /// <summary>
  158. /// 查询对应的评价表信息List(启用状态为是或已使用)
  159. /// </summary>
  160. /// <param name="configuretView"></param>
  161. /// <param name="evaluationTableID"></param>
  162. /// <param name="evaluationParticipateTypeID"></param>
  163. /// <param name="evaluationTypeID"></param>
  164. /// <returns></returns>
  165. public IList<EvaluationTableView> GetEnabledAndUseEvaluationTableViewList(ConfiguretView configuretView, Guid? evaluationTableID, Guid? evaluationParticipateTypeID, Guid? evaluationTypeID)
  166. {
  167. Expression<Func<EM_EvaluationTable, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  168. if (evaluationTableID.HasValue)
  169. {
  170. exp = exp.And(x => x.IsEnabled == true || x.EvaluationTableID == evaluationTableID);
  171. }
  172. else
  173. {
  174. exp = exp.And(x => x.IsEnabled == true);
  175. }
  176. if (evaluationParticipateTypeID.HasValue)
  177. {
  178. exp = exp.And(x => x.EvaluationParticipateTypeID == evaluationParticipateTypeID);
  179. }
  180. if (evaluationTypeID.HasValue)
  181. {
  182. exp = exp.And(x => x.EvaluationIntTypeID == evaluationTypeID);
  183. }
  184. var query = EvaluationTableDAL.GetEvaluationTableViewQueryable(exp);
  185. //查询条件
  186. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  187. {
  188. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  189. }
  190. return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
  191. }
  192. /// <summary>
  193. /// 查询对应的评价表信息EvaluationTableView
  194. /// </summary>
  195. /// <param name="evaluationTableID"></param>
  196. /// <returns></returns>
  197. public EvaluationTableView GetEvaluationTableView(Guid? evaluationTableID)
  198. {
  199. try
  200. {
  201. Expression<Func<EM_EvaluationTable, bool>> exp = (x => x.EvaluationTableID == evaluationTableID);
  202. var query = EvaluationTableDAL.GetEvaluationTableViewQueryable(exp).SingleOrDefault();
  203. return query;
  204. }
  205. catch (Exception ex)
  206. {
  207. throw new Exception(ex.Message);
  208. }
  209. }
  210. /// <summary>
  211. /// 编辑
  212. /// </summary>
  213. /// <param name="evaluationTableView"></param>
  214. public void EvaluationTableEdit(EvaluationTableView evaluationTableView)
  215. {
  216. try
  217. {
  218. var evaluationTableVerify = EvaluationTableDAL.EvaluationTableRepository.GetList(x => x.EvaluationTableID != evaluationTableView.EvaluationTableID && (x.Code == evaluationTableView.Code.Trim() || x.Name == evaluationTableView.Name.Trim())).SingleOrDefault();
  219. if (evaluationTableVerify == null)
  220. {
  221. if (evaluationTableView.EvaluationTableID != Guid.Empty)
  222. {
  223. var evaluationTable = EvaluationTableDAL.EvaluationTableRepository.GetList(x => x.EvaluationTableID == evaluationTableView.EvaluationTableID).SingleOrDefault();
  224. if (evaluationTable == null)
  225. {
  226. throw new Exception("数据有误,请核查。");
  227. }
  228. else
  229. {
  230. //表示修改
  231. evaluationTable.Code = evaluationTableView.Code.Trim();
  232. evaluationTable.Name = evaluationTableView.Name.Trim();
  233. evaluationTable.EvaluationParticipateTypeID = evaluationTableView.EvaluationParticipateTypeID;
  234. evaluationTable.EvaluationIntTypeID = evaluationTableView.EvaluationTypeID;
  235. evaluationTable.Weight = evaluationTableView.Weight;
  236. evaluationTable.IsEnabled = evaluationTableView.IsEnabled;
  237. evaluationTable.Remark = evaluationTableView.Remark;
  238. SetModifyStatus(evaluationTable);
  239. }
  240. }
  241. else
  242. {
  243. //表示新增
  244. var newEvaluationTable = new EM_EvaluationTable();
  245. newEvaluationTable.EvaluationTableID = Guid.NewGuid();
  246. newEvaluationTable.Code = evaluationTableView.Code.Trim();
  247. newEvaluationTable.Name = evaluationTableView.Name.Trim();
  248. newEvaluationTable.EvaluationParticipateTypeID = evaluationTableView.EvaluationParticipateTypeID;
  249. newEvaluationTable.EvaluationIntTypeID = evaluationTableView.EvaluationTypeID;
  250. newEvaluationTable.Weight = evaluationTableView.Weight;
  251. newEvaluationTable.IsEnabled = evaluationTableView.IsEnabled;
  252. newEvaluationTable.Remark = evaluationTableView.Remark;
  253. SetNewStatus(newEvaluationTable);
  254. UnitOfWork.Add(newEvaluationTable);
  255. }
  256. }
  257. else
  258. {
  259. throw new Exception("已存在相同的评价表信息(编号或评价表名唯一),请核查。");
  260. }
  261. UnitOfWork.Commit();
  262. }
  263. catch (Exception ex)
  264. {
  265. throw new Exception(ex.Message);
  266. }
  267. }
  268. /// <summary>
  269. /// 删除
  270. /// </summary>
  271. /// <param name="evaluationTableIDs"></param>
  272. /// <returns></returns>
  273. public bool EvaluationTableDelete(List<Guid?> evaluationTableIDs)
  274. {
  275. try
  276. {
  277. UnitOfWork.Delete<EM_EvaluationTable>(x => evaluationTableIDs.Contains(x.EvaluationTableID));
  278. return true;
  279. }
  280. catch (Exception)
  281. {
  282. throw;
  283. }
  284. }
  285. }
  286. }