ChargeProjectServices.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.CommonLogic.ChargeManage;
  6. using EMIS.CommonLogic;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel.ChargeManage.ChargeSituation;
  9. using EMIS.ViewModel;
  10. using EMIS.Entities;
  11. using System.Text.RegularExpressions;
  12. using EMIS.DataLogic.ChargeManage.ChargeSituation;
  13. using System.Linq.Expressions;
  14. using Bowin.Common.Linq;
  15. namespace EMIS.CommonLogic.ChargeManage.ChargeSituation
  16. {
  17. public class ChargeProjectServices : BaseServices, IChargeProjectServices
  18. {
  19. public ChargeProjectDAL ChargeProjectDAL { get; set; }
  20. /// <summary>
  21. /// 查询收费项目信息View
  22. /// </summary>
  23. /// <param name="configuretView"></param>
  24. /// <param name="pageIndex"></param>
  25. /// <param name="pageSize"></param>
  26. /// <returns></returns>
  27. public IGridResultSet<ChargeProjectView> GetChargeProjectViewGrid(ConfiguretView configuretView,
  28. int pageIndex, int pageSize)
  29. {
  30. Expression<Func<EC_ChargeProject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  31. var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
  32. //查询条件
  33. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  34. {
  35. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  36. }
  37. return query.OrderBy(x => x.ChrageProjectName)
  38. .ToGridResultSet<ChargeProjectView>(pageIndex, pageSize);
  39. }
  40. /// <summary>
  41. /// 查询收费项目信息List
  42. /// </summary>
  43. /// <param name="configuretView"></param>
  44. /// <returns></returns>
  45. public List<ChargeProjectView> GetChargeProjectViewList(ConfiguretView configuretView)
  46. {
  47. Expression<Func<EC_ChargeProject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  48. var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
  49. //查询条件
  50. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  51. {
  52. string conditionValue = string.Empty;
  53. Regex rg = new Regex(@"^[0-9]*$");
  54. if (rg.IsMatch(configuretView.ConditionValue))
  55. {
  56. conditionValue = Convert.ToInt32(configuretView.ConditionValue).ToString();
  57. }
  58. else
  59. {
  60. conditionValue = configuretView.ConditionValue;
  61. }
  62. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, conditionValue);
  63. }
  64. return query.OrderBy(x => x.ChrageProjectName).ToList();
  65. }
  66. /// <summary>
  67. /// 查询收费项目实体
  68. /// </summary>
  69. /// <param name="chargeProjectID"></param>
  70. /// <returns></returns>
  71. public EC_ChargeProject GetChargeProject(Guid? chargeProjectID)
  72. {
  73. try
  74. {
  75. Expression<Func<EC_ChargeProject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  76. exp = exp.And(x => x.ChargeProjectID == chargeProjectID);
  77. return ChargeProjectDAL.chargeProjectRepository.GetSingle(exp);
  78. }
  79. catch (Exception ex)
  80. {
  81. throw new Exception(ex.Message);
  82. }
  83. }
  84. /// <summary>
  85. /// 查询收费项目View
  86. /// </summary>
  87. /// <param name="chargeProjectID"></param>
  88. /// <returns></returns>
  89. public ChargeProjectView GetChargeProjectView(Guid? chargeProjectID)
  90. {
  91. try
  92. {
  93. Expression<Func<EC_ChargeProject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  94. exp = exp.And(x => x.ChargeProjectID == chargeProjectID);
  95. var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
  96. return query.SingleOrDefault();
  97. }
  98. catch (Exception ex)
  99. {
  100. throw new Exception(ex.Message);
  101. }
  102. }
  103. /// <summary>
  104. /// 查询收费项目明细View
  105. /// </summary>
  106. /// <param name="chargeProjectID"></param>
  107. /// <returns></returns>
  108. public ChargeProjectView GetChargeProjectDetailsView(Guid? chargeProjectID)
  109. {
  110. try
  111. {
  112. Expression<Func<EC_ChargeProject, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  113. exp = exp.And(x => x.ChargeProjectID == chargeProjectID);
  114. var query = ChargeProjectDAL.GetChargeProjectViewQueryAble(exp);
  115. return query.SingleOrDefault();
  116. }
  117. catch (Exception ex)
  118. {
  119. throw new Exception(ex.Message);
  120. }
  121. }
  122. /// <summary>
  123. /// 编辑(新增、修改)
  124. /// </summary>
  125. /// <param name="chargeProjectView"></param>
  126. public void ChargeProjectAdd(ChargeProjectView chargeProjectView)
  127. {
  128. try
  129. {
  130. //查询数据库进行验证(需排除自己)
  131. var chargeProject = ChargeProjectDAL.chargeProjectRepository
  132. .GetList(x => x.ChargeProjectID != chargeProjectView.ChargeProjectID
  133. && x.Name == chargeProjectView.ChrageProjectName).FirstOrDefault();
  134. if (chargeProject == null)
  135. {
  136. //数据有误验证
  137. if (chargeProjectView.ChargeProjectID != null && chargeProjectView.ChargeProjectID != Guid.Empty)
  138. {
  139. chargeProject = ChargeProjectDAL.chargeProjectRepository
  140. .GetList(x => x.ChargeProjectID == chargeProjectView.ChargeProjectID).SingleOrDefault();
  141. if (chargeProject == null)
  142. {
  143. throw new Exception("数据有误,请核查");
  144. }
  145. else
  146. {
  147. chargeProject.Name = chargeProjectView.ChrageProjectName;
  148. chargeProject.Remark = chargeProjectView.Remark;
  149. SetModifyStatus(chargeProject);
  150. }
  151. }
  152. else
  153. {
  154. EC_ChargeProject newChargeProject = new EC_ChargeProject();
  155. newChargeProject.ChargeProjectID = Guid.NewGuid();
  156. newChargeProject.Name = chargeProjectView.ChrageProjectName;
  157. newChargeProject.Remark = chargeProjectView.Remark;
  158. SetNewStatus(newChargeProject);
  159. UnitOfWork.Add(newChargeProject);
  160. }
  161. }
  162. else
  163. {
  164. throw new Exception("已存在相同的收费项目");
  165. }
  166. UnitOfWork.Commit();
  167. }
  168. catch (Exception ex)
  169. {
  170. throw new Exception(ex.Message);
  171. }
  172. }
  173. /// <summary>
  174. /// 删除
  175. /// </summary>
  176. /// <param name="chargeProjectIDs"></param>
  177. /// <returns></returns>
  178. public bool ChargeProjectDelete(List<Guid> chargeProjectIDs)
  179. {
  180. try
  181. {
  182. UnitOfWork.Delete<EC_ChargeProject>(x => chargeProjectIDs.Contains(x.ChargeProjectID));
  183. UnitOfWork.Commit();
  184. return true;
  185. }
  186. catch (Exception)
  187. {
  188. throw;
  189. }
  190. }
  191. /// <summary>
  192. /// 验证
  193. /// </summary>
  194. /// <param name="chargeProjectID"></param>
  195. /// <param name="chrageProjectName"></param>
  196. /// <returns></returns>
  197. public string GetVerification(Guid? chargeProjectID, string chrageProjectName)
  198. {
  199. //查询数据库进行验证(需排除自己)
  200. var chargeProject = ChargeProjectDAL.chargeProjectRepository.GetList(x => x.ChargeProjectID != chargeProjectID
  201. && x.Name == chrageProjectName).FirstOrDefault();
  202. if (chargeProject == null)
  203. {
  204. //数据有误验证
  205. if (chargeProjectID.HasValue && chargeProjectID != Guid.Empty)
  206. {
  207. chargeProject = ChargeProjectDAL.chargeProjectRepository
  208. .GetList(x => x.ChargeProjectID == chargeProjectID).SingleOrDefault();
  209. if (chargeProject == null)
  210. {
  211. return "数据有误,请核查";
  212. }
  213. else
  214. {
  215. return "成功";
  216. }
  217. }
  218. else
  219. {
  220. return "成功";
  221. }
  222. }
  223. else
  224. {
  225. return "已存在相同的收费项目";
  226. }
  227. }
  228. }
  229. }