CodeController.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Ant.Service.Common;
  7. using MES.Production.Service.IService;
  8. using Ant.Service.Common.Enums;
  9. using Central.Control.Domain;
  10. using ChangFa.Machinery.WebPage.Controllers;
  11. using Ant.ORM;
  12. using Ant.Data;
  13. using JsonHelper = Ant.Service.Common.JsonHelper;
  14. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  15. {
  16. /// <summary>
  17. /// 数据字典管理
  18. /// add 作者: 季健国 QQ:181589805 by 2016-05-22
  19. /// </summary>
  20. public class CodeController : BaseController
  21. {
  22. #region 声明容器
  23. /// <summary>
  24. /// 编码管理
  25. /// </summary>
  26. ICodeManage CodeManage { get; set; }
  27. #endregion
  28. #region 基本视图
  29. /// <summary>
  30. /// 加载主页
  31. /// </summary>
  32. [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "View")]
  33. public ActionResult Index()
  34. {
  35. try
  36. {
  37. #region 处理查询参数
  38. string codetype = Request.QueryString["codetype"];
  39. #endregion
  40. #region 加载列表
  41. var result = BindList(codetype);
  42. ViewBag.Search = base.keywords;
  43. ViewData["codeType"] = ClsDic.DicCodeType;
  44. ViewData["codet"] = codetype;
  45. #endregion
  46. return View(result);
  47. }
  48. catch (Exception e)
  49. {
  50. WriteLog(enumOperator.Select, "数据字典管理加载主页:", e);
  51. throw e.InnerException;
  52. }
  53. }
  54. /// <summary>
  55. /// 加载列表
  56. /// </summary>
  57. private PageInfo BindList(string codetype)
  58. {
  59. //var predicate = PredicateBuilder.True<SYS_CODE>();
  60. ////关键词
  61. //if (!string.IsNullOrEmpty(keywords))
  62. //{
  63. // predicate = predicate.And(p => p.NAMETEXT.Contains(keywords));
  64. //}
  65. ////编码类型
  66. //if (!string.IsNullOrEmpty(codetype))
  67. //{
  68. // predicate = predicate.And(p => p.CODETYPE == codetype);
  69. //}
  70. //var query = this.CodeManage.LoadAll(predicate).OrderByDescending(p => p.CREATEDATE).
  71. // OrderBy(p => p.SHOWORDER).OrderBy(p => p.CODETYPE);//.OrderByDescending(p => p.UPDATEDATE)
  72. //return this.CodeManage.Query(query, base.page, base.pagesize);
  73. #region 加载列表
  74. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<SYS_CODE>()));
  75. using (AntORM orm = new AntORM())
  76. {
  77. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  78. RequestModel res = new RequestModel();
  79. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取学校列表" };
  80. var syscodeList = orm.Queryable<SYS_CODE>();
  81. int pageno = (base.page - 1) * base.pagesize;
  82. //if (!nameOrProject.IsEmpty())
  83. //{
  84. // syscodeList = syscodeList.Where(p => (!string.IsNullOrEmpty(p.Name) && p.Name.Contains(nameOrProject)));
  85. //}
  86. //编码类型
  87. if (!string.IsNullOrEmpty(codetype))
  88. {
  89. syscodeList = syscodeList.Where(p => p.CODETYPE == codetype);
  90. }
  91. if(!keywords.IsEmpty())
  92. {
  93. syscodeList = syscodeList.Where(p => (!string.IsNullOrEmpty(p.NAMETEXT) && p.NAMETEXT.Contains(keywords)));
  94. }
  95. var reslut = syscodeList.OrderByDesc(p => p.CODETYPE).ThenBy(p=>p.SHOWORDER).Skip(pageno).Top(pagesize).ToList(res);
  96. if (reslut.IsSuccess)
  97. {
  98. reslut.RecordNum = syscodeList.Count();
  99. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  100. }
  101. }
  102. //ViewData["nameOrProject"] = nameOrProject;
  103. return pageInfo;
  104. #endregion
  105. }
  106. /// <summary>
  107. /// 加载详情
  108. /// </summary>
  109. /// <param name="id">编码ID</param>
  110. /// <returns></returns>
  111. [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "Detail")]
  112. public ActionResult Detail(int? id)
  113. {
  114. var entity = this.CodeManage.Get(p => p.ID == id) ?? new SYS_CODE();
  115. ViewData["codeType"] = ClsDic.DicCodeType;
  116. return View(entity);
  117. }
  118. /// <summary>
  119. /// 保存编码
  120. /// </summary>
  121. [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "Add,Edit")]
  122. public ActionResult Save(SYS_CODE entity)
  123. {
  124. bool isEdit = false;
  125. JsonHelper json = new JsonHelper() { Msg = "保存编码成功", Status = "n" };
  126. try
  127. {
  128. if (entity != null)
  129. {
  130. entity.ISCODE = !string.IsNullOrEmpty(Request.Form["ISCODE"]) ? 1 : 0;
  131. var _entity = new SYS_CODE();
  132. //添加
  133. if (entity.ID <= 0)
  134. {
  135. _entity = entity;
  136. _entity.CREATEDATE = DateTime.Now;
  137. _entity.CREATEUSER = this.CurrentUser.Name;
  138. _entity.UPDATEDATE = DateTime.Now;
  139. _entity.UPDATEUSER = this.CurrentUser.Name;
  140. }
  141. else //修改
  142. {
  143. _entity = this.CodeManage.Get(p => p.ID == entity.ID);
  144. entity.CREATEDATE = _entity.CREATEDATE;
  145. entity.CREATEUSER = _entity.CREATEUSER;
  146. entity.UPDATEDATE = DateTime.Now;
  147. entity.UPDATEUSER = this.CurrentUser.Name;
  148. _entity = entity;
  149. isEdit = true;
  150. }
  151. //判断岗位是否重名
  152. if (!this.CodeManage.IsExist(p => p.NAMETEXT == _entity.NAMETEXT && p.CODETYPE == _entity.CODETYPE && p.ID != _entity.ID))
  153. {
  154. if (CodeManage.SaveOrUpdate(entity, isEdit))
  155. {
  156. json.Status = "y";
  157. }
  158. else
  159. {
  160. json.Msg = "保存失败";
  161. }
  162. }
  163. else
  164. {
  165. json.Msg = "编码" + _entity.NAMETEXT + "已存在,不能重复添加";
  166. }
  167. }
  168. else
  169. {
  170. json.Msg = "未找到需要保存的编码记录";
  171. }
  172. if (isEdit)
  173. {
  174. WriteLog(enumOperator.Edit, "修改编码,结果:" + json.Msg, enumLog4net.INFO);
  175. }
  176. else
  177. {
  178. WriteLog(enumOperator.Add, "添加编码,结果:" + json.Msg, enumLog4net.INFO);
  179. }
  180. }
  181. catch (Exception e)
  182. {
  183. json.Msg = "保存编码发生内部错误!";
  184. WriteLog(enumOperator.None, "保存编码:", e);
  185. }
  186. return Json(json);
  187. }
  188. /// <summary>
  189. /// 删除编码
  190. /// </summary>
  191. /// <param name="idList">编码ID字符串</param>
  192. [UserAuthorizeAttribute(ModuleAlias = "Warehouse", OperaAction = "Remove")]
  193. public ActionResult Delete(string idList)
  194. {
  195. var json = new JsonHelper() { Msg = "删除编码完毕", Status = "n" };
  196. try
  197. {
  198. if (!string.IsNullOrEmpty(idList))
  199. {
  200. var idList1 = idList.Trim(',').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList();
  201. this.CodeManage.Delete(p => idList1.Any(e => e == p.ID));
  202. json.Status = "y";
  203. }
  204. else
  205. {
  206. json.Msg = "未找到要删除的记录";
  207. }
  208. WriteLog(enumOperator.Remove, "删除编码,结果:" + json.Msg, enumLog4net.WARN);
  209. }
  210. catch (Exception e) { WriteLog(enumOperator.Remove, "删除编码出现异常:", e); }
  211. return Json(json);
  212. }
  213. #endregion
  214. #region 其他调用
  215. /// <summary>
  216. /// 根据类别获取上下级关系
  217. /// </summary>
  218. public ActionResult GetParentCode()
  219. {
  220. var json = new JsonHelper() { Status = "n", Data = "" };
  221. string codetype = Request.Form["type"];
  222. if (!string.IsNullOrEmpty(codetype))
  223. {
  224. var result = this.CodeManage.LoadListAll(p => p.CODETYPE == codetype);
  225. if (result != null && result.Count > 0)
  226. {
  227. json.Data = result;
  228. json.Status = "y";
  229. }
  230. }
  231. return Json(json);
  232. }
  233. #endregion
  234. }
  235. }