using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMFrameWork.WebUI.Attribute;
using QMAPP.Web.Models.Sys;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.Data;
using QMAPP.Entity.Sys;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
namespace QMAPP.Web.Controllers
{
///
/// 系统锁定控制器
/// 创建者:韩磊
/// 创建日期:2014.12.17
///
public class SystemLockController : QController
{
#region 系统锁定列表
///
/// 系统锁定列表加载
///
///
[HandleException]
public ActionResult SystemLockList(bool? callBack)
{
SystemLockModel seachModel = new SystemLockModel();
if (callBack == true)
{
TryGetSelectBuffer(out seachModel);
}
else
{
seachModel.ValidFlg = "1";
}
seachModel.rownumbers = false;
seachModel.url = "/SystemLock/GetList";
return View("SystemLockList", seachModel);
}
///
/// 获取系统锁定列表
///
/// 是否回调
///
[HandleException]
public ActionResult GetList(bool? callBack)
{
List lockInfo = new List();
SystemLockModel seachModel = null;
DataPage page = null;
SystemLockInfo condition = null;
try
{
//获取查询对象
seachModel = GetModel();
if (seachModel.ValidFlg == null)
{
seachModel.ValidFlg = "1";
}
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
//获取查询条件
condition = CopyToModel(seachModel);
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
page = agent.InvokeServiceFunction("SystemLockBLL_GetList", condition, page);
//转换查询结果
DataGridResult result = new DataGridResult();
result.Total = page.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString());
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 系统锁定信息添加、修改、删除
///
/// 锁定信息编辑
///
/// 锁定信息
[HandleException]
public ActionResult SystemLockEdit()
{
string Pid = Request.Params["PID"];
SystemLockModel model = new SystemLockModel();
SystemLockInfo lockInfo = new SystemLockInfo();
try
{
if (string.IsNullOrEmpty(Pid) == false)
{
//获取原信息
lockInfo.PID = Pid;
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
lockInfo=agent.InvokeServiceFunction("SystemLockBLL_Get", lockInfo);
model = CopyToModel(lockInfo);
}
return View(model);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存系统锁定信息
///
/// 系统锁定信息
/// 返回动作
[HttpPost]
[HandleException]
public ActionResult SystemLockSave(SystemLockModel saveModel)
{
SystemLockInfo lockInfo = new SystemLockInfo();
int r = 0;
try
{
lockInfo = CopyToModel(saveModel);
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
if (string.IsNullOrEmpty(lockInfo.PID) == true)
{
//基本信息
lockInfo.StartTime = Convert.ToDateTime(saveModel.StartTime);
lockInfo.EndTime = Convert.ToDateTime(saveModel.EndTime);
//新增
r = agent.InvokeServiceFunction("SystemLockBLL_Insert", lockInfo);
}
else
{
//修改
r = agent.InvokeServiceFunction("SystemLockBLL_Update", lockInfo);
}
//刷新数据锁定标志
agent.RefreshDataLock();
//保存成功
SetMessage(AppResource.SaveMessge);
return this.GetJsViewResult(string.Format("parent.List();parent.showTitle('{0}');parent.closeAppWindow1();"
, AppResource.SaveMessge));
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 删除系统锁定信息
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult SystemLockDelete()
{
string selectKey = Request.Form["selectKey"];
string[] list = selectKey.Split(":".ToCharArray());
ArrayList locks = new ArrayList();
try
{
//调用服务
foreach (string id in list)
{
locks.Add(id);
}
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction("SystemLockBLL_DeleteAll", locks);
//刷新数据锁定标志
agent.RefreshDataLock();
SetMessage(AppResource.DeleteMessage);
return SystemLockList(true);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 解除系统锁定信息
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult SystemUnLock()
{
string selectKey = Request.Form["selectKey"];
try
{
//调用服务
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction("SystemLockBLL_UnLock", new SystemLockInfo {PID=selectKey });
//刷新数据锁定标志
agent.RefreshDataLock();
SetMessage(AppResource.UnLock);
return SystemLockList(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}