DictionaryServices.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. //查询数据库进行验证
  110. var dictionaryVerification = DictionaryDAL.DictionaryRepository
  111. .GetList(x => x.DictionaryCode != dictionaryView.DictionaryCode
  112. && x.Name == dictionaryView.DictionaryName)
  113. .SingleOrDefault();
  114. if (dictionaryVerification == null)
  115. {
  116. //数据有误验证
  117. if (!string.IsNullOrEmpty(dictionaryView.DictionaryCode))
  118. {
  119. var dictionary = DictionaryDAL.DictionaryRepository
  120. .GetList(x => x.DictionaryCode == dictionaryView.DictionaryCode)
  121. .SingleOrDefault();
  122. if (dictionary == null)
  123. {
  124. throw new Exception("数据有误,请核查");
  125. }
  126. else
  127. {
  128. //表示修改
  129. dictionary.OrderNo = (short)dictionaryView.OrderNo;
  130. dictionary.Name = dictionaryView.DictionaryName;
  131. //SetModifyStatus(dictionary);
  132. }
  133. }
  134. else
  135. {
  136. //表示新增(暂不考虑)
  137. }
  138. }
  139. else
  140. {
  141. throw new Exception("已存在相同的类型名称,请核查");
  142. }
  143. //事务提交
  144. UnitOfWork.Commit();
  145. }
  146. catch (Exception ex)
  147. {
  148. throw new Exception(ex.Message);
  149. }
  150. }
  151. /// <summary>
  152. /// 删除(不可删除)
  153. /// </summary>
  154. /// <param name="dictionaryCodeList"></param>
  155. /// <returns></returns>
  156. public bool DictionaryDelete(IList<string> dictionaryCodeList)
  157. {
  158. try
  159. {
  160. //UnitOfWork.Delete<Sys_Dictionary>(x => dictionaryCodeList.Contains(x.DictionaryCode));
  161. //UnitOfWork.Commit();
  162. return false;
  163. }
  164. catch (Exception ex)
  165. {
  166. throw new Exception(ex.Message);
  167. }
  168. }
  169. }
  170. }