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.FJC.Entity.ProduceManage; using QMAPP.Entity; using QMFrameWork.WebUI.DataSource; using QMFrameWork.Common.Serialization; using System.Data; namespace QMAPP.FJC.Web.Controllers { public class ScrapRecordController : QController { #region 获取列表 [HandleException] public ActionResult List(bool? callBack) { MendRecorderModel searchmodel = new MendRecorderModel(); searchmodel.CREATEDATESTART = DateTime.Now.AddDays(-10).ToString("yyyy-MM-dd"); searchmodel.CREATEDATEEND = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"); searchmodel.ImmediateSearch = false; if (callBack == true) TryGetSelectBuffer(out searchmodel); searchmodel.rownumbers = true; searchmodel.url = "/ScrapRecord/GetList"; return View("ScrapRecordList", searchmodel); } /// /// 获取列表 /// /// 是否回调 /// 列表 [HandleException] public ActionResult GetList(bool? callBack) { MendRecorderModel searchmodel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); MendRecorder condition = null; DataResult pageResult = new DataResult(); try { searchmodel = GetModel(); if (callBack != null) { TryGetSelectBuffer(out searchmodel); } else { //保存搜索条件 SetSelectBuffer(searchmodel); } page = this.GetDataPage(searchmodel); condition = CopyToModel(searchmodel); #region wcf服务统一接口 pageResult = wcfAgent.InvokeServiceFunction>("ScrapRecordBLL_GetLists", condition, page); 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 导出excel /// /// 导出excel /// /// 结果 [HttpPost] public ActionResult ExportExcel() { 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); //获取数据 result = wcfAgent.InvokeServiceFunction>("ScrapRecordBLL_GetExportData", 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(); } //因为模版只能保存20条记录,所以截取20条。 //var rows= result.Result.Select().Take(20); //DataTable dt20 = result.Result.Clone(); //foreach (DataRow row in rows) //{ // dt20.ImportRow(row); //} //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("ScrapRecordExp", "材料报废单.xlsx", result.Result); } catch (Exception ex) { throw ex; } } #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>("ScrapRecordBLL_GetMenderReasonList", 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("ScrapRecordBLL_Delete", selectKey); if (result == 0) { SetMessage("删除失败!"); return List(true); } SetMessage(AppResource.DeleteMessage); return List(true); } catch (Exception ex) { throw ex; } } #endregion } }