ToChargeBackRecordSubService.cs 8.7 KB

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