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