旧版报表、仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

191 lines
8.1 KiB

using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
using Warehouse.DAL.WOFinsihStatus;
using Warehouse.WebApi.Model;
namespace Warehouse.WebApi
{
//工单达成情况
[RoutePrefix("api/WOFinishStatusNew")]
public class WOFinsihStatusNewController : BaseController
{
WOFinsihStatus scp = new WOFinsihStatus();
[Route("QueryInfoNew")]
[HttpPost]
public IHttpActionResult QueryInfoNew(WOFinsihStatusModel model)
{
try
{
var res = scp.QueryInfo(model.WorkOrder, model.Sales, model.Customer, model.TestTimeBegin, model.TestTimeEnd);
var list = new List<dynamic>();
res.ForEach(x =>
{
string a = "s"; a.Split('|');
string[] grade = x.gradeqty.Split('|');
string[] power = x.testpower.Split('|');
list.Add(new
{
create_date = x.create_date.ToString() ?? "-",
firstlottime = x.firstlottime.ToString() ?? "-",
customer = x.customer.ToString() ?? "-",
sale_order = x.sale_order.ToString() ?? "-",
workorder = x.workorder.ToString() ?? "-",
firstlot = x.firstlot.ToString() ?? "-",
product_code = x.product_code.ToString() ?? "-", //.ToString("yyyy-MM-dd HH:mm:ss")
plan_qty = x.plan_qty.ToString() ?? "-",
laminationqty = x.laminationqty.ToString() ?? "-",
ZKT = x.ZKT.ToString() ?? "-",
QXT = x.QXT.ToString() ?? "-",
cell_supplier_desc = x.cell_supplier_desc.ToString() ?? "-",
cell_uop = x.cell_uop.ToString() ?? "-",
A = grade[0] ?? "-",
B = grade[1] ?? "-",
C = grade[2] ?? "-",
max = power[0].ToString()?? "-",
min = power[1] ?? "-",
avg = power[2] ?? "-",
});
});
return Success(new
{
data = list
});
}
catch (Exception e)
{
}
return Failure("查询异常");
}
#region 下载
[HttpPost, Route("DownloadWOFinishStatusReportGet")]
public HttpResponseMessage DownloadWOFinishStatusReportGet(WOFinsihStatusModel model)
{
try
{
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
hssfworkbook.CreateSheet("工单达成报表");
ICellStyle style = hssfworkbook.CreateCellStyle();
//设置单元格的样式:水平对齐居中
style.Alignment = HorizontalAlignment.Center;
ISheet sheet = null;
sheet = hssfworkbook.GetSheetAt(0);
IRow row = null;
#region 添加表头
var thList = new List<string> {
"工单日期",
"生码日期",
"客户",
"订单号",
"工单号",
"生产批次",
"组件功率",
"工单数量",
"叠层数量",
"装框数量",
"清洗数量",
"电池片厂家",
"电池片档位",
"组件等级分布",
"测试功率"
};
//设置第一列列宽
// sheet.SetColumnWidth(0, 20 * 256);
//设置第一列之后的列宽
for (int i = 1; i < thList.Count; i++)
{
sheet.SetColumnWidth(i, 10 * 256);
}
var rowCount = sheet.LastRowNum;
row = sheet.CreateRow(rowCount);
//添加表头并设置样式字体居中
for (int i = 0; i < thList.Count; i++)
{
row.CreateCell(i).SetCellValue(thList[i]);
row.GetCell(i).CellStyle = style;
}
#endregion
//获取数据
var res = scp.QueryInfo(model.WorkOrder, model.Sales, model.Customer, model.TestTimeBegin, model.TestTimeEnd);
foreach (var item in res.ToList())
{
var rowCount1 = sheet.LastRowNum + 1;
string a = "s"; a.Split('|');
string[] grade = item.gradeqty.Split('|');
item.A = grade[0];
item.B = grade[1];
item.C = grade[2];
string[] power = item.testpower.Split('|');
item.max = power[0];
item.min = power[1];
item.avg = power[2];
row = sheet.CreateRow(rowCount1);
row.CreateCell(0).SetCellValue(item.create_date.ToString());
row.GetCell(0).CellStyle = style;
row.CreateCell(1).SetCellValue(item.firstlottime.ToString());
row.GetCell(1).CellStyle = style;
row.CreateCell(2).SetCellValue(item.customer.ToString());
row.GetCell(2).CellStyle = style;
row.CreateCell(3).SetCellValue(item.sale_order.ToString());
row.GetCell(3).CellStyle = style;
row.CreateCell(4).SetCellValue(item.workorder.ToString());
row.GetCell(4).CellStyle = style;
row.CreateCell(5).SetCellValue(item.firstlot.ToString());
row.GetCell(5).CellStyle = style;
row.CreateCell(6).SetCellValue(item.product_code.ToString());
row.GetCell(6).CellStyle = style;
row.CreateCell(7).SetCellValue(item.plan_qty.ToString());
row.GetCell(7).CellStyle = style;
row.CreateCell(8).SetCellValue(item.laminationqty.ToString());
row.GetCell(8).CellStyle = style;
row.CreateCell(9).SetCellValue(item.ZKT.ToString());
row.GetCell(9).CellStyle = style;
row.CreateCell(10).SetCellValue(item.QXT.ToString());
row.GetCell(10).CellStyle = style;
row.CreateCell(11).SetCellValue(item.cell_supplier_desc.ToString());
row.GetCell(11).CellStyle = style;
row.CreateCell(12).SetCellValue(item.cell_uop.ToString());
row.GetCell(12).CellStyle = style;
row.CreateCell(13).SetCellValue(item.gradeqty.ToString());
row.GetCell(13).CellStyle = style;
row.CreateCell(14).SetCellValue(item.testpower.ToString());
row.GetCell(14).CellStyle = style;
}
MemoryStream ms = new MemoryStream(); //创建内存流用于写入文件
hssfworkbook.Write(ms);//将Excel写入流
ms.Flush();
ms.Position = 0;
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(ms);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "工单达成情况报表.xls"
};
return result;
}
catch (Exception)
{
}
return new HttpResponseMessage(HttpStatusCode.NoContent);
}
#endregion
}
}