PageUpdateInfoService.cs 8.2 KB

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