ProfitObjectsRuleService.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 ProfitObjectsRuleService
  14. {
  15. string _conn = "";
  16. public ProfitObjectsRuleService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["SqlConnStr"].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 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("Name"); //名称
  36. fields.Add("StartDate"); //活动开始时间
  37. fields.Add("EndDate"); //活动结束时间
  38. fields.Add("Code"); //编号
  39. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("ProfitObjectsRule", relationData, orderBy, page, limit, condition, fields);
  40. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  41. count = int.Parse(obj["count"].ToString());
  42. return diclist;
  43. }
  44. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  45. {
  46. List<string> fields = new List<string>(); //要显示的列
  47. fields.Add("Id");
  48. fields.Add("CreateDate"); //添加时间
  49. fields.Add("Status"); //状态
  50. fields.Add("Name"); //名称
  51. fields.Add("StartDate"); //活动开始时间
  52. fields.Add("EndDate"); //活动结束时间
  53. fields.Add("Code"); //编号
  54. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("ProfitObjectsRule", relationData, orderBy, page, limit, condition, fields);
  55. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  56. return diclist;
  57. }
  58. /// <summary>
  59. /// 查询一条记录
  60. /// </summary>
  61. /// <param name="Id">主键Id</param>
  62. /// <returns></returns>
  63. public ProfitObjectsRule Query(int Id)
  64. {
  65. WebCMSEntities db = new WebCMSEntities();
  66. ProfitObjectsRule editData = db.ProfitObjectsRule.FirstOrDefault(m => m.Id == Id) ?? new ProfitObjectsRule();
  67. db.Dispose();
  68. return editData;
  69. }
  70. /// <summary>
  71. /// 查询记录数
  72. /// </summary>
  73. /// <param name="Id">主键Id</param>
  74. /// <returns></returns>
  75. public int Count(string condition = "")
  76. {
  77. int result = 0;
  78. DataTable dt = CustomerSqlConn.dtable("select count(Id) from ProfitObjectsRule where 1=1" + condition, _conn);
  79. if(dt.Rows.Count > 0)
  80. {
  81. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  82. }
  83. return result;
  84. }
  85. /// <summary>
  86. /// 查询是否存在
  87. /// </summary>
  88. /// <param name="Id">主键Id</param>
  89. /// <returns></returns>
  90. public bool Exist(int Id)
  91. {
  92. WebCMSEntities db = new WebCMSEntities();
  93. bool check = db.ProfitObjectsRule.Any(m => m.Id == Id);
  94. db.Dispose();
  95. return check;
  96. }
  97. /// <summary>
  98. /// 添加数据
  99. /// </summary>
  100. /// <param name="Fields">要设置的字段</param>
  101. /// <returns></returns>
  102. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  103. {
  104. if(check)
  105. {
  106. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  107. {
  108. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  109. }
  110. if (string.IsNullOrEmpty(fields["StartDate"].ToString()))
  111. {
  112. return new AppResultJson() { Status = "-1", Info = "请填写活动开始时间" };
  113. }
  114. if (string.IsNullOrEmpty(fields["EndDate"].ToString()))
  115. {
  116. return new AppResultJson() { Status = "-1", Info = "请填写活动结束时间" };
  117. }
  118. if (string.IsNullOrEmpty(fields["Code"].ToString()))
  119. {
  120. return new AppResultJson() { Status = "-1", Info = "请填写编号" };
  121. }
  122. }
  123. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("ProfitObjectsRule", fields, 0);
  124. return new AppResultJson(){ Status = "1", Data = Id };
  125. }
  126. /// <summary>
  127. /// 修改数据
  128. /// </summary>
  129. /// <param name="Fields">要设置的字段</param>
  130. /// <param name="Id">主键Id</param>
  131. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  132. {
  133. if(check)
  134. {
  135. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  136. {
  137. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  138. }
  139. if (string.IsNullOrEmpty(fields["StartDate"].ToString()))
  140. {
  141. return new AppResultJson() { Status = "-1", Info = "请填写活动开始时间" };
  142. }
  143. if (string.IsNullOrEmpty(fields["EndDate"].ToString()))
  144. {
  145. return new AppResultJson() { Status = "-1", Info = "请填写活动结束时间" };
  146. }
  147. if (string.IsNullOrEmpty(fields["Code"].ToString()))
  148. {
  149. return new AppResultJson() { Status = "-1", Info = "请填写编号" };
  150. }
  151. }
  152. new DbService(AppConfig.Base.dbTables, _conn).Edit("ProfitObjectsRule", fields, Id);
  153. return new AppResultJson(){ Status = "1", Data = Id };
  154. }
  155. /// <summary>
  156. /// 逻辑删除
  157. /// </summary>
  158. /// <param name="Id">主键Id</param>
  159. public void Remove(int Id)
  160. {
  161. Dictionary<string, object> fields = new Dictionary<string, object>();
  162. fields.Add("Status", -1);
  163. new DbService(AppConfig.Base.dbTables, _conn).Edit("ProfitObjectsRule", fields, Id);
  164. }
  165. /// <summary>
  166. /// 删除数据
  167. /// </summary>
  168. /// <param name="Id">主键Id</param>
  169. public void Delete(int Id)
  170. {
  171. new DbService(AppConfig.Base.dbTables, _conn).Delete("ProfitObjectsRule", Id);
  172. }
  173. /// <summary>
  174. /// 排序
  175. /// </summary>
  176. /// <param name="Id">主键Id</param>
  177. /// <param name="Sort">排序序号</param>
  178. public void Sort(int Id, int Sort)
  179. {
  180. new DbService(AppConfig.Base.dbTables, _conn).Sort("ProfitObjectsRule", Sort, Id);
  181. }
  182. /// <summary>
  183. /// 导入数据
  184. /// </summary>
  185. /// <param name="ExcelData">json数据</param>
  186. public void Import(string ExcelData)
  187. {
  188. WebCMSEntities db = new WebCMSEntities();
  189. JsonData list = JsonMapper.ToObject(ExcelData);
  190. for (int i = 1; i < list.Count;i++ )
  191. {
  192. JsonData dr = list[i];
  193. db.ProfitObjectsRule.Add(new ProfitObjectsRule()
  194. {
  195. CreateDate = DateTime.Now,
  196. UpdateDate = DateTime.Now,
  197. });
  198. db.SaveChanges();
  199. }
  200. db.Dispose();
  201. }
  202. /// <summary>
  203. /// 导出excel表格
  204. /// </summary>
  205. /// <param name="fields">查询条件(单个字段)</param>
  206. /// <param name="condition">查询条件(sql语句)</param>
  207. /// <returns></returns>
  208. // public void ExportExcel(List<RelationData> relationData, string condition)
  209. // {
  210. // }
  211. }
  212. }