MsgSmsSetService.cs 8.5 KB

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