ConsumerOrderForNoService.cs 7.7 KB

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