using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MES.Production.Service.IService;
using Central.Control.Domain;
using Ant.Service.Common;
using Ant.Service.Common.Enums;
using ChangFa.Machinery.WebPage.Controllers;
namespace ChangFa.Machinery.WebPage.Areas.ComManage.Controllers
{
///
/// 自定义流程表单控制器
/// add 作者: 季健国 QQ:181589805 by 2016-12-07
///
public class FlowInfoController : BaseController
{
#region 声明容器
///
/// 流程管理
///
IFlowInfoManage FlowInfoManage { get; set; }
#endregion
#region 公共变量
#endregion
#region 基本视图
///
/// 主页
///
[UserAuthorizeAttribute(ModuleAlias = "FlowInfo", OperaAction = "View")]
public ActionResult Index()
{
var result = BindList();
return View(result);
}
///
/// 详情页
///
[UserAuthorizeAttribute(ModuleAlias = "FlowInfo", OperaAction = "Detail")]
public ActionResult Detail(string id)
{
var entity = this.FlowInfoManage.Get(p => p.ID == id) ?? new COM_FLOWINFO();
return View(entity);
}
///
/// 提交保存
///
[UserAuthorizeAttribute(ModuleAlias = "FlowInfo", OperaAction = "Add,Edit")]
[ValidateInput(false)]
public ActionResult Save(COM_FLOWINFO entity)
{
JsonHelper json = new JsonHelper() { Msg = "保存完毕", Status = "n" };
bool isEdit = false;
try
{
if (entity!=null)
{
var _entity = new COM_FLOWINFO();
//添加
if (string.IsNullOrEmpty(entity.ID))
{
_entity = entity;
_entity.ID = Guid.NewGuid().ToString();
_entity.CREATEUSER = this.CurrentUser.Name;
_entity.CREATETIME = DateTime.Now;
_entity.UPDATETIME = DateTime.Now;
_entity.UPDATEUSER = this.CurrentUser.Name;
}
else //修改
{
_entity = this.FlowInfoManage.Get(p => p.ID == entity.ID);
entity.CREATEUSER = _entity.CREATEUSER;
entity.CREATETIME = _entity.CREATETIME;
entity.UPDATEUSER = this.CurrentUser.Name;
entity.UPDATETIME = DateTime.Now;
_entity = entity;
isEdit = true;
}
//验证重复
if (!this.FlowInfoManage.IsExist(p => p.ID != _entity.ID && p.REMARK == _entity.REMARK && p.FLOWNO == _entity.FLOWNO))
{
if (this.FlowInfoManage.SaveOrUpdate(_entity, isEdit))
{
json.Status = "y";
WriteLog((isEdit ? enumOperator.Edit : enumOperator.Add), "保存流程成功",enumLog4net.INFO);
}
else
{
json.Msg = "保存流程失败";
WriteLog((isEdit ? enumOperator.Edit : enumOperator.Add), "保存流程失败",enumLog4net.INFO);
}
}
else
{
json.Msg = "流程" + _entity.REMARK + "已存在,不能重复添加";
}
}
else
{
json.Msg = "未接收到要处理的数据";
}
}
catch (Exception e)
{
json.Msg = e.InnerException.Message;
WriteLog((isEdit ? enumOperator.Edit : enumOperator.Add), "保存流程出现异常", e);
}
return Json(json);
}
///
/// 删除
///
[UserAuthorizeAttribute(ModuleAlias = "FlowInfo", OperaAction = "Remove")]
public ActionResult Delete(string idList)
{
JsonHelper json = new JsonHelper() { Msg = "删除流程完毕", Status = "n" };
try
{
if (!string.IsNullOrEmpty(idList))
{
var idList1 = idList.Trim(',').Split(',').ToList();
this.FlowInfoManage.Delete(p => idList1.Contains(p.ID));
json.Status = "y";
}
else
{
json.Msg = "未找到要删除的记录";
}
WriteLog(enumOperator.Remove, "删除流程,结果:" + json.Msg,enumLog4net.WARN);
}
catch (Exception e) { WriteLog(enumOperator.Remove, "删除流程出现异常", e); }
return Json(json);
}
#endregion
#region 私有方法
///
/// 绑定列表
///
private PageInfo BindList()
{
var query = this.FlowInfoManage.LoadAll(null);
if (!string.IsNullOrEmpty(base.keywords))
{
query = query.Where(p => p.REMARK.Contains(keywords) || p.FLOWNO.Contains(keywords));
}
query = query.OrderByDescending(p => p.CREATETIME);
return this.FlowInfoManage.Query(query, base.page, base.pagesize);
}
#endregion
#region 其他调用
#endregion
}
}