AppBottomNavsService.cs 7.8 KB

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