using BLL.DAL;
using Common;
using Json;
using Lib;
using Model;
using System.Collections;
using System.Web.Mvc;
using System.Web.Script.Serialization;
namespace wms.Areas.BaseInfo.Controllers
{
public class AlarmInfoController : MasterPage
{
// GET: BaseInfo/AlarmInfo
[LoginFilter]
public ActionResult Index()
{
ViewBag.Title = "报警维护";
return View();
}
///
/// 新增编辑工位对应的流程字
///
///
[LoginFilter]
public ActionResult AddEditAlarmInfo()
{
try
{
string id = Request.QueryString.Get("Id");
DAL_AlarmInfo provider = new DAL_AlarmInfo();
if (id != null)
{
var model = provider.GetAlarmInfo(id);
ViewBag.PlcIP = model.PlcIP;
ViewBag.AlarmCode = model.AlarmCode;
ViewBag.AlarmName = model.AlarmName;
ViewBag.LedIP = model.LedIP;
ViewBag.Type = model.Type;
ViewBag.AlarmType = model.AlarmType;
//ViewBag.Type = provider.GetPlcPosHtml(model.PlcInfoId.ToString());
}
else
{
//ViewBag.Type = provider.GetPlcPosHtml();
}
return View();
}
catch (System.Exception)
{
return View();
}
}
}
public class AlarmInfoAjaxController : AjaxPage
{
///
/// 获取报警信息表
///
///
[HttpPost]
public ActionResult GetAlarmInfoList()
{
var dd = Request["ajaxdata"];
var models = new JavaScriptSerializer().Deserialize(dd);
if (models != null)
{
PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize };
DAL_AlarmInfo provider = new DAL_AlarmInfo();
var entity = provider.GetAlarmInfoList(models, ref pageInfo);
string json = JsonHelper.IListToJson(entity, "List");
string pjson = ConvertJson.Serializer(pageInfo);
ReturnJson.AddProperty("Result", new JsonObject(json));
ReturnJson.AddProperty("PageInfo", new JsonObject(pjson));
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "响应成功");
return Content(this.ReturnJson.ToString());
}
return Content(null);
}
///
/// 新增编辑报警信息
///
///
[HttpPost]
public ActionResult AddAlarmInfo()
{
var dd = Request["ajaxdata"];
var models = new JavaScriptSerializer().Deserialize(dd);
string Operation = models.Operation;
if (models != null)
{
DAL_AlarmInfo provider = new DAL_AlarmInfo();
if (Operation == "Add")
{
models.CreateUser = this.LoginUser.ID;
string sqlWhere = " (AlarmCode = '" + models.AlarmCode + "') and isdel = '0' ";
if (provider.IsExist(sqlWhere))
{
bool value = provider.AddAlarmInfo(models, this.LoginUser.ID.ToString());
if (value)
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "新增报警信息成功!");
}
else
{
ReturnJson.AddProperty("Code", -1);
ReturnJson.AddProperty("Message", "新增报警信息失败!");
}
}
else
{
ReturnJson.AddProperty("Code", -1);
ReturnJson.AddProperty("Message", "该报警编号已存在!");
}
}
else if (Operation == "Edit")
{
bool value = provider.AddAlarmInfo(models, this.LoginUser.ID.ToString());
if (value)
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "编辑报警信息成功!");
}
else
{
ReturnJson.AddProperty("Code", -1);
ReturnJson.AddProperty("Message", "编辑报警信息失败!");
}
}
}
else
{
ReturnJson.AddProperty("Code", -1);
ReturnJson.AddProperty("Message", "报警信息有误!!!");
}
return Content(this.ReturnJson.ToString());
}
///
/// 删除报警信息
///
///
[HttpPost]
public ActionResult DeleteAlarmInfo()
{
string dd = Request["list"];
ArrayList models = new JavaScriptSerializer().Deserialize(dd);
string[] list = (string[])models.ToArray(typeof(string));
if (models != null)
{
DAL_AlarmInfo provider = new DAL_AlarmInfo();
bool value = provider.DeleteAlarmInfo(list);
if (value)
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "删除报警信息成功");
}
else
{
ReturnJson.AddProperty("Code", -1);
ReturnJson.AddProperty("Message", "删除报警信息失败");
}
return Content(this.ReturnJson.ToString());
}
return Content(null);
}
}
}