MachineApplyService.cs 10 KB

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