public async Task <ActionResult> DetailQuery(MaterialReceiptDetailQueryViewModel model) { if (ModelState.IsValid) { using (MaterialReceiptServiceClient client = new MaterialReceiptServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { OrderBy = "CreateTime Desc,Key.ReceiptNo,Key.ItemNo", Where = GetWhereCondition(model) }; MethodReturnResult <IList <MaterialReceiptDetail> > result = client.GetDetail(ref cfg); if (result.Code == 0) { ViewBag.PagingConfig = cfg; ViewBag.List = result.Data; } }); } } if (Request.IsAjaxRequest()) { return(PartialView("_DetailListPartial", new MaterialReceiptDetailViewModel())); } else { return(View("Detail", model)); } }
public string GetWhereCondition(MaterialReceiptDetailQueryViewModel model) { StringBuilder where = new StringBuilder(); if (model != null) { if (!string.IsNullOrEmpty(model.ReceiptNo)) { where.AppendFormat(" {0} Key.ReceiptNo = '{1}'" , where.Length > 0 ? "AND" : string.Empty , model.ReceiptNo); } 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 MaterialReceipt as p WHERE p.Key=self.Key.ReceiptNo AND p.OrderNumber = '{1}')" , where.Length > 0 ? "AND" : string.Empty , model.OrderNumber); } if (!string.IsNullOrEmpty(model.ReceiptDate)) { where.AppendFormat(@" {0} EXISTS(FROM MaterialReceipt as p WHERE p.Key=self.Key.ReceiptNo AND p.ReceiptDate = '{1}')" , where.Length > 0 ? "AND" : string.Empty , model.ReceiptDate); } } return(where.ToString()); }
public async Task <ActionResult> ExportToExcel(MaterialReceiptDetailQueryViewModel model) { IList <MaterialReceiptDetail> lst = new List <MaterialReceiptDetail>(); using (MaterialReceiptServiceClient client = new MaterialReceiptServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "CreateTime Desc,Key.ReceiptNo,Key.ItemNo", Where = GetWhereCondition(model) }; MethodReturnResult <IList <MaterialReceiptDetail> > 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.MaterialReceiptViewModel_ReceiptNo); //领料号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptViewModel_OrderNumber); //工单号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptViewModel_ReceiptDate); //领料日期 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptDetailViewModel_ItemNo); //项目号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptDetailViewModel_LineStoreName); //线别仓 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptDetailViewModel_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.MaterialReceiptDetailViewModel_MaterialLot); //物料批号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptDetailViewModel_Qty); //数量 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptDetailViewModel_SupplierMaterialLot); //供应商批号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(LSMResources.StringResource.MaterialReceiptDetailViewModel_SupplierCode); //供应商编码 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; } MaterialReceiptDetail obj = lst[j]; MaterialReceipt mrObj = model.GetMaterialReceipt(obj.Key.ReceiptNo); Material m = model.GetMaterial(obj.MaterialCode); Supplier s = model.GetSupplier(obj.SupplierCode); row = ws.CreateRow(j + 1); #region //数据 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.Key.ReceiptNo); //领料号 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.ReceiptDate)); //领料日期 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.SupplierMaterialLot); //供应商批号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(obj.SupplierCode); //供应商编码 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(s == null ? string.Empty : s.Name); //供应商名称 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", "MaterialReceiptData.xls")); }
// // GET: /LSM/MaterialReceipt/ public async Task <ActionResult> Detail(MaterialReceiptDetailQueryViewModel model) { return(await DetailQuery(model)); }