StoreForOperateService.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * 分仓关联表
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Operate;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Operate
  12. {
  13. public class StoreForOperateService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  16. // public StoreForOperateService()
  17. // {
  18. // _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  19. // }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. 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")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("OpId"); //运用中心
  36. fields.Add("StoreId"); //分仓
  37. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("StoreForOperate", relationData, orderBy, page, limit, condition, fields);
  38. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  39. count = int.Parse(obj["count"].ToString());
  40. return diclist;
  41. }
  42. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  43. {
  44. List<string> fields = new List<string>(); //要显示的列
  45. fields.Add("Id");
  46. fields.Add("CreateDate"); //添加时间
  47. fields.Add("Status"); //状态
  48. fields.Add("OpId"); //运用中心
  49. fields.Add("StoreId"); //分仓
  50. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("StoreForOperate", relationData, orderBy, page, limit, condition, fields);
  51. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  52. return diclist;
  53. }
  54. /// <summary>
  55. /// 查询一条记录
  56. /// </summary>
  57. /// <param name="Id">主键Id</param>
  58. /// <returns></returns>
  59. public static StoreForOperate Query(int Id)
  60. {
  61. WebCMSEntities db = new WebCMSEntities();
  62. StoreForOperate editData = db.StoreForOperate.FirstOrDefault(m => m.Id == Id) ?? new StoreForOperate();
  63. db.Dispose();
  64. return editData;
  65. }
  66. /// <summary>
  67. /// 根据指定条件查询数据
  68. /// </summary>
  69. /// <param name="condition"></param>
  70. /// <returns></returns>
  71. public static StoreForOperate Query(string condition, string fields = "*")
  72. {
  73. // DataTable dt = new DbService(AppConfig.Base.opTables, _conn).QueryDetail("*", "StoreForOperate", condition);
  74. // if (dt.Rows.Count > 0)
  75. // {
  76. // Dictionary<string, object> row = new Dictionary<string, object>();
  77. // foreach (DataColumn dc in dt.Columns)
  78. // {
  79. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  80. // }
  81. // return Newtonsoft.Json.JsonConvert.DeserializeObject<StoreForOperate>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  82. // }
  83. var storeForOperate = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "StoreForOperate", condition);
  84. if (storeForOperate.Count > 0)
  85. {
  86. return Newtonsoft.Json.JsonConvert.DeserializeObject<StoreForOperate>(Newtonsoft.Json.JsonConvert.SerializeObject(storeForOperate));
  87. }
  88. return new StoreForOperate();
  89. }
  90. /// <summary>
  91. /// 通过仓库Id查询正常关联运营中心分仓数据
  92. /// </summary>
  93. /// <param name="StoreId">主键Id</param>
  94. /// <returns></returns>
  95. public static StoreForOperate QueryStoreLinkOpByStoreId(int StoreId)
  96. {
  97. WebCMSEntities db = new WebCMSEntities();
  98. StoreForOperate editData = db.StoreForOperate.FirstOrDefault(m => m.Sort == 0 && m.StoreId == StoreId && m.Status > -1) ?? new StoreForOperate();
  99. db.Dispose();
  100. return editData;
  101. }
  102. /// <summary>
  103. /// 查询记录数
  104. /// </summary>
  105. /// <param name="Id">主键Id</param>
  106. /// <returns></returns>
  107. public static int Count(string condition = "")
  108. {
  109. int result = 0;
  110. DataTable dt = CustomerSqlConn.dtable("select count(Id) from StoreForOperate where 1=1" + condition, _conn);
  111. if (dt.Rows.Count > 0)
  112. {
  113. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  114. }
  115. return result;
  116. }
  117. /// <summary>
  118. /// 查询是否存在
  119. /// </summary>
  120. /// <param name="Id">主键Id</param>
  121. /// <returns></returns>
  122. public static bool Exist(int Id)
  123. {
  124. WebCMSEntities db = new WebCMSEntities();
  125. bool check = db.StoreForOperate.Any(m => m.Id == Id);
  126. db.Dispose();
  127. return check;
  128. }
  129. public static bool Exist(string condition)
  130. {
  131. DataTable dt = new DbService(AppConfig.Base.opTables, _conn).QueryDetail("1", "StoreHouse", condition);
  132. if (dt.Rows.Count > 0)
  133. {
  134. return true;
  135. }
  136. return false;
  137. }
  138. /// <summary>
  139. /// 添加数据
  140. /// </summary>
  141. /// <param name="Fields">要设置的字段</param>
  142. /// <returns></returns>
  143. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  144. {
  145. if (check)
  146. {
  147. }
  148. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("StoreForOperate", fields, 0);
  149. return new AppResultJson() { Status = "1", Data = Id };
  150. }
  151. /// <summary>
  152. /// 修改数据
  153. /// </summary>
  154. /// <param name="Fields">要设置的字段</param>
  155. /// <param name="Id">主键Id</param>
  156. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  157. {
  158. if (check)
  159. {
  160. }
  161. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreForOperate", fields, Id);
  162. return new AppResultJson() { Status = "1", Data = Id };
  163. }
  164. /// <summary>
  165. /// 逻辑删除
  166. /// </summary>
  167. /// <param name="Id">主键Id</param>
  168. public static void Remove(int Id)
  169. {
  170. Dictionary<string, object> fields = new Dictionary<string, object>();
  171. fields.Add("Status", -1);
  172. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreForOperate", fields, Id);
  173. }
  174. /// <summary>
  175. /// 删除数据
  176. /// </summary>
  177. /// <param name="Id">主键Id</param>
  178. public static void Delete(int Id)
  179. {
  180. new DbService(AppConfig.Base.mainTables, _conn).Delete("StoreForOperate", Id);
  181. }
  182. /// <summary>
  183. /// 排序
  184. /// </summary>
  185. /// <param name="Id">主键Id</param>
  186. /// <param name="Sort">排序序号</param>
  187. public static void Sort(int Id, int Sort)
  188. {
  189. new DbService(AppConfig.Base.mainTables, _conn).Sort("StoreForOperate", Sort, Id);
  190. }
  191. /// <summary>
  192. /// 导入数据
  193. /// </summary>
  194. /// <param name="ExcelData">json数据</param>
  195. public static void Import(string ExcelData)
  196. {
  197. WebCMSEntities db = new WebCMSEntities();
  198. JsonData list = JsonMapper.ToObject(ExcelData);
  199. for (int i = 1; i < list.Count; i++)
  200. {
  201. JsonData dr = list[i];
  202. db.StoreForOperate.Add(new StoreForOperate()
  203. {
  204. CreateDate = DateTime.Now,
  205. UpdateDate = DateTime.Now,
  206. });
  207. db.SaveChanges();
  208. }
  209. db.Dispose();
  210. }
  211. /// <summary>
  212. /// 导出excel表格
  213. /// </summary>
  214. /// <param name="fields">查询条件(单个字段)</param>
  215. /// <param name="condition">查询条件(sql语句)</param>
  216. /// <returns></returns>
  217. // public void ExportExcel(List<RelationData> relationData, string condition)
  218. // {
  219. // }
  220. }
  221. }