using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMFrameWork.WebUI.Attribute;
using QMAPP.FJC.Web.Models.Basic;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Basic;
using QMAPP.ServicesAgent;
using QMAPP.Entity;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMFrameWork.WebUI.Util;
namespace QMAPP.FJC.Web.Controllers
{
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 ROUTE_PID = Request.Params["ROUTE_PID"];
if (callBack == true)
TryGetSelectBuffer(out processRouteModel);
processRouteModel.rownumbers = false;
processRouteModel.url = "/ProcessRoute/GetProcessRouteWorkCellList?ROUTE_PID=" + ROUTE_PID;
processRouteModel.ROUTE_PID = ROUTE_PID;
return View("ProcessRouteWorkCellList", processRouteModel);
}
///
/// 获取列表
///
///
///
public ActionResult GetProcessRouteWorkCellList(bool? callBack)
{
string ROUTE_PID = Request.Params["ROUTE_PID"];
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);
condition = CopyToModel(seachModel);
if (string.IsNullOrEmpty(ROUTE_PID))
{
condition.ROUTE_PID = ROUTE_PID;
}
#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_PID = Request.Params["ROUTE_PID"];
try
{
#region 获取前置工序下拉列表
model.workCellSeqModel.Editable = true;
//获取前置工序下拉列表
model.workCellSeqModel.ComboBoxList = new Dictionary>();
Dictionary workCells = this.GetWorkCellComboBoxList();
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();
string ROUTE_PID = Request.Params["ROUTE_PID"];
string WORKCELL_PID = Request.Params["WORKCELL_PID"];
try
{
entity = CopyToModel(saveModel);
entity.Details = JsonConvertHelper.DeserializeObject>(saveModel.DetailValue);
//工序顺序信息
//info = CopyToModel(saveInfo);
//工艺路线主键
if (string.IsNullOrEmpty(ROUTE_PID))
{
entity.ROUTE_PID = ROUTE_PID;
}
//前一工序主键
//if (string.IsNullOrEmpty(WORKCELL_PID))
//{
// info.PRE_PRW_PID = WORKCELL_PID;
//}
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_PID = Request.Form["ROUTE_PID"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("ProcessRouteBLL_ProcessRouteWorkCellDelete", selectKey, ROUTE_PID);
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 ROUTE_PID = Request.Params["ROUTE_PID"];
try
{
var dataResult = wcfAgent.InvokeServiceFunction>>
("ProcessRouteBLL_GeProcessRouteWorkCellList", new ProcessRouteWorkCell() { ROUTE_PID = ROUTE_PID });
foreach (ProcessRouteWorkCell item in dataResult.Result)
{
list.Add(item);
}
list.Insert(0, new ProcessRouteWorkCell { WORKCELL_PID = "", WORKCELL_NAME = " " });
return Content(QMFrameWork.Common.Serialization.JsonConvertHelper.GetSerializes(list));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
#region 获取工序下拉列表
///
/// 获取工序下拉列表
///
///
public Dictionary GetWorkCellComboBoxList()
{
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
//获取零件类型下拉列表
Dictionary listWorkCell = new Dictionary();
List list = agent.InvokeServiceFunction>("ProcessInfoBLL_GetProcessInfoList", new QMAPP.FJC.Entity.Basic.ProcessInfo());
listWorkCell.Add(this.EmptyItemTitle, this.EmptyItemTitle);
foreach (QMAPP.FJC.Entity.Basic.ProcessInfo item in list)
{
listWorkCell.Add(item.PID, item.PROCESSNAME);
}
return listWorkCell;
}
#endregion
}
}