EntryConditionsController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.SuperSocket.Common;
  4. using Ant.Service.Common;
  5. using Ant.Service.Common.Enums;
  6. using Central.Control.Domain;
  7. using MES.Production.Entity;
  8. using MES.Production.Entity.Entity;
  9. using MES.Production.Entity.Enum;
  10. using Ant.Service.Mongodb;
  11. using MES.Production.Service.IService;
  12. using MES.Production.Service.ServiceImp;
  13. using Ant.Service.Utility;
  14. using ChangFa.Machinery.WebPage.Areas.SysManage.Models;
  15. using ChangFa.Machinery.WebPage.Controllers;
  16. using MongoDB.Driver.Builders;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Data;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Web;
  24. using System.Web.Mvc;
  25. using JsonHelper = Ant.Service.Common.JsonHelper;
  26. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  27. {
  28. public class EntryConditionsController : BaseController
  29. {
  30. // GET: SysManage/EntryConditions
  31. public ActionResult Index()
  32. {
  33. return View();
  34. }
  35. [UserAuthorize(ModuleAlias = "SportsEventList", OperaAction = "Add,Edit")]
  36. [ValidateInput(false)]
  37. [HttpPost]
  38. public ActionResult Save(YW_EntryConditions entity)
  39. {
  40. JsonHelper json = new JsonHelper() { Msg = "保存组别设置成功", Status = "n", ReUrl = "/Sys/EntryConditions/SetEntryConditions" };
  41. try
  42. {
  43. entity.BigEventCode = Request.Form["sportsId"];
  44. entity.BigEventName = Request.Form["sportsName"];
  45. entity.SEPID = Request.Form["SEPID"].ToInt32();
  46. //2021-05-17jjg把限制设置条件去掉
  47. //if (entity.BoysMax > 0 || entity.GirlsMax > 0)
  48. //{
  49. // if (entity.MixedMax > 0)
  50. // {
  51. // json.Msg = "混合和男女不能同时填写!";
  52. // return Json(json);
  53. // }
  54. //}
  55. //if(entity.BoysMax==0&&entity.GirlsMax==0&&entity.MixedMax==0)
  56. //{
  57. // json.Msg = "混合和男女不能同时为零!";
  58. // return Json(json);
  59. //}
  60. using (AntORM orm = new AntORM())
  61. {
  62. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  63. RequestModel request = new RequestModel();
  64. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存赛事" };
  65. if (entity.ID > 0)
  66. {
  67. request.Oid = entity.ID.ToString();
  68. var reslut = orm.UpdateById(entity, request);
  69. if (reslut.IsSuccess)
  70. {
  71. json.Status = "y";
  72. }
  73. else
  74. {
  75. json.Msg = "保存组别设置失败";
  76. }
  77. }
  78. else
  79. {
  80. entity.Createper = this.CurrentUser.Name;
  81. entity.CreateDate = DateTime.Now;
  82. var reslut = orm.Save(entity, request);
  83. if (reslut.IsSuccess)
  84. {
  85. json.Status = "y";
  86. }
  87. else
  88. {
  89. json.Msg = "保存组别设置失败";
  90. }
  91. }
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. json.Msg = "保存组别设置发生内部错误!";
  97. WriteLog(enumOperator.None, "保存组别设置:", ex);
  98. }
  99. return Json(json);
  100. }
  101. public ActionResult SaveSportsEntries(string sportsName, string sportsId, string SEPID, string sportsNames, string sportsIds)
  102. {
  103. JsonHelper json = new JsonHelper()
  104. {
  105. Msg = "保存失败",
  106. Status = "n"
  107. };
  108. int i = 0;
  109. if (sportsIds.IndexOf(',') > 0)
  110. {
  111. var arr = sportsNames.Split(',');
  112. foreach (var s in sportsIds.Split(','))
  113. {
  114. if (!s.IsEmpty())
  115. {
  116. YW_SportsEntries entity = new YW_SportsEntries();
  117. entity.BigEventCode = sportsId;
  118. entity.BigEventName = sportsName;
  119. entity.SmallEventCode = s;
  120. entity.SmallEventName = arr[i];
  121. entity.SEPID = SEPID;
  122. entity.State = 1;
  123. using (AntORM orm = new AntORM())
  124. {
  125. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  126. RequestModel request = new RequestModel();
  127. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存赛事" };
  128. var num = orm.Queryable<YW_SportsEntries>().Where(p => p.SmallEventCode == s && p.BigEventCode == sportsId).Count();
  129. if (num == 0)
  130. {
  131. var reslut = orm.Save(entity, request);
  132. if (reslut.IsSuccess)
  133. {
  134. json.Msg = "保存成功";
  135. json.Status = "y";
  136. }
  137. }
  138. }
  139. }
  140. i++;
  141. }
  142. }
  143. return Json(json);
  144. }
  145. /// <summary>
  146. ///
  147. /// </summary>
  148. /// <param name="idList"></param>
  149. /// <returns></returns>
  150. public ActionResult Delete(string idList)
  151. {
  152. JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除裁判成功" };
  153. try
  154. {
  155. //是否为空
  156. if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的裁判"; return Json(json); }
  157. string[] id = idList.Trim(',').Split(',');
  158. for (int i = 0; i < id.Length; i++)
  159. {
  160. var userId = (id[i]);
  161. using (AntORM orm = new AntORM())
  162. {
  163. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  164. RequestModel request = new RequestModel
  165. {
  166. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "删除裁判" },
  167. Oid = userId.ToString()
  168. };
  169. var reslut = orm.DeleteById<YW_EntryConditions>(request);
  170. if (reslut.IsSuccess)
  171. {
  172. var dreslut = orm.DeleteByLambda<YW_ProjectEntry>(p => p.SCID == userId, request);
  173. int ecid = userId.ToInt32();
  174. var reportreslut = orm.DeleteByLambda<YW_MatchReport>(p => p.ECID == ecid, request);
  175. json.Status = "y";
  176. WriteLog(enumOperator.Remove, json.Msg, enumLog4net.WARN);
  177. }
  178. }
  179. }
  180. }
  181. catch (Exception e)
  182. {
  183. json.Msg = "删除裁判发生内部错误!";
  184. WriteLog(enumOperator.Remove, "删除教练:", e);
  185. }
  186. return Json(json);
  187. }
  188. /// <summary>
  189. ///
  190. /// </summary>
  191. /// <param name="id"></param>
  192. /// <param name="sportsName"></param>
  193. /// <param name="sportsId"></param>
  194. /// <param name="SEPID"></param>
  195. /// <returns></returns>
  196. [UserAuthorize(ModuleAlias = "SportsEventList", OperaAction = "Detail")]
  197. public ActionResult Detail(int? id, string sportsName, string sportsId, string SEPID)
  198. {
  199. ViewData["Year"] = DateTime.Now.ToString("yyyy");
  200. ViewData["sportsName"] = sportsName;
  201. ViewData["sportsId"] = sportsId;
  202. ViewData["SEPID"] = SEPID;
  203. YW_EntryConditions mod = new YW_EntryConditions();
  204. mod.BigEventCode = sportsId;
  205. mod.BigEventName = sportsName;
  206. mod.SEPID = SEPID.ToInt32();
  207. if (id != null)
  208. {
  209. using (AntORM orm = new AntORM())
  210. {
  211. try
  212. {
  213. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  214. RequestModel request = new RequestModel
  215. {
  216. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询赛事的单个实体方法" },
  217. Oid = id.ToString()
  218. };
  219. var reslut = orm.GetEntity<YW_EntryConditions>(request);
  220. if (reslut.IsSuccess)
  221. {
  222. mod = reslut.ResultModel;
  223. }
  224. }
  225. catch (Exception e)
  226. {
  227. }
  228. }
  229. }
  230. else
  231. {
  232. mod.GirlsMin = 0;
  233. mod.BoysMin = 0;
  234. mod.MixedMin = 0;
  235. }
  236. List<SelectListItem> items = new List<SelectListItem>();
  237. items.Add(new SelectListItem { Text = "请选择", Value = "" });
  238. var sysCodes = CommonEnumHelper.LoadDic(CommonCodeType.年级);
  239. foreach (var item in sysCodes)
  240. {
  241. items.Add(new SelectListItem { Text = item.NAMETEXT, Value = item.NAMETEXT });
  242. }
  243. ViewBag.Grades = items;
  244. items = new List<SelectListItem>();
  245. items.Add(new SelectListItem { Text = "请选择", Value = "" });
  246. sysCodes = CommonEnumHelper.LoadDic(CommonCodeType.学校小类);
  247. foreach (var item in sysCodes)
  248. {
  249. items.Add(new SelectListItem { Text = item.NAMETEXT, Value = item.NAMETEXT });
  250. }
  251. ViewBag.SchoolSmallTypes = items;
  252. return View(mod);
  253. }
  254. /// <summary>
  255. ///
  256. /// </summary>
  257. /// <param name="id"></param>
  258. /// <param name="sports"></param>
  259. /// <returns></returns>
  260. [UserAuthorize(ModuleAlias = "SportsEventList", OperaAction = "View,Add,Edit")]
  261. public ActionResult SetEntryConditions(int id, string sportsId, string sportsName, string state)
  262. {
  263. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<YW_EntryConditions>()));
  264. ViewData["sportsName"] = sportsName;
  265. ViewData["sportsId"] = sportsId;
  266. ViewData["ID"] = id;
  267. ViewData["state"] = state;
  268. string sportsNames = "";
  269. using (AntORM orm = new AntORM())
  270. {
  271. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  272. RequestModel request = new RequestModel();
  273. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存赛事" };
  274. var SportsReslut = orm.Queryable<YW_SportsEntries>().Where(p => p.BigEventCode == sportsId).ToList(request);
  275. if (SportsReslut.IsSuccess)
  276. {
  277. foreach (YW_SportsEntries mod in SportsReslut.ResultModel)
  278. {
  279. sportsNames += mod.SmallEventName + ",";
  280. }
  281. }
  282. }
  283. if (sportsNames.IndexOf(',') >= 0)
  284. {
  285. ViewData["SmallEventName"] = sportsNames.Substring(0, sportsNames.LastIndexOf(","));
  286. }
  287. using (AntORM orm = new AntORM())
  288. {
  289. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  290. RequestModel res = new RequestModel();
  291. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取比赛级别条件列表" };
  292. var coachList = orm.Queryable<YW_EntryConditions>();
  293. int pageno = (base.page - 1) * base.pagesize;
  294. //if (!nameOrProject.IsEmpty())
  295. //{
  296. // coachList = coachList.Where(p => (!string.IsNullOrEmpty(p.SportType) && p.SportType.Contains(nameOrProject)));
  297. //}
  298. if (id > 0)
  299. {
  300. coachList = coachList.Where(p => p.SEPID == id);
  301. }
  302. var reslut = coachList.OrderByDesc(p => p.CreateDate).Skip(pageno).Top(pagesize).ToList(res);
  303. if (reslut.IsSuccess)
  304. {
  305. reslut.RecordNum = coachList.Count();
  306. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  307. }
  308. }
  309. return View(pageInfo);
  310. }
  311. public ActionResult SetProjectEntry(string sportsName, string sportsId, string SEPID, string SCID, string smallSport, string smallSportId)
  312. {
  313. JsonHelper json = new JsonHelper()
  314. {
  315. Msg = "保存失败",
  316. Status = "n"
  317. };
  318. int i = 0;
  319. RequestModel request = new RequestModel();
  320. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存项目规则" };
  321. using (AntORM orm = new AntORM())
  322. {
  323. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  324. orm.DeleteByLambda<YW_ProjectEntry>(p => p.SCID == SCID, request);
  325. }
  326. YW_EntryConditions entryConditions = new YW_EntryConditions();
  327. using (AntORM orm = new AntORM())
  328. {
  329. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  330. int cid = SCID.ToInt32();
  331. var entryResult = orm.Queryable<YW_EntryConditions>().Where(p => p.ID == cid).FirstOrDefault(request);
  332. if (entryResult.IsSuccess)
  333. {
  334. entryConditions = entryResult.ResultModel;
  335. }
  336. }
  337. if (smallSportId.IndexOf(',') >= 0)
  338. {
  339. var arr = smallSport.Split(',');
  340. foreach (var s in smallSportId.Split(','))
  341. {
  342. if (!s.IsEmpty())
  343. {
  344. YW_ProjectEntry entity = new YW_ProjectEntry();
  345. entity.BigEventCode = sportsId;
  346. entity.BigEventName = sportsName;
  347. entity.SmallEventCode = s;
  348. entity.SmallEventName = arr[i];
  349. entity.SEPID = SEPID;
  350. entity.BoysMum = entryConditions.BoysMax;
  351. entity.GirlsMum = entryConditions.GirlsMax;
  352. entity.MixedMum = entryConditions.MixedMax;
  353. entity.State = 1;
  354. entity.SCID = SCID;
  355. entity.Createper = this.CurrentUser.LogName;
  356. entity.CreateDate = DateTime.Now;
  357. using (AntORM orm = new AntORM())
  358. {
  359. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  360. var reslut = orm.Save(entity, request);
  361. if (reslut.IsSuccess)
  362. {
  363. json.Msg = "设置成功";
  364. json.Status = "y";
  365. }
  366. }
  367. }
  368. i++;
  369. }
  370. }
  371. else
  372. {
  373. YW_ProjectEntry entity = new YW_ProjectEntry();
  374. entity.BigEventCode = sportsId;
  375. entity.BigEventName = sportsName;
  376. entity.SmallEventCode = smallSportId;
  377. entity.SmallEventName = smallSport;
  378. entity.SEPID = SEPID;
  379. entity.BoysMum = entryConditions.BoysMax;
  380. entity.GirlsMum = entryConditions.GirlsMax;
  381. entity.MixedMum = entryConditions.MixedMax;
  382. entity.State = 1;
  383. entity.SCID = SCID;
  384. entity.Createper = this.CurrentUser.LogName;
  385. entity.CreateDate = DateTime.Now;
  386. using (AntORM orm = new AntORM())
  387. {
  388. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  389. var reslut = orm.Save(entity, request);
  390. if (reslut.IsSuccess)
  391. {
  392. json.Msg = "设置成功";
  393. json.Status = "y";
  394. }
  395. }
  396. }
  397. return Json(json);
  398. }
  399. }
  400. }