MerchantQrCodeService.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 MerchantQrCodeService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. // static string _conn = ConfigurationManager.AppSettings["ZsSqlConnStr"].ToString();
  17. /// <summary>
  18. /// 查询列表
  19. /// </summary>
  20. /// <param name="relationData">关联表</param>
  21. /// <param name="condition">查询条件(sql语句)</param>
  22. /// <param name="count">总数(输出)</param>
  23. /// <param name="page">页码</param>
  24. /// <param name="limit">每页条数</param>
  25. /// <returns></returns>
  26. 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")
  27. {
  28. List<string> fields = new List<string>(); //要显示的列
  29. fields.Add("Id");
  30. fields.Add("CreateDate"); //添加时间
  31. fields.Add("Status"); //状态
  32. fields.Add("MerchantId"); //商户
  33. fields.Add("MachineId"); //设备
  34. fields.Add("SnNo"); //Sn编号
  35. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantQrCode", relationData, orderBy, page, limit, condition, fields);
  36. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  37. count = int.Parse(obj["count"].ToString());
  38. return diclist;
  39. }
  40. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  41. {
  42. List<string> fields = new List<string>(); //要显示的列
  43. fields.Add("Id");
  44. fields.Add("CreateDate"); //添加时间
  45. fields.Add("Status"); //状态
  46. fields.Add("MerchantId"); //商户
  47. fields.Add("MachineId"); //设备
  48. fields.Add("SnNo"); //Sn编号
  49. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantQrCode", relationData, orderBy, page, limit, condition, fields);
  50. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  51. return diclist;
  52. }
  53. /// <summary>
  54. /// 查询一条记录
  55. /// </summary>
  56. /// <param name="Id">主键Id</param>
  57. /// <returns></returns>
  58. public static MerchantQrCode Query(int Id)
  59. {
  60. WebCMSEntities db = new WebCMSEntities();
  61. MerchantQrCode editData = db.MerchantQrCode.FirstOrDefault(m => m.Id == Id) ?? new MerchantQrCode();
  62. db.Dispose();
  63. return editData;
  64. }
  65. public static MerchantQrCode Query(string condition, string fields = "*")
  66. {
  67. var merchantQrCode = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantQrCode", condition);
  68. if (merchantQrCode.Count > 0)
  69. {
  70. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantQrCode>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantQrCode));
  71. }
  72. return new MerchantQrCode();
  73. }
  74. public static decimal Sum(string condition, string field)
  75. {
  76. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantQrCode", condition);
  77. decimal amount = 0;
  78. if (dt.Count > 0)
  79. {
  80. amount = decimal.Parse(dt[field].ToString());
  81. }
  82. return amount;
  83. }
  84. /// <summary>
  85. /// 查询记录数
  86. /// </summary>
  87. /// <param name="Id">主键Id</param>
  88. /// <returns></returns>
  89. public static int Count(string condition = "", string field = "Id")
  90. {
  91. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantQrCode", condition);
  92. int result = 0;
  93. if (dt.Count > 0)
  94. {
  95. result = int.Parse(dt[field].ToString());
  96. }
  97. return result;
  98. }
  99. /// <summary>
  100. /// 查询是否存在
  101. /// </summary>
  102. /// <param name="Id">主键Id</param>
  103. /// <returns></returns>
  104. public static bool Exist(int Id)
  105. {
  106. WebCMSEntities db = new WebCMSEntities();
  107. bool check = db.MerchantQrCode.Any(m => m.Id == Id);
  108. db.Dispose();
  109. return check;
  110. }
  111. /// <summary>
  112. /// 添加数据
  113. /// </summary>
  114. /// <param name="Fields">要设置的字段</param>
  115. /// <returns></returns>
  116. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  117. {
  118. if (check)
  119. {
  120. }
  121. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantQrCode", fields, 0);
  122. return new AppResultJson() { Status = "1", Data = Id };
  123. }
  124. /// <summary>
  125. /// 修改数据
  126. /// </summary>
  127. /// <param name="Fields">要设置的字段</param>
  128. /// <param name="Id">主键Id</param>
  129. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  130. {
  131. if (check)
  132. {
  133. }
  134. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantQrCode", fields, Id);
  135. return new AppResultJson() { Status = "1", Data = Id };
  136. }
  137. /// <summary>
  138. /// 逻辑删除
  139. /// </summary>
  140. /// <param name="Id">主键Id</param>
  141. public static void Remove(int Id)
  142. {
  143. Dictionary<string, object> fields = new Dictionary<string, object>();
  144. fields.Add("Status", -1);
  145. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantQrCode", fields, Id);
  146. }
  147. /// <summary>
  148. /// 删除数据
  149. /// </summary>
  150. /// <param name="Id">主键Id</param>
  151. public static void Delete(int Id)
  152. {
  153. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantQrCode", Id);
  154. }
  155. /// <summary>
  156. /// 排序
  157. /// </summary>
  158. /// <param name="Id">主键Id</param>
  159. /// <param name="Sort">排序序号</param>
  160. public static void Sort(int Id, int Sort)
  161. {
  162. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantQrCode", Sort, Id);
  163. }
  164. /// <summary>
  165. /// 导入数据
  166. /// </summary>
  167. /// <param name="ExcelData">json数据</param>
  168. public static void Import(string ExcelData)
  169. {
  170. WebCMSEntities db = new WebCMSEntities();
  171. JsonData list = JsonMapper.ToObject(ExcelData);
  172. for (int i = 1; i < list.Count; i++)
  173. {
  174. JsonData dr = list[i];
  175. db.MerchantQrCode.Add(new MerchantQrCode()
  176. {
  177. CreateDate = DateTime.Now,
  178. UpdateDate = DateTime.Now,
  179. });
  180. db.SaveChanges();
  181. }
  182. db.Dispose();
  183. }
  184. /// <summary>
  185. /// 导出excel表格
  186. /// </summary>
  187. /// <param name="fields">查询条件(单个字段)</param>
  188. /// <param name="condition">查询条件(sql语句)</param>
  189. /// <returns></returns>
  190. // public static void ExportExcel(List<RelationData> relationData, string condition)
  191. // {
  192. // }
  193. }
  194. }