MachineChangeService.cs 9.4 KB

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