using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using QMAPP.FJC.Entity.Basic; using QMFrameWork.WebUI.DataSource; using QMAPP.ServicesAgent; using QMAPP.Common.Web.Controllers; using QMFrameWork.WebUI.Attribute; using QMAPP.FJC.Entity.Operation; using QMAPP.FJC.Web.Models.ProductPetrospect; using QMAPP.FJC.Entity; using QMAPP.Entity; using QMFrameWork.Data; using QMFrameWork.Common.Serialization; using System.Data; using QMFrameWork.WebUI; using QMAPP.FJC.BLL.Operation; using QMFrameWork.Common.ExcelOperation; namespace QMAPP.FJC.Web.Controllers { /// /// 模块编号: /// 作 用:设备加工记录控制层 /// 作 者:王丹丹 /// 编写日期:2015年06月30日 /// public class MainOperationController : QController { #region 获取列表 /// /// 加载列表 /// /// 结果 [HandleException] public ActionResult List(bool? callBack) { MainOperationModel seachModel = new MainOperationModel(); //seachModel.PROCESSTYPE = Request.Params["PROCESSTYPE"]; seachModel.WORKCELL_CODE = Request.Params["WORKCELL_CODE"]; //初始状态当工序类别为空,且日期条件为空 if (callBack==null) { seachModel.CREATEDATESTART = DateTime.Now.Date.AddDays(-3).ToString("yyyy-MM-dd HH:mm:ss"); seachModel.CREATEDATEEND = DateTime.Now.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"); } seachModel.ImmediateSearch = false; if (callBack == true) TryGetSelectBuffer(out seachModel); if (callBack == null || callBack == false) { //seachModel.PROCESSTYPE = Request.Params["PROCESSTYPE"]; seachModel.WORKCELL_CODE = Request.Params["WORKCELL_CODE"]; if (!string.IsNullOrEmpty(seachModel.WORKCELL_CODE) || callBack == false) //if (!string.IsNullOrEmpty(seachModel.PROCESSTYPE) || callBack == false) { seachModel.PRODUCTCODETXT = Request.Params["PRODUCTCODETXT"]; seachModel.PRODUCESHIFTTCODE = Request.Params["PRODUCESHIFTTCODE"]; seachModel.MACHINECODDE = Request.Params["MACHINECODDE"]; seachModel.STATUS = Request.Params["STATUS"]; seachModel.MATERIAL_TYPE_CODE = Request.Params["STATUS"]; seachModel.MATERIAL_CODE = Request.Params["MATERIAL_CODE"]; seachModel.WORKCENTER_CODE = Request.Params["WORKCENTER_CODE"]; seachModel.ROUTE_CODE = Request.Params["ROUTE_CODE"]; seachModel.WORKCELL_CODE = Request.Params["WORKCELL_CODE"]; seachModel.CREATEDATESTART = Request.Params["CREATEDATESTART"]; seachModel.CREATEDATESTART = Request.Params["CREATEDATESTART"]; seachModel.CREATEDATEEND = Request.Params["CREATEDATEEND"]; } List list = GetShowTitleList(seachModel); list = list.OrderBy(o => o.SHOWINDEX).ToList(); seachModel.url = "/MainOperation/GetList"; seachModel.checkbox = false; seachModel.ColumnList = new List(); foreach (var para in list) { DGColumn dg = new DGColumn { ColumnName = para.PARANAME, ColumnTitle = para.PARADESCRIBE, Width = Convert.ToInt32(para.WIDTH), Sortable = true, DataAlign = (para.ALIGNVALUE == "2") ? QMFrameWork.WebUI.DataAlign.center : ((para.ALIGNVALUE == "0") ? QMFrameWork.WebUI.DataAlign.left : QMFrameWork.WebUI.DataAlign.right) }; seachModel.ColumnList.Add(dg); } } return View("MainOperationList", seachModel); } /// /// 获取列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetList(bool? callBack) { DataResult dataResult = new DataResult(); MainOperationModel seachModel = null; MainOperationModel defaultModel = new MainOperationModel(); MainOperation condition = null; DataPage page = new DataPage(); ServiceAgent wcfAgent = this.GetServiceAgent(); string strRusult = ""; string resultJson = ""; try { #region 获取缓存值 TryGetSelectBuffer(out defaultModel); #endregion //获取查询对象 seachModel = GetModel(); seachModel.WORKCELL_CODE = defaultModel.WORKCELL_CODE; //获取默认前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); if (!string.IsNullOrEmpty(condition.WORKCELL_CODE)) //if (!string.IsNullOrEmpty(condition.PROCESSTYPE)) { List list = GetShowTitleList(seachModel); list = list.OrderBy(o => o.SHOWINDEX).ToList(); seachModel.ColumnList = new List(); foreach (var para in list) { DGColumn dg = new DGColumn { ColumnName = para.PARANAME, ColumnTitle = para.PARADESCRIBE, Width = Convert.ToInt32(para.WIDTH), Sortable = true, DataAlign = (para.ALIGNVALUE == "2") ? QMFrameWork.WebUI.DataAlign.center : ((para.ALIGNVALUE == "0") ? QMFrameWork.WebUI.DataAlign.left : QMFrameWork.WebUI.DataAlign.right) }; seachModel.ColumnList.Add(dg); } } #region wcf服务统一接口 dataResult = wcfAgent.InvokeServiceFunction>("MainOperationBLL_GetListWithParameterForWeb", new MainOperation { //产品条码 PRODUCTCODE = seachModel.PRODUCTCODETXT, //班次信息 PRODUCESHIFTTCODE = seachModel.PRODUCESHIFTTCODE, //设备编码 MACHINECODDE = seachModel.MACHINECODDE, //产品状态 STATUS = seachModel.STATUS, //物料类别 MATERIAL_TYPE_CODE = seachModel.MATERIAL_TYPE_CODE, //物料号 MATERIAL_CODE = seachModel.MATERIAL_CODE, //工作中心 WORKCENTER_CODE = seachModel.WORKCENTER_CODE, //工艺路线 ROUTE_CODE = seachModel.ROUTE_CODE, //工序 WORKCELL_CODE=seachModel.WORKCELL_CODE, //操作时间 起始 DATEOPESTART = string.IsNullOrEmpty(seachModel.CREATEDATESTART) ? DateTime.MinValue : Convert.ToDateTime(seachModel.CREATEDATESTART), //操作时间 结束 DATEOPEEND = string.IsNullOrEmpty(seachModel.CREATEDATEEND) ? DateTime.MinValue : Convert.ToDateTime(seachModel.CREATEDATEEND), }, page); #endregion if (dataResult.IsSuccess == false) { SetMessage(dataResult.Msg); resultJson = "{\"total\":\"" + dataResult.Result.RecordCount + "\",\"rows\":[]}"; } else { strRusult = dataResult.Result.Result.ToString(); resultJson = "{\"total\":\"" + dataResult.Result.RecordCount + "\",\"rows\":" + strRusult + "}"; } return Content(resultJson); } catch (Exception ex) { throw ex; } } #endregion #region 获取设备编号下拉列表 /// /// 获取设备编号下拉列表 /// /// public ContentResult GetMachineInfoComboxSource() { List listMachineInfo = new List(); ComboboxResult model = new ComboboxResult(); ServiceAgent wcfAgent = this.GetServiceAgent(); MachineInfo entity = new MachineInfo(); try { //获取设备信息 listMachineInfo = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.FeedInManage.InjectionRecorderBLL_GetMachineInfoList.ToString(), entity); foreach (var item in listMachineInfo) { if (model.Items.Count == 0) { model.Add(new ComboboxItem { ID = "", Text = new DictController().EmptyItemTitle }); model.Add(new ComboboxItem { ID = item.MACHINECODDE, Text = item.MACHINECODDE }); } else { model.Add(new ComboboxItem { ID = item.MACHINECODDE, Text = item.MACHINECODDE }); } } return Content(model.ToString()); } catch (Exception ex) { throw ex; } } #endregion #region 获取班次编号下拉列表 /// /// 获取班次编号下拉列表 /// /// public ContentResult GetProductShiftComboxSource() { List listProductShiftInfo = new List(); ComboboxResult model = new ComboboxResult(); ServiceAgent wcfAgent = this.GetServiceAgent(); ProduceShift entity = new ProduceShift(); try { //获取班次信息 listProductShiftInfo = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.FeedInManage.InjectionRecorderBLL_GetProduceShiftList.ToString(), entity); foreach (var item in listProductShiftInfo) { if (model.Items.Count == 0) { model.Add(new ComboboxItem { ID = "", Text = new DictController().EmptyItemTitle }); model.Add(new ComboboxItem { ID = item.PRODUCESHIFTTCODE, Text = item.PRODUCESHIFTTCODE }); } else { model.Add(new ComboboxItem { ID = item.PRODUCESHIFTTCODE, Text = item.PRODUCESHIFTTCODE }); } } return Content(model.ToString()); } catch (Exception ex) { throw ex; } } #endregion #region 获取列头 /// /// 获取列表 /// /// 是否回调 /// 列表 [HandleException] public DataTable GetListTitle(MainOperationModel seachModel) { DataResult dataResult = new DataResult(); MainOperation condition = null; DataPage page = new DataPage(); ServiceAgent wcfAgent = this.GetServiceAgent(); try { //保存搜索条件 SetSelectBuffer(seachModel); condition = CopyToModel(seachModel); #region wcf服务统一接口 dataResult = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.B9BasicService.MainOperationBLL_GetListWithParameterForWebTitle.ToString(), new MainOperation { WORKCELL_CODE=seachModel.WORKCELL_CODE, }); #endregion if (dataResult.IsSuccess == false) { SetMessage(dataResult.Msg); return new DataTable(); } return dataResult.Result; } catch (Exception ex) { throw ex; } } /// /// web显示列头字段 /// /// /// public List GetShowTitleList(MainOperationModel seachModel) { List titlesList = new List(); MainOperation condition = null; DataPage page = new DataPage(); ServiceAgent wcfAgent = this.GetServiceAgent(); try { //保存搜索条件 SetSelectBuffer(seachModel); condition = CopyToModel(seachModel); #region wcf服务统一接口 titlesList = wcfAgent.InvokeServiceFunction>("MainOperationBLL_GetParameterForWebTitle", new MainOperation { WORKCELL_CODE = seachModel.WORKCELL_CODE, }); #endregion return titlesList; } catch (Exception ex) { throw ex; } } #endregion #region 导出excel /// /// 导出excel /// /// 结果 [HandleException] public ActionResult ExportExcel() { MainOperationModel seachModel = null; MainOperation condition = null; DataTable exportDt = new DataTable(); string selectKey = Request["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); condition.PID = Request.Form["selectKey"]; //condition.TableName = "EpidermisExp"; string processTypeStr = seachModel.PROCESSTYPE; string excelName = ""; switch (processTypeStr) { case "0": excelName = "SlushExp"; break; case "6": excelName = "SkinCutExp"; break; case "7": excelName = "FlameExp"; break; case "9": excelName = "CastExp"; break; case "11": excelName = "PunchExp"; break; case "12": excelName = "MillingExp"; break; case "13": excelName = "MaoJieExp"; break; case "14": excelName = "UltraExp"; break; case "15": excelName = "WeldExp"; break; case "16": excelName = "ZczpExp"; break; default : excelName = "InjectionExp"; break; } //获取数据 // var dataResult = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.FeedInManage.EpidermisBLL_GetExportData.ToString(), condition); MainOperationBLL bll = new MainOperationBLL(); var dataResult = bll.GetExportData(new MainOperation { PROCESSTYPE = seachModel.PROCESSTYPE, PROCESSTYPES = seachModel.PROCESSTYPES, //PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString(), MACHINECODDE = seachModel.MACHINECODDE, PRODUCESHIFTTCODE = seachModel.PRODUCESHIFTTCODE, PRODUCTCODE = seachModel.PRODUCTCODETXT, DATEOPESTART = string.IsNullOrEmpty(seachModel.CREATEDATESTART) ? DateTime.MinValue : Convert.ToDateTime(seachModel.CREATEDATESTART), DATEOPEEND = string.IsNullOrEmpty(seachModel.CREATEDATEEND) ? DateTime.MinValue : Convert.ToDateTime(seachModel.CREATEDATEEND), STATUS = seachModel.STATUS, }); //通过返回dataResult判断 if (dataResult.Ex != null) { throw dataResult.Ex; } else if (dataResult.IsSuccess) { exportDt = dataResult.Result; } else { SetMessage(dataResult.Msg); return List(true); } //导出 IEExcelHelper ieExcelHelper = new IEExcelHelper(); var sheetInfo = ieExcelHelper.GetMainInfo(excelName); var fileName = System.Guid.NewGuid().ToString() + ".xlsx"; ieExcelHelper.ExportExcel(sheetInfo, exportDt, QMAPP.Web.Common.ExcelOperationHelper.GetTempPath() + fileName, true); return Content(fileName); } catch (Exception ex) { SetMessage("导出excel失败"); return List(true); } } /// /// 导出文件 /// /// public ActionResult ExportFile() { String filePath = QMAPP.Web.Common.ExcelOperationHelper.GetTempPath(); String fileName = Request["FileName"]; String processType = Request["PROCESSTYPE"]; string excelName = ""; switch (processType) { case "0": excelName = "搪塑设备加工记录查询.xlsx"; break; case "6": excelName = "冷刀设备加工记录查询.xlsx"; break; case "7": excelName = "火焰加工设备加工记录查询.xlsx"; break; case "9": excelName = "浇注设备加工记录查询.xlsx"; break; case "11": excelName = "冲切设备加工记录查询.xlsx"; break; case "12": excelName = "铣削装配加工记录查询.xlsx"; break; case "13": excelName = "铆接设备加工记录查询.xlsx"; break; case "14": excelName = "超声波焊接设备加工记录查询.xlsx"; break; case "15": excelName = "红外焊接设备加工记录查询.xlsx"; break; case "16": excelName = "总成装配加工记录查询.xlsx"; break; default: excelName = "注塑设备加工记录查询.xlsx"; break; } QMAPP.Web.Common.ExcelOperationHelper.FileDownload(Response, filePath + fileName, excelName); return Content(""); } #endregion } }