StoreChangeHistoryService.cs 9.1 KB

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