using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using QMAPP.Common.Web.Controllers; using QMFrameWork.WebUI.Attribute; using QMAPP.FJC.Web.Models.ProduceManage; using QMFrameWork.Data; using QMAPP.ServicesAgent; using QMAPP.KB.Entity; using QMAPP.FJC.Entity.ProduceManage; using QMFrameWork.Common.Serialization; using QMFrameWork.WebUI.DataSource; using System.Data; using QMFrameWork.Log; using QMAPP.FJC.BLL.ProduceManage; namespace QMAPP.FJC.Web.Controllers { /// /// 模块编号:M9-13 /// 作 用:不合格品记录查询 /// 作 者:王济 /// 编写日期:2015年07月010日 /// public class MendRecorderController : QController { #region 获取列表 [HandleException] public ActionResult List(bool? callBack) { MendRecorderModel searchmodel = new MendRecorderModel(); searchmodel.CREATEDATESTART = DateTime.Now.AddDays(-10).ToString("yyyy-MM-dd HH:mm:ss"); searchmodel.CREATEDATEEND = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"); searchmodel.ImmediateSearch = false; if (callBack == true) TryGetSelectBuffer(out searchmodel); searchmodel.rownumbers = true; searchmodel.url = "/MendRecorder/GetList"; return View("MendRecorderList", searchmodel); } /// /// 获取列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetList(bool? callBack) { MendRecorderModel searchmodel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); MendRecorder condition = null; DataResult pageResult = new DataResult(); DateGridResult result = new DateGridResult(); try { searchmodel = GetModel(); //如果类型为空,不执行查询。 if (string.IsNullOrEmpty(searchmodel.MENDRESULT)) { //return Content(result.GetJsonSource()); // return List(true); } if (callBack != null) { TryGetSelectBuffer(out searchmodel); } else { //保存搜索条件 SetSelectBuffer(searchmodel); } page = this.GetDataPage(searchmodel); condition = CopyToModel(searchmodel); //condition.MENDRESULT = "0"; #region wcf服务统一接口 pageResult = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.B9IPCService.MendRecorderBLL_GetLists.ToString(), condition, page); 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 导出excel不合格 /// /// 导出excel /// /// 结果 [HttpPost] public ActionResult ExportExcelMend() { MendRecorderModel seachModel = null; MendRecorder condition = null; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); string selectKey = Request.Form["selectKey"]; string[] list = selectKey.Split(":".ToCharArray()); try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); //condition.MENDRESULT = null; //获取数据 result = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.B9IPCService.MendRecorderBLL_GetExportData.ToString(), condition); //根据所选信息进行导出 if (!String.IsNullOrEmpty(selectKey)) { DataView dv = new DataView(result.Result); string strWhere = ""; //string[] list = selectKey.Split(":".ToCharArray()); foreach (string ID in list) { strWhere += " PID='" + ID + "' or"; } if (strWhere != "") { strWhere = strWhere.Remove((strWhere.Length - 2), 2); } dv.RowFilter = strWhere; result.Result = dv.ToTable(); } //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("MendRecorderExp", "不合格品处理单.xlsx", result.Result); } catch (Exception ex) { throw ex; } } #endregion #region 导出excel报废 /// /// 导出excel /// /// 结果 [HttpPost] public ActionResult ExportExcelScrap() { MendRecorderModel seachModel = null; MendRecorder condition = null; ServiceAgent wcfAgent = this.GetServiceAgent(); DataResult result = new DataResult(); string selectKey = Request.Form["selectKey"]; try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); condition.MENDRESULT = "2"; condition.PIDS = selectKey; //获取数据 result = wcfAgent.InvokeServiceFunction>("MendRecorderBLL_GetExportDataScrap", condition); //根据所选信息进行导出 //if (!String.IsNullOrEmpty(selectKey)) //{ // DataView dv = new DataView(result.Result); // string strWhere = ""; // string[] list = selectKey.Split(":".ToCharArray()); // foreach (string ID in list) // { // strWhere += " PID='" + ID + "' or"; // } // if (strWhere != "") // { // strWhere = strWhere.Remove((strWhere.Length - 2), 2); // } // dv.RowFilter = strWhere; // result.Result = dv.ToTable(); //} //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("ScrapRecordExp", "材料报废单.xlsx", result.Result); } catch (Exception ex) { throw ex; } } #endregion #region 导出excel /// /// 导出excel /// /// 结果 [HandleException] public ActionResult ExportExcel() { MendRecorderModel seachModel = null; MendRecorder condition = null; DataTable exportDt = new DataTable(); ServiceAgent wcfAgent = this.GetServiceAgent(); try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); condition.TableName = "MendRecorderAllExp"; condition.PIDList = Request.Form["selectKey"]; //获取数据 MendRecorderBLL bll = new MendRecorderBLL(); exportDt = bll.GetCheckStatic(condition); //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("MendRecorderAllExp", "不合格品记录查询.xlsx", exportDt); } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo { ErrorInfo = ex, Info = "导出excel", Tag = "不合格品记录查询" }); this.SetMessage("导出excel失败"); return this.List(true); } } #endregion #region 加载投料列表 /// /// 加载投料列表 /// /// 结果 [HandleException] public ActionResult GetMendReasonList() { string pid = Request.Params["PID"]; ServiceAgent wcfAgent = this.GetServiceAgent(); List list = new List(); MenderReason condition = new MenderReason(); #region wcf服务统一接口 list = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.B9IPCService.MendRecorderBLL_GetMenderReasonList.ToString(), new MendRecorder() { PPID = pid }); //通过返回dataResult判断 List objlist = new List(); foreach (var o in list) { objlist.Add(new { POSITION = o.POSITION, DEFECTKEY = o.DEFECTKEY, DEFECTVALUE = o.DEFECTVALUE }); } return Content(JsonConvertHelper.GetSerializes(objlist)); #endregion } #endregion #region 删除 /// /// 删除 /// /// 结果 [HttpPost] [HandleException] public ActionResult Delete() { string selectKey = Request.Form["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); try { int result = wcfAgent.InvokeServiceFunction("MendRecorderBLL_Delete", selectKey); if (result == 0) { SetMessage("删除失败!"); return List(true); } SetMessage(AppResource.DeleteMessage); return List(true); } catch (Exception ex) { throw ex; } } #endregion } }