UserStoreChangeService.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * 创客库存变动记录
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public static class UserStoreChangeService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="relationData">关联表</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="count">总数(输出)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  26. {
  27. List<string> fields = new List<string>(); //要显示的列
  28. fields.Add("Id");
  29. fields.Add("CreateDate"); //添加时间
  30. fields.Add("Status"); //状态
  31. fields.Add("UserId"); //创客
  32. fields.Add("BrandId"); //产品类型
  33. fields.Add("TransType"); //交易类型
  34. fields.Add("SnNo"); //SN编号
  35. fields.Add("SnType"); //SN机具类型
  36. fields.Add("StockOpDirect"); //库存操作方向
  37. fields.Add("ToUserId"); //收货创客
  38. fields.Add("ToStoreId"); //创客退货收货仓库
  39. fields.Add("SourceStoreId"); //源仓库
  40. fields.Add("SnStatus"); //SN状态
  41. fields.Add("BindStatus"); //绑定状态
  42. fields.Add("BindMerchantId"); //绑定商户
  43. fields.Add("ActiveStatus"); //激活状态
  44. fields.Add("ActRewardUserId"); //激活奖励创客
  45. fields.Add("FromUserId"); //出货创客
  46. fields.Add("BrandType"); //品牌类型
  47. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserStoreChange", relationData, orderBy, page, limit, condition, fields);
  48. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  49. count = int.Parse(obj["count"].ToString());
  50. return diclist;
  51. }
  52. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  53. {
  54. List<string> fields = new List<string>(); //要显示的列
  55. fields.Add("Id");
  56. fields.Add("CreateDate"); //添加时间
  57. fields.Add("Status"); //状态
  58. fields.Add("UserId"); //创客
  59. fields.Add("BrandId"); //产品类型
  60. fields.Add("TransType"); //交易类型
  61. fields.Add("SnNo"); //SN编号
  62. fields.Add("SnType"); //SN机具类型
  63. fields.Add("StockOpDirect"); //库存操作方向
  64. fields.Add("ToUserId"); //收货创客
  65. fields.Add("ToStoreId"); //创客退货收货仓库
  66. fields.Add("SourceStoreId"); //源仓库
  67. fields.Add("SnStatus"); //SN状态
  68. fields.Add("BindStatus"); //绑定状态
  69. fields.Add("BindMerchantId"); //绑定商户
  70. fields.Add("ActiveStatus"); //激活状态
  71. fields.Add("ActRewardUserId"); //激活奖励创客
  72. fields.Add("FromUserId"); //出货创客
  73. fields.Add("BrandType"); //品牌类型
  74. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserStoreChange", relationData, orderBy, page, limit, condition, fields);
  75. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  76. return diclist;
  77. }
  78. /// <summary>
  79. /// 查询一条记录
  80. /// </summary>
  81. /// <param name="Id">主键Id</param>
  82. /// <returns></returns>
  83. public static UserStoreChange Query(int Id)
  84. {
  85. WebCMSEntities db = new WebCMSEntities();
  86. UserStoreChange editData = db.UserStoreChange.FirstOrDefault(m => m.Id == Id) ?? new UserStoreChange();
  87. db.Dispose();
  88. return editData;
  89. }
  90. /// <summary>
  91. /// 查询记录数
  92. /// </summary>
  93. /// <param name="Id">主键Id</param>
  94. /// <returns></returns>
  95. public static int Count(string condition = "")
  96. {
  97. int result = 0;
  98. DataTable dt = CustomerSqlConn.dtable("select count(Id) from UserStoreChange where 1=1" + condition, _conn);
  99. if (dt.Rows.Count > 0)
  100. {
  101. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  102. }
  103. return result;
  104. }
  105. /// <summary>
  106. /// 查询是否存在
  107. /// </summary>
  108. /// <param name="Id">主键Id</param>
  109. /// <returns></returns>
  110. public static bool Exist(int Id)
  111. {
  112. WebCMSEntities db = new WebCMSEntities();
  113. bool check = db.UserStoreChange.Any(m => m.Id == Id);
  114. db.Dispose();
  115. return check;
  116. }
  117. /// <summary>
  118. /// 添加数据
  119. /// </summary>
  120. /// <param name="Fields">要设置的字段</param>
  121. /// <returns></returns>
  122. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  123. {
  124. if (check)
  125. {
  126. }
  127. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("UserStoreChange", fields, 0);
  128. return new AppResultJson() { Status = "1", Data = Id };
  129. }
  130. /// <summary>
  131. /// 修改数据
  132. /// </summary>
  133. /// <param name="Fields">要设置的字段</param>
  134. /// <param name="Id">主键Id</param>
  135. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  136. {
  137. if (check)
  138. {
  139. }
  140. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserStoreChange", fields, Id);
  141. return new AppResultJson() { Status = "1", Data = Id };
  142. }
  143. /// <summary>
  144. /// 逻辑删除
  145. /// </summary>
  146. /// <param name="Id">主键Id</param>
  147. public static void Remove(int Id)
  148. {
  149. Dictionary<string, object> fields = new Dictionary<string, object>();
  150. fields.Add("Status", -1);
  151. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserStoreChange", fields, Id);
  152. }
  153. /// <summary>
  154. /// 删除数据
  155. /// </summary>
  156. /// <param name="Id">主键Id</param>
  157. public static void Delete(int Id)
  158. {
  159. new DbService(AppConfig.Base.mainTables, _conn).Delete("UserStoreChange", Id);
  160. }
  161. /// <summary>
  162. /// 排序
  163. /// </summary>
  164. /// <param name="Id">主键Id</param>
  165. /// <param name="Sort">排序序号</param>
  166. public static void Sort(int Id, int Sort)
  167. {
  168. new DbService(AppConfig.Base.mainTables, _conn).Sort("UserStoreChange", Sort, Id);
  169. }
  170. /// <summary>
  171. /// 导入数据
  172. /// </summary>
  173. /// <param name="ExcelData">json数据</param>
  174. public static void Import(string ExcelData)
  175. {
  176. WebCMSEntities db = new WebCMSEntities();
  177. JsonData list = JsonMapper.ToObject(ExcelData);
  178. for (int i = 1; i < list.Count; i++)
  179. {
  180. JsonData dr = list[i];
  181. db.UserStoreChange.Add(new UserStoreChange()
  182. {
  183. CreateDate = DateTime.Now,
  184. UpdateDate = DateTime.Now,
  185. });
  186. db.SaveChanges();
  187. }
  188. db.Dispose();
  189. }
  190. /// <summary>
  191. /// 导出excel表格
  192. /// </summary>
  193. /// <param name="fields">查询条件(单个字段)</param>
  194. /// <param name="condition">查询条件(sql语句)</param>
  195. /// <returns></returns>
  196. // public static void ExportExcel(List<RelationData> relationData, string condition)
  197. // {
  198. // }
  199. }
  200. }