public async Task <ActionResult> DetailQuery(MaterialReturnDetailQueryViewModel model) { if (ModelState.IsValid) { using (MaterialReturnServiceClient client = new MaterialReturnServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { OrderBy = "CreateTime Desc,Key.ReturnNo,Key.ItemNo", Where = GetWhereCondition(model) }; MethodReturnResult <IList <MaterialReturnDetail> > result = client.GetDetail(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.List = result.Data; } }); } } if (Request.IsAjaxRequest()) { return(PartialView("_DetailListPartial", new MaterialReturnDetailViewModel())); } else { return(View("Detail", model)); } }
public string GetWhereCondition(MaterialReturnDetailQueryViewModel model) { StringBuilder where = new StringBuilder(); if (model != null) { if (!string.IsNullOrEmpty(model.ReturnNo)) { where.AppendFormat(" {0} Key.ReturnNo = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.ReturnNo); } if (!string.IsNullOrEmpty(model.LineStoreName)) { where.AppendFormat(" {0} LineStoreName = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.LineStoreName); } if (!string.IsNullOrEmpty(model.MaterialCode)) { where.AppendFormat(" {0} MaterialCode LIKE '{1}%'" , where.Length > 0 ? "AND" : string.Empty , model.MaterialCode); } if (!string.IsNullOrEmpty(model.MaterialLot)) { where.AppendFormat(" {0} MaterialLot LIKE '{1}%'" , where.Length > 0 ? "AND" : string.Empty , model.MaterialLot); } if (!string.IsNullOrEmpty(model.OrderNumber)) { where.AppendFormat(@" {0} EXISTS(FROM MaterialReturn as p WHERE p.Key=self.Key.ReturnNo AND p.OrderNumber = '{1}')" , where.Length > 0 ? "AND" : string.Empty , model.OrderNumber); } if (!string.IsNullOrEmpty(model.ReturnDate)) { where.AppendFormat(@" {0} EXISTS(FROM MaterialReturn as p WHERE p.Key=self.Key.ReturnNo AND p.ReturnDate = '{1}')" , where.Length > 0 ? "AND" : string.Empty , model.ReturnDate); } } return(where.ToString()); }
public async Task <ActionResult> ExportToExcel(MaterialReturnDetailQueryViewModel model) { IList <MaterialReturnDetail> lst = new List <MaterialReturnDetail>(); using (MaterialReturnServiceClient client = new MaterialReturnServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "CreateTime Desc,Key.ReturnNo,Key.ItemNo", Where = GetWhereCondition(model) }; MethodReturnResult <IList <MaterialReturnDetail> > 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.MaterialReturnViewModel_ReturnNo); //退料号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReturnViewModel_OrderNumber); //工单号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReturnViewModel_ReturnDate); //领料日期 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReturnDetailViewModel_ItemNo); //项目号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReturnDetailViewModel_LineStoreName); //线别仓 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReturnDetailViewModel_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.MaterialReturnDetailViewModel_MaterialLot); //物料批号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReturnDetailViewModel_Qty); //数量 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; } MaterialReturnDetail obj = lst[j]; MaterialReturn mrObj = model.GetMaterialReturn(obj.Key.ReturnNo); 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.ReturnNo); //领料号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(mrObj == null ? string.Empty : mrObj.OrderNumber); //工单号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(mrObj == null ? string.Empty : string.Format("{0:yyyy-MM-dd}", mrObj.ReturnDate)); //领料日期 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(obj.LineStoreName); //线别仓 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.Qty); //数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.Description); //描述 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", "MaterialReturnData.xls")); }
// // GET: /LSM/MaterialReturn/ public async Task <ActionResult> Detail(MaterialReturnDetailQueryViewModel model) { return(await DetailQuery(model)); }