DictionaryServices.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.Entity;
  7. using Bowin.Common.Linq;
  8. using EMIS.DataLogic.SystemSetting;
  9. using EMIS.ViewModel.SystemSetting;
  10. using EMIS.ViewModel;
  11. using EMIS.Entities;
  12. namespace EMIS.CommonLogic.SystemSetting
  13. {
  14. public class DictionaryServices : BaseServices, IDictionaryServices
  15. {
  16. public DictionaryDAL DictionaryDAL { get; set; }
  17. /// <summary>
  18. /// 查询对应的字典类型信息View
  19. /// </summary>
  20. /// <param name="configuretView"></param>
  21. /// <param name="isEditable"></param>
  22. /// <param name="pageIndex"></param>
  23. /// <param name="pageSize"></param>
  24. /// <returns></returns>
  25. public IGridResultSet<DictionaryView> GetDictionaryViewGird(ConfiguretView configuretView, int? isEditable, int pageIndex, int pageSize)
  26. {
  27. //字典类型
  28. Expression<Func<Sys_Dictionary, bool>> exp = (x => true);
  29. if (isEditable.HasValue)
  30. {
  31. //可否编辑
  32. if (isEditable == (int)CF_GeneralPurpose.IsYes)
  33. {
  34. exp = exp.And(x => x.IsEditable == true);
  35. }
  36. if (isEditable == (int)CF_GeneralPurpose.IsNo)
  37. {
  38. exp = exp.And(x => x.IsEditable != true);
  39. }
  40. }
  41. var query = DictionaryDAL.GetDictionaryViewQueryable(exp);
  42. //查询条件
  43. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  44. {
  45. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  46. }
  47. return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName)
  48. .ThenBy(x => x.OrderNo)
  49. .ToGridResultSet<DictionaryView>(pageIndex, pageSize);
  50. }
  51. /// <summary>
  52. /// 查询对应的字典类型信息List
  53. /// </summary>
  54. /// <param name="configuretView"></param>
  55. /// <param name="isEditable"></param>
  56. /// <returns></returns>
  57. public IList<DictionaryView> GetDictionaryViewList(ConfiguretView configuretView, int? isEditable)
  58. {
  59. //字典类型
  60. Expression<Func<Sys_Dictionary, bool>> exp = (x => true);
  61. if (isEditable.HasValue)
  62. {
  63. //可否编辑
  64. if (isEditable == (int)CF_GeneralPurpose.IsYes)
  65. {
  66. exp = exp.And(x => x.IsEditable == true);
  67. }
  68. if (isEditable == (int)CF_GeneralPurpose.IsNo)
  69. {
  70. exp = exp.And(x => x.IsEditable != true);
  71. }
  72. }
  73. var query = DictionaryDAL.GetDictionaryViewQueryable(exp);
  74. //查询条件
  75. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  76. {
  77. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  78. }
  79. return query.OrderBy(x => x.DictionaryCode).ThenBy(x => x.DictionaryName)
  80. .ThenBy(x => x.OrderNo)
  81. .ToList();
  82. }
  83. /// <summary>
  84. /// 根据字典类型Code查询对应的字典类型信息DictionaryView
  85. /// </summary>
  86. /// <param name="DictionaryCode"></param>
  87. /// <returns></returns>
  88. public DictionaryView GetDictionaryView(string DictionaryCode)
  89. {
  90. try
  91. {
  92. var dictionaryView = DictionaryDAL
  93. .GetDictionaryViewQueryable(x => x.DictionaryCode == DictionaryCode).SingleOrDefault();
  94. return dictionaryView;
  95. }
  96. catch (Exception ex)
  97. {
  98. throw new Exception(ex.Message);
  99. }
  100. }
  101. /// <summary>
  102. /// 编辑(修改)
  103. /// </summary>
  104. /// <param name="dictionaryView"></param>
  105. public void DictionaryEdit(DictionaryView dictionaryView)
  106. {
  107. try
  108. {
  109. var dictionaryVerify = DictionaryDAL.DictionaryRepository.GetList(x => x.DictionaryCode != dictionaryView.DictionaryCode && x.Name == dictionaryView.DictionaryName).SingleOrDefault();
  110. if (dictionaryVerify == null)
  111. {
  112. if (!string.IsNullOrEmpty(dictionaryView.DictionaryCode))
  113. {
  114. var dictionary = DictionaryDAL.DictionaryRepository.GetList(x => x.DictionaryCode == dictionaryView.DictionaryCode).SingleOrDefault();
  115. if (dictionary == null)
  116. {
  117. throw new Exception("数据有误,请核查");
  118. }
  119. else
  120. {
  121. dictionary.OrderNo = (short)dictionaryView.OrderNo;
  122. dictionary.Name = dictionaryView.DictionaryName;
  123. }
  124. }
  125. }
  126. else
  127. {
  128. throw new Exception("已存在相同的字典类型(类型代码或类型名称唯一),请核查");
  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="dictionaryCodeList"></param>
  141. /// <returns></returns>
  142. public bool DictionaryDelete(IList<string> dictionaryCodeList)
  143. {
  144. try
  145. {
  146. UnitOfWork.Delete<Sys_Dictionary>(x => dictionaryCodeList.Contains(x.DictionaryCode));
  147. UnitOfWork.Commit();
  148. return true;
  149. }
  150. catch (Exception ex)
  151. {
  152. throw new Exception(ex.Message);
  153. }
  154. }
  155. }
  156. }