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 获取列表 /// /// 加载列表 /// /// 结果 [HandleException] public ActionResult List(bool? callBack) { WorkCenterModel seachModel = new WorkCenterModel(); if (callBack == true) TryGetSelectBuffer(out seachModel); seachModel.rownumbers = false; seachModel.url = "/WorkCenter/GetList"; return View("WorkCenterList", seachModel); } /// /// 获取列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetList(bool? callBack) { WorkCenterModel seachModel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); WorkCenter 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>("WorkCenterBLL_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 Add() //{ // WorkCenterModel model = new WorkCenterModel(); // try // { // return View("WorkCenterEdit", model); // } // catch (Exception ex) // { // throw ex; // } //} /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult Edit() { WorkCenterModel model = new WorkCenterModel(); string ID = Request.Params["PID"]; WorkCenter Entity = new WorkCenter(); ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { if (string.IsNullOrEmpty(ID) == false) { //修改获取原数据 Entity.PID = ID; result = wcfAgent.InvokeServiceFunction>("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(result.Result); } return View("WorkCenterEdit", model); } catch (Exception ex) { throw ex; } } /// /// 获取明细数据 /// /// //[HandleException] //public ActionResult GetDetailList() //{ // DataGridResult result = new DataGridResult(); // result.Total = 0; // result.Rows = SessionHelper.GetSession("Equipment_Detail") as List; // SessionHelper.SessionDispose("Equipment_Detail"); // if (result.Rows == null) // result.Rows = new List(); // return Content(result.GetJsonSource()); //} /// /// 保存 /// /// /// 处理结果 [HttpPost] [HandleException] public ActionResult Save(WorkCenterModel saveModel) { WorkCenter Entity = null; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { Entity = CopyToModel(saveModel); //Entity.Details = JsonConvertHelper.DeserializeObject>(saveModel.DetailValue); if (string.IsNullOrEmpty(Entity.PID) == true) { //新增 result = wcfAgent.InvokeServiceFunction>("WorkCenterBLL_Insert", Entity); if (result.IsSuccess == false) { SetMessage("编号已存在,请换一个!"); return View("WorkCenterEdit", saveModel); } } else { //修改 result = wcfAgent.InvokeServiceFunction>("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 删除 /// /// 删除 /// /// 结果 [HttpPost] [HandleException] public ActionResult Delete(WorkCenter model) { string selectKey = Request.Form["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { result = wcfAgent.InvokeServiceFunction>("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 编辑 /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult SetMachine() { WorkCenterModel model = new WorkCenterModel(); string pid = Request.Params["PID"]; WorkCenter workequipment = new WorkCenter(); DataResult result = new DataResult(); try { if (string.IsNullOrEmpty(pid) == false) { //修改获取原数据 workequipment.PID = pid; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); result = agent.InvokeServiceFunction>("WorkCenterBLL_Get", workequipment); model = CopyToModel(result.Result); model.isEdit = "true"; } return View("SetMachine", model); } catch (Exception ex) { throw ex; } } #region 工作中心与设备信息树 /// /// 工作中心与设备信息树 /// /// 处理结果 public ActionResult GetTreeWcWithEquipment() { List list = new List(); //选择的工作中心编号 string pid = Request.QueryString["PID"]; try { QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); //获取工作中心与设备关联信息 List wmList = agent.InvokeServiceFunction>("WorkCenterBLL_GetWcWithEquipmentList", new WcWithEquipment { WORKCENTERPID = pid }); //获取设备信息 DataResult> aResult = agent.InvokeServiceFunction>>("EquipmentBLL_GetEquipmentList", new MachineInfo()); List 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 保存 /// /// 保存 /// /// /// 处理结果 [HttpPost] [HandleException] public ActionResult DataPowerSave(WorkCenterModel saveModel) { WorkCenter workcenter = null; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); try { workcenter = CopyToModel(saveModel); //处理所选设备 string[] equipments = null; if (saveModel.SelectedEquipment != null) { equipments = saveModel.SelectedEquipment.Split(":".ToArray()); workcenter.EQUIPMENT = new List(); foreach (string equipment in equipments) { workcenter.EQUIPMENT.Add(new WcWithEquipment { PID = Guid.NewGuid().ToString(), WORKCENTERPID = workcenter.PID, EQUIPMENTPID = equipment }); } } //保存 agent.InvokeServiceFunction("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 } }