MachineUnBindService.cs 9.6 KB

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