using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Central.Control.Domain;
using MES.Production.Service.IService;
using Ant.Service.Common;
using Ant.Service.Common.Enums;
using ChangFa.Machinery.WebPage.Controllers;
namespace ChangFa.Machinery.WebPage.Areas.ComManage.Controllers
{
///
/// 快速导航控制器
///
public class WinIndexController : BaseController
{
#region 声明容器
///
/// 快速导航
///
IWinIndexManage WinIndexManage { get; set; }
#endregion
#region 公共变量
#endregion
#region 基本视图
///
/// 快速导航列表
///
public ActionResult Index()
{
var result = this.WinIndexManage.LoadAll(null).OrderBy(p => p.SHOWORDER).ToList();
return View(result);
}
///
/// 详情
///
public ActionResult Detail(string id)
{
var entity = this.WinIndexManage.Get(p => p.ID == id) ?? new COM_INDEX();
return View(entity);
}
///
/// 保存
///
public ActionResult Save(COM_INDEX entity)
{
var json = new JsonHelper() { Status = "n", Msg = "保存成功" };
bool isEdit = true;
if (entity != null)
{
entity.COLOR = Request["COLOR"] ?? "";
entity.BACKGROUNDCOLOR = Request["BACKGROUNDCOLOR"] ?? "";
var _entity = new COM_INDEX();
_entity = entity;
//添加
if (string.IsNullOrEmpty(entity.ID))
{
_entity.ID = Guid.NewGuid().ToString();
isEdit = false;
}
//判断是否重名
if (!this.WinIndexManage.IsExist(p => p.TITLE == _entity.TITLE && p.ID != _entity.ID))
{
if (this.WinIndexManage.SaveOrUpdate(entity, isEdit))
{
json.Status = "y";
}
else
{
json.Msg = "保存失败";
}
}
else
{
json.Msg = "导航" + _entity.TITLE + "已存在,不能重复添加";
}
}
else
{
json.Msg = "未找到需要保存的记录";
}
return Json(json);
}
///
/// 移除
///
public ActionResult Delete(string idlist)
{
var json = new JsonHelper() { Msg = "删除成功", Status = "n" };
try
{
if (!string.IsNullOrEmpty(idlist))
{
var idlist1 = idlist.Trim(',').Split(',').ToList();
this.WinIndexManage.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 其他调用
///
/// 首页快速导航按钮
///
public ActionResult GetCenterIndex()
{
var json = new JsonHelper() { Status = "n" };
var num = (Request["num"] ?? "") == "" ? 5 : int.Parse(Request["num"].ToString());
try
{
json.Data = this.WinIndexManage.LoadAll(null).OrderBy(p => p.SHOWORDER).Take(num).ToList();
json.Status = "y";
}
catch { }
return Json(json);
}
#endregion
#region 帮助方法
#endregion
}
}