旧版报表、仓库
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.

440 lines
24 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.Text.RegularExpressions;
using System.Web.Http;
using Warehouse.DAL.Report;
using Warehouse.DAL.YL;
using Warehouse.WebApi.Model;
namespace Warehouse.WebApi.YL
{
public class DataQueryNewController : BaseController
{
DataQueryDal DT = new DataQueryDal();
[Route("api/DataQueryNew/DataQuery")]
[HttpPost]
public IHttpActionResult Dataquery(DataQueryModel model)
{
try
{
var serialNum = "";
if (!string.IsNullOrEmpty(model.SerialNum))
{
var serialNumGet = model.SerialNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var serialNumList = serialNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
serialNum = string.Join("','", serialNumList);
serialNum = "'" + serialNum + "'";
}
var res = DT.Query(model.WorkOrder, model.TestTimeBegin, model.TestTimeEnd, serialNum);
//处理数据
var list = new List<dynamic>();
res.ForEach(x =>
{
list.Add(new
{
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-", //.ToString("yyyy-MM-dd HH:mm:ss")
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x. ?? "-",
= x..ToString() ?? "-",
EVA规格 = x.EVA规格.ToString() ?? "-",
EVA批号 = x.EVA批号.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
EVA厂商 = x.EVA厂商.ToString() ?? "-",
EVA规格 = x.EVA规格.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
EL测试时间 = x.EL测试时间.ToString() ?? "-",
EL机台编号 = x.EL机台编号.ToString() ?? "-",
EL测试结果 = x.EL测试结果.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
线 = x.线.ToString() ?? "-",
线 = x.线.ToString() ?? "-",
线 = x.线.ToString() ?? "-",
线 = x.线.ToString() ?? "-",
线 = x.线.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
线 = x.线.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
IV机台编号 = x.IV机台编号.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
EL测试时间 = x.EL测试时间.ToString() ?? "-",
EL机台编号 = x.EL机台编号.ToString() ?? "-",
EL测试结果 = x.EL测试结果.ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
= x..ToString() ?? "-",
});
});
//返回数据
return Success(new
{
data = list
});
}
catch (Exception e)
{
//TODO 记录日志
}
return Failure("查询异常");
}
#region 下载
[Route("api/DataQueryNew/DownloadDataQueryReportGet")]
[HttpPost]
public HttpResponseMessage DownloadDataQueryReportGet(DataQueryModel 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> {
"组件编号" ,
"车间编号",
" 工单类型" ,
"工单号" ,
"客户名称 ",
"片源批号" ,
"片源厂商",
"片源档位",
"电池尺寸",
"分选操作人员",
"片源规格",
"片源用量",
"单片功率",
"电池种类 ",
"焊接时间 ",
"机台编号",
"助焊剂厂商",
"助焊剂批号",
"操作人员",
"操作班次",
"电池片效率",
"互联条厂商",
"互联条规格",
"叠层时间",
"叠层机台编号",
"高透EVA规格",
"高透EVA批号",
"玻璃厂商",
"玻璃规格",
"玻璃批号",
"汇流条厂商",
"汇流条规格",
"叠层操作人员",
"叠层操作班次",
" EVA厂商",
"普通EVA规格",
"背板规格",
"背板厂商",
"背板批号",
"汇流条批号",
"前EL测试时间",
"前EL机台编号",
"前EL测试结果",
"层压时间",
"层压机台编号",
"层压操作班次",
" 层压后检验时间",
" 层压后检验操作人员",
"层压后检验操作班次",
"装框时间",
"装框机台编号",
"线盒厂家",
"线盒规格",
" 线盒批号",
"线盒胶厂商",
"线盒胶批号",
"装框操作人员",
"装框操作班次 ",
"接线盒拍照时间",
"型材厂商",
"型材规格",
"型材批号",
"型材胶厂商",
"型材胶批号",
"IV机台编号",
"测试功率",
"标称功率",
"测试时间",
"测试电流",
"后EL测试时间",
"后EL机台编号",
"后EL测试结果",
"全检时间",
"全检机台编号",
"全检操作人员",
};
//设置第一列列宽
// sheet.SetColumnWidth(0, 20 * 256);
//设置第一列之后的列宽
for (int i = 1; i < thList.Count; i++)
{
sheet.SetColumnWidth(i, 10 * 500);
}
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 serialNum = "";
if (!string.IsNullOrEmpty(model.SerialNum))
{
var serialNumGet = model.SerialNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var serialNumList = serialNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
serialNum = string.Join("','", serialNumList);
serialNum = "'" + serialNum + "'";
}
//获取数据
var res = DT.Query(model.WorkOrder, model.TestTimeBegin, model.TestTimeEnd, serialNum);
foreach (var item in res.ToList())
{
var rowCount1 = sheet.LastRowNum + 1;
row = sheet.CreateRow(rowCount1);
row.CreateCell(0).SetCellValue(item..ToString());
row.GetCell(0).CellStyle = style;
row.CreateCell(1).SetCellValue(item..ToString());
row.GetCell(1).CellStyle = style;
row.CreateCell(2).SetCellValue(item..ToString());
row.GetCell(2).CellStyle = style;
row.CreateCell(3).SetCellValue(item..ToString());
row.GetCell(3).CellStyle = style;
row.CreateCell(4).SetCellValue(item..ToString());
row.GetCell(4).CellStyle = style;
row.CreateCell(5).SetCellValue(item..ToString());
row.GetCell(5).CellStyle = style;
row.CreateCell(6).SetCellValue(item..ToString());
row.GetCell(6).CellStyle = style;
row.CreateCell(7).SetCellValue(item..ToString());
row.GetCell(7).CellStyle = style;
row.CreateCell(8).SetCellValue(item..ToString());
row.GetCell(8).CellStyle = style;
row.CreateCell(9).SetCellValue(item..ToString());
row.GetCell(9).CellStyle = style;
row.CreateCell(10).SetCellValue(item..ToString());
row.GetCell(10).CellStyle = style;
row.CreateCell(11).SetCellValue(item..ToString());
row.GetCell(11).CellStyle = style;
row.CreateCell(12).SetCellValue(item..ToString());
row.GetCell(12).CellStyle = style;
row.CreateCell(13).SetCellValue(item..ToString());
row.GetCell(13).CellStyle = style;
row.CreateCell(14).SetCellValue(item..ToString());
row.GetCell(14).CellStyle = style;
row.CreateCell(15).SetCellValue(item..ToString());
row.GetCell(15).CellStyle = style;
row.CreateCell(16).SetCellValue(item..ToString());
row.GetCell(16).CellStyle = style;
row.CreateCell(17).SetCellValue(item..ToString());
row.GetCell(17).CellStyle = style;
row.CreateCell(18).SetCellValue(item..ToString());
row.GetCell(18).CellStyle = style;
row.CreateCell(19).SetCellValue(item..ToString());
row.GetCell(19).CellStyle = style;
row.CreateCell(20).SetCellValue(item..ToString());
row.GetCell(20).CellStyle = style;
row.CreateCell(21).SetCellValue(item..ToString());
row.GetCell(21).CellStyle = style;
row.CreateCell(22).SetCellValue(item..ToString());
row.GetCell(22).CellStyle = style;
row.CreateCell(23).SetCellValue(item..ToString());
row.GetCell(23).CellStyle = style;
row.CreateCell(24).SetCellValue(item.EVA规格.ToString());
row.GetCell(24).CellStyle = style;
row.CreateCell(25).SetCellValue(item.EVA批号.ToString());
row.GetCell(25).CellStyle = style;
row.CreateCell(26).SetCellValue(item..ToString());
row.GetCell(26).CellStyle = style;
row.CreateCell(27).SetCellValue(item..ToString());
row.GetCell(27).CellStyle = style;
row.CreateCell(28).SetCellValue(item..ToString());
row.GetCell(28).CellStyle = style;
row.CreateCell(29).SetCellValue(item..ToString());
row.GetCell(29).CellStyle = style;
row.CreateCell(30).SetCellValue(item..ToString());
row.GetCell(30).CellStyle = style;
row.CreateCell(31).SetCellValue(item..ToString());
row.GetCell(31).CellStyle = style;
row.CreateCell(32).SetCellValue(item..ToString());
row.GetCell(32).CellStyle = style;
row.CreateCell(33).SetCellValue(item.EVA厂商.ToString());
row.GetCell(33).CellStyle = style;
row.CreateCell(34).SetCellValue(item.EVA规格.ToString());
row.GetCell(34).CellStyle = style;
row.CreateCell(35).SetCellValue(item..ToString());
row.GetCell(35).CellStyle = style;
row.CreateCell(36).SetCellValue(item..ToString());
row.GetCell(36).CellStyle = style;
row.CreateCell(37).SetCellValue(item..ToString());
row.GetCell(37).CellStyle = style;
row.CreateCell(38).SetCellValue(item..ToString());
row.GetCell(38).CellStyle = style;
row.CreateCell(39).SetCellValue(item.EL测试时间.ToString());
row.GetCell(39).CellStyle = style;
row.CreateCell(40).SetCellValue(item.EL机台编号.ToString());
row.GetCell(40).CellStyle = style;
row.CreateCell(41).SetCellValue(item.EL测试结果.ToString());
row.GetCell(41).CellStyle = style;
row.CreateCell(42).SetCellValue(item..ToString());
row.GetCell(42).CellStyle = style;
row.CreateCell(43).SetCellValue(item..ToString());
row.GetCell(43).CellStyle = style;
row.CreateCell(44).SetCellValue(item..ToString());
row.GetCell(44).CellStyle = style;
row.CreateCell(45).SetCellValue(item..ToString());
row.GetCell(45).CellStyle = style;
row.CreateCell(46).SetCellValue(item..ToString());
row.GetCell(46).CellStyle = style;
row.CreateCell(47).SetCellValue(item..ToString());
row.GetCell(47).CellStyle = style;
row.CreateCell(48).SetCellValue(item..ToString());
row.GetCell(48).CellStyle = style;
row.CreateCell(49).SetCellValue(item..ToString());
row.GetCell(49).CellStyle = style;
row.CreateCell(50).SetCellValue(item.线.ToString());
row.GetCell(50).CellStyle = style;
row.CreateCell(51).SetCellValue(item.线.ToString());
row.GetCell(51).CellStyle = style;
row.CreateCell(52).SetCellValue(item.线.ToString());
row.GetCell(52).CellStyle = style;
row.CreateCell(53).SetCellValue(item.线.ToString());
row.GetCell(53).CellStyle = style;
row.CreateCell(54).SetCellValue(item.线.ToString());
row.GetCell(54).CellStyle = style;
row.CreateCell(55).SetCellValue(item..ToString());
row.GetCell(55).CellStyle = style;
row.CreateCell(56).SetCellValue(item..ToString());
row.GetCell(56).CellStyle = style;
row.CreateCell(57).SetCellValue(item.线.ToString());
row.GetCell(57).CellStyle = style;
row.CreateCell(58).SetCellValue(item..ToString());
row.GetCell(58).CellStyle = style;
row.CreateCell(59).SetCellValue(item..ToString());
row.GetCell(59).CellStyle = style;
row.CreateCell(60).SetCellValue(item..ToString());
row.GetCell(60).CellStyle = style;
row.CreateCell(61).SetCellValue(item..ToString());
row.GetCell(61).CellStyle = style;
row.CreateCell(62).SetCellValue(item..ToString());
row.GetCell(62).CellStyle = style;
row.CreateCell(63).SetCellValue(item.IV机台编号.ToString());
row.GetCell(63).CellStyle = style;
row.CreateCell(64).SetCellValue(item..ToString());
row.GetCell(64).CellStyle = style;
row.CreateCell(65).SetCellValue(item..ToString());
row.GetCell(65).CellStyle = style;
row.CreateCell(66).SetCellValue(item..ToString());
row.GetCell(66).CellStyle = style;
row.CreateCell(67).SetCellValue(item..ToString());
row.GetCell(67).CellStyle = style;
row.CreateCell(68).SetCellValue(item.EL测试时间.ToString());
row.GetCell(68).CellStyle = style;
row.CreateCell(69).SetCellValue(item.EL机台编号.ToString());
row.GetCell(69).CellStyle = style;
row.CreateCell(70).SetCellValue(item.EL测试结果.ToString());
row.GetCell(70).CellStyle = style;
row.CreateCell(71).SetCellValue(item..ToString());
row.GetCell(71).CellStyle = style;
row.CreateCell(72).SetCellValue(item..ToString());
row.GetCell(72).CellStyle = style;
row.CreateCell(73).SetCellValue(item..ToString());
row.GetCell(73).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
}
}