天津投入产出系统后端
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.

361 lines
13 KiB

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 QMAPP.FJC.Entity.Basic;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMAPP.ServicesAgent;
using QMAPP.Entity;
using QMAPP.MD.Entity;
using QMAPP.MD.Web.Models;
using QMFrameWork.WebUI.Util;
using QMFrameWork.Data;
namespace QMAPP.FJC.Web.Controllers
{
public class WorkCenterController : QController
{
#region 获取列表
/// <summary>
/// 加载列表
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult List(bool? callBack)
{
WorkCenterModel seachModel = new WorkCenterModel();
if (callBack == true)
TryGetSelectBuffer<WorkCenterModel>(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/WorkCenter/GetList";
return View("WorkCenterList", seachModel);
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>列表</returns>
[HandleException]
public ActionResult GetList(bool? callBack)
{
WorkCenterModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
WorkCenter condition = null;
DataResult<DataPage> pageResult = new DataResult<DataPage>();
try
{
//获取查询对象
seachModel = GetModel<WorkCenterModel>();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer<WorkCenterModel>(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer<WorkCenterModel>(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<WorkCenter, WorkCenterModel>(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction<DataResult<DataPage>>("WorkCenterBLL_GetList", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return List(true);
}
DateGridResult<WorkCenter> result = new DateGridResult<WorkCenter>();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize<List<WorkCenter>>(pageResult.Result.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑
/// <summary>
/// 添加载入
/// </summary>
/// <returns>处理结果</returns>
//[HandleException]
//public ActionResult Add()
//{
// WorkCenterModel model = new WorkCenterModel();
// try
// {
// return View("WorkCenterEdit", model);
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
/// <summary>
/// 编辑载入
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult Edit()
{
WorkCenterModel model = new WorkCenterModel();
string ID = Request.Params["PID"];
WorkCenter Entity = new WorkCenter();
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<WorkCenter> result = new DataResult<WorkCenter>();
try
{
if (string.IsNullOrEmpty(ID) == false)
{
//修改获取原数据
Entity.PID = ID;
result = wcfAgent.InvokeServiceFunction<DataResult<WorkCenter>>("WorkCenterBLL_Get", Entity);
//QMFrameWork.WebUI.Util.SessionHelper.SetSession("Equipment_Detail", Entity.Details);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("WorkCenterEdit", model);
}
model = CopyToModel<WorkCenterModel, WorkCenter>(result.Result);
}
return View("WorkCenterEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取明细数据
/// </summary>
/// <returns></returns>
//[HandleException]
//public ActionResult GetDetailList()
//{
// DataGridResult<MachineInfo> result = new DataGridResult<MachineInfo>();
// result.Total = 0;
// result.Rows = SessionHelper.GetSession("Equipment_Detail") as List<MachineInfo>;
// SessionHelper.SessionDispose("Equipment_Detail");
// if (result.Rows == null)
// result.Rows = new List<MachineInfo>();
// return Content(result.GetJsonSource());
//}
/// <summary>
/// 保存
/// </summary>
/// <param name="model"></param>
/// <returns>处理结果</returns>
[HttpPost]
[HandleException]
public ActionResult Save(WorkCenterModel saveModel)
{
WorkCenter Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
Entity = CopyToModel<WorkCenter, WorkCenterModel>(saveModel);
//Entity.Details = JsonConvertHelper.DeserializeObject<List<Equipment>>(saveModel.DetailValue);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("WorkCenterBLL_Insert", Entity);
if (result.IsSuccess == false)
{
SetMessage("编号已存在,请换一个!");
return View("WorkCenterEdit", saveModel);
}
}
else
{
//修改
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("WorkCenterBLL_Update", Entity);
if (result.IsSuccess == false)
{
SetMessage("编号已存在,请换一个!");
return View("WorkCenterEdit", 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(WorkCenter model)
{
string selectKey = Request.Form["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("WorkCenterBLL_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 编辑
/// <summary>
/// 编辑载入
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult SetMachine()
{
WorkCenterModel model = new WorkCenterModel();
string pid = Request.Params["PID"];
WorkCenter workequipment = new WorkCenter();
DataResult<WorkCenter> result = new DataResult<WorkCenter>();
try
{
if (string.IsNullOrEmpty(pid) == false)
{
//修改获取原数据
workequipment.PID = pid;
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
result = agent.InvokeServiceFunction<DataResult<WorkCenter>>("WorkCenterBLL_Get", workequipment);
model = CopyToModel<WorkCenterModel, WorkCenter>(result.Result);
model.isEdit = "true";
}
return View("SetMachine", model);
}
catch (Exception ex)
{
throw ex;
}
}
#region 工作中心与设备信息树
/// <summary>
/// 工作中心与设备信息树
/// </summary>
/// <returns>处理结果</returns>
public ActionResult GetTreeWcWithEquipment()
{
List<TreeNodeResult> list = new List<TreeNodeResult>();
//选择的工作中心编号
string pid = Request.QueryString["PID"];
try
{
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
//获取工作中心与设备关联信息
List<WcWithEquipment> wmList = agent.InvokeServiceFunction<List<WcWithEquipment>>("WorkCenterBLL_GetWcWithEquipmentList", new WcWithEquipment { WORKCENTERPID = pid });
//获取设备信息
DataResult<List<MachineInfo>> aResult = agent.InvokeServiceFunction<DataResult<List<MachineInfo>>>("EquipmentBLL_GetEquipmentList", new MachineInfo());
List<MachineInfo> mList = aResult.Result.OrderBy(o => o.MACHINECODDE).ToList();
foreach (MachineInfo item in mList)
{
TreeNodeResult node = new TreeNodeResult();
node.Tid = item.PID;
node.Ttext = item.MACHINECODDE + "/" + item.MACHINENAME;
var IsExsit = wmList.Where(o => o.EQUIPMENTPID == item.PID).ToList();
if (IsExsit.Count > 0)
{
node.TChecked = true;
}
else
{
node.TChecked = false;
}
list.Add(node);
}
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存
/// <summary>
/// 保存
/// </summary>
/// <param name="model"></param>
/// <returns>处理结果</returns>
[HttpPost]
[HandleException]
public ActionResult DataPowerSave(WorkCenterModel saveModel)
{
WorkCenter workcenter = null;
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
try
{
workcenter = CopyToModel<WorkCenter, WorkCenterModel>(saveModel);
//处理所选设备
string[] equipments = null;
if (saveModel.SelectedEquipment != null)
{
equipments = saveModel.SelectedEquipment.Split(":".ToArray());
workcenter.EQUIPMENT = new List<WcWithEquipment>();
foreach (string equipment in equipments)
{
workcenter.EQUIPMENT.Add(new WcWithEquipment
{
PID = Guid.NewGuid().ToString(),
WORKCENTERPID = workcenter.PID,
EQUIPMENTPID = equipment
});
}
}
//保存
agent.InvokeServiceFunction<int>("WorkCenterBLL_DataPowerSave", workcenter);
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();"
, AppResource.SaveMessge));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
}
}