public async Task <ActionResult> DetailQuery(MaterialLoadingDetailQueryViewModel model) { if (ModelState.IsValid) { using (MaterialLoadingServiceClient client = new MaterialLoadingServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { OrderBy = "CreateTime Desc,Key.LoadingKey,Key.ItemNo", Where = GetWhereCondition(model) }; MethodReturnResult <IList <MaterialLoadingDetail> > result = client.GetDetail(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.List = result.Data; } }); } } if (Request.IsAjaxRequest()) { return(PartialView("_DetailListPartial", new MaterialLoadingDetailViewModel())); } else { return(View("Detail", model)); } }
public async Task <ActionResult> ExportToExcel(MaterialLoadingDetailQueryViewModel model) { IList <MaterialLoadingDetail> lst = new List <MaterialLoadingDetail>(); using (MaterialLoadingServiceClient client = new MaterialLoadingServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "CreateTime Desc,Key.LoadingKey,Key.ItemNo", Where = GetWhereCondition(model) }; MethodReturnResult <IList <MaterialLoadingDetail> > result = client.GetDetail(ref cfg); if (result.Code == 0) { lst = 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); ICell cell = null; IRow row = null; ISheet ws = null; for (int j = 0; j < lst.Count; j++) { if (j % 65535 == 0) { ws = wb.CreateSheet(); row = ws.CreateRow(0); #region //列名 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_LoadingNo); //上料号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_ItemNo); //项目号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_RouteOperationName); //工序 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_ProductionLineCode); //生产线 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_EquipmentCode); //设备 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("上料日期"); //上料时间 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_LoadingTime); //上料时间 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_Operator); //操作人 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_LineStoreName); //线边仓 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingViewModel_OrderNumber); //工单号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_MaterialCode); //物料编码 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("物料名称"); //物料名称 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_MaterialLot); //物料批号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_LoadingQty); //上料数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_UnloadingQty); //下料数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialLoadingDetailViewModel_CurrentQty); //当前数量 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; } MaterialLoadingDetail obj = lst[j]; MaterialLoading objMaterialLoading = model.GetMaterialLoading(obj.Key.LoadingKey); Material m = model.GetMaterial(obj.MaterialCode); row = ws.CreateRow(j + 1); #region //数据 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.Key.LoadingKey); //上料号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.Key.ItemNo); //项目号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(objMaterialLoading.RouteOperationName); //工序 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(objMaterialLoading.ProductionLineCode); //生产线 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(objMaterialLoading.EquipmentCode); //设备 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(string.Format("{0:yyyy-MM-dd}", objMaterialLoading.LoadingTime)); //上料日期 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", objMaterialLoading.LoadingTime)); //上料时间 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(objMaterialLoading.Operator); //操作人 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.LineStoreName); //线边仓 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.OrderNumber); //工单号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.MaterialCode); //物料编码 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(m == null ? string.Empty : m.Name); //物料名称 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.MaterialLot); //物料批号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.LoadingQty); //上料数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.UnloadingQty); //下料数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.CurrentQty); //当前数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.Editor); //编辑人 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.EditTime)); //编辑时间 #endregion } MemoryStream ms = new MemoryStream(); wb.Write(ms); ms.Flush(); ms.Position = 0; return(File(ms, "application/vnd.ms-excel", "MaterialLoadingData.xls")); }
public string GetWhereCondition(MaterialLoadingDetailQueryViewModel model) { StringBuilder where = new StringBuilder(); StringBuilder whereExists = new StringBuilder(); bool isUseWhereExists = false; if (model != null) { if (model.IsShowZeroData == true) { where.Append(" CurrentQty>0"); } if (!string.IsNullOrEmpty(model.LoadingNo)) { where.AppendFormat(" {0} Key.LoadingKey = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.LoadingNo); whereExists.AppendFormat(" {0} p.Key = '{1}'" , whereExists.Length > 0 ? "AND" : string.Empty , model.LoadingNo); } if (!string.IsNullOrEmpty(model.RouteOperationName)) { whereExists.AppendFormat(" {0} p.RouteOperationName LIKE '{1}%'" , whereExists.Length > 0 ? "AND" : string.Empty , model.RouteOperationName); isUseWhereExists = true; } if (!string.IsNullOrEmpty(model.ProductionLineCode)) { whereExists.AppendFormat(" {0} p.ProductionLineCode LIKE '{1}%'" , whereExists.Length > 0 ? "AND" : string.Empty , model.ProductionLineCode); isUseWhereExists = true; } if (!string.IsNullOrEmpty(model.EquipmentCode)) { whereExists.AppendFormat(" {0} p.EquipmentCode LIKE '{1}%'" , whereExists.Length > 0 ? "AND" : string.Empty , model.EquipmentCode); isUseWhereExists = true; } if (model.StartLoadingTime != null) { whereExists.AppendFormat(" {0} p.LoadingTime >= '{1:yyyy-MM-dd HH:mm:ss}'" , whereExists.Length > 0 ? "AND" : string.Empty , model.StartLoadingTime); isUseWhereExists = true; } if (model.EndLoadingTime != null) { whereExists.AppendFormat(" {0} p.LoadingTime <= '{1:yyyy-MM-dd HH:mm:ss}'" , whereExists.Length > 0 ? "AND" : string.Empty , model.EndLoadingTime); isUseWhereExists = true; } if (!string.IsNullOrEmpty(model.OrderNumber)) { where.AppendFormat(" {0} OrderNumber = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.OrderNumber); } if (!string.IsNullOrEmpty(model.MaterialCode)) { where.AppendFormat(" {0} MaterialCode = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.MaterialCode); } if (!string.IsNullOrEmpty(model.MaterialLot)) { where.AppendFormat(" {0} MaterialLot = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.MaterialLot); } } if (isUseWhereExists) { where.AppendFormat(" {0} EXISTS( From MaterialLoading as p WHERE p.Key=self.Key.LoadingKey AND {1})" , where.Length > 0 ? "AND" : string.Empty , whereExists); } return(where.ToString()); }
// // GET: /LSM/MaterialLoading/ public async Task <ActionResult> Detail(MaterialLoadingDetailQueryViewModel model) { return(await DetailQuery(model)); }