PosCouponRecordService.cs 8.4 KB

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