BaseSupplier.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using WMS.Info;
  5. using WMS.Util;
  6. namespace WMS.Core
  7. {
  8. public class BaseSupplier
  9. {
  10. /// <summary>
  11. /// 获取列表数据
  12. /// <summary>
  13. /// <returns></returns>
  14. public IEnumerable<BASE_SUPPLIER> GetList(string keyword)
  15. {
  16. try
  17. {
  18. return SysDbCore.GetDbCtx().Queryable<BASE_SUPPLIER>().Where(it => it.F_ISDELETE == 0).WhereIF(!keyword.IsEmpty(), it => it.F_NO.Contains(keyword) || it.F_NAME.Contains(keyword)).ToList();
  19. }
  20. catch (Exception ex)
  21. {
  22. throw ex;
  23. }
  24. }
  25. /// <summary>
  26. /// 获取列表数据
  27. /// <summary>
  28. /// <returns></returns>
  29. public IEnumerable<BASE_SUPPLIER> GetListByNo(ViewParams queryJson)
  30. {
  31. SqlSugarClient client = null;
  32. try
  33. {
  34. client = SysDbCore.GetDbCtx();
  35. var db = client.Queryable<BASE_SUPPLIER>().Where(it => it.F_ISDELETE == 0);
  36. if (queryJson != null)
  37. {
  38. if (!string.IsNullOrEmpty(queryJson.txt_Supper))
  39. {
  40. db.Where(v => v.F_NO.Contains(queryJson.txt_Supper));
  41. }
  42. }
  43. return db.ToList();
  44. }
  45. catch (Exception ex)
  46. {
  47. throw ex;
  48. }
  49. finally { client.Dispose(); }
  50. }
  51. /// <summary>
  52. /// 获取分页数据
  53. /// <summary>
  54. /// <returns></returns>
  55. public IEnumerable<BASE_SUPPLIER> GetPageList(string keyword, Pagination pagination)
  56. {
  57. try
  58. {
  59. int count = 0;
  60. var db = SysDbCore.GetDbCtx().Queryable<BASE_SUPPLIER>().Where(it => it.F_ISDELETE == 0).WhereIF(!keyword.IsEmpty(), it => it.F_NO.Contains(keyword) || it.F_NAME.Contains(keyword));
  61. List<BASE_SUPPLIER> list = null;
  62. if (pagination.sord.ToUpper() == "ASC")
  63. {
  64. list = db.OrderBy(pagination.sidx).ToPageList(pagination.page, pagination.rows, ref count);
  65. }
  66. else
  67. {
  68. string orderstr = pagination.sidx + " desc";
  69. list = db.OrderBy(orderstr).ToPageList(pagination.page, pagination.rows, ref count);
  70. }
  71. pagination.records = count;
  72. return list;
  73. }
  74. catch (Exception ex)
  75. {
  76. throw ex;
  77. }
  78. }
  79. /// <summary>
  80. /// 获取实体数据
  81. /// <param name="keyValue">主键</param>
  82. /// <summary>
  83. /// <returns></returns>
  84. public BASE_SUPPLIER GetEntity(string keyValue)
  85. {
  86. try
  87. {
  88. return SysDbCore.GetDbCtx().Queryable<BASE_SUPPLIER>().Where(it => it.F_ISDELETE == 0 && it.F_NO == keyValue).First();
  89. }
  90. catch (Exception ex)
  91. {
  92. throw ex;
  93. }
  94. }
  95. /// <summary>
  96. /// 删除实体数据
  97. /// <param name="keyValue">主键</param>
  98. /// <summary>
  99. /// <returns></returns>
  100. public void DeleteEntity(string keyValue)
  101. {
  102. try
  103. {
  104. //SysDbCore.GetDbCtx().Deleteable<BASE_SUPPLIER>().Where(it => it.F_NO == keyValue).ExecuteCommand();
  105. SysDbCore.GetDbCtx().Updateable<BASE_SUPPLIER>().UpdateColumns(it => new BASE_SUPPLIER { F_ISDELETE = 1 }).Where(it => it.F_NO == keyValue).ExecuteCommand();
  106. }
  107. catch (Exception ex)
  108. {
  109. throw ex;
  110. }
  111. }
  112. /// <summary>
  113. /// 保存实体数据(新增、修改)
  114. /// <param name="keyValue">主键</param>
  115. /// <summary>
  116. /// <returns></returns>
  117. public void SaveEntity(LoginUserInfo loginUserInfo, string keyValue, BASE_SUPPLIER entity)
  118. {
  119. try
  120. {
  121. if (entity == null)
  122. {
  123. throw SysExCore.ThrowFailException("输入数据为空。");
  124. }
  125. if (string.IsNullOrWhiteSpace(entity.F_NO))
  126. {
  127. throw SysExCore.ThrowFailException("编码为空。");
  128. }
  129. if (string.IsNullOrWhiteSpace(entity.F_NAME))
  130. {
  131. throw SysExCore.ThrowFailException("名称为空。");
  132. }
  133. entity.F_EDITTIME = DateTime.Now;
  134. entity.F_EDITUSERNO = loginUserInfo.UserNo;
  135. if (string.IsNullOrEmpty(keyValue))
  136. {
  137. var item = SysDbCore.GetDbCtx().Queryable<BASE_SUPPLIER>().First(v => v.F_NO == entity.F_NO);
  138. if (item != null)
  139. {
  140. throw SysExCore.ThrowFailException("供应商编号不能重复。");
  141. }
  142. entity.F_ADDTIME = DateTime.Now;
  143. entity.F_ADDUSERNO = loginUserInfo.UserNo;
  144. entity.F_ISDELETE = 0;
  145. //entity.F_ISSTOP = 0;
  146. SysDbCore.GetDbCtx().Insertable(entity).ExecuteCommand();
  147. }
  148. else
  149. {
  150. SysDbCore.GetDbCtx().Updateable(entity).IgnoreColumns(it => new { it.F_ADDTIME, it.F_ADDUSERNO }).Where(it => it.F_NO == keyValue).ExecuteCommand();
  151. }
  152. }
  153. catch (Exception ex)
  154. {
  155. throw ex;
  156. }
  157. }
  158. public Dictionary<string, BASE_SUPPLIER> GetMap()
  159. {
  160. try
  161. {
  162. Dictionary<string, BASE_SUPPLIER> dics = new Dictionary<string, BASE_SUPPLIER>();
  163. SysDbCore.GetDbCtx().Queryable<BASE_SUPPLIER>().ToList().ForEach(it => dics.Add(it.F_NO, it));
  164. return dics;
  165. }
  166. catch (Exception ex)
  167. {
  168. throw ex;
  169. }
  170. }
  171. /// <summary>
  172. /// 获取按钮列表树形数据(基于供应商模块)
  173. /// </summary>
  174. /// <returns></returns>
  175. public List<TreeModel> GetCheckTree()
  176. {
  177. List<BASE_SUPPLIER> list = SysDbCore.GetDbCtx().Queryable<BASE_SUPPLIER>().Where(it => it.F_ISDELETE == 0 && it.F_ISSTOP == 0).OrderBy(v=>v.F_NO).ToList();
  178. List<TreeModel> treeList = new List<TreeModel>();
  179. //{
  180. // TreeModel node = new TreeModel();
  181. // node.id = ACLAuthorize.ALLAuthorize;
  182. // node.text = "授权所有";
  183. // node.value = ACLAuthorize.ALLAuthorize;
  184. // node.showcheck = true;
  185. // node.checkstate = 0;
  186. // node.isexpand = true;
  187. // node.icon = ACLAuthorize.IcoAuthorize;
  188. // node.parentId = "";
  189. // treeList.Add(node);
  190. //}
  191. foreach (var item in list)
  192. {
  193. TreeModel node = new TreeModel();
  194. node.id = item.F_NO;
  195. node.text = item.F_NO+"_"+item.F_NAME;
  196. node.value = item.F_NO;
  197. node.showcheck = true;
  198. node.checkstate = 0;
  199. node.isexpand = true;
  200. node.icon = ACLAuthorize.IcoAuthorize;
  201. node.parentId = "";
  202. treeList.Add(node);
  203. }
  204. return treeList.ToTree();
  205. }
  206. }
  207. }