BusinessScopeService.cs 7.5 KB

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