123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using MES.Production.Service.IService;
- using Ant.Service.Common;
- using Ant.Service.Common.Enums;
- using Central.Control.Domain;
- using ChangFa.Machinery.WebPage.Controllers;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- /// <summary>
- /// 系统管理控制器
- /// add 作者: 季健国 QQ:181589805 by 2016-09-09
- /// </summary>
- public class SystemController : BaseController
- {
- #region 声明容器
- /// <summary>
- /// 系统管理
- /// </summary>
- ISystemManage SystemManage { get; set; }
- /// <summary>
- /// 模块管理
- /// </summary>
- IModuleManage ModuleManage { get; set; }
- #endregion
- /// <summary>
- /// 加载主页
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias="SystemSet",OperaAction="View")]
- public ActionResult Index()
- {
- try
- {
- #region 处理查询参数
- //状态
- string status = Request.QueryString["status"];
- #endregion
- #region 加载列表
- var result = BindList(status);
- ViewData["status"] = status;
- #endregion
- return View(result);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载系统列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 列表
- /// </summary>
- private object BindList(string status)
- {
- var query = this.SystemManage.LoadAll(null);
- if (!string.IsNullOrEmpty(status))
- {
- var islogin = int.Parse(status);
- query = query.Where(p => p.IS_LOGIN == islogin);
- }
- query = query.OrderBy(p => p.ID);
- return this.SystemManage.Query(query, base.page, base.pagesize);
- }
- /// <summary>
- /// 加载详情
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "SystemSet", OperaAction = "Detail")]
- public ActionResult Detail(string id)
- {
- var entity = this.SystemManage.Get(p => p.ID == id) ?? new SYS_SYSTEM();
- return View(entity);
- }
- /// <summary>
- /// 保存系统
- /// </summary>
- [ValidateInput(false)]
- [UserAuthorizeAttribute(ModuleAlias = "SystemSet", OperaAction = "Add,Edit")]
- public ActionResult Save(SYS_SYSTEM entity)
- {
- bool isEdit = false;
- JsonHelper json = new JsonHelper() { Msg = "保存系统成功", Status = "n" };
- try
- {
- if (entity != null)
- {
- var _entity = new SYS_SYSTEM();
- if (string.IsNullOrEmpty(entity.ID))
- {
- _entity = entity;
- _entity.ID = Guid.NewGuid().ToString();
- _entity.CREATEDATE = DateTime.Now;
- if (!string.IsNullOrEmpty(_entity.DOCKPASS))
- {
- //密码加密
- _entity.DOCKPASS = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(_entity.DOCKPASS);
- }
- }
- else
- {
- _entity = this.SystemManage.Get(p => p.ID == entity.ID);
- entity.CREATEDATE = _entity.CREATEDATE;
- if (string.IsNullOrEmpty(entity.DOCKPASS))
- {
- entity.DOCKPASS = _entity.DOCKPASS;
- }
- else
- {
- //密码加密
- _entity.DOCKPASS = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(entity.DOCKPASS);
- }
- _entity = entity;
- isEdit = true;
- }
- //系统是否存在
- if (!this.SystemManage.IsExist(p => p.ID != _entity.ID && p.NAME == _entity.NAME && p.SITEURL == _entity.SITEURL))
- {
- if (this.SystemManage.SaveOrUpdate(_entity, isEdit))
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存系统失败";
- }
- }
- else
- {
- json.Msg = _entity.NAME + "系统已存在,不能重复添加";
- }
- }
- else
- {
- json.Msg = "未找到需要保存的系统";
- }
- if (isEdit)
- {
- WriteLog(enumOperator.Edit, "修改系统,结果:" + json.Msg, enumLog4net.INFO);
- }
- else
- {
- WriteLog(enumOperator.Add, "添加系统,结果:" + json.Msg, enumLog4net.INFO);
- }
- }
- catch (Exception e)
- {
- json.Msg = "保存系统发生内部错误!";
- WriteLog(enumOperator.None, "保存系统:", e);
- }
- return Json(json);
-
- }
- /// <summary>
- /// 删除系统
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "SystemSet", OperaAction = "Remove")]
- public ActionResult Delete(string idlist)
- {
- var json = new JsonHelper() { Msg = "删除成功", Status = "n" };
- try
- {
- idlist = idlist.TrimEnd(',');
- if (!string.IsNullOrEmpty(idlist))
- {
- //验证系统是否为主系统
- if (idlist.ToLower().Contains(siteId.ToLower()))
- {
- json.Msg = "不能删除主系统";
- }
- else
- {
- //验证是否是正常使用的系统
- if (this.SystemManage.IsExist(p => idlist.Contains(p.ID) && p.IS_LOGIN == 1))
- {
- json.Msg = "要删除的系统正在使用中,不能删除";
- }
- else
- {
- //验证系统是否配置了模块
- if (this.ModuleManage.IsExist(p => idlist.Contains(p.FK_BELONGSYSTEM)))
- {
- json.Msg = "要删除的系统存在使用中的模块,不能删除";
- }
- else
- {
- //删除
- this.SystemManage.Delete(p => idlist.Contains(p.ID));
- json.Status = "y";
- }
- }
- }
- }
- else
- {
- json.Msg = "未找到要删除的系统记录";
- }
- WriteLog(enumOperator.Remove, "删除系统:" + json.Msg, enumLog4net.WARN);
- }
- catch(Exception e)
- {
- json.Msg = "删除系统发生内部错误!";
- WriteLog(enumOperator.Remove, "删除系统:", e);
- }
- return Json(json);
- }
- }
- }
|