using System.Collections.Generic;
using System.Web.Mvc;
using QMFrameWork.Common.Serialization;
using QMFrameWork.Data;
using QMFrameWork.WebUI.Attribute;
using QMFrameWork.WebUI.Util;
using QMAPP.ServicesAgent;
using QMAPP.Common.Web.Controllers;
using QMAPP.Entity;
using QMFrameWork.WebUI.DataSource;
using QMAPP.MD.Web.Models;
using QMAPP.MD.Entity;
namespace QMAPP.MD.Web.Controllers
{
/// 模块名称:采集数据借口
/// 作 者:QMMES
/// 编写日期:2017年09月05日
public class DaiController : QController
{
#region 获取列表
///
/// 加载列表
///
/// 结果
[HandleException]
public ActionResult DaiList(bool? callBack)
{
DaiModel seachModel = new DaiModel();
if (callBack == false)
TryGetSelectBuffer(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/Dai/GetList";
return View("DaiList", seachModel);
}
///
/// 获取列表
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
var wcfAgent = GetServiceAgent();
//获取查询对象
var seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
var page = GetDataPage(seachModel);
var condition = CopyToModel(seachModel);
page = wcfAgent.InvokeServiceFunction("DaiBLL_GetList", condition, page);
DataGridResult result = new DataGridResult
{
Total = page.RecordCount,
Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString())
};
return Content(result.GetJsonSource());
}
#endregion
#region 编辑
///
/// 添加载入
///
/// 处理结果
[HandleException]
public ActionResult DaiAdd()
{
DaiModel model = new DaiModel();
return View("DaiEdit", model);
}
///
/// 编辑载入
///
/// 处理结果
[HandleException]
public ActionResult DaiEdit()
{
DaiModel model = new DaiModel();
string id = Request.QueryString["PID"];
Dai info = new Dai();
ServiceAgent wcfAgent = GetServiceAgent();
if (!string.IsNullOrEmpty(id))
{
//修改获取原数据
info.PID = id;
info = wcfAgent.InvokeServiceFunction("DaiBLL_Get", info);
model = CopyToModel(info);
//QMFrameWork.WebUI.Util.SessionHelper.SetSession("Dai_Detail", info.Details);
}
return View(model);
}
///
/// 获取明细数据
///
///
[HandleException]
public ActionResult GetDetailList()
{
DataGridResult result = new DataGridResult
{
Total = 0,
Rows = SessionHelper.GetSession("Dai_Detail") as List
};
SessionHelper.SessionDispose("Dai_Detail");
if (result.Rows == null)
result.Rows = new List();
return Content(result.GetJsonSource());
}
///
/// 保存
///
/// 处理结果
[HttpPost]
[HandleException]
public ActionResult DaiSave(DaiModel saveModel)
{
var wcfAgent = GetServiceAgent();
//如何MATERIAL_CODE==MATERIAL_TYPE说明页面选的是类型
//if (saveModel.MATERIAL_CODE == saveModel.MATERIAL_TYPE)
//{
// saveModel.MATERIAL_CODE = null;
//}
var info = CopyToModel(saveModel);
//info.Details = JsonConvertHelper.DeserializeObject>(saveModel.DetailValue);
DataResult serviceResult;
if (string.IsNullOrEmpty(info.PID))
{
//新增
info.DA_STATUS = "1";
serviceResult=wcfAgent.InvokeServiceFunction>("DaiBLL_Insert", info);
}
else
{
//修改
serviceResult=wcfAgent.InvokeServiceFunction>("DaiBLL_Update", info);
}
if (serviceResult.Ex != null)
throw serviceResult.Ex;
if (!serviceResult.IsSuccess)
{
//保存失败
SetMessage(serviceResult.Msg);
return View("DaiEdit", saveModel);
}
return GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();",AppResource.SaveMessge));
}
#endregion
#region 删除
///
/// 删除
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult DaiDelete()
{
string selectKey = Request.Form["selectKey"];
var wcfAgent = GetServiceAgent();
var serviceResult = wcfAgent.InvokeServiceFunction>("DaiBLL_DeleteArray", selectKey);
SetMessage(string.IsNullOrEmpty(serviceResult.Msg) ? AppResource.DeleteMessage : serviceResult.Msg);
return DaiList(true);
}
#endregion
}
}