天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

430 lines
14 KiB

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
{
/// <summary>
/// 模具信息
/// 日期:20171011
/// 作者:郭兆福
/// </summary>
public class MouldController : QController
{
#region 获取信息
/// <summary>
/// 加载列表
/// </summary>
/// <param name="coolback"></param>
/// <returns></returns>
[HandleException]
public ActionResult List(bool? callBack)
{
MouldModel seachModel = new MouldModel();
//seachModel.ImmediateSearch = false;
if (callBack == true)
TryGetSelectBuffer<MouldModel>(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/Mould/GetList";
return View("MouldList", seachModel);
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>列表</returns>
[HandleException]
public ActionResult GetList(bool? callBack)
{
MouldModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
Mould condition = null;
try
{
//获取查询对象
seachModel = GetModel<MouldModel>();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer<MouldModel>(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer<MouldModel>(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<Mould, MouldModel>(seachModel);
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<DataPage>>("MouldBLL_GetList", condition, page);
//通过返回dataResult判断
if (dataResult.Ex != null)
{
throw dataResult.Ex;
}
else if (dataResult.IsSuccess)
{
page = dataResult.Result;
}
DateGridResult<Mould> result = new DateGridResult<Mould>();
result.Total = page.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize<List<Mould>>(page.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑
/// <summary>
/// 编辑载入
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult Edit()
{
MouldModel model = new MouldModel();
string ID = Request.Params["PID"];
Mould Entity = new Mould();
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<Mould> result = new DataResult<Mould>();
try
{
if (string.IsNullOrEmpty(ID) == false)
{
//修改获取原数据
Entity.PID = ID;
result = wcfAgent.InvokeServiceFunction<DataResult<Mould>>("MouldBLL_Get", Entity);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("MouldEdit", model);
}
model = CopyToModel<MouldModel, Mould>(result.Result);
}
return View("MouldEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 保存
/// </summary>
/// <param name="model"></param>
/// <returns>处理结果</returns>
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult Save(MouldModel saveModel)
{
Mould Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
Entity = CopyToModel<Mould, MouldModel>(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MouldBLL_Insert", Entity);
}
else
{
//修改
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("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 删除
/// <summary>
/// 删除
/// </summary>
/// <returns>结果</returns>
[HttpPost]
[HandleException]
public ActionResult Delete(Mould model)
{
string selectKey = Request.Form["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MouldBLL_Delete", selectKey);
if (result.IsSuccess == false)
{
SetMessage("信息有关联,删除失败!");
return List(true);
}
SetMessage(AppResource.DeleteMessage);
return List(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 模具资料维护
/// <summary>
/// 加载列表
/// </summary>
/// <param name="callBack"></param>
/// <returns></returns>
public ActionResult MouldDataList(bool? callBack)
{
MouldDataModel mouldModel = new MouldDataModel();
string routeCode = Request.Params["MOULDDATA_CODE"];
if (callBack == true)
TryGetSelectBuffer<MouldDataModel>(out mouldModel);
mouldModel.rownumbers = false;
mouldModel.url = "/Mould/GetMouldDataList?MOULDDATA_CODE=" + routeCode;
mouldModel.MOULDDATA_CODE = routeCode;
return View("MouldDataList", mouldModel);
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="callBack"></param>
/// <returns></returns>
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<DataPage> pageResult = new DataResult<DataPage>();
try
{
//获取查询对象
seachModel = GetModel<MouldDataModel>();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer<MouldDataModel>(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer<MouldDataModel>(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
if (string.IsNullOrEmpty(seachModel.MOULDDATA_CODE))
{
seachModel.MOULDDATA_CODE = routeCode;
}
condition = CopyToModel<MouldData, MouldDataModel>(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction<DataResult<DataPage>>
("MouldBLL_GetMouldData", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return MouldDataList(true);
}
DateGridResult<MouldData> result = new DateGridResult<MouldData>();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize<List<MouldData>>(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<MouldDataModel>();
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<int> result = new DataResult<int>();
try
{
entity = CopyToModel<MouldData, QMAPP.FJC.Web.Models.Equipment.MouldDataModel>(saveModel);
if (string.IsNullOrEmpty(entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction<DataResult<int>>
("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<int> result = new DataResult<int>();
try
{
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("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
/// <summary>
/// 导出excel
/// </summary>
/// <returns>结果</returns>
[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<MouldModel>();
condition = CopyToModel<Mould, MouldModel>(seachModel);
//获取数据
exportDt = wcfAgent.InvokeServiceFunction<DataTable>("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
}
}