MerchantAmountSummayService.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 MerchantAmountSummay Query(string condition, string fields = "*")
  44. {
  45. var merchantAmountSummay = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantAmountSummay", condition);
  46. if (merchantAmountSummay.Count > 0)
  47. {
  48. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantAmountSummay>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantAmountSummay));
  49. }
  50. return new MerchantAmountSummay();
  51. }
  52. public Dictionary<string, string> Sum(string field, string condition)
  53. {
  54. Dictionary<string, string> result = new Dictionary<string, string>();
  55. string sumString = "";
  56. string[] fieldlist = field.Split(',');
  57. foreach(string f in fieldlist)
  58. {
  59. sumString += "sum(" + f + ") " + f + ",";
  60. }
  61. sumString = sumString.TrimEnd(',');
  62. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantAmountSummay where 1=1" + condition, _conn);
  63. if(dt.Rows.Count > 0)
  64. {
  65. foreach(string f in fieldlist)
  66. {
  67. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  68. }
  69. }
  70. return result;
  71. }
  72. /// <summary>
  73. /// 添加数据
  74. /// </summary>
  75. /// <param name="Fields">要设置的字段</param>
  76. /// <returns></returns>
  77. public int Add(Dictionary<string, object> Fields)
  78. {
  79. return new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantAmountSummay", Fields, 0);
  80. }
  81. /// <summary>
  82. /// 修改数据
  83. /// </summary>
  84. /// <param name="Fields">要设置的字段</param>
  85. /// <param name="Id">主键Id</param>
  86. public void Edit(Dictionary<string, object> Fields, int Id)
  87. {
  88. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAmountSummay", Fields, Id);
  89. }
  90. /// <summary>
  91. /// 删除数据
  92. /// </summary>
  93. /// <param name="Id">主键Id</param>
  94. public void Delete(int Id)
  95. {
  96. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantAmountSummay", Id);
  97. }
  98. /// <summary>
  99. /// 排序
  100. /// </summary>
  101. /// <param name="Id">主键Id</param>
  102. /// <param name="Sort">排序序号</param>
  103. public void Sort(int Id, int Sort)
  104. {
  105. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantAmountSummay", Sort, Id);
  106. }
  107. /// <summary>
  108. /// 导入数据
  109. /// </summary>
  110. /// <param name="ExcelData">json数据</param>
  111. public void Import(string ExcelData)
  112. {
  113. WebCMSEntities db = new WebCMSEntities();
  114. JsonData list = JsonMapper.ToObject(ExcelData);
  115. for (int i = 1; i < list.Count;i++ )
  116. {
  117. JsonData dr = list[i];
  118. db.MerchantAmountSummay.Add(new MerchantAmountSummay()
  119. {
  120. CreateDate = DateTime.Now,
  121. UpdateDate = DateTime.Now,
  122. });
  123. db.SaveChanges();
  124. }
  125. db.Dispose();
  126. }
  127. // /// <summary>
  128. // /// 导出excel表格
  129. // /// </summary>
  130. // /// <param name="fields">查询条件(单个字段)</param>
  131. // /// <param name="condition">查询条件(sql语句)</param>
  132. // /// <returns></returns>
  133. // public Dictionary<string, object> ExportExcel(List<FieldItem> fields, string condition, string orderby = "Id desc")
  134. // {
  135. // Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAmountSummay", fields, orderby, "0", 1, 20000, condition, "Id", false);
  136. // List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  137. // foreach (Dictionary<string, object> dic in diclist)
  138. // {
  139. // }
  140. // Dictionary<string, object> result = new Dictionary<string, object>();
  141. // result.Add("Status", "1");
  142. // result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  143. // result.Add("Obj", diclist);
  144. // Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  145. // result.Add("Fields", ReturnFields);
  146. // return result;
  147. // }
  148. }
  149. }