using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.WebUI.Attribute;
using QMAPP.FJC.Web.Models.Equipment;
using QMFrameWork.Data;
using QMAPP.ServicesAgent;
using QMAPP.FJC.Entity.Equipment;
using QMAPP.Entity;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using System.Data;
using QMFrameWork.WebUI.Util;
using QMAPP.FJC.Web.Models.Basic;
namespace QMAPP.FJC.Web.Controllers
{
///
/// 模具信息
/// 日期:20171011
/// 作者:郭兆福
///
public class MouldController : QController
{
#region 获取信息
///
/// 加载列表
///
///
///
[HandleException]
public ActionResult List(bool? callBack)
{
MouldModel seachModel = new MouldModel();
//seachModel.ImmediateSearch = false;
if (callBack == true)
TryGetSelectBuffer(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/Mould/GetList";
return View("MouldList", seachModel);
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
MouldModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
Mould condition = null;
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel(seachModel);
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction>("MouldBLL_GetList", condition, page);
//通过返回dataResult判断
if (dataResult.Ex != null)
{
throw dataResult.Ex;
}
else if (dataResult.IsSuccess)
{
page = dataResult.Result;
}
DateGridResult result = new DateGridResult();
result.Total = page.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑
///
/// 编辑载入
///
/// 处理结果
[HandleException]
public ActionResult Edit()
{
MouldModel model = new MouldModel();
string ID = Request.Params["PID"];
Mould Entity = new Mould();
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
if (string.IsNullOrEmpty(ID) == false)
{
//修改获取原数据
Entity.PID = ID;
result = wcfAgent.InvokeServiceFunction>("MouldBLL_Get", Entity);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("MouldEdit", model);
}
model = CopyToModel(result.Result);
}
return View("MouldEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存
///
///
/// 处理结果
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult Save(MouldModel saveModel)
{
Mould Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
Entity = CopyToModel(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction>("MouldBLL_Insert", Entity);
}
else
{
//修改
result = wcfAgent.InvokeServiceFunction>("MouldBLL_Update", Entity);
}
if (result.IsSuccess == false)
{
SetMessage("模具编码已存在!");
return View("MouldEdit", saveModel);
}
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
///
/// 删除
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult Delete(Mould model)
{
string selectKey = Request.Form["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("MouldBLL_Delete", selectKey);
if (result.IsSuccess == false)
{
SetMessage("信息有关联,删除失败!");
return List(true);
}
SetMessage(AppResource.DeleteMessage);
return List(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 模具资料维护
///
/// 加载列表
///
///
///
public ActionResult MouldDataList(bool? callBack)
{
MouldDataModel mouldModel = new MouldDataModel();
string routeCode = Request.Params["MOULDDATA_CODE"];
if (callBack == true)
TryGetSelectBuffer(out mouldModel);
mouldModel.rownumbers = false;
mouldModel.url = "/Mould/GetMouldDataList?MOULDDATA_CODE=" + routeCode;
mouldModel.MOULDDATA_CODE = routeCode;
return View("MouldDataList", mouldModel);
}
///
/// 获取列表
///
///
///
public ActionResult GetMouldDataList(bool? callBack)
{
string routeCode = Request.Params["MOULDDATA_CODE"];
MouldDataModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
MouldData condition = null;
DataResult pageResult = new DataResult();
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
if (string.IsNullOrEmpty(seachModel.MOULDDATA_CODE))
{
seachModel.MOULDDATA_CODE = routeCode;
}
condition = CopyToModel(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction>
("MouldBLL_GetMouldData", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return MouldDataList(true);
}
DateGridResult result = new DateGridResult();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize>(pageResult.Result.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 维护添加页面
public ActionResult MouldDataEdit()
{
MouldDataModel model = new MouldDataModel();
model = GetModel();
model.MOULD_ID = Request.Params["MOULD_ID"];
//model.MOULD_ID = Request.Params["MOULD_ID"];
try
{
return View("MouldDataEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存模具资料维护信息
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult MouldDataSave(QMAPP.FJC.Web.Models.Equipment.MouldDataModel saveModel)
{
MouldData entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
entity = CopyToModel(saveModel);
if (string.IsNullOrEmpty(entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction>
("MouldBLL_MouldDataSave", entity);
}
//if (result.IsSuccess == false)
//{
// SetMessage("模具资料编码已存在");
// return View("MouldDataEdit", saveModel);
//}
//else
//{
// SetMessage("模具资料名称已存在");
// return View("MouldDataEdit", saveModel);
//}
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("MouldDataEdit", saveModel);
}
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
}
catch (Exception)
{
throw;
}
}
#endregion
#region 删除模具资料维护信息
public ActionResult MouldDataDelete(MouldDataModel saveMode)
{
string selectKey = Request.Form["selectKey"];
string MOULD_ID = Request.Form["MOULD_ID"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("MouldBLL_MouldDataDelete", selectKey, MOULD_ID);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return MouldDataList(true);
}
SetMessage(AppResource.DeleteMessage);
return MouldDataList(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出excel
///
/// 导出excel
///
/// 结果
[HttpPost]
public ActionResult ExportExcel()
{
MouldModel seachModel = null;
Mould condition = null;
DataTable exportDt = new DataTable();
ServiceAgent wcfAgent = this.GetServiceAgent();
string selectKey = Request.Form["selectKey"];
try
{
//获取查询对象
seachModel = GetModel();
condition = CopyToModel(seachModel);
//获取数据
exportDt = wcfAgent.InvokeServiceFunction("MouldBLL_GetExportData", condition);
if (selectKey != "")
{
DataView dv = new DataView(exportDt);
string strWhere = "";
string[] list = selectKey.Split(":".ToCharArray());
foreach (string id in list)
{
strWhere += " PID='" + id + "' or";
}
if (strWhere != "")
{
strWhere = strWhere.Remove((strWhere.Length - 2), 2);
}
dv.RowFilter = strWhere;
exportDt = dv.ToTable();
}
//导出
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
return efTool.GetExcelFileResult("MouldExp", "MouldExp.xlsx", exportDt);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}