SystemSetService.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * 系统设置
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Bs;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Bs
  12. {
  13. public class SystemSetService
  14. {
  15. string _conn = "";
  16. public SystemSetService()
  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("WebUrl"); //网站地址
  36. fields.Add("WebName"); //网站名称
  37. fields.Add("UploadMaxSize"); //允许最大上传
  38. fields.Add("UploadAutoZoomWidth"); //自动缩略图宽
  39. fields.Add("UploadAutoZoomHeight"); //自动缩略图高
  40. fields.Add("UploadAutoWater"); //自动水印
  41. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("SystemSet", relationData, orderBy, page, limit, condition, fields);
  42. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  43. count = int.Parse(obj["count"].ToString());
  44. return diclist;
  45. }
  46. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  47. {
  48. List<string> fields = new List<string>(); //要显示的列
  49. fields.Add("Id");
  50. fields.Add("CreateDate"); //添加时间
  51. fields.Add("Status"); //状态
  52. fields.Add("WebUrl"); //网站地址
  53. fields.Add("WebName"); //网站名称
  54. fields.Add("UploadMaxSize"); //允许最大上传
  55. fields.Add("UploadAutoZoomWidth"); //自动缩略图宽
  56. fields.Add("UploadAutoZoomHeight"); //自动缩略图高
  57. fields.Add("UploadAutoWater"); //自动水印
  58. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("SystemSet", relationData, orderBy, page, limit, condition, fields);
  59. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  60. return diclist;
  61. }
  62. /// <summary>
  63. /// 查询一条记录
  64. /// </summary>
  65. /// <param name="Id">主键Id</param>
  66. /// <returns></returns>
  67. public SystemSet Query(int Id)
  68. {
  69. WebCMSEntities db = new WebCMSEntities();
  70. SystemSet editData = db.SystemSet.FirstOrDefault(m => m.Id == Id) ?? new SystemSet();
  71. db.Dispose();
  72. return editData;
  73. }
  74. /// <summary>
  75. /// 查询记录数
  76. /// </summary>
  77. /// <param name="Id">主键Id</param>
  78. /// <returns></returns>
  79. public int Count(string condition = "")
  80. {
  81. int result = 0;
  82. DataTable dt = CustomerSqlConn.dtable("select count(Id) from SystemSet where 1=1" + condition, _conn);
  83. if(dt.Rows.Count > 0)
  84. {
  85. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  86. }
  87. return result;
  88. }
  89. /// <summary>
  90. /// 查询是否存在
  91. /// </summary>
  92. /// <param name="Id">主键Id</param>
  93. /// <returns></returns>
  94. public bool Exist(int Id)
  95. {
  96. WebCMSEntities db = new WebCMSEntities();
  97. bool check = db.SystemSet.Any(m => m.Id == Id);
  98. db.Dispose();
  99. return check;
  100. }
  101. /// <summary>
  102. /// 添加数据
  103. /// </summary>
  104. /// <param name="Fields">要设置的字段</param>
  105. /// <returns></returns>
  106. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  107. {
  108. if(check)
  109. {
  110. if (!function.IsInt(fields["UploadMaxSize"].ToString()))
  111. {
  112. return new AppResultJson() { Status = "-1", Info = "请填写正确的允许最大上传" };
  113. }
  114. if (string.IsNullOrEmpty(fields["UploadAutoZoomWidth"].ToString()))
  115. {
  116. return new AppResultJson() { Status = "-1", Info = "请填写自动缩略图宽" };
  117. }
  118. if (!function.IsInt(fields["UploadAutoZoomWidth"].ToString()))
  119. {
  120. return new AppResultJson() { Status = "-1", Info = "请填写正确的自动缩略图宽" };
  121. }
  122. if (string.IsNullOrEmpty(fields["UploadAutoZoomHeight"].ToString()))
  123. {
  124. return new AppResultJson() { Status = "-1", Info = "请填写自动缩略图高" };
  125. }
  126. if (!function.IsInt(fields["UploadAutoZoomHeight"].ToString()))
  127. {
  128. return new AppResultJson() { Status = "-1", Info = "请填写正确的自动缩略图高" };
  129. }
  130. }
  131. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("SystemSet", fields, 0);
  132. return new AppResultJson(){ Status = "1", Data = Id };
  133. }
  134. /// <summary>
  135. /// 修改数据
  136. /// </summary>
  137. /// <param name="Fields">要设置的字段</param>
  138. /// <param name="Id">主键Id</param>
  139. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  140. {
  141. if(check)
  142. {
  143. if (!function.IsInt(fields["UploadMaxSize"].ToString()))
  144. {
  145. return new AppResultJson() { Status = "-1", Info = "请填写正确的允许最大上传" };
  146. }
  147. if (string.IsNullOrEmpty(fields["UploadAutoZoomWidth"].ToString()))
  148. {
  149. return new AppResultJson() { Status = "-1", Info = "请填写自动缩略图宽" };
  150. }
  151. if (!function.IsInt(fields["UploadAutoZoomWidth"].ToString()))
  152. {
  153. return new AppResultJson() { Status = "-1", Info = "请填写正确的自动缩略图宽" };
  154. }
  155. if (string.IsNullOrEmpty(fields["UploadAutoZoomHeight"].ToString()))
  156. {
  157. return new AppResultJson() { Status = "-1", Info = "请填写自动缩略图高" };
  158. }
  159. if (!function.IsInt(fields["UploadAutoZoomHeight"].ToString()))
  160. {
  161. return new AppResultJson() { Status = "-1", Info = "请填写正确的自动缩略图高" };
  162. }
  163. }
  164. new DbService(AppConfig.Base.dbTables, _conn).Edit("SystemSet", fields, Id);
  165. return new AppResultJson(){ Status = "1", Data = Id };
  166. }
  167. /// <summary>
  168. /// 逻辑删除
  169. /// </summary>
  170. /// <param name="Id">主键Id</param>
  171. public void Remove(int Id)
  172. {
  173. Dictionary<string, object> fields = new Dictionary<string, object>();
  174. fields.Add("Status", -1);
  175. new DbService(AppConfig.Base.dbTables, _conn).Edit("SystemSet", fields, Id);
  176. }
  177. /// <summary>
  178. /// 删除数据
  179. /// </summary>
  180. /// <param name="Id">主键Id</param>
  181. public void Delete(int Id)
  182. {
  183. new DbService(AppConfig.Base.dbTables, _conn).Delete("SystemSet", Id);
  184. }
  185. /// <summary>
  186. /// 排序
  187. /// </summary>
  188. /// <param name="Id">主键Id</param>
  189. /// <param name="Sort">排序序号</param>
  190. public void Sort(int Id, int Sort)
  191. {
  192. new DbService(AppConfig.Base.dbTables, _conn).Sort("SystemSet", Sort, Id);
  193. }
  194. /// <summary>
  195. /// 导入数据
  196. /// </summary>
  197. /// <param name="ExcelData">json数据</param>
  198. public void Import(string ExcelData)
  199. {
  200. WebCMSEntities db = new WebCMSEntities();
  201. JsonData list = JsonMapper.ToObject(ExcelData);
  202. for (int i = 1; i < list.Count;i++ )
  203. {
  204. JsonData dr = list[i];
  205. db.SystemSet.Add(new SystemSet()
  206. {
  207. CreateDate = DateTime.Now,
  208. UpdateDate = DateTime.Now,
  209. });
  210. db.SaveChanges();
  211. }
  212. db.Dispose();
  213. }
  214. /// <summary>
  215. /// 导出excel表格
  216. /// </summary>
  217. /// <param name="fields">查询条件(单个字段)</param>
  218. /// <param name="condition">查询条件(sql语句)</param>
  219. /// <returns></returns>
  220. // public void ExportExcel(List<RelationData> relationData, string condition)
  221. // {
  222. // }
  223. }
  224. }