PosMachinesTwoService.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.Models.Main1;
  6. using Library;
  7. using LitJson;
  8. namespace MySystem.Service.Main
  9. {
  10. public class PosMachinesTwoService
  11. {
  12. // static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  13. static string _conn = ConfigurationManager.AppSettings["ZsSqlConnStr"].ToString();
  14. /// <summary>
  15. /// 查询列表
  16. /// </summary>
  17. /// <param name="relationData">关联表</param>
  18. /// <param name="condition">查询条件(sql语句)</param>
  19. /// <param name="count">总数(输出)</param>
  20. /// <param name="page">页码</param>
  21. /// <param name="limit">每页条数</param>
  22. /// <returns></returns>
  23. 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")
  24. {
  25. List<string> fields = new List<string>(); //要显示的列
  26. fields.Add("Id");
  27. fields.Add("CreateDate"); //添加时间
  28. fields.Add("Status"); //状态
  29. fields.Add("Name"); //名称
  30. fields.Add("Mobile"); //手机号
  31. fields.Add("Areas"); //所在地区
  32. fields.Add("Address"); //详细地址
  33. fields.Add("IsAuth"); //是否认证
  34. fields.Add("TotalAmount"); //平台总收益
  35. fields.Add("TotalOrder"); //累计订单
  36. fields.Add("TotalCustomer"); //累计客户
  37. fields.Add("TotalUser"); //会员数
  38. fields.Add("TotalActual"); //营收总额
  39. fields.Add("LastAddConsumerDate"); //最后加入会员时间
  40. fields.Add("TotalConsumeCount"); //累计消费次数
  41. fields.Add("LastConsumeDate"); //最后消费时间
  42. fields.Add("UserId"); //所属创客
  43. fields.Add("ActivationStatus"); //激活状态
  44. fields.Add("ActivationDate"); //激活时间
  45. Dictionary<string, object> obj = new DbService(AppConfig.Base.main1Tables, _conn).IndexData("PosMachinesTwo", 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("Name"); //名称
  57. fields.Add("Mobile"); //手机号
  58. fields.Add("Areas"); //所在地区
  59. fields.Add("Address"); //详细地址
  60. fields.Add("IsAuth"); //是否认证
  61. fields.Add("TotalAmount"); //平台总收益
  62. fields.Add("TotalOrder"); //累计订单
  63. fields.Add("TotalCustomer"); //累计客户
  64. fields.Add("TotalUser"); //会员数
  65. fields.Add("TotalActual"); //营收总额
  66. fields.Add("LastAddConsumerDate"); //最后加入会员时间
  67. fields.Add("TotalConsumeCount"); //累计消费次数
  68. fields.Add("LastConsumeDate"); //最后消费时间
  69. fields.Add("UserId"); //所属创客
  70. fields.Add("ActivationStatus"); //激活状态
  71. fields.Add("ActivationDate"); //激活时间
  72. Dictionary<string, object> obj = new DbService(AppConfig.Base.main1Tables, _conn).IndexData("PosMachinesTwo", relationData, orderBy, page, limit, condition, fields);
  73. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  74. return diclist;
  75. }
  76. /// <summary>
  77. /// 查询一条记录
  78. /// </summary>
  79. /// <param name="Id">主键Id</param>
  80. /// <returns></returns>
  81. public static PosMachinesTwo Query(int Id)
  82. {
  83. WebCMSEntities db = new WebCMSEntities();
  84. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  85. db.Dispose();
  86. return editData;
  87. }
  88. public static PosMachinesTwo Query(string condition, string fields = "*")
  89. {
  90. var PosMachinesTwo = new DbService(AppConfig.Base.main1Tables, _conn).Query(fields, "PosMachinesTwo", condition);
  91. if (PosMachinesTwo.Count > 0)
  92. {
  93. return Newtonsoft.Json.JsonConvert.DeserializeObject<PosMachinesTwo>(Newtonsoft.Json.JsonConvert.SerializeObject(PosMachinesTwo));
  94. }
  95. return new PosMachinesTwo();
  96. }
  97. public static decimal Sum(string condition, string field)
  98. {
  99. var dt = new DbService(AppConfig.Base.main1Tables, _conn).Query("Sum(" + field + ") " + field, "PosMachinesTwo", condition);
  100. decimal amount = 0;
  101. if (dt.Count > 0)
  102. {
  103. amount = decimal.Parse(dt[field].ToString());
  104. }
  105. return amount;
  106. }
  107. /// <summary>
  108. /// 查询记录数
  109. /// </summary>
  110. /// <param name="Id">主键Id</param>
  111. /// <returns></returns>
  112. public static int Count(string condition = "", string field = "Id")
  113. {
  114. var dt = new DbService(AppConfig.Base.main1Tables, _conn).Query("Count(" + field + ") " + field, "PosMachinesTwo", condition);
  115. int result = 0;
  116. if (dt.Count > 0)
  117. {
  118. result = int.Parse(dt[field].ToString());
  119. }
  120. return result;
  121. }
  122. /// <summary>
  123. /// 查询是否存在
  124. /// </summary>
  125. /// <param name="Id">主键Id</param>
  126. /// <returns></returns>
  127. public static bool Exist(int Id)
  128. {
  129. WebCMSEntities db = new WebCMSEntities();
  130. bool check = db.PosMachinesTwo.Any(m => m.Id == Id);
  131. db.Dispose();
  132. return check;
  133. }
  134. /// <summary>
  135. /// 添加数据
  136. /// </summary>
  137. /// <param name="Fields">要设置的字段</param>
  138. /// <returns></returns>
  139. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  140. {
  141. if (check)
  142. {
  143. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  144. {
  145. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  146. }
  147. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  148. {
  149. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  150. }
  151. }
  152. int Id = new DbService(AppConfig.Base.main1Tables, _conn).Add("PosMachinesTwo", 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. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  165. {
  166. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  167. }
  168. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  169. {
  170. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  171. }
  172. }
  173. new DbService(AppConfig.Base.main1Tables, _conn).Edit("PosMachinesTwo", fields, Id);
  174. return new AppResultJson() { Status = "1", Data = Id };
  175. }
  176. /// <summary>
  177. /// 逻辑删除
  178. /// </summary>
  179. /// <param name="Id">主键Id</param>
  180. public static void Remove(int Id)
  181. {
  182. Dictionary<string, object> fields = new Dictionary<string, object>();
  183. fields.Add("Status", -1);
  184. new DbService(AppConfig.Base.main1Tables, _conn).Edit("PosMachinesTwo", fields, Id);
  185. }
  186. /// <summary>
  187. /// 删除数据
  188. /// </summary>
  189. /// <param name="Id">主键Id</param>
  190. public static void Delete(int Id)
  191. {
  192. new DbService(AppConfig.Base.main1Tables, _conn).Delete("PosMachinesTwo", Id);
  193. }
  194. /// <summary>
  195. /// 排序
  196. /// </summary>
  197. /// <param name="Id">主键Id</param>
  198. /// <param name="Sort">排序序号</param>
  199. public static void Sort(int Id, int Sort)
  200. {
  201. new DbService(AppConfig.Base.main1Tables, _conn).Sort("PosMachinesTwo", Sort, Id);
  202. }
  203. /// <summary>
  204. /// 导入数据
  205. /// </summary>
  206. /// <param name="ExcelData">json数据</param>
  207. public static void Import(string ExcelData)
  208. {
  209. WebCMSEntities db = new WebCMSEntities();
  210. JsonData list = JsonMapper.ToObject(ExcelData);
  211. for (int i = 1; i < list.Count; i++)
  212. {
  213. JsonData dr = list[i];
  214. db.PosMachinesTwo.Add(new PosMachinesTwo()
  215. {
  216. CreateDate = DateTime.Now,
  217. UpdateDate = DateTime.Now,
  218. });
  219. db.SaveChanges();
  220. }
  221. db.Dispose();
  222. }
  223. /// <summary>
  224. /// 导出excel表格
  225. /// </summary>
  226. /// <param name="fields">查询条件(单个字段)</param>
  227. /// <param name="condition">查询条件(sql语句)</param>
  228. /// <returns></returns>
  229. // public static void ExportExcel(List<RelationData> relationData, string condition)
  230. // {
  231. // }
  232. }
  233. }