SystemController.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using MES.Production.Service.IService;
  7. using Ant.Service.Common;
  8. using Ant.Service.Common.Enums;
  9. using Central.Control.Domain;
  10. using ChangFa.Machinery.WebPage.Controllers;
  11. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  12. {
  13. /// <summary>
  14. /// 系统管理控制器
  15. /// add 作者: 季健国 QQ:181589805 by 2016-09-09
  16. /// </summary>
  17. public class SystemController : BaseController
  18. {
  19. #region 声明容器
  20. /// <summary>
  21. /// 系统管理
  22. /// </summary>
  23. ISystemManage SystemManage { get; set; }
  24. /// <summary>
  25. /// 模块管理
  26. /// </summary>
  27. IModuleManage ModuleManage { get; set; }
  28. #endregion
  29. /// <summary>
  30. /// 加载主页
  31. /// </summary>
  32. [UserAuthorizeAttribute(ModuleAlias="SystemSet",OperaAction="View")]
  33. public ActionResult Index()
  34. {
  35. try
  36. {
  37. #region 处理查询参数
  38. //状态
  39. string status = Request.QueryString["status"];
  40. #endregion
  41. #region 加载列表
  42. var result = BindList(status);
  43. ViewData["status"] = status;
  44. #endregion
  45. return View(result);
  46. }
  47. catch (Exception e)
  48. {
  49. WriteLog(enumOperator.Select, "加载系统列表:", e);
  50. throw e.InnerException;
  51. }
  52. }
  53. /// <summary>
  54. /// 列表
  55. /// </summary>
  56. private object BindList(string status)
  57. {
  58. var query = this.SystemManage.LoadAll(null);
  59. if (!string.IsNullOrEmpty(status))
  60. {
  61. var islogin = int.Parse(status);
  62. query = query.Where(p => p.IS_LOGIN == islogin);
  63. }
  64. query = query.OrderBy(p => p.ID);
  65. return this.SystemManage.Query(query, base.page, base.pagesize);
  66. }
  67. /// <summary>
  68. /// 加载详情
  69. /// </summary>
  70. [UserAuthorizeAttribute(ModuleAlias = "SystemSet", OperaAction = "Detail")]
  71. public ActionResult Detail(string id)
  72. {
  73. var entity = this.SystemManage.Get(p => p.ID == id) ?? new SYS_SYSTEM();
  74. return View(entity);
  75. }
  76. /// <summary>
  77. /// 保存系统
  78. /// </summary>
  79. [ValidateInput(false)]
  80. [UserAuthorizeAttribute(ModuleAlias = "SystemSet", OperaAction = "Add,Edit")]
  81. public ActionResult Save(SYS_SYSTEM entity)
  82. {
  83. bool isEdit = false;
  84. JsonHelper json = new JsonHelper() { Msg = "保存系统成功", Status = "n" };
  85. try
  86. {
  87. if (entity != null)
  88. {
  89. var _entity = new SYS_SYSTEM();
  90. if (string.IsNullOrEmpty(entity.ID))
  91. {
  92. _entity = entity;
  93. _entity.ID = Guid.NewGuid().ToString();
  94. _entity.CREATEDATE = DateTime.Now;
  95. if (!string.IsNullOrEmpty(_entity.DOCKPASS))
  96. {
  97. //密码加密
  98. _entity.DOCKPASS = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(_entity.DOCKPASS);
  99. }
  100. }
  101. else
  102. {
  103. _entity = this.SystemManage.Get(p => p.ID == entity.ID);
  104. entity.CREATEDATE = _entity.CREATEDATE;
  105. if (string.IsNullOrEmpty(entity.DOCKPASS))
  106. {
  107. entity.DOCKPASS = _entity.DOCKPASS;
  108. }
  109. else
  110. {
  111. //密码加密
  112. _entity.DOCKPASS = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(entity.DOCKPASS);
  113. }
  114. _entity = entity;
  115. isEdit = true;
  116. }
  117. //系统是否存在
  118. if (!this.SystemManage.IsExist(p => p.ID != _entity.ID && p.NAME == _entity.NAME && p.SITEURL == _entity.SITEURL))
  119. {
  120. if (this.SystemManage.SaveOrUpdate(_entity, isEdit))
  121. {
  122. json.Status = "y";
  123. }
  124. else
  125. {
  126. json.Msg = "保存系统失败";
  127. }
  128. }
  129. else
  130. {
  131. json.Msg = _entity.NAME + "系统已存在,不能重复添加";
  132. }
  133. }
  134. else
  135. {
  136. json.Msg = "未找到需要保存的系统";
  137. }
  138. if (isEdit)
  139. {
  140. WriteLog(enumOperator.Edit, "修改系统,结果:" + json.Msg, enumLog4net.INFO);
  141. }
  142. else
  143. {
  144. WriteLog(enumOperator.Add, "添加系统,结果:" + json.Msg, enumLog4net.INFO);
  145. }
  146. }
  147. catch (Exception e)
  148. {
  149. json.Msg = "保存系统发生内部错误!";
  150. WriteLog(enumOperator.None, "保存系统:", e);
  151. }
  152. return Json(json);
  153. }
  154. /// <summary>
  155. /// 删除系统
  156. /// </summary>
  157. [UserAuthorizeAttribute(ModuleAlias = "SystemSet", OperaAction = "Remove")]
  158. public ActionResult Delete(string idlist)
  159. {
  160. var json = new JsonHelper() { Msg = "删除成功", Status = "n" };
  161. try
  162. {
  163. idlist = idlist.TrimEnd(',');
  164. if (!string.IsNullOrEmpty(idlist))
  165. {
  166. //验证系统是否为主系统
  167. if (idlist.ToLower().Contains(siteId.ToLower()))
  168. {
  169. json.Msg = "不能删除主系统";
  170. }
  171. else
  172. {
  173. //验证是否是正常使用的系统
  174. if (this.SystemManage.IsExist(p => idlist.Contains(p.ID) && p.IS_LOGIN == 1))
  175. {
  176. json.Msg = "要删除的系统正在使用中,不能删除";
  177. }
  178. else
  179. {
  180. //验证系统是否配置了模块
  181. if (this.ModuleManage.IsExist(p => idlist.Contains(p.FK_BELONGSYSTEM)))
  182. {
  183. json.Msg = "要删除的系统存在使用中的模块,不能删除";
  184. }
  185. else
  186. {
  187. //删除
  188. this.SystemManage.Delete(p => idlist.Contains(p.ID));
  189. json.Status = "y";
  190. }
  191. }
  192. }
  193. }
  194. else
  195. {
  196. json.Msg = "未找到要删除的系统记录";
  197. }
  198. WriteLog(enumOperator.Remove, "删除系统:" + json.Msg, enumLog4net.WARN);
  199. }
  200. catch(Exception e)
  201. {
  202. json.Msg = "删除系统发生内部错误!";
  203. WriteLog(enumOperator.Remove, "删除系统:", e);
  204. }
  205. return Json(json);
  206. }
  207. }
  208. }