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.
454 lines
20 KiB
454 lines
20 KiB
3 months ago
|
using MESClassLibrary.BLL.Check;
|
||
|
using MESClassLibrary.EFModel;
|
||
|
using MESClassLibrary.Model;
|
||
|
using NPOI.SS.UserModel;
|
||
|
using NPOI.XSSF.UserModel;
|
||
|
using org.in2bits.MyXls;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.IO;
|
||
|
using System.Linq;
|
||
|
using System.Web;
|
||
|
|
||
|
namespace MESWebSite.HttpHandlers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// PlatingInspectionHandler 的摘要说明
|
||
|
/// </summary>
|
||
|
public class PlatingInspectionHandler : IHttpHandler
|
||
|
{
|
||
|
|
||
|
HttpRequest Request = null;
|
||
|
HttpResponse Response = null;
|
||
|
|
||
|
public void ProcessRequest(HttpContext context)
|
||
|
{
|
||
|
context.Response.ContentType = "text/plain";
|
||
|
Request = context.Request;
|
||
|
Response = context.Response;
|
||
|
|
||
|
string method = Request.Params["method"];
|
||
|
switch (method)
|
||
|
{
|
||
|
|
||
|
case "QueryList":
|
||
|
QueryList();
|
||
|
break;
|
||
|
case "QueryExcel":
|
||
|
QueryExcelNew();
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public bool IsReusable
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void QueryList()
|
||
|
{
|
||
|
string page = Request.Params["page"];
|
||
|
string pagesize = Request.Params["rows"];
|
||
|
string StartTime = Request.Params["StartTime"];
|
||
|
string EndTime = Request.Params["EndTime"];
|
||
|
string position = Request.Params["position"];
|
||
|
string inspectResult = Request.Params["inspectResult"];
|
||
|
string barCode = Request.Params["barCode"];
|
||
|
|
||
|
if (string.IsNullOrEmpty(page))
|
||
|
{
|
||
|
page = "0";
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(pagesize))
|
||
|
{
|
||
|
pagesize = "15";
|
||
|
}
|
||
|
InspectResultBLL bll = new InspectResultBLL();
|
||
|
Response.Write(bll.SearchInfo(page, pagesize, StartTime, EndTime, position, inspectResult, barCode));
|
||
|
Response.End();
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
void QueryExcel()
|
||
|
{
|
||
|
string StartTime = Request.Params["StartTime"];
|
||
|
string EndTime = Request.Params["EndTime"];
|
||
|
string position = Request.Params["position"];
|
||
|
string inspectResult = Request.Params["inspectResult"];
|
||
|
string barCode = Request.Params["barCode"];
|
||
|
|
||
|
InspectResultBLL bll = new InspectResultBLL();
|
||
|
List<InspectResultGroup> list = bll.SearchInfoAll(StartTime, EndTime, position, inspectResult, barCode);
|
||
|
|
||
|
XlsDocument xls = new XlsDocument();
|
||
|
xls.FileName = "喷涂检测记录-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
|
||
|
|
||
|
// Sheet标题样式
|
||
|
XF titleXF = xls.NewXF(); // 为xls生成一个XF实例,XF是单元格格式对象
|
||
|
titleXF.HorizontalAlignment = HorizontalAlignments.Centered; // 设定文字居中
|
||
|
titleXF.VerticalAlignment = VerticalAlignments.Centered; // 垂直居中
|
||
|
titleXF.UseBorder = true; // 使用边框
|
||
|
titleXF.TopLineStyle = 1; // 上边框样式
|
||
|
titleXF.TopLineColor = Colors.Black; // 上边框颜色
|
||
|
titleXF.LeftLineStyle = 1; // 左边框样式
|
||
|
titleXF.LeftLineColor = Colors.Black; // 左边框颜色
|
||
|
titleXF.RightLineStyle = 1; // 右边框样式
|
||
|
titleXF.RightLineColor = Colors.Black; // 右边框颜色
|
||
|
titleXF.Font.FontName = "宋体"; // 字体
|
||
|
titleXF.Font.Bold = true; // 是否加楚
|
||
|
titleXF.Font.Height = 20 * 20; // 字大小(字体大小是以 1/20 point 为单位的)
|
||
|
|
||
|
// 列标题样式
|
||
|
XF columnTitleXF = xls.NewXF(); // 为xls生成一个XF实例,XF是单元格格式对象
|
||
|
columnTitleXF.HorizontalAlignment = HorizontalAlignments.Centered; // 设定文字居中
|
||
|
columnTitleXF.VerticalAlignment = VerticalAlignments.Centered; // 垂直居中
|
||
|
columnTitleXF.UseBorder = true; // 使用边框
|
||
|
columnTitleXF.TopLineStyle = 1;
|
||
|
columnTitleXF.TopLineColor = Colors.Black;
|
||
|
columnTitleXF.BottomLineStyle = 1;
|
||
|
columnTitleXF.BottomLineColor = Colors.Black;
|
||
|
columnTitleXF.LeftLineStyle = 1;
|
||
|
columnTitleXF.LeftLineColor = Colors.Black;
|
||
|
columnTitleXF.RightLineStyle = 1;
|
||
|
columnTitleXF.RightLineColor = Colors.Black;
|
||
|
columnTitleXF.Pattern = 1; // 单元格填充风格。如果设定为0,则是纯色填充(无色),1代表没有间隙的实色
|
||
|
columnTitleXF.PatternBackgroundColor = Colors.Red; // 填充的底色
|
||
|
columnTitleXF.PatternColor = Colors.Default2F; // 填充背景色
|
||
|
|
||
|
// 数据单元格样式
|
||
|
XF dataXF = xls.NewXF(); // 为xls生成一个XF实例,XF是单元格格式对象
|
||
|
dataXF.HorizontalAlignment = HorizontalAlignments.Centered; // 设定文字居中
|
||
|
dataXF.VerticalAlignment = VerticalAlignments.Centered; // 垂直居中
|
||
|
dataXF.UseBorder = true; // 使用边框
|
||
|
dataXF.TopLineStyle = 1;
|
||
|
dataXF.TopLineColor = Colors.Black;
|
||
|
dataXF.BottomLineStyle = 1;
|
||
|
dataXF.BottomLineColor = Colors.Black;
|
||
|
dataXF.LeftLineStyle = 1;
|
||
|
dataXF.LeftLineColor = Colors.Black;
|
||
|
dataXF.RightLineStyle = 1;
|
||
|
dataXF.RightLineColor = Colors.Black;
|
||
|
dataXF.Font.FontName = "宋体";
|
||
|
dataXF.Font.Height = 9 * 20; // 设定字大小(字体大小是以 1/20 point 为单位的)
|
||
|
dataXF.UseProtection = false; // 默认的就是受保护的,导出后需要启用编辑才可修改
|
||
|
dataXF.TextWrapRight = true; // 自动换行
|
||
|
Worksheet sheet = xls.Workbook.Worksheets.Add("喷涂检测记录");
|
||
|
|
||
|
//设定列
|
||
|
ArrayList col;
|
||
|
List<ArrayList> listColumn = new List<ArrayList>();
|
||
|
col = new ArrayList() { 25, "条码", "barcode" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "A/B侧", "side" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "位置", "position" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "班次", "workClass" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "产品信息", "productInfo" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "生产模式", "productOption" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "一次结果", "inspectResult_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "一次缺陷位置", "damnPosition_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "一次缺陷原因", "reason_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 20, "一次时间", "createTime_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "二次结果", "inspectResult_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "二次缺陷位置", "damnPosition_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "二次缺陷原因", "reason_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 20, "二次时间", "createTime_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "三次结果", "inspectResult_3" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "三次缺陷位置", "damnPosition_3" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "三次缺陷原因", "reason_3" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 20, "三次时间", "createTime_3" };
|
||
|
listColumn.Add(col);
|
||
|
|
||
|
|
||
|
for (int i = 0; i < listColumn.Count; i++)
|
||
|
{
|
||
|
ArrayList c = listColumn[i];
|
||
|
ColumnInfo colinfo = new ColumnInfo(xls, sheet);
|
||
|
int w = (int)c[0];
|
||
|
string s = (string)c[1];
|
||
|
colinfo.ColumnIndexStart = (ushort)i;
|
||
|
colinfo.ColumnIndexEnd = (ushort)i;
|
||
|
colinfo.Width = (ushort)(w * 256);
|
||
|
sheet.AddColumnInfo(colinfo);
|
||
|
}
|
||
|
|
||
|
|
||
|
org.in2bits.MyXls.
|
||
|
|
||
|
|
||
|
//行设置
|
||
|
RowInfo rolinfo = new RowInfo();
|
||
|
rolinfo.RowHeight = 16 * 20; //行高
|
||
|
rolinfo.RowIndexStart = 3; //起始行,从1开始计算
|
||
|
rolinfo.RowIndexEnd = (ushort)(list.Count + 2); //结束行
|
||
|
sheet.AddRowInfo(rolinfo);
|
||
|
|
||
|
//设置表头
|
||
|
MergeArea titleArea = new MergeArea(1, 1, 1, listColumn.Count);
|
||
|
sheet.AddMergeArea(titleArea); //合并单元格
|
||
|
Cells cells = sheet.Cells;
|
||
|
//Sheet标题行,行和列的索引都是从1开始的
|
||
|
for (int i = 0; i < listColumn.Count; i++)
|
||
|
cells.Add(1, i + 1, "", titleXF); //合并单元格后仍需要设置每一个单元格,样式才有效
|
||
|
sheet.Rows[1].RowHeight = 40 * 20; //设置标题行行高
|
||
|
cells.Add(1, 1, "喷涂检测记录", titleXF); //标题内容
|
||
|
|
||
|
for (int i = 0; i < listColumn.Count; i++) //设置表头行
|
||
|
{
|
||
|
ArrayList c = listColumn[i];
|
||
|
string s = (string)c[1];
|
||
|
cells.Add(2, i + 1, s, columnTitleXF);
|
||
|
}
|
||
|
sheet.Rows[2].RowHeight = 18 * 20; //设置表头行高
|
||
|
|
||
|
//数据写入cell
|
||
|
Int32 k = 0;
|
||
|
foreach (var item in list)
|
||
|
{
|
||
|
for (Int32 j = 0; j < listColumn.Count; j++)
|
||
|
{
|
||
|
ArrayList c = listColumn[j];
|
||
|
string strColName = (string)c[2];
|
||
|
string s = GetModelValue(strColName, item);
|
||
|
cells.Add(3 + k, j + 1, s);
|
||
|
}
|
||
|
k++;
|
||
|
}
|
||
|
|
||
|
xls.Send();
|
||
|
Response.End();
|
||
|
}
|
||
|
|
||
|
void QueryExcelNew()
|
||
|
{
|
||
|
string StartTime = Request.Params["StartTime"];
|
||
|
string EndTime = Request.Params["EndTime"];
|
||
|
string position = Request.Params["position"];
|
||
|
string inspectResult = Request.Params["inspectResult"];
|
||
|
string barCode = Request.Params["barCode"];
|
||
|
|
||
|
InspectResultBLL bll = new InspectResultBLL();
|
||
|
List<InspectResultGroup> list = bll.SearchInfoAll(StartTime, EndTime, position, inspectResult,barCode);
|
||
|
|
||
|
//XlsDocument xls = new XlsDocument();
|
||
|
//xls.FileName = "喷涂检测记录-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
|
||
|
|
||
|
//// Sheet标题样式
|
||
|
//XF titleXF = xls.NewXF(); // 为xls生成一个XF实例,XF是单元格格式对象
|
||
|
//titleXF.HorizontalAlignment = HorizontalAlignments.Centered; // 设定文字居中
|
||
|
//titleXF.VerticalAlignment = VerticalAlignments.Centered; // 垂直居中
|
||
|
//titleXF.UseBorder = true; // 使用边框
|
||
|
//titleXF.TopLineStyle = 1; // 上边框样式
|
||
|
//titleXF.TopLineColor = Colors.Black; // 上边框颜色
|
||
|
//titleXF.LeftLineStyle = 1; // 左边框样式
|
||
|
//titleXF.LeftLineColor = Colors.Black; // 左边框颜色
|
||
|
//titleXF.RightLineStyle = 1; // 右边框样式
|
||
|
//titleXF.RightLineColor = Colors.Black; // 右边框颜色
|
||
|
//titleXF.Font.FontName = "宋体"; // 字体
|
||
|
//titleXF.Font.Bold = true; // 是否加楚
|
||
|
//titleXF.Font.Height = 20 * 20; // 字大小(字体大小是以 1/20 point 为单位的)
|
||
|
|
||
|
//// 列标题样式
|
||
|
//XF columnTitleXF = xls.NewXF(); // 为xls生成一个XF实例,XF是单元格格式对象
|
||
|
//columnTitleXF.HorizontalAlignment = HorizontalAlignments.Centered; // 设定文字居中
|
||
|
//columnTitleXF.VerticalAlignment = VerticalAlignments.Centered; // 垂直居中
|
||
|
//columnTitleXF.UseBorder = true; // 使用边框
|
||
|
//columnTitleXF.TopLineStyle = 1;
|
||
|
//columnTitleXF.TopLineColor = Colors.Black;
|
||
|
//columnTitleXF.BottomLineStyle = 1;
|
||
|
//columnTitleXF.BottomLineColor = Colors.Black;
|
||
|
//columnTitleXF.LeftLineStyle = 1;
|
||
|
//columnTitleXF.LeftLineColor = Colors.Black;
|
||
|
//columnTitleXF.RightLineStyle = 1;
|
||
|
//columnTitleXF.RightLineColor = Colors.Black;
|
||
|
//columnTitleXF.Pattern = 1; // 单元格填充风格。如果设定为0,则是纯色填充(无色),1代表没有间隙的实色
|
||
|
//columnTitleXF.PatternBackgroundColor = Colors.Red; // 填充的底色
|
||
|
//columnTitleXF.PatternColor = Colors.Default2F; // 填充背景色
|
||
|
|
||
|
//// 数据单元格样式
|
||
|
//XF dataXF = xls.NewXF(); // 为xls生成一个XF实例,XF是单元格格式对象
|
||
|
//dataXF.HorizontalAlignment = HorizontalAlignments.Centered; // 设定文字居中
|
||
|
//dataXF.VerticalAlignment = VerticalAlignments.Centered; // 垂直居中
|
||
|
//dataXF.UseBorder = true; // 使用边框
|
||
|
//dataXF.TopLineStyle = 1;
|
||
|
//dataXF.TopLineColor = Colors.Black;
|
||
|
//dataXF.BottomLineStyle = 1;
|
||
|
//dataXF.BottomLineColor = Colors.Black;
|
||
|
//dataXF.LeftLineStyle = 1;
|
||
|
//dataXF.LeftLineColor = Colors.Black;
|
||
|
//dataXF.RightLineStyle = 1;
|
||
|
//dataXF.RightLineColor = Colors.Black;
|
||
|
//dataXF.Font.FontName = "宋体";
|
||
|
//dataXF.Font.Height = 9 * 20; // 设定字大小(字体大小是以 1/20 point 为单位的)
|
||
|
//dataXF.UseProtection = false; // 默认的就是受保护的,导出后需要启用编辑才可修改
|
||
|
//dataXF.TextWrapRight = true; // 自动换行
|
||
|
//Worksheet sheet = xls.Workbook.Worksheets.Add("喷涂检测记录");
|
||
|
|
||
|
////设定列
|
||
|
ArrayList col;
|
||
|
List<ArrayList> listColumn = new List<ArrayList>();
|
||
|
col = new ArrayList() { 25, "条码", "barcode" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "A/B侧", "side" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "位置", "position" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "班次", "workClass" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "产品信息", "productInfo" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "生产模式", "productOption" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "一次结果", "inspectResult_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "一次缺陷位置", "damnPosition_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "一次缺陷原因", "reason_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 20, "一次时间", "createTime_1" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "二次结果", "inspectResult_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "二次缺陷位置", "damnPosition_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "二次缺陷原因", "reason_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 20, "二次时间", "createTime_2" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "三次结果", "inspectResult_3" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 10, "三次缺陷位置", "damnPosition_3" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 30, "三次缺陷原因", "reason_3" };
|
||
|
listColumn.Add(col);
|
||
|
col = new ArrayList() { 20, "三次时间", "createTime_3" };
|
||
|
listColumn.Add(col);
|
||
|
|
||
|
|
||
|
//for (int i = 0; i < listColumn.Count; i++)
|
||
|
//{
|
||
|
// ArrayList c = listColumn[i];
|
||
|
// ColumnInfo colinfo = new ColumnInfo(xls, sheet);
|
||
|
// int w = (int)c[0];
|
||
|
// string s = (string)c[1];
|
||
|
// colinfo.ColumnIndexStart = (ushort)i;
|
||
|
// colinfo.ColumnIndexEnd = (ushort)i;
|
||
|
// colinfo.Width = (ushort)(w * 256);
|
||
|
// sheet.AddColumnInfo(colinfo);
|
||
|
//}
|
||
|
|
||
|
|
||
|
//org.in2bits.MyXls.
|
||
|
|
||
|
|
||
|
////行设置
|
||
|
//RowInfo rolinfo = new RowInfo();
|
||
|
//rolinfo.RowHeight = 16 * 20; //行高
|
||
|
//rolinfo.RowIndexStart = 3; //起始行,从1开始计算
|
||
|
//rolinfo.RowIndexEnd = (ushort)(list.Count + 2); //结束行
|
||
|
//sheet.AddRowInfo(rolinfo);
|
||
|
|
||
|
////设置表头
|
||
|
//MergeArea titleArea = new MergeArea(1, 1, 1, listColumn.Count);
|
||
|
//sheet.AddMergeArea(titleArea); //合并单元格
|
||
|
//Cells cells = sheet.Cells;
|
||
|
////Sheet标题行,行和列的索引都是从1开始的
|
||
|
//for (int i = 0; i < listColumn.Count; i++)
|
||
|
// cells.Add(1, i + 1, "", titleXF); //合并单元格后仍需要设置每一个单元格,样式才有效
|
||
|
//sheet.Rows[1].RowHeight = 40 * 20; //设置标题行行高
|
||
|
//cells.Add(1, 1, "喷涂检测记录", titleXF); //标题内容
|
||
|
|
||
|
//for (int i = 0; i < listColumn.Count; i++) //设置表头行
|
||
|
//{
|
||
|
// ArrayList c = listColumn[i];
|
||
|
// string s = (string)c[1];
|
||
|
// cells.Add(2, i + 1, s, columnTitleXF);
|
||
|
//}
|
||
|
//sheet.Rows[2].RowHeight = 18 * 20; //设置表头行高
|
||
|
|
||
|
////数据写入cell
|
||
|
//Int32 k = 0;
|
||
|
|
||
|
|
||
|
//xls.Send();
|
||
|
//Response.End();
|
||
|
|
||
|
|
||
|
XSSFWorkbook book = new XSSFWorkbook();
|
||
|
ISheet sheet = book.CreateSheet("Sheet1");
|
||
|
|
||
|
IRow row = sheet.CreateRow(0);
|
||
|
for (int i = 0; i < listColumn.Count; i++) //设置表头行
|
||
|
{
|
||
|
ArrayList c = listColumn[i];
|
||
|
string s = (string)c[1];
|
||
|
row.CreateCell(i).SetCellValue(s);
|
||
|
}
|
||
|
row.Height = 16 * 20;
|
||
|
|
||
|
int row_num = 1;
|
||
|
foreach (var item in list)
|
||
|
{
|
||
|
IRow rowBody = sheet.CreateRow(row_num);
|
||
|
for (Int32 j = 0; j < listColumn.Count; j++)
|
||
|
{
|
||
|
ArrayList c = listColumn[j];
|
||
|
string strColName = (string)c[2];
|
||
|
string s = GetModelValue(strColName, item);
|
||
|
rowBody.CreateCell(j).SetCellValue(s);
|
||
|
}
|
||
|
row_num++;
|
||
|
}
|
||
|
|
||
|
// 写入到客户端
|
||
|
MemoryStream ms = new MemoryStream();
|
||
|
book.Write(ms);
|
||
|
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
|
||
|
Response.BinaryWrite(ms.ToArray());
|
||
|
book = null;
|
||
|
ms.Close();
|
||
|
ms.Dispose();
|
||
|
}
|
||
|
|
||
|
|
||
|
public string GetModelValue(string FieldName, object obj)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
Type Ts = obj.GetType();
|
||
|
object o = Ts.GetProperty(FieldName).GetValue(obj, null);
|
||
|
string Value = Convert.ToString(o);
|
||
|
if (string.IsNullOrEmpty(Value)) return null;
|
||
|
return Value;
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|