MsgAlertService.cs 7.8 KB

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