StoreStockChangeService.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 class StoreStockChangeService
  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("StoreId"); //仓库
  32. fields.Add("BrandId"); //产品类型
  33. fields.Add("TransType"); //交易类型
  34. fields.Add("SnNo"); //SN编号
  35. fields.Add("StockOpDirect"); //库存操作方向
  36. fields.Add("SnStatus"); //SN状态
  37. fields.Add("BindStatus"); //绑定状态
  38. fields.Add("BindMerchant"); //绑定商户
  39. fields.Add("ActiveStatus"); //激活状态
  40. fields.Add("ExpressNo"); //快递单号
  41. fields.Add("BrandType"); //品牌类型
  42. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("StoreStockChange", relationData, orderBy, page, limit, condition, fields);
  43. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  44. count = int.Parse(obj["count"].ToString());
  45. return diclist;
  46. }
  47. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  48. {
  49. List<string> fields = new List<string>(); //要显示的列
  50. fields.Add("Id");
  51. fields.Add("CreateDate"); //添加时间
  52. fields.Add("Status"); //状态
  53. fields.Add("StoreId"); //仓库
  54. fields.Add("BrandId"); //产品类型
  55. fields.Add("TransType"); //交易类型
  56. fields.Add("SnNo"); //SN编号
  57. fields.Add("StockOpDirect"); //库存操作方向
  58. fields.Add("SnStatus"); //SN状态
  59. fields.Add("BindStatus"); //绑定状态
  60. fields.Add("BindMerchant"); //绑定商户
  61. fields.Add("ActiveStatus"); //激活状态
  62. fields.Add("ExpressNo"); //快递单号
  63. fields.Add("BrandType"); //品牌类型
  64. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("StoreStockChange", relationData, orderBy, page, limit, condition, fields);
  65. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  66. return diclist;
  67. }
  68. /// <summary>
  69. /// 查询一条记录
  70. /// </summary>
  71. /// <param name="Id">主键Id</param>
  72. /// <returns></returns>
  73. public static StoreStockChange Query(int Id)
  74. {
  75. WebCMSEntities db = new WebCMSEntities();
  76. StoreStockChange editData = db.StoreStockChange.FirstOrDefault(m => m.Id == Id) ?? new StoreStockChange();
  77. db.Dispose();
  78. return editData;
  79. }
  80. public static StoreStockChange Query(string condition, string fields = "*")
  81. {
  82. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "StoreStockChange", condition);
  83. if (dt.Rows.Count > 0)
  84. {
  85. Dictionary<string, object> row = new Dictionary<string, object>();
  86. foreach (DataColumn dc in dt.Columns)
  87. {
  88. row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  89. }
  90. return Newtonsoft.Json.JsonConvert.DeserializeObject<StoreStockChange>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  91. }
  92. return new StoreStockChange();
  93. }
  94. public static decimal Sum(string condition, string field)
  95. {
  96. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "StoreStockChange", condition);
  97. decimal amount = 0;
  98. if (dt.Rows.Count > 0)
  99. {
  100. amount = decimal.Parse(dt.Rows[0][0].ToString());
  101. }
  102. return amount;
  103. }
  104. /// <summary>
  105. /// 查询记录数
  106. /// </summary>
  107. /// <param name="Id">主键Id</param>
  108. /// <returns></returns>
  109. public static int Count(string condition = "", string field = "Id")
  110. {
  111. int result = 0;
  112. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "StoreStockChange", condition);
  113. if (dt.Rows.Count > 0)
  114. {
  115. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  116. }
  117. return result;
  118. }
  119. /// <summary>
  120. /// 查询是否存在
  121. /// </summary>
  122. /// <param name="Id">主键Id</param>
  123. /// <returns></returns>
  124. public static bool Exist(int Id)
  125. {
  126. WebCMSEntities db = new WebCMSEntities();
  127. bool check = db.StoreStockChange.Any(m => m.Id == Id);
  128. db.Dispose();
  129. return check;
  130. }
  131. /// <summary>
  132. /// 添加数据
  133. /// </summary>
  134. /// <param name="Fields">要设置的字段</param>
  135. /// <returns></returns>
  136. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  137. {
  138. if (check)
  139. {
  140. }
  141. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("StoreStockChange", fields, 0);
  142. return new AppResultJson() { Status = "1", Data = Id };
  143. }
  144. /// <summary>
  145. /// 修改数据
  146. /// </summary>
  147. /// <param name="Fields">要设置的字段</param>
  148. /// <param name="Id">主键Id</param>
  149. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  150. {
  151. if (check)
  152. {
  153. }
  154. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreStockChange", fields, Id);
  155. return new AppResultJson() { Status = "1", Data = Id };
  156. }
  157. /// <summary>
  158. /// 逻辑删除
  159. /// </summary>
  160. /// <param name="Id">主键Id</param>
  161. public static void Remove(int Id)
  162. {
  163. Dictionary<string, object> fields = new Dictionary<string, object>();
  164. fields.Add("Status", -1);
  165. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreStockChange", fields, Id);
  166. }
  167. /// <summary>
  168. /// 删除数据
  169. /// </summary>
  170. /// <param name="Id">主键Id</param>
  171. public static void Delete(int Id)
  172. {
  173. new DbService(AppConfig.Base.mainTables, _conn).Delete("StoreStockChange", Id);
  174. }
  175. /// <summary>
  176. /// 排序
  177. /// </summary>
  178. /// <param name="Id">主键Id</param>
  179. /// <param name="Sort">排序序号</param>
  180. public static void Sort(int Id, int Sort)
  181. {
  182. new DbService(AppConfig.Base.mainTables, _conn).Sort("StoreStockChange", Sort, Id);
  183. }
  184. /// <summary>
  185. /// 导入数据
  186. /// </summary>
  187. /// <param name="ExcelData">json数据</param>
  188. public static void Import(string ExcelData)
  189. {
  190. WebCMSEntities db = new WebCMSEntities();
  191. JsonData list = JsonMapper.ToObject(ExcelData);
  192. for (int i = 1; i < list.Count; i++)
  193. {
  194. JsonData dr = list[i];
  195. db.StoreStockChange.Add(new StoreStockChange()
  196. {
  197. CreateDate = DateTime.Now,
  198. UpdateDate = DateTime.Now,
  199. });
  200. db.SaveChanges();
  201. }
  202. db.Dispose();
  203. }
  204. /// <summary>
  205. /// 导出excel表格
  206. /// </summary>
  207. /// <param name="fields">查询条件(单个字段)</param>
  208. /// <param name="condition">查询条件(sql语句)</param>
  209. /// <returns></returns>
  210. // public static void ExportExcel(List<RelationData> relationData, string condition)
  211. // {
  212. // }
  213. }
  214. }