using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using QMFrameWork.WebUI.Attribute; using QMAPP.Common.Web.Controllers; using QMAPP.FJC.Web.Models.FIS; using QMFrameWork.Data; using QMAPP.ServicesAgent; using QMAPP.Entity; using QMAPP.FJC.Entity.FIS; using QMFrameWork.WebUI.DataSource; using QMFrameWork.Common.Serialization; using System.Data; using QMAPP.Common.Web.Models; using QMAPP.FJC.Entity.Basic; using QMAPP.MD.Entity; using QMAPP.FJC.BLL.FIS; namespace QMAPP.FJC.Web.Controllers { /// /// 模块名称:仪表板计划 /// 作 者:郭兆福 /// 创建时间:2017年09月15日 /// public class DashBoardPlanController : QController { #region 获取信息 /// /// 加载列表 /// /// 结果 [HandleException] public ActionResult List(bool? callback) { DashBoardPlanModel seachModel = new DashBoardPlanModel(); string order_type = Request["ORDER_TYPE"]; seachModel.PLANTIMESTART = DateTime.Now.Date.AddDays(-10).ToString("yyyy-MM-dd HH:mm:ss"); seachModel.PLANTIMEEND = DateTime.Now.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"); seachModel.ImmediateSearch = false; seachModel.ORDER_TYPE = order_type; if (callback == true) TryGetSelectBuffer(out seachModel); seachModel.rownumbers = false; seachModel.url = "/DashBoardPlan/GetList"; return View("DashBoardPlanList", seachModel); } #endregion #region 获取列表 /// /// 获取列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetList(bool? callBack) { DashBoardPlanModel seachModel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); OrderPlan 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); pageResult = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_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()); return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 编辑 /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult Edit() { DashBoardPlanModel model = new DashBoardPlanModel(); string ID = Request.QueryString["PID"]; string TYPE = Request.Params["ORDER_TYPE"]; OrderPlan Entity = new OrderPlan(); ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { if (string.IsNullOrEmpty(ID) == false) { //修改获取原数据 Entity.PID = ID; result = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_Get", Entity); if (result.IsSuccess == false) { SetMessage(result.Msg); return View("DashBoardPlanEdit", model); } model = CopyToModel(result.Result); } else { model.PLAN_DATE = DateTime.Now; } model.ORDER_TYPE = TYPE; return View("DashBoardPlanEdit", model); } catch (Exception ex) { throw ex; } } /// /// 保存 /// /// /// 处理结果 [HttpPost] [HandleException] [ValidateInput(false)] public ActionResult Save(DashBoardPlanModel saveModel) { OrderPlan Entity = null; string TYPE = Request.Form["ORDER_TYPE"]; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { Entity = CopyToModel(saveModel); if (string.IsNullOrEmpty(Entity.PID) == true) { //新增 result = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_Insert", Entity); if (result.IsSuccess == false) { SetMessage("计划单号已存在!"); return View("DashBoardPlanEdit", saveModel); } } else { //修改 result = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_Update", Entity); if (result.IsSuccess == false) { SetMessage(result.Msg ); return View("DashBoardPlanEdit", 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(OrderPlan model) { string selectKey = Request.Form["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { result = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_Delete", selectKey); if (result.IsSuccess == false) { SetMessage("存在完成数量数据,删除失败!"); return List(true); } SetMessage(AppResource.DeleteMessage); return List(true); } catch (Exception ex) { throw ex; } } #endregion #region 发布 /// /// 发布 /// /// [HttpPost] [HandleException] public ActionResult PutOut(OrderPlan model) { string selectKey = Request.Form["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); result = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_PutOut", selectKey); if (result.IsSuccess == false) { SetMessage(result.Msg); return List(true); } SetMessage(AppResource.PutOutMessage); return List(true); } #endregion #region 发布 /// /// 发布 /// /// [HttpPost] [HandleException] public ActionResult PutOutEndWorkCell(OrderPlan model) { string selectKey = Request.Form["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); result = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_PutOutEndWorkCell", selectKey); if (result.IsSuccess == false) { SetMessage(result.Msg); return List(true); } SetMessage(AppResource.PutOutMessage); return List(true); } #endregion #region 导出excel /// /// 导出excel /// /// 结果 [HttpPost] public ActionResult ExportExcel() { DashBoardPlanModel seachModel = null; OrderPlan condition = null; DataTable exportDt = new DataTable(); ServiceAgent wcfAgent = this.GetServiceAgent(); try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); condition.PIDList = Request.Form["selectKey"]; DashBoardPlanBLL db = new DashBoardPlanBLL(); exportDt = db.GetExportData(condition); //exportDt = wcfAgent.InvokeServiceFunction("DashBoardPlanBLL_GetExportData", condition); //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("DashBoardPlanExp", "仪表板计划信息.xlsx", exportDt); } catch (Exception ex) { throw ex; } } #endregion #region 导入excel /// /// 导入excel /// /// 结果 [HttpPost] public ActionResult ImportExcel() { DataTable dt = null; List list = new List(); DataResult serviceResult = null; string fileName = Request.Form["fileName"]; string orderby = Request.Form["ORDER_TYPE"]; ServiceAgent wcfAgent = this.GetServiceAgent(); Materiel materialmodel = new Materiel(); ProduceShift produceshiftmodel = new ProduceShift(); //初始工作中心编号条件 QMAPP.MD.Entity.WorkCell workcell=new QMAPP.MD.Entity.WorkCell(); workcell.WORKCELL_CODE = orderby; MachineInfo machine = new MachineInfo(); try { dt = this.GetTableByExcel("DashBoardPlanImp", fileName, dt); //格式转换 list = QMFrameWork.Common.Util.BindHelper.ConvertToList(dt).ToList(); serviceResult = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_GetImportData", list, materialmodel,machine, produceshiftmodel, workcell); if (serviceResult.Ex != null) { throw serviceResult.Ex; } if (serviceResult.Result.failureNum != 0) { foreach (RowError error in serviceResult.Result.Errors) { dt.Rows[error.Key - 1]["InfoError"] = error.Value; } ImportMessageModel model = new ImportMessageModel(); model.InfoName = "DashBoardPlanImp"; model.ReturnUrl = "/DashBoardPlan/List?callBack=true"; model.Message = serviceResult.Result; model.ErrorDt = dt; return new MessageOutputController().OutputImportMessage(model); } else { SetMessage(serviceResult.Msg + ",如下:
" + "插入" + serviceResult.Result.insertNum + "条," + "更新" + serviceResult.Result.updateNum + "条" ); return List(true); } } catch (Exception ex) { throw ex; } finally { System.IO.File.Delete(MvcApplication.TempPath + fileName); } } #endregion #region 下载模板 /// /// 下载导入模板 /// /// 结果 [HttpPost] public ActionResult GetTemplate() { try { string path = AppDomain.CurrentDomain.BaseDirectory + "App_Data/Excel/"; string fileName = "DashBoardPlanImp.xlsx"; return File(path + fileName, "application/vnd.ms-excel", Url.Encode("仪表板信息导入模板.xlsx")); } catch (Exception ex) { throw ex; } } #endregion #region 仪表板顺序号编辑 /// /// 仪表板顺序号编辑 /// /// public ActionResult DashBoardEditSeq() { DashBoardPlanModel model = new DashBoardPlanModel(); OrderPlan Entity = new OrderPlan(); ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); try { model = GetModel(); return View("DashBoardEditSeq", model); } catch (Exception ex) { throw ex; } } #endregion #region 获取编辑系列号列表 /// /// 获取编辑系列号列表 /// /// /// [HandleException] public ActionResult GetDashBoardPlanList(bool? callBack) { DashBoardPlanModel seachModel = null; DataResult pageResult = new DataResult(); DataPage page = new DataPage(); ServiceAgent wcfAgent = this.GetServiceAgent(); OrderPlan condition = new OrderPlan(); try { //获取查询对象 seachModel = GetModel(); condition.PIDList = seachModel.PIDList; condition.ORDER_TYPE = seachModel.ORDER_TYPE; #region 获取缓存值 if (callBack != null) { TryGetSelectBuffer(out seachModel); } else { //保存搜索条件 SetSelectBuffer(seachModel); } #endregion //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); #region wcf服务统一接口 pageResult = wcfAgent.InvokeServiceFunction>("DashBoardPlanBLL_GetDashBoardPlanList", 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 保存顺序号修改 /// /// /// /// /// 处理结果 [HttpPost] [HandleException] [ValidateInput(false)] public ActionResult DashBoardPlanSeqSave(DashBoardPlanModel saveModel) { OrderPlan entity = new OrderPlan(); ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); entity.PLAN_SEQ = saveModel.PLAN_SEQ; entity.PIDList = saveModel.PIDList; entity = CopyToModel(saveModel); //修改 result = wcfAgent.InvokeServiceFunction>("DoorPlankPlanBLL_UpdateDoorPlankPlanSeq", entity); return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge)); } #endregion } }