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.MD.Web.Models;
using QMAPP.Entity;
using QMAPP.MD.Entity;
using QMAPP.ServicesAgent;
using QMFrameWork.Data;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMFrameWork.WebUI.Util;
namespace QMAPP.MD.Web.Controllers
{
///
/// 模块名称:工艺路线
/// 作 者:郭兆福
/// 编写日期:2017年05月12日
///
public class ProcessRouteController : QController
{
///
/// 空数据项显示值
///
public string EmptyItemTitle = " ";
#region 获取列表
///
/// 加载列表
///
/// 结果
[HandleException]
public ActionResult List(bool? callBack)
{
ProcessRouteModel seachModel = new ProcessRouteModel();
if (callBack == true)
TryGetSelectBuffer(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/ProcessRoute/GetList";
return View("ProcessRouteList", seachModel);
}
///
/// 获取列表
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
ProcessRouteModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
ProcessRoute condition = null;
DataResult pageResult = new DataResult();
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_GetList", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return List(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 编辑
///
/// 编辑载入
///
/// 处理结果
[HandleException]
public ActionResult Edit()
{
ProcessRouteModel model = new ProcessRouteModel();
string ID = Request.Params["PID"];
ProcessRoute Entity = new ProcessRoute();
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
if (string.IsNullOrEmpty(ID) == false)
{
//修改获取原数据
Entity.PID = ID;
result = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_Get", Entity);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("ProcessRouteEdit", model);
}
model = CopyToModel(result.Result);
}
return View("ProcessRouteEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存
///
/// 保存
///
///
/// 处理结果
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult Save(ProcessRouteModel saveModel)
{
ProcessRoute Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
Entity = CopyToModel(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_Insert", Entity);
}
else
{
//修改
result = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_Update", Entity);
}
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("ProcessRouteEdit", 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(ProcessRouteModel saveMode)
{
string selectKey = Request.Form["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_Delete", selectKey);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return List(true);
}
SetMessage(AppResource.DeleteMessage);
return List(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 配置工艺路线工序
///
/// 加载列表
///
///
///
public ActionResult ProcessRouteWorkCellList(bool? callBack)
{
ProcessRouteWorkCellModel processRouteModel = new ProcessRouteWorkCellModel();
string routeCode = Request.Params["ROUTE_CODE_PARAM"];
string routeVer = Request.Params["ROUTE_VER_PARAM"];
string factory = Request.Params["FACTORY_CODE"];
if (callBack == true)
TryGetSelectBuffer(out processRouteModel);
processRouteModel.rownumbers = false;
processRouteModel.url = "/ProcessRoute/GetProcessRouteWorkCellList?ROUTE_CODE_PARAM=" + routeCode + "&ROUTE_VER_PARAM=" + routeVer;
processRouteModel.ROUTE_CODE = routeCode;
processRouteModel.VER_NUM = routeVer;
processRouteModel.FACTORY_CODE = factory;
return View("ProcessRouteWorkCellList", processRouteModel);
}
///
/// 获取列表
///
///
///
public ActionResult GetProcessRouteWorkCellList(bool? callBack)
{
string routeCode = Request.Params["ROUTE_CODE_PARAM"];
ProcessRouteWorkCellModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
ProcessRouteWorkCell 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.ROUTE_CODE))
{
seachModel.ROUTE_CODE = routeCode;
}
condition = CopyToModel(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction>
("ProcessRouteBLL_GetProcessRouteWorkCellData", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return ProcessRouteWorkCellList(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;
}
}
///
/// 配置添加页面
///
///
public ActionResult ProcessRouteWorkCellEdit()
{
ProcessRouteWorkCellModel model = new ProcessRouteWorkCellModel();
model = GetModel();
model.ROUTE_CODE = Request.Params["ROUTE_CODE_PARAM"];
model.VER_NUM = Request.Params["ROUTE_VER_PARAM"];
try
{
#region 获取前置工序下拉列表
model.workCellSeqModel.Editable = true;
//获取前置工序下拉列表
model.workCellSeqModel.ComboBoxList = new Dictionary>();
Dictionary workCells = this.GetWorkCellComboBoxList(model.ROUTE_CODE);
model.workCellSeqModel.ComboBoxList.Add("PRE_WORKCELL_CODE", workCells);
#endregion
return View("ProcessRouteWorkCellEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取明细数据
///
///
[HandleException]
public ActionResult GetDetailList()
{
DataGridResult result = new DataGridResult();
result.Total = 0;
result.Rows = SessionHelper.GetSession("ProcessRouteWorkCell_Detail") as List;
SessionHelper.SessionDispose("ProcessRouteWorkCell_Detail");
if (result.Rows == null)
result.Rows = new List();
return Content(result.GetJsonSource());
}
///
/// 保存工序配置
///
///
public ActionResult ProcessRouteWorkCellSave(ProcessRouteWorkCellModel saveModel, ProcessRouteWorkCellSeqModel saveInfo)
{
ProcessRouteWorkCell entity = null;
ProcessRouteWorkCellSeq info = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
entity = CopyToModel(saveModel);
entity.Details = JsonConvertHelper.DeserializeObject>(saveModel.DetailValue);
//工序顺序信息
info = CopyToModel(saveInfo);
if (string.IsNullOrEmpty(entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction>
("ProcessRouteBLL_ProcessRouteWorkCellSave", entity);
}
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("ProcessRouteWorkCellEdit", saveModel);
}
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
}
catch (Exception)
{
throw;
}
}
///
/// 删除
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult ProcessRouteWorkCellDelete(ProcessRouteWorkCellModel saveMode)
{
string selectKey = Request.Form["selectKey"];
string ROUTE_CODE = Request.Form["ROUTE_CODE_PARAM"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_ProcessRouteWorkCellDelete", selectKey, ROUTE_CODE);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return ProcessRouteWorkCellList(true);
}
SetMessage(AppResource.DeleteMessage);
return ProcessRouteWorkCellList(true);
}
catch (Exception ex)
{
throw ex;
}
}
#region 获取当前工艺路线下的工序下拉列表
///
/// 获取当前工艺路线下的工序下拉列表
///
/// 数据源
[HandleException]
public ActionResult GetProcessComboxSource()
{
List list = new List();
ServiceAgent wcfAgent = this.GetServiceAgent();
string routeCode = Request.Params["ROUTE_CODE_PARAM"];
try
{
var dataResult = wcfAgent.InvokeServiceFunction>>
("ProcessRouteBLL_GeProcessRouteWorkCellList", new ProcessRouteWorkCell() { ROUTE_CODE = routeCode });
foreach (ProcessRouteWorkCell item in dataResult.Result)
{
list.Add(item);
}
list.Insert(0, new ProcessRouteWorkCell { WORKCELL_CODE = "", WORKCELL_NAME = " " });
return Content(QMFrameWork.Common.Serialization.JsonConvertHelper.GetSerializes(list));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
#region 获取当前工艺路线下的工序下拉列表
///
/// 获取工序下拉列表
///
/// 工艺路线编码
///
public Dictionary GetWorkCellComboBoxList(string routeCode)
{
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
//获取工序型下拉列表
Dictionary listWorkCell = new Dictionary();
DataResult> result = agent.InvokeServiceFunction>>("ProcessRouteBLL_GeProcessRouteWorkCellList", new ProcessRouteWorkCell() { ROUTE_CODE = routeCode });
listWorkCell.Add(this.EmptyItemTitle, this.EmptyItemTitle);
foreach (ProcessRouteWorkCell item in result.Result)
{
listWorkCell.Add(item.WORKCELL_CODE, item.WORKCELL_CODE + "/" + item.WORKCELL_NAME);
}
return listWorkCell;
}
#endregion
}
}