TeamConfigService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 TeamConfigService
  14. {
  15. string _conn = "";
  16. public TeamConfigService()
  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("LimitBuddyNo"); //限制人
  36. fields.Add("MinUserNum"); //最小队伍人数
  37. fields.Add("MaxUserNum"); //最大队伍人数
  38. fields.Add("MinCycleNum"); //最小周期天数
  39. fields.Add("MaxCycleNum"); //最大周期天数
  40. fields.Add("MinStartDayLimit"); //最小间隔天数
  41. fields.Add("MaxStartDayLimit"); //最大间隔天数
  42. fields.Add("OverlineStatus"); //是否允许跨顶级线报名
  43. fields.Add("BlacklistCycle"); //黑名单周期
  44. fields.Add("EnterEndMin"); //活动时间差
  45. fields.Add("Remark"); //备注
  46. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("TeamConfig", relationData, orderBy, page, limit, condition, fields);
  47. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  48. count = int.Parse(obj["count"].ToString());
  49. return diclist;
  50. }
  51. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  52. {
  53. List<string> fields = new List<string>(); //要显示的列
  54. fields.Add("Id");
  55. fields.Add("CreateDate"); //添加时间
  56. fields.Add("Status"); //状态
  57. fields.Add("LimitBuddyNo"); //限制人
  58. fields.Add("MinUserNum"); //最小队伍人数
  59. fields.Add("MaxUserNum"); //最大队伍人数
  60. fields.Add("MinCycleNum"); //最小周期天数
  61. fields.Add("MaxCycleNum"); //最大周期天数
  62. fields.Add("MinStartDayLimit"); //最小间隔天数
  63. fields.Add("MaxStartDayLimit"); //最大间隔天数
  64. fields.Add("OverlineStatus"); //是否允许跨顶级线报名
  65. fields.Add("BlacklistCycle"); //黑名单周期
  66. fields.Add("EnterEndMin"); //活动时间差
  67. fields.Add("Remark"); //备注
  68. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("TeamConfig", relationData, orderBy, page, limit, condition, fields);
  69. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  70. return diclist;
  71. }
  72. /// <summary>
  73. /// 查询一条记录
  74. /// </summary>
  75. /// <param name="Id">主键Id</param>
  76. /// <returns></returns>
  77. public TeamConfig Query(int Id)
  78. {
  79. WebCMSEntities db = new WebCMSEntities();
  80. TeamConfig editData = db.TeamConfig.FirstOrDefault(m => m.Id == Id) ?? new TeamConfig();
  81. db.Dispose();
  82. return editData;
  83. }
  84. /// <summary>
  85. /// 查询记录数
  86. /// </summary>
  87. /// <param name="Id">主键Id</param>
  88. /// <returns></returns>
  89. public int Count(string condition = "")
  90. {
  91. int result = 0;
  92. DataTable dt = CustomerSqlConn.dtable("select count(Id) from TeamConfig where 1=1" + condition, _conn);
  93. if(dt.Rows.Count > 0)
  94. {
  95. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  96. }
  97. return result;
  98. }
  99. /// <summary>
  100. /// 查询是否存在
  101. /// </summary>
  102. /// <param name="Id">主键Id</param>
  103. /// <returns></returns>
  104. public bool Exist(int Id)
  105. {
  106. WebCMSEntities db = new WebCMSEntities();
  107. bool check = db.TeamConfig.Any(m => m.Id == Id);
  108. db.Dispose();
  109. return check;
  110. }
  111. /// <summary>
  112. /// 添加数据
  113. /// </summary>
  114. /// <param name="Fields">要设置的字段</param>
  115. /// <returns></returns>
  116. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  117. {
  118. if(check)
  119. {
  120. if (string.IsNullOrEmpty(fields["MinUserNum"].ToString()))
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写最小队伍人数" };
  123. }
  124. if (!function.IsInt(fields["MinUserNum"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小队伍人数" };
  127. }
  128. if (string.IsNullOrEmpty(fields["MaxUserNum"].ToString()))
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "请填写最大队伍人数" };
  131. }
  132. if (!function.IsInt(fields["MaxUserNum"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大队伍人数" };
  135. }
  136. if (string.IsNullOrEmpty(fields["MinCycleNum"].ToString()))
  137. {
  138. return new AppResultJson() { Status = "-1", Info = "请填写最小周期天数" };
  139. }
  140. if (!function.IsInt(fields["MinCycleNum"].ToString()))
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小周期天数" };
  143. }
  144. if (string.IsNullOrEmpty(fields["MaxCycleNum"].ToString()))
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "请填写最大周期天数" };
  147. }
  148. if (!function.IsInt(fields["MaxCycleNum"].ToString()))
  149. {
  150. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大周期天数" };
  151. }
  152. if (string.IsNullOrEmpty(fields["MinStartDayLimit"].ToString()))
  153. {
  154. return new AppResultJson() { Status = "-1", Info = "请填写最小间隔天数" };
  155. }
  156. if (!function.IsInt(fields["MinStartDayLimit"].ToString()))
  157. {
  158. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小间隔天数" };
  159. }
  160. if (string.IsNullOrEmpty(fields["MaxStartDayLimit"].ToString()))
  161. {
  162. return new AppResultJson() { Status = "-1", Info = "请填写最大间隔天数" };
  163. }
  164. if (!function.IsInt(fields["MaxStartDayLimit"].ToString()))
  165. {
  166. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大间隔天数" };
  167. }
  168. if (string.IsNullOrEmpty(fields["BlacklistCycle"].ToString()))
  169. {
  170. return new AppResultJson() { Status = "-1", Info = "请填写黑名单周期" };
  171. }
  172. if (!function.IsInt(fields["BlacklistCycle"].ToString()))
  173. {
  174. return new AppResultJson() { Status = "-1", Info = "请填写正确的黑名单周期" };
  175. }
  176. if (string.IsNullOrEmpty(fields["EnterEndMin"].ToString()))
  177. {
  178. return new AppResultJson() { Status = "-1", Info = "请填写活动时间差" };
  179. }
  180. if (!function.IsInt(fields["EnterEndMin"].ToString()))
  181. {
  182. return new AppResultJson() { Status = "-1", Info = "请填写正确的活动时间差" };
  183. }
  184. }
  185. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("TeamConfig", fields, 0);
  186. return new AppResultJson(){ Status = "1", Data = Id };
  187. }
  188. /// <summary>
  189. /// 修改数据
  190. /// </summary>
  191. /// <param name="Fields">要设置的字段</param>
  192. /// <param name="Id">主键Id</param>
  193. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  194. {
  195. if(check)
  196. {
  197. if (string.IsNullOrEmpty(fields["MinUserNum"].ToString()))
  198. {
  199. return new AppResultJson() { Status = "-1", Info = "请填写最小队伍人数" };
  200. }
  201. if (!function.IsInt(fields["MinUserNum"].ToString()))
  202. {
  203. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小队伍人数" };
  204. }
  205. if (string.IsNullOrEmpty(fields["MaxUserNum"].ToString()))
  206. {
  207. return new AppResultJson() { Status = "-1", Info = "请填写最大队伍人数" };
  208. }
  209. if (!function.IsInt(fields["MaxUserNum"].ToString()))
  210. {
  211. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大队伍人数" };
  212. }
  213. if (string.IsNullOrEmpty(fields["MinCycleNum"].ToString()))
  214. {
  215. return new AppResultJson() { Status = "-1", Info = "请填写最小周期天数" };
  216. }
  217. if (!function.IsInt(fields["MinCycleNum"].ToString()))
  218. {
  219. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小周期天数" };
  220. }
  221. if (string.IsNullOrEmpty(fields["MaxCycleNum"].ToString()))
  222. {
  223. return new AppResultJson() { Status = "-1", Info = "请填写最大周期天数" };
  224. }
  225. if (!function.IsInt(fields["MaxCycleNum"].ToString()))
  226. {
  227. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大周期天数" };
  228. }
  229. if (string.IsNullOrEmpty(fields["MinStartDayLimit"].ToString()))
  230. {
  231. return new AppResultJson() { Status = "-1", Info = "请填写最小间隔天数" };
  232. }
  233. if (!function.IsInt(fields["MinStartDayLimit"].ToString()))
  234. {
  235. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小间隔天数" };
  236. }
  237. if (string.IsNullOrEmpty(fields["MaxStartDayLimit"].ToString()))
  238. {
  239. return new AppResultJson() { Status = "-1", Info = "请填写最大间隔天数" };
  240. }
  241. if (!function.IsInt(fields["MaxStartDayLimit"].ToString()))
  242. {
  243. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大间隔天数" };
  244. }
  245. if (string.IsNullOrEmpty(fields["BlacklistCycle"].ToString()))
  246. {
  247. return new AppResultJson() { Status = "-1", Info = "请填写黑名单周期" };
  248. }
  249. if (!function.IsInt(fields["BlacklistCycle"].ToString()))
  250. {
  251. return new AppResultJson() { Status = "-1", Info = "请填写正确的黑名单周期" };
  252. }
  253. if (string.IsNullOrEmpty(fields["EnterEndMin"].ToString()))
  254. {
  255. return new AppResultJson() { Status = "-1", Info = "请填写活动时间差" };
  256. }
  257. if (!function.IsInt(fields["EnterEndMin"].ToString()))
  258. {
  259. return new AppResultJson() { Status = "-1", Info = "请填写正确的活动时间差" };
  260. }
  261. }
  262. new DbService(AppConfig.Base.dbTables, _conn).Edit("TeamConfig", fields, Id);
  263. return new AppResultJson(){ Status = "1", Data = Id };
  264. }
  265. /// <summary>
  266. /// 逻辑删除
  267. /// </summary>
  268. /// <param name="Id">主键Id</param>
  269. public void Remove(int Id)
  270. {
  271. Dictionary<string, object> fields = new Dictionary<string, object>();
  272. fields.Add("Status", -1);
  273. new DbService(AppConfig.Base.dbTables, _conn).Edit("TeamConfig", fields, Id);
  274. }
  275. /// <summary>
  276. /// 删除数据
  277. /// </summary>
  278. /// <param name="Id">主键Id</param>
  279. public void Delete(int Id)
  280. {
  281. new DbService(AppConfig.Base.dbTables, _conn).Delete("TeamConfig", Id);
  282. }
  283. /// <summary>
  284. /// 排序
  285. /// </summary>
  286. /// <param name="Id">主键Id</param>
  287. /// <param name="Sort">排序序号</param>
  288. public void Sort(int Id, int Sort)
  289. {
  290. new DbService(AppConfig.Base.dbTables, _conn).Sort("TeamConfig", Sort, Id);
  291. }
  292. /// <summary>
  293. /// 导入数据
  294. /// </summary>
  295. /// <param name="ExcelData">json数据</param>
  296. public void Import(string ExcelData)
  297. {
  298. WebCMSEntities db = new WebCMSEntities();
  299. JsonData list = JsonMapper.ToObject(ExcelData);
  300. for (int i = 1; i < list.Count;i++ )
  301. {
  302. JsonData dr = list[i];
  303. db.TeamConfig.Add(new TeamConfig()
  304. {
  305. CreateDate = DateTime.Now,
  306. UpdateDate = DateTime.Now,
  307. });
  308. db.SaveChanges();
  309. }
  310. db.Dispose();
  311. }
  312. /// <summary>
  313. /// 导出excel表格
  314. /// </summary>
  315. /// <param name="fields">查询条件(单个字段)</param>
  316. /// <param name="condition">查询条件(sql语句)</param>
  317. /// <returns></returns>
  318. // public void ExportExcel(List<RelationData> relationData, string condition)
  319. // {
  320. // }
  321. }
  322. }