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.
146 lines
4.9 KiB
146 lines
4.9 KiB
2 years ago
|
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.Packdalhistory;
|
||
|
using Warehouse.WebApi.Model;
|
||
|
|
||
|
namespace Warehouse.WebApi
|
||
|
{
|
||
|
//托盘删除记录
|
||
|
[RoutePrefix("api/PackDelHistoryNew")]
|
||
|
public class PackDelHistoryNewController : BaseController
|
||
|
{
|
||
|
Packdalhistory PDH = new Packdalhistory();
|
||
|
[Route("QueryInfoNew")]
|
||
|
[HttpPost]
|
||
|
public IHttpActionResult QueryInfoNew(PackDelHistoryModel model)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var res = PDH.QueryInfonew(model);
|
||
|
//处理数据
|
||
|
var list = new List<dynamic>();
|
||
|
res.ForEach(x => {
|
||
|
list.Add(new
|
||
|
{
|
||
|
pallet_nbr = x.pallet_nbr.ToString() ?? "-",
|
||
|
del_time = x.del_time.ToString() ?? "-",
|
||
|
worker = x.worker.ToString() ?? "-",
|
||
|
machine_name = x.machine_name.ToString() ?? "-"
|
||
|
});
|
||
|
});
|
||
|
//返回数据
|
||
|
return Success(new
|
||
|
{
|
||
|
data = list
|
||
|
});
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
//TODO 记录日志
|
||
|
}
|
||
|
return Failure("查询异常");
|
||
|
|
||
|
}
|
||
|
|
||
|
[Route("QueryStatus")]
|
||
|
[HttpPost]
|
||
|
public IHttpActionResult QueryStatus()
|
||
|
{
|
||
|
var res = PDH.QueryStatus();
|
||
|
return Json(res);
|
||
|
}
|
||
|
|
||
|
#region 下载
|
||
|
[HttpPost, Route("PackDelHistoryReportGet")]
|
||
|
public HttpResponseMessage DownloadPackOutReportGet(PackOutputControllerModel 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 = PDH.QueryInfonew(model);
|
||
|
foreach (var item in res.ToList())
|
||
|
{
|
||
|
var rowCount1 = sheet.LastRowNum + 1;
|
||
|
row = sheet.CreateRow(rowCount1);
|
||
|
row.CreateCell(0).SetCellValue(item.pallet_nbr.ToString());
|
||
|
row.GetCell(0).CellStyle = style;
|
||
|
row.CreateCell(1).SetCellValue(item.del_time.ToString());
|
||
|
row.GetCell(1).CellStyle = style;
|
||
|
row.CreateCell(2).SetCellValue(item.worker.ToString());
|
||
|
row.GetCell(2).CellStyle = style;
|
||
|
row.CreateCell(3).SetCellValue(item.machine_name.ToString());
|
||
|
row.GetCell(3).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
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|