MerchantAmountSummayService.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. using Library;
  6. using LitJson;
  7. using System.Data;
  8. namespace MySystem
  9. {
  10. public class MerchantAmountSummayService
  11. {
  12. string _conn = "";
  13. public MerchantAmountSummayService()
  14. {
  15. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. }
  17. /// <summary>
  18. /// 查询列表
  19. /// </summary>
  20. /// <param name="fields">查询条件(单个字段)</param>
  21. /// <param name="condition">查询条件(sql语句)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. public List<Dictionary<string, object>> List(List<FieldItem> fields, string condition, int page = 1, int limit = 30, string orderby = "Id desc")
  26. {
  27. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAmountSummay", fields, orderby, "0", page, limit, condition);
  28. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  29. return diclist;
  30. }
  31. /// <summary>
  32. /// 查询一条记录
  33. /// </summary>
  34. /// <param name="Id">主键Id</param>
  35. /// <returns></returns>
  36. public MerchantAmountSummay Query(int MerchantId, string TradeDate)
  37. {
  38. WebCMSEntities db = new WebCMSEntities();
  39. MerchantAmountSummay editData = db.MerchantAmountSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeDate == TradeDate) ?? new MerchantAmountSummay();
  40. db.Dispose();
  41. return editData;
  42. }
  43. public Dictionary<string, string> QueryAmount(string field, string condition)
  44. {
  45. Dictionary<string, string> result = new Dictionary<string, string>();
  46. string sumString = "";
  47. string[] fieldlist = field.Split(',');
  48. foreach(string f in fieldlist)
  49. {
  50. sumString += "sum(" + f + ") " + f + ",";
  51. }
  52. sumString = sumString.TrimEnd(',');
  53. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantAmountSummay where 1=1" + condition, _conn);
  54. if(dt.Rows.Count > 0)
  55. {
  56. foreach(string f in fieldlist)
  57. {
  58. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  59. }
  60. }
  61. return result;
  62. }
  63. public Dictionary<string, string> Sum(string field, string condition)
  64. {
  65. Dictionary<string, string> result = new Dictionary<string, string>();
  66. string sumString = "";
  67. string[] fieldlist = field.Split(',');
  68. foreach(string f in fieldlist)
  69. {
  70. sumString += "sum(" + f + ") " + f + ",";
  71. }
  72. sumString = sumString.TrimEnd(',');
  73. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantAmountSummay where 1=1" + condition, _conn);
  74. if(dt.Rows.Count > 0)
  75. {
  76. foreach(string f in fieldlist)
  77. {
  78. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  79. }
  80. }
  81. return result;
  82. }
  83. /// <summary>
  84. /// 添加数据
  85. /// </summary>
  86. /// <param name="Fields">要设置的字段</param>
  87. /// <returns></returns>
  88. public int Add(Dictionary<string, object> Fields)
  89. {
  90. return new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantAmountSummay", Fields, 0);
  91. }
  92. /// <summary>
  93. /// 修改数据
  94. /// </summary>
  95. /// <param name="Fields">要设置的字段</param>
  96. /// <param name="Id">主键Id</param>
  97. public void Edit(Dictionary<string, object> Fields, int Id)
  98. {
  99. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAmountSummay", Fields, Id);
  100. }
  101. /// <summary>
  102. /// 删除数据
  103. /// </summary>
  104. /// <param name="Id">主键Id</param>
  105. public void Delete(int Id)
  106. {
  107. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantAmountSummay", Id);
  108. }
  109. /// <summary>
  110. /// 排序
  111. /// </summary>
  112. /// <param name="Id">主键Id</param>
  113. /// <param name="Sort">排序序号</param>
  114. public void Sort(int Id, int Sort)
  115. {
  116. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantAmountSummay", Sort, Id);
  117. }
  118. /// <summary>
  119. /// 导入数据
  120. /// </summary>
  121. /// <param name="ExcelData">json数据</param>
  122. public void Import(string ExcelData)
  123. {
  124. WebCMSEntities db = new WebCMSEntities();
  125. JsonData list = JsonMapper.ToObject(ExcelData);
  126. for (int i = 1; i < list.Count;i++ )
  127. {
  128. JsonData dr = list[i];
  129. db.MerchantAmountSummay.Add(new MerchantAmountSummay()
  130. {
  131. CreateDate = DateTime.Now,
  132. UpdateDate = DateTime.Now,
  133. });
  134. db.SaveChanges();
  135. }
  136. db.Dispose();
  137. }
  138. // /// <summary>
  139. // /// 导出excel表格
  140. // /// </summary>
  141. // /// <param name="fields">查询条件(单个字段)</param>
  142. // /// <param name="condition">查询条件(sql语句)</param>
  143. // /// <returns></returns>
  144. // public Dictionary<string, object> ExportExcel(List<FieldItem> fields, string condition, string orderby = "Id desc")
  145. // {
  146. // Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAmountSummay", fields, orderby, "0", 1, 20000, condition, "Id", false);
  147. // List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  148. // foreach (Dictionary<string, object> dic in diclist)
  149. // {
  150. // }
  151. // Dictionary<string, object> result = new Dictionary<string, object>();
  152. // result.Add("Status", "1");
  153. // result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  154. // result.Add("Obj", diclist);
  155. // Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  156. // result.Add("Fields", ReturnFields);
  157. // return result;
  158. // }
  159. }
  160. }