public string GetQueryCondition(WIPDisplayDetailQueryViewModel model) { StringBuilder where = new StringBuilder(); if (model != null) { if (!string.IsNullOrEmpty(model.LocationName)) { where.AppendFormat(" {0} LocationName = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.LocationName); } if (!string.IsNullOrEmpty(model.OrderNumber)) { where.AppendFormat(" {0} OrderNumber LIKE '{1}%'" , where.Length > 0 ? "AND" : string.Empty , model.OrderNumber); } if (!string.IsNullOrEmpty(model.MaterialCode)) { where.AppendFormat(" {0} MaterialCode LIKE '{1}%'" , where.Length > 0 ? "AND" : string.Empty , model.MaterialCode); } if (!string.IsNullOrEmpty(model.RouteOperationName) && model.RouteOperationName != "合计") { where.AppendFormat(" {0} RouteStepName = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.RouteOperationName); } if (model.Status == "等待") { where.AppendFormat(" {0} StateFlag = '{1}' AND HoldFlag = '0'" , where.Length > 0 ? "AND" : string.Empty , Convert.ToInt32(EnumLotState.WaitTrackIn)); } else if (model.Status == "运行") { where.AppendFormat(" {0} StateFlag >= '{1}' AND StateFlag<'{2}' AND HoldFlag = '0'" , where.Length > 0 ? "AND" : string.Empty , Convert.ToInt32(EnumLotState.WaitTrackIn) , Convert.ToInt32(EnumLotState.Finished)); } else if (model.Status == "暂停") { where.AppendFormat(" {0} HoldFlag = '1'" , where.Length > 0 ? "AND" : string.Empty); } where.AppendFormat(" {0} EDIT_TIME <= DATEADD(MI,-{1},SYSDATETIME())" , where.Length > 0 ? "AND" : string.Empty , model.OnlineTime); where.AppendFormat(" AND DeletedFlag=0 AND Status=1 AND StateFlag<>16"); } return(where.ToString()); }
// // GET: /RPT/WIPDisplay/Detail public ActionResult Detail(WIPDisplayDetailQueryViewModel model) { using (LotQueryServiceClient client = new LotQueryServiceClient()) { PagingConfig cfg = new PagingConfig() { OrderBy = "CreateTime DESC", Where = GetQueryCondition(model) }; MethodReturnResult <IList <Lot> > result = client.Get(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.List = result.Data; } } if (Request.IsAjaxRequest()) { return(PartialView("_DetailListPartial")); } else { return(View(model)); } }
public async Task <ActionResult> ExportToExcel(WIPDisplayDetailQueryViewModel model) { IList <Lot> lstLot = new List <Lot>(); using (LotQueryServiceClient client = new LotQueryServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "CreateTime DESC", Where = GetQueryCondition(model) }; MethodReturnResult <IList <Lot> > result = client.Get(ref cfg); if (result.Code == 0) { lstLot = result.Data; } }); } //创建工作薄。 IWorkbook wb = new HSSFWorkbook(); //设置EXCEL格式 ICellStyle style = wb.CreateCellStyle(); style.FillForegroundColor = 10; //有边框 style.BorderBottom = BorderStyle.Thin; style.BorderLeft = BorderStyle.Thin; style.BorderRight = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin; IFont font = wb.CreateFont(); font.Boldweight = 10; style.SetFont(font); ISheet ws = null; for (int j = 0; j < lstLot.Count; j++) { if (j % 65535 == 0) { ws = wb.CreateSheet(); IRow row = ws.CreateRow(0); #region //列名 ICell cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("序号"); //序号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("批次号(组件序列号)"); //批次号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("工单号"); //工单号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("物料编码"); //产品号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("数量"); //数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("效率档"); //效率档 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("等级"); //等级 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("花色"); //花色 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("线别"); //线别代码 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("设备代码"); //设备代码 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("车间名称"); //车间名称 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("工艺流程"); //工艺流程 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("工序"); //工序 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("状态"); //状态 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("批次类型"); //批次类型 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("暂停?"); //暂停标志 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("包装号"); //包装号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("返修?"); //返修标志 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("返工?"); //返工标志 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("返工时间"); //返工时间 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("返工操作人"); //返工操作人 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("创建时间"); //创建时间 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("创建人"); //创建人 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("编辑时间"); //编辑时间 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("编辑人"); //编辑人 #endregion font.Boldweight = 5; } Lot obj = lstLot[j]; IRow rowData = ws.CreateRow(j + 1); #region //数据 ICell cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(j + 1); //序号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Key); //批次号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.OrderNumber); //工单号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.MaterialCode); //产品号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Quantity); //数量 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Attr1); //效率档 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Grade); //等级 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Color); //花色 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.LineCode); //线别代码 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.EquipmentCode); //设备代码 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.LocationName); //车间名称 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.RouteName); //工艺流程 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.RouteStepName); //工步 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.StateFlag.GetDisplayName()); //批次状态 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.LotType.GetDisplayName()); //批次类型 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.HoldFlag ? StringResource.Yes : StringResource.No); //暂停标志 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.PackageNo); //包装号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.RepairFlag); //返修次数 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.ReworkFlag); //返工次数 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.ReworkTime)); //返工时间 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Reworker); //返工操作人 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.CreateTime)); //创建时间 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Creator); //创建人 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.EditTime)); //编辑时间 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Editor); //编辑人 #endregion } MemoryStream ms = new MemoryStream(); wb.Write(ms); ms.Flush(); ms.Position = 0; return(File(ms, "application/vnd.ms-excel", "WIPDetailData.xls")); }