MsgSmsSetService.cs 9.3 KB

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