AmountRecordService.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * 额度变更新记录
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Operate;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Operate
  12. {
  13. public class AmountRecordService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  16. // public AmountRecordService()
  17. // {
  18. // _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  19. // }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. 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")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("UserId"); //运营中心
  36. fields.Add("ApplyId"); //申请单
  37. fields.Add("UseAmount"); //使用额度
  38. fields.Add("BeforeAmount"); //使用前剩余额度
  39. fields.Add("AfterAmount"); //使用后剩余额度
  40. fields.Add("OperateType"); //操作类别
  41. Dictionary<string, object> obj = new DbService(AppConfig.Base.opTables, _conn).IndexData("AmountRecord", relationData, orderBy, page, limit, condition, fields);
  42. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  43. count = int.Parse(obj["count"].ToString());
  44. return diclist;
  45. }
  46. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  47. {
  48. List<string> fields = new List<string>(); //要显示的列
  49. fields.Add("Id");
  50. fields.Add("CreateDate"); //添加时间
  51. fields.Add("Status"); //状态
  52. fields.Add("UserId"); //运营中心
  53. fields.Add("ApplyId"); //申请单
  54. fields.Add("UseAmount"); //使用额度
  55. fields.Add("BeforeAmount"); //使用前剩余额度
  56. fields.Add("AfterAmount"); //使用后剩余额度
  57. fields.Add("OperateType"); //操作类别
  58. Dictionary<string, object> obj = new DbService(AppConfig.Base.opTables, _conn).IndexData("AmountRecord", relationData, orderBy, page, limit, condition, fields);
  59. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  60. return diclist;
  61. }
  62. /// <summary>
  63. /// 查询一条记录
  64. /// </summary>
  65. /// <param name="Id">主键Id</param>
  66. /// <returns></returns>
  67. public static AmountRecord Query(int Id)
  68. {
  69. WebCMSEntities db = new WebCMSEntities();
  70. AmountRecord editData = db.AmountRecord.FirstOrDefault(m => m.Id == Id) ?? new AmountRecord();
  71. db.Dispose();
  72. return editData;
  73. }
  74. /// <summary>
  75. /// 查询记录数
  76. /// </summary>
  77. /// <param name="Id">主键Id</param>
  78. /// <returns></returns>
  79. public static int Count(string condition = "")
  80. {
  81. int result = 0;
  82. DataTable dt = CustomerSqlConn.dtable("select count(Id) from AmountRecord where 1=1" + condition, _conn);
  83. if (dt.Rows.Count > 0)
  84. {
  85. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  86. }
  87. return result;
  88. }
  89. /// <summary>
  90. /// 查询是否存在
  91. /// </summary>
  92. /// <param name="Id">主键Id</param>
  93. /// <returns></returns>
  94. public static bool Exist(int Id)
  95. {
  96. WebCMSEntities db = new WebCMSEntities();
  97. bool check = db.AmountRecord.Any(m => m.Id == Id);
  98. db.Dispose();
  99. return check;
  100. }
  101. /// <summary>
  102. /// 添加数据
  103. /// </summary>
  104. /// <param name="Fields">要设置的字段</param>
  105. /// <returns></returns>
  106. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  107. {
  108. if (check)
  109. {
  110. }
  111. int Id = new DbService(AppConfig.Base.opTables, _conn).Add("AmountRecord", fields, 0);
  112. return new AppResultJson() { Status = "1", Data = Id };
  113. }
  114. /// <summary>
  115. /// 修改数据
  116. /// </summary>
  117. /// <param name="Fields">要设置的字段</param>
  118. /// <param name="Id">主键Id</param>
  119. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  120. {
  121. if (check)
  122. {
  123. }
  124. new DbService(AppConfig.Base.opTables, _conn).Edit("AmountRecord", fields, Id);
  125. return new AppResultJson() { Status = "1", Data = Id };
  126. }
  127. /// <summary>
  128. /// 逻辑删除
  129. /// </summary>
  130. /// <param name="Id">主键Id</param>
  131. public static void Remove(int Id)
  132. {
  133. Dictionary<string, object> fields = new Dictionary<string, object>();
  134. fields.Add("Status", -1);
  135. new DbService(AppConfig.Base.opTables, _conn).Edit("AmountRecord", fields, Id);
  136. }
  137. /// <summary>
  138. /// 删除数据
  139. /// </summary>
  140. /// <param name="Id">主键Id</param>
  141. public static void Delete(int Id)
  142. {
  143. new DbService(AppConfig.Base.opTables, _conn).Delete("AmountRecord", Id);
  144. }
  145. /// <summary>
  146. /// 排序
  147. /// </summary>
  148. /// <param name="Id">主键Id</param>
  149. /// <param name="Sort">排序序号</param>
  150. public static void Sort(int Id, int Sort)
  151. {
  152. new DbService(AppConfig.Base.opTables, _conn).Sort("AmountRecord", Sort, Id);
  153. }
  154. /// <summary>
  155. /// 导入数据
  156. /// </summary>
  157. /// <param name="ExcelData">json数据</param>
  158. public static void Import(string ExcelData)
  159. {
  160. WebCMSEntities db = new WebCMSEntities();
  161. JsonData list = JsonMapper.ToObject(ExcelData);
  162. for (int i = 1; i < list.Count; i++)
  163. {
  164. JsonData dr = list[i];
  165. db.AmountRecord.Add(new AmountRecord()
  166. {
  167. CreateDate = DateTime.Now,
  168. UpdateDate = DateTime.Now,
  169. });
  170. db.SaveChanges();
  171. }
  172. db.Dispose();
  173. }
  174. /// <summary>
  175. /// 导出excel表格
  176. /// </summary>
  177. /// <param name="fields">查询条件(单个字段)</param>
  178. /// <param name="condition">查询条件(sql语句)</param>
  179. /// <returns></returns>
  180. // public void ExportExcel(List<RelationData> relationData, string condition)
  181. // {
  182. // }
  183. }
  184. }