geboshi_V1/LeatherProject/LeatherApp/Page/FReport.cs

1424 lines
69 KiB
C#
Raw Normal View History

2024-12-18 10:44:17 +08:00
using CCWin.Win32.Const;
using ClosedXML.Excel;
2024-03-07 14:03:22 +08:00
using LeatherApp.Utils;
using Models;
using Newtonsoft.Json.Linq;
using Service;
using SqlSugar;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LeatherApp.Page
{
public partial class FReport : UIPage
{
RecordsService service=new RecordsService();
2024-05-21 14:22:10 +08:00
ProductService productService =new ProductService();
2024-03-07 14:03:22 +08:00
public FReport( )
{
InitializeComponent();
uiDatePicker1.Value = DateTime.Now.AddMonths(-1);
uiDatePicker2.Value=DateTime.Now;
this.lineChartDefect.Size = new Size(600,800);
this.lineChartFaceWidth.Size = new Size(1000, 300);
#region dataGridView设置
uiDataGridView1.AutoGenerateColumns = false;//自动创建列
uiDataGridView1.AllowUserToAddRows = uiDataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
uiDataGridView1.AllowUserToResizeRows = true;//用户调整行大小
uiDataGridView1.AllowUserToResizeColumns = true;//用户调整行大小
//uiDataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
2024-03-07 14:03:22 +08:00
uiDataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//只可选中整行,不是单元格
//显示行号与列宽度自动调整
uiDataGridView1.RowHeadersVisible = true;
uiDataGridView1.RowHeadersWidth = 30;
uiDataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
uiDataGridView1.RowPostPaint += (sender, e) =>//序号列头
{
Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.uiDataGridView1, sender, e);
};
uiDataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
//for (int i = 0; i < dataGridView1.Columns.Count; i++)//禁止点击列头排序
// uiDataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
//行列交叉处标题
//if (uiDataGridView1.RowHeadersVisible) uiDataGridView1.TopLeftHeaderCell.Value = "SPH/CYL";
//事件
this.uiDataGridView1.DataBindingComplete += this.uiDataGridView1_DataBindingComplete;//bing data时发生可修改单元格内容
//this.uiDataGridView1.SelectIndexChange += uiDataGridView1_SelectIndexChange;//选择行时发行
//this.uiDataGridView1.CellClick += UiDataGridView1_CellClick;
#endregion
#region
this.uiPagination1.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.uiPagination1_PageChanged);
//设置分页控件每页数量
uiPagination1.PageSize = 25;
2024-03-07 14:03:22 +08:00
//设置统计绑定的表格
//uiDataGridViewFooter1.DataGridView = uiDataGridView1;
//激活第1第触发uiPagination1_PageChanged
uiPagination1.ActivePage = 1;
#endregion
}
private Expression<Func<Records, bool>> createQueryExpression()
{
return Expressionable.Create<Records>()
.And(it => it.CreateTime >= uiDatePicker1.Value.SetTime(0,0,0))
.And(it => it.CreateTime < uiDatePicker2.Value.SetTime(0, 0, 0).AddDays(1))
.AndIF(!string.IsNullOrWhiteSpace(txtBarcode.Text), it => it.BarCode.Contains(txtBarcode.Text.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(txtBatchId.Text), it => it.BatchId.Contains(txtBatchId.Text.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(txtReelId.Text), it => it.ReelId.Contains(txtReelId.Text.Trim()))
.AndIF(!string.IsNullOrWhiteSpace(txtWorkT.Text), it => it.WorkTeam.Contains(txtWorkT.Text.Trim()))
2024-03-07 14:03:22 +08:00
.ToExpression();//注意 这一句 不能少
}
private Expression<Func<Records, bool>> createQueryExpressionByToDay()
{
return Expressionable.Create<Records>()
.And(it => it.CreateTime >= DateTime.Now.SetTime(0, 0, 0))
.And(it => it.CreateTime < DateTime.Now.SetTime(0, 0, 0).AddDays(1))
.ToExpression();//注意 这一句 不能少
}
public void GetToDayLen()
{
//int totalCount = 0;
//double len = 0;
//int listcnt = 0;
//var list = service.GetListNav(1, 1000, ref totalCount, createQueryExpressionByToDay());
//if(list != null && list.Count > 0)
//{
// listcnt = list.Count;
// foreach (var item in list)
// {
// len += item.Len;
// }
//}
//txtAllLen.Text = $"卷数:{listcnt},米数:{Math.Round(len, 2)}";
}
2024-03-07 14:03:22 +08:00
/// <summary>
/// 分页控件页面切换事件
/// </summary>
/// <param name="sender"></param>
/// <param name="pagingSource"></param>
/// <param name="pageIndex"></param>
/// <param name="count"></param>
private void uiPagination1_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
//未连接数据库,通过模拟数据来实现
//一般通过ORM的分页去取数据来填充
//pageIndex第几页和界面对应从1开始取数据可能要用pageIndex
//count单页数据量也就是PageSize值
int totalCount = 0;
var list = service.GetListNav(pageIndex , count, ref totalCount, createQueryExpression());
uiDataGridView1.DataSource = list;
uiPagination1.TotalCount = totalCount;
double len = 0;
int listcnt = 0;
var list2 = service.GetListNav(1, 10000, ref totalCount, createQueryExpression());
if (list2 != null && list2.Count > 0)
{
listcnt = list2.Count;
foreach (var item in list2)
{
len += item.Len;
}
}
txtAllLen.Text = $"卷数:{listcnt},米数:{Math.Round(len, 2)}";
2024-03-07 14:03:22 +08:00
//表脚合计
//uiDataGridViewFooter1.Clear();
//uiDataGridViewFooter1["Column1"] = "合计:";
//uiDataGridViewFooter1["Column2"] = "Column2_" + pageIndex;
//uiDataGridViewFooter1["Column3"] = "Column3_" + pageIndex;
//uiDataGridViewFooter1["Column4"] = "Column4_" + pageIndex;
//
//this.uiDataGridView1.CurrentCell = null;
//this.uiDataGridView1.ClearSelection();
}
private void uiDataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
var list = uiDataGridView1.DataSource as List<Records>;
for (int i = 0; i < uiDataGridView1.Rows.Count; i++)
{
if (Config.CustomerName == "XCL")
{
if (list[i].Grade < 1) uiDataGridView1.Rows[i].Cells["colGrade"].Value = "一等品";
else if (list[i].Grade <= 5)
{
if(list[i].Grade == 1)
uiDataGridView1.Rows[i].Cells["colGrade"].Value = "一等品";
else if (list[i].Grade == 5)
uiDataGridView1.Rows[i].Cells["colGrade"].Value = "废品";
else uiDataGridView1.Rows[i].Cells["colGrade"].Value = "二等品";
}
else uiDataGridView1.Rows[i].Cells["colGrade"].Value = "二等品";
}
else
{
if (list[i].Grade < 1) uiDataGridView1.Rows[i].Cells["colGrade"].Value = "";
else if (list[i].Grade <= 5) uiDataGridView1.Rows[i].Cells["colGrade"].Value = (char)(list[i].Grade + 64);
else uiDataGridView1.Rows[i].Cells["colGrade"].Value = "不合格";
}
2024-03-07 14:03:22 +08:00
//if (list[i].RoleInfo != null)
// uiDataGridView1.Rows[i].Cells["colRoleName"].Value = list[i].RoleInfo.Name;
}
}
private void btnQuery_Click(object sender, EventArgs e)
{
uiPagination1.ActivePage = 1;
}
private void btnExport_Click(object sender, EventArgs e)
{
2024-08-05 09:39:58 +08:00
int err = 0;
2024-03-07 14:03:22 +08:00
try
{
2024-08-05 09:39:58 +08:00
2024-03-07 14:03:22 +08:00
if (this.uiDataGridView1.CurrentRow == null)
return;
Models.Records record = service.GetModelNav(int.Parse(this.uiDataGridView1.CurrentRow.Cells[0].Value.ToString()));
if (record.DefectInfoList.Count < 0)
throw new Exception("当前记录无缺陷!");
string path = FileUtil.selectFolder();
if (string.IsNullOrWhiteSpace(path))
return;
2024-08-05 09:39:58 +08:00
err = 1;
//获取对应产品信息
var pdt = productService.GetModelNav(record.ProductId);
JArray defectLabelList;
Config.LoadModelDefectItemList(pdt.ModelName, out defectLabelList);
2024-03-07 14:03:22 +08:00
//var list = uiDataGridView1.DataSource as List<Records>;
//var table = ExcelUtil.ConvertToDataTable<Records>(list);
//{ 名称=x.Name,Xcm=x.X,Ym=x.Y/100,宽cm=x.Width,高cm=x.Height,面积=x.Area, 置信度 =x.ZXD}
var list = record.DefectInfoList;//.Select(x => new { x.Name,x.X,x.Y,x.Width,x.Height,x.Area, x.ZXD}).ToList();
//绘图0
ucColorListDefect.initData(defectLabelList);
2024-03-07 14:03:22 +08:00
//绘图1
double len = Math.Round(record.Len*100, 2);//cm
this.reDrawDefectPoints(pdt.ModelName, record.DefectInfoList, new double[] { 0, Math.Round(record.FaceWidthMax + 0.005f, 2) }, new double[] { 0, len });
2024-08-05 09:39:58 +08:00
err = 2;
2024-03-07 14:03:22 +08:00
//绘图2
//var points = Array.ConvertAll(record.FaceWidthListStr.Split(new[] { ',', }, StringSplitOptions.RemoveEmptyEntries),Double.Parse).ToList();
2024-04-28 14:05:46 +08:00
//reDrawFaceWidth(record.FacePointList,
// new double[] { 0, Math.Round(len + 0.005f, 2) },
// new double[] { record.FaceWidthMin, Math.Round(record.FaceWidthMax + 0.005f, 2) });
double miny = record.FaceWidthMin > 130 ? 130 : record.FaceWidthMin;
double maxy = Math.Round(record.FaceWidthMax + 0.005f, 2) > 160 ? Math.Round(record.FaceWidthMax + 0.005f, 2) : 160;
2024-03-07 14:03:22 +08:00
reDrawFaceWidth(record.FacePointList,
new double[] { 0, Math.Round(len + 0.005f, 2) },
new double[] { miny, maxy });
if (record.ThicknessList != null && record.ThicknessList.Count > 0)
{
List<double> hdMax = new List<double>(){
record.ThicknessList.Select(t=> t.Value1).ToList().Max(),
record.ThicknessList.Select(t => t.Value2).ToList().Max(),
record.ThicknessList.Select(t => t.Value3).ToList().Max(),
};
List<double> hdMin = new List<double>(){
record.ThicknessList.Select(t=> t.Value1).ToList().Min(),
record.ThicknessList.Select(t => t.Value2).ToList().Min(),
record.ThicknessList.Select(t => t.Value3).ToList().Min(),
};
reDrawHouDu(record.ThicknessList,
new double[] { 0, Math.Round(len + 0.005f, 2) },
new double[] { (hdMin.Min()-0.1) <=0? 0: (hdMin.Min() - 0.1),
(hdMax.Max() + 0.1)> 5?5: (hdMax.Max() + 0.1) });
}
2024-08-05 09:39:58 +08:00
err = 3;
2024-03-07 14:03:22 +08:00
//
foreach (var item in list) {
item.Name = Config.getDefectName(pdt.ModelName, item.Code);
2024-03-07 14:03:22 +08:00
//item.Height = item.Height / 100; //单位错误,保证单位一致
}
2024-08-05 09:39:58 +08:00
err = 4;
2024-03-07 14:03:22 +08:00
//
string Grade = "";
if (Config.CustomerName != "XCL")
{
if (record.Grade < 1) Grade = "";
else if (record.Grade <= 5) Grade = (char)(record.Grade + 64) + "";
else Grade = "不合格";
}
else
{
if (record.Grade < 1) Grade = "一等品";
else if (record.Grade <= 5)
{
if(record.Grade == 1)
Grade = "一等品";
else if (record.Grade == 5)
Grade = "废品";
else
Grade = "二等品";
}
else Grade = "二等品";
}
2024-03-07 14:03:22 +08:00
JsonProductDefects data = new JsonProductDefects()
{
ProName = record.BarCodeName,
BatchId = record.BatchId,
ReelId = string.IsNullOrEmpty(record.PartReelId) ? "'" + record.ReelId : $"{record.ReelId}-{record.PartReelId}",
2024-03-07 14:03:22 +08:00
Len = record.Len.ToString(),
Speed = Math.Round(record.Len / record.TimeLen, 2).ToString(),
Grade= Grade,
DateTime = record.CreateTime.ToString("yyyy年MM月dd日 HH:mm"),
UserName = record.UserName,
WorkTeam = record.WorkTeam,
PartNote1 = record.PartReelNote,
PartNote2 = record.PartReelNote2,
2024-03-07 14:03:22 +08:00
};
2024-08-05 09:39:58 +08:00
err = 5;
2024-03-07 14:03:22 +08:00
data.DefectTotal = record.DefectInfoList.GroupBy(x => x.Name).Select(g => new JDefectTotal { Name = g.Key,Count=g.Count() }).ToList();
data.DefectDetail = record.DefectInfoList.Select(x => new JDefectDetail {
Index=x.PhotoIndex,Name=x.Name, X=x.X,Y=Math.Round(x.Y/100.0d,2),Width=x.Width * 10,Height=x.Height * 10,ZXD=x.ZXD,Area=x.Area * 100,Contrast=x.Contrast })
2024-03-07 14:03:22 +08:00
.OrderBy(x=>x.Index).ThenBy(x=>x.Y).ToList();
data.FaceWidthDetail = record.FacePointList.Select(x => new JFaceWidthDetail
{
Y = x[0],
data = x[1],
}).OrderBy(x => x.Y).ThenBy(x => x.Y).ToList();
data.ThicknessDetail = record.ThicknessList.Select(x => new JThicknessDetail
{
Y = x.Y_Dis,
d1 = x.Value1,
d2 = x.Value2,
d3 = x.Value3,
}).OrderBy(x => x.Y).ThenBy(x => x.Y).ToList();
2024-08-05 09:39:58 +08:00
err = 6;
2024-05-21 14:22:10 +08:00
data.Pdt = productService.GetModelNav(record.ProductId);
data.xyPix = $"X:{Config.cm2px_x},Y:{Config.cm2px_y}";
2024-08-05 09:39:58 +08:00
err = 7;
var image0 = captureControl2(this.ucColorListDefect.Controls[0]);
2024-03-07 14:03:22 +08:00
var image1 = captureControl(this.lineChartDefect);
2024-04-28 14:05:46 +08:00
var image2 = captureControl(this.lineChartFaceWidth);
var image3 = captureControl(this.lineChartHouDu);
2024-03-07 14:03:22 +08:00
var filePath = $"{path}缺陷列表_{record.BatchId}_{record.ReelId}.xlsx";
2024-08-05 09:39:58 +08:00
err = 8;
exportTabel(data, image0, image1, image2, image3, filePath);
2024-03-07 14:03:22 +08:00
//if (!res)
// throw new Exception("导出失败!");
UIMessageTip.ShowOk("导出成功!", 1000);
System.Diagnostics.Process.Start(filePath);
}
catch (Exception ex)
{
2024-08-05 09:39:58 +08:00
UIMessageTip.ShowError($"err:{err} + {ex.Message}", 2000);
2024-03-07 14:03:22 +08:00
API.OutputDebugString(ex.StackTrace);
}
}
private void btnExport_Click1(object sender, EventArgs e)
{
try
{
if (this.uiDataGridView1.CurrentRow == null)
return;
Models.Records record = service.GetModelNav(int.Parse(this.uiDataGridView1.CurrentRow.Cells[0].Value.ToString()));
if (record.DefectInfoList.Count < 0)
throw new Exception("当前记录无缺陷!");
string path = FileUtil.selectFolder();
if (string.IsNullOrWhiteSpace(path))
return;
var pdt = productService.GetModelNav(record.ProductId);
2024-03-07 14:03:22 +08:00
//var list = uiDataGridView1.DataSource as List<Records>;
//var table = ExcelUtil.ConvertToDataTable<Records>(list);
//{ 名称=x.Name,Xcm=x.X,Ym=x.Y/100,宽cm=x.Width,高cm=x.Height,面积=x.Area, 置信度 =x.ZXD}
var list = record.DefectInfoList;//.Select(x => new { x.Name,x.X,x.Y,x.Width,x.Height,x.Area, x.ZXD}).ToList();
foreach (var item in list)
{
item.Name = Config.getDefectName(pdt.ModelName, item.Code);
2024-03-07 14:03:22 +08:00
item.Height = item.Height / 100;
}
var table = ExcelUtil.ConvertToDataTable<DefectInfo>(list, new List<string> { "PhotoIndex", "Name", "ZXD", "Contrast", "X", "Y", "Width", "Height", "Area" });
for (int i = 0; i < table.Columns.Count; i++)
{
switch (table.Columns[i].ColumnName)
{
case "PhotoIndex":
table.Columns[i].ColumnName = "源图";
break;
case "Name":
table.Columns[i].ColumnName = "名称";
break;
case "ZXD":
table.Columns[i].ColumnName = "置信度";
break;
case "Contrast":
table.Columns[i].ColumnName = "对比度";
break;
case "X":
table.Columns[i].ColumnName = "X(cm)";
break;
case "Y":
table.Columns[i].ColumnName = "Y(cm)";
break;
case "Width":
table.Columns[i].ColumnName = "宽(cm)";
break;
case "Height":
table.Columns[i].ColumnName = "长度(米)";
break;
case "Area":
table.Columns[i].ColumnName = "面积cm^2)";
break;
}
}
ExcelUtil.DataTable2CSV($"{path}\\缺陷列表_{record.BarCodeName}.csv", table);
UIMessageTip.ShowOk("导出成功!", 1000);
}
catch (Exception ex)
{
UIMessageTip.ShowError(ex.Message, 2000);
}
}
public void exportTabel(JsonProductDefects ProductDefects, byte[] defectlabelImage, byte[] defectImage, byte[] faceWidthImage, byte[] HouduImage, string savePath)
2024-03-07 14:03:22 +08:00
{
//try
//{
if (ProductDefects == null)
throw new Exception("传入的参数为空");
using (var workbook = new XLWorkbook())
{
#region
2024-03-07 14:03:22 +08:00
var wsDefectsDetail = workbook.Worksheets.Add("正面疵点列表");
wsDefectsDetail.RowHeight = 20;
wsDefectsDetail.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wsDefectsDetail.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
wsDefectsDetail.Style.Font.FontName = "宋体";
wsDefectsDetail.Column("A").Width = 12;
wsDefectsDetail.Column("B").Width = 25;
wsDefectsDetail.Column("C").Width = 10;
wsDefectsDetail.Column("D").Width = 10;
wsDefectsDetail.Column("E").Width = 10;
wsDefectsDetail.Column("F").Width = 10;
wsDefectsDetail.Column("G").Width = 12;
wsDefectsDetail.Column("H").Width = 14;
wsDefectsDetail.Column("I").Width = 14;
int rowIndex = 1;
int cellIndex = 1;
#region
var row1_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row1_cell1.Value = "产品疵点缺陷分布图表";
row1_cell1.Style.Font.Bold = true;
//row1_cell1.Style.Font.FontName = "宋体";
row1_cell1.Style.Font.FontSize = 12;
var mergeRange_row1 = wsDefectsDetail.Range("A1:I1").Row(1).Merge();
mergeRange_row1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
#endregion
#region
rowIndex++;
var row2_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row2_cell1.Value = "产品品名";
row2_cell1.Style.Font.Bold = true;
row2_cell1.Style.Font.FontSize = 10;
row2_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row2_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row2_cell2.DataType = XLDataType.Text;
row2_cell2.Value = ProductDefects.ProName;
row2_cell2.Style.Font.FontSize = 10;
row2_cell2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row2_cell3 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 2);
row2_cell3.Value = "产品批号";
row2_cell3.Style = row2_cell1.Style;
var row2_cell4 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 3);
row2_cell4.Value = "'" + ProductDefects.BatchId;
row2_cell4.Style = row2_cell2.Style;
var row2_cell5 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 4);
row2_cell5.Value = "产品卷号";
row2_cell5.Style = row2_cell1.Style;
var row2_cell6 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 5);
//row2_cell6.SetDataType(XLDataType.Text);//类型设置不起作用 用"'"+内容代替
//row2_cell6.DataType = XLDataType.Text;
row2_cell6.Value = ProductDefects.ReelId;
2024-03-07 14:03:22 +08:00
row2_cell6.Style = row2_cell2.Style;
var row2_cell7 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 6);
row2_cell7.Value = "长度(米)";
row2_cell7.Style = row2_cell1.Style;
var row2_cell8 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 7);
row2_cell8.Value = ProductDefects.Len;
row2_cell8.Style = row2_cell2.Style;
//操作员
2024-03-07 14:03:22 +08:00
var row2_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row2_cell9.Value = "操作员";
2024-03-07 14:03:22 +08:00
row2_cell9.Style = row2_cell2.Style;
#endregion
#region
rowIndex++;
var row3_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row3_cell1.Value = "检验时间";
row3_cell1.Style = row2_cell1.Style;
var row3_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row3_cell2.Value = "'" + ProductDefects.DateTime;
row3_cell2.Style = row2_cell2.Style;
var row3_cell3 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 2);
row3_cell3.Value = "检验长度";
row3_cell3.Style = row2_cell1.Style;
var row3_cell4 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 3);
row3_cell4.Value = ProductDefects.Len;
row3_cell4.Style = row2_cell2.Style;
var row3_cell5 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 4);
row3_cell5.Value = "平均速度";
row3_cell5.Style = row2_cell1.Style;
var row3_cell6 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 5);
row3_cell6.Value = ProductDefects.Speed;
row3_cell6.Style = row2_cell2.Style;
var row3_cell7 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 6);
row3_cell7.Value = "等级";
row3_cell7.Style = row2_cell1.Style;
var row3_cell8 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 7);
row3_cell8.Value = ProductDefects.Grade;
row3_cell8.Style = row2_cell2.Style;
var row3_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row3_cell9.Value = ProductDefects.UserName == null ? "": ProductDefects.UserName;
2024-03-07 14:03:22 +08:00
row3_cell9.Style = row2_cell2.Style;
#endregion
2024-05-21 14:22:10 +08:00
#region
rowIndex++;
var row4_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row4_cell1.Value = "设备参数";
row4_cell1.Style = row2_cell1.Style;
row4_cell1.Style.Font.Bold = true;
row4_cell1.Style.Font.FontSize = 10;
row4_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var mergeRange_row4 = wsDefectsDetail.Range("A4:A5").Column(1).Merge();
mergeRange_row4.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row4_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row4_cell2.Value = "光源亮度";
row4_cell2.Style = row2_cell1.Style;
var row4_cell3 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 2);
row4_cell3.Value = "曝光时间";
row4_cell3.Style = row2_cell1.Style;
var row4_cell4 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 3);
row4_cell4.Value = "增益";
row4_cell4.Style = row2_cell1.Style;
var row4_cell5 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 4);
row4_cell5.Value = "行频比";
row4_cell5.Style = row2_cell1.Style;
var row4_cell6 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 5);
row4_cell6.Value = "物面分辨率";
row4_cell6.Style = row2_cell1.Style;
var row4_cell7 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 6);
row4_cell7.Value = "触发计数";
row4_cell7.Style = row2_cell1.Style;
var row4_cell8 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 7);
row4_cell8.Value = "采集计数";
row4_cell8.Style = row2_cell1.Style;
var row4_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row4_cell9.Value = "班组";
2024-05-21 14:22:10 +08:00
row4_cell9.Style = row2_cell1.Style;
2024-03-07 14:03:22 +08:00
rowIndex++;
2024-05-21 14:22:10 +08:00
var row5_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row5_cell2.Value = ProductDefects.Pdt.LightValue;
row5_cell2.Style = row2_cell1.Style;
var row5_cell3 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 2);
row5_cell3.Value = ProductDefects.Pdt.ExposureTime;
row5_cell3.Style = row2_cell1.Style;
var row5_cell4 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 3);
row5_cell4.Value = ProductDefects.Pdt.Gain;
row5_cell4.Style = row2_cell1.Style;
var row5_cell5 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 4);
row5_cell5.Value = "";
row5_cell5.Style = row2_cell1.Style;
var row5_cell6 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 5);
row5_cell6.Value = ProductDefects.xyPix;
row5_cell6.Style = row2_cell1.Style;
var row5_cell7 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 6);
row5_cell7.Value = "";
row5_cell7.Style = row2_cell1.Style;
var row5_cell8 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 7);
row5_cell8.Value = "";
row5_cell8.Style = row2_cell1.Style;
var row5_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row5_cell9.Value = ProductDefects.WorkTeam == null? "": ProductDefects.WorkTeam;
2024-05-21 14:22:10 +08:00
row5_cell9.Style = row2_cell1.Style;
#endregion
2024-03-07 14:03:22 +08:00
#region
rowIndex++;
2024-12-18 10:44:17 +08:00
wsDefectsDetail.Rows(6, 6).Height = 50; // 重新设置高度
var row6_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row6_cell1.Value = "检测结论";
row6_cell1.Style = row2_cell1.Style;
row6_cell1.Style.Font.Bold = true;
row6_cell1.Style.Font.FontSize = 10;
row6_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row6_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row6_cell2.Value = ProductDefects.PartNote1 == null ? "" : ProductDefects.PartNote1;
row6_cell2.Style.Font.Bold = true;
row6_cell2.Style.Font.FontSize = 10;
row6_cell2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var mergeRange_row6 = wsDefectsDetail.Range("B6:I6").Row(1).Merge();
mergeRange_row6.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-12-18 10:44:17 +08:00
mergeRange_row6.Style.Alignment.SetWrapText(true); //设置自动换行
rowIndex++;
var row7_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row7_cell1.Value = "分卷结论";
row7_cell1.Style = row2_cell1.Style;
row7_cell1.Style.Font.Bold = true;
row7_cell1.Style.Font.FontSize = 10;
row7_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row7_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row7_cell2.Value = ProductDefects.PartNote2 == null? "": ProductDefects.PartNote2;
row7_cell2.Style.Font.Bold = true;
row7_cell2.Style.Font.FontSize = 10;
row7_cell2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var mergeRange_row7 = wsDefectsDetail.Range("B7:I7").Row(1).Merge();
mergeRange_row7.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
#endregion
#region
2024-05-21 14:22:10 +08:00
rowIndex++;
2024-03-07 14:03:22 +08:00
if (ProductDefects.DefectTotal != null && ProductDefects.DefectTotal.Count > 0)
{
cellIndex = 1;
int DefectTotalCount = ProductDefects.DefectTotal.Count;
//最少5行固定4列
var row8_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
2024-03-07 14:03:22 +08:00
row8_cell1.Value = "检测参数";
row8_cell1.Style.Font.Bold = true;
row8_cell1.Style.Font.FontSize = 10;
row8_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-03-07 14:03:22 +08:00
string cellstr = $"A8:A{9 + ProductDefects.DefectTotal.Count}";
var mergeRange_row8 = wsDefectsDetail.Range(cellstr).Column(1).Merge();
mergeRange_row8.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-03-07 14:03:22 +08:00
var row8_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
2024-03-07 14:03:22 +08:00
row8_cell2.Value = "筛选标准";
row8_cell2.Style.Font.Bold = true;
row8_cell2.Style.Font.FontSize = 10;
row8_cell2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-03-07 14:03:22 +08:00
var mergeRange_row8_2 = wsDefectsDetail.Range($"B8:I8").Row(1).Merge();
mergeRange_row8_2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-03-07 14:03:22 +08:00
//第九行
2024-05-21 14:22:10 +08:00
rowIndex++;
var row9_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row9_cell2.Value = "缺陷类型";
row9_cell2.Style = row2_cell1.Style;
var row9_cell3 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 2);
row9_cell3.Value = "置信度";
row9_cell3.Style = row2_cell1.Style;
var row9_cell4 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 3);
row9_cell4.Value = "面积";
row9_cell4.Style = row2_cell1.Style;
var row9_cell5 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 4);
row9_cell5.Value = "对比度下限";
row9_cell5.Style = row2_cell1.Style;
var row9_cell6 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 5);
row9_cell6.Value = "对比度上限";
row9_cell6.Style = row2_cell1.Style;
var row9_cell7 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 6);
row9_cell7.Value = "所用模型版本";
row9_cell7.Style = row2_cell1.Style;
var row9_cell8 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 7);
row9_cell8.Value = "或向选择";
row9_cell8.Style = row2_cell1.Style;
var row9_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row9_cell9.Value = "本次检出数量";
row9_cell9.Style = row2_cell1.Style;
//第十行之后
2024-05-21 14:22:10 +08:00
rowIndex++;
for (int j = 1; j <= ProductDefects.DefectTotal.Count; j++) // 行
{
var temprowcel2 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 1);
var temprowcel3 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 2);
var temprowcel4 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 3);
var temprowcel5 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 4);
var temprowcel6 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 5);
var temprowcel7 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 6);
var temprowcel8 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 7);
var temprowcel9 = wsDefectsDetail.Row(rowIndex + j - 1).Cell(cellIndex + 8);
var tempItemDefectTotal = ProductDefects.DefectTotal[j - 1];
temprowcel2.Value = tempItemDefectTotal.Name;
temprowcel2.Style.Font.Bold = true;
temprowcel2.Style.Font.FontSize = 10;
temprowcel2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var temp = ProductDefects.Pdt.QualifiedLimitList.Find(x => Config.getDefectName(ProductDefects.Pdt.ModelName, x.Code) == tempItemDefectTotal.Name);
if (temp != null)
{
temprowcel3.Value = temp.ZXD;
temprowcel3.Style.Font.Bold = true;
temprowcel3.Style.Font.FontSize = 10;
temprowcel3.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel4.Value = temp.Area;
temprowcel4.Style.Font.Bold = true;
temprowcel4.Style.Font.FontSize = 10;
temprowcel4.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel5.Value = ContrastToPercent(temp.ContrastLower);
temprowcel5.Style.Font.Bold = true;
temprowcel5.Style.Font.FontSize = 10;
temprowcel5.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel6.Value = ContrastToPercent(temp.ContrastTop);
temprowcel6.Style.Font.Bold = true;
temprowcel6.Style.Font.FontSize = 10;
temprowcel6.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel7.Value = ProductDefects.Pdt.ModelName;
temprowcel7.Style.Font.Bold = true;
temprowcel7.Style.Font.FontSize = 10;
temprowcel7.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel8.Value = temp.IsOR;
temprowcel8.Style.Font.Bold = true;
temprowcel8.Style.Font.FontSize = 10;
temprowcel8.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
2024-05-21 14:22:10 +08:00
temprowcel9.Value = tempItemDefectTotal.Count;
temprowcel9.Style.Font.FontSize = 10;
temprowcel9.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
2024-05-21 14:22:10 +08:00
//更新行号
rowIndex = rowIndex + ProductDefects.DefectTotal.Count;
2024-03-07 14:03:22 +08:00
}
#endregion
2024-05-21 14:22:10 +08:00
#region
2024-03-07 14:03:22 +08:00
//rowIndex++;
if (ProductDefects.DefectDetail != null && ProductDefects.DefectDetail.Count > 0)
{
List<string> lstRow5str = new List<string>() { "源图", "名称", "X(cm)", "Y(米)", "宽(mm)", "高(mm)", "置信度", "面积mm^2)", "对比度" };
2024-03-07 14:03:22 +08:00
for (int i = 0; i < lstRow5str.Count; i++)
{
var temp_row5_cell = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + i);
temp_row5_cell.Value = lstRow5str[i];
temp_row5_cell.Style.Font.Bold = true;
temp_row5_cell.Style.Font.FontSize = 11;
temp_row5_cell.Style.Font.FontName = "等线";
temp_row5_cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
rowIndex++;
for (int i = 0; i < ProductDefects.DefectDetail.Count; i++)
for (int j = 0; j < lstRow5str.Count; j++)
{
var temp_row6_cell = wsDefectsDetail.Row(rowIndex + i).Cell(cellIndex + j);
switch (lstRow5str[j])
{
case "源图":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Index;
break;
case "名称":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Name;
break;
case "X(cm)":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].X;
break;
case "Y(米)":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Y;
break;
2024-04-28 14:05:46 +08:00
case "宽(mm)":
2024-03-07 14:03:22 +08:00
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Width;
break;
2024-04-28 14:05:46 +08:00
case "高(mm)":
2024-03-07 14:03:22 +08:00
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Height;
break;
case "置信度":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].ZXD;
break;
2024-04-28 14:05:46 +08:00
case "面积mm^2)":
2024-03-07 14:03:22 +08:00
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Area;
break;
case "对比度":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Contrast;
break;
}
temp_row6_cell.Style.Font.FontSize = 11;
temp_row6_cell.Style.Font.FontName = "等线";
temp_row6_cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
// row6_cell1.InsertTable(ProductDefects.DefectDetail);
}
#endregion
#endregion
2024-03-07 14:03:22 +08:00
#region
2024-03-07 14:03:22 +08:00
var wsDefectsImg = workbook.Worksheets.Add("正面疵点分布图");
wsDefectsImg.AddPicture(new MemoryStream(defectlabelImage), "疵点label")
2024-03-07 14:03:22 +08:00
.MoveTo(wsDefectsImg.Cell(1, 1));
wsDefectsImg.AddPicture(new MemoryStream(defectImage), "纵向计算")
.MoveTo(wsDefectsImg.Cell(5, 1));
#endregion
2024-03-07 14:03:22 +08:00
#region 线&
2024-03-07 14:03:22 +08:00
var wsFaceWidthImg = workbook.Worksheets.Add("门幅曲线");
wsFaceWidthImg.AddPicture(new MemoryStream(faceWidthImage), "幅宽曲线图")
.MoveTo(wsFaceWidthImg.Cell(1, 4));
wsFaceWidthImg.RowHeight = 20;
wsFaceWidthImg.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wsFaceWidthImg.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
wsFaceWidthImg.Style.Font.FontName = "宋体";
rowIndex = 1;
cellIndex = 1;
wsFaceWidthImg.Column("A").Width = 15;
wsFaceWidthImg.Column("B").Width = 15;
#region
row1_cell1 = wsFaceWidthImg.Row(rowIndex).Cell(cellIndex);
row1_cell1.Value = "门幅数据详细列表";
row1_cell1.Style.Font.Bold = true;
row1_cell1.Style.Font.FontSize = 12;
mergeRange_row1 = wsFaceWidthImg.Range("A1:B1").Row(1).Merge();
mergeRange_row1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
#endregion
#region
rowIndex++;
row2_cell1 = wsFaceWidthImg.Row(rowIndex).Cell(cellIndex);
row2_cell1.Value = "Y计米距离(m)";
row2_cell1.Style.Font.Bold = true;
row2_cell1.Style.Font.FontSize = 10;
row2_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
row2_cell2 = wsFaceWidthImg.Row(rowIndex).Cell(cellIndex + 1);
row2_cell2.Value = "数据(cm)";
row2_cell2.Style = row2_cell1.Style;
#endregion
#region
//第八行之后
rowIndex++;
for (int j = 1; j <= ProductDefects.FaceWidthDetail.Count; j++) // 行
{
var temprowcel1 = wsFaceWidthImg.Row(rowIndex + j - 1).Cell(cellIndex + 0);
var temprowcel2 = wsFaceWidthImg.Row(rowIndex + j - 1).Cell(cellIndex + 1);
temprowcel1.Value = ProductDefects.FaceWidthDetail[j - 1].Y / 100;
temprowcel1.Style.Font.Bold = true;
temprowcel1.Style.Font.FontSize = 10;
temprowcel1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-03-07 14:03:22 +08:00
temprowcel2.Value = Math.Round(ProductDefects.FaceWidthDetail[j - 1].data, 3);
temprowcel2.Style.Font.Bold = true;
temprowcel2.Style.Font.FontSize = 10;
temprowcel2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
#endregion
#endregion
#region
var wsHouDuList = workbook.Worksheets.Add("测厚数据列表");
if (ProductDefects.ThicknessDetail != null && ProductDefects.ThicknessDetail.Count > 0)
{
wsHouDuList.AddPicture(new MemoryStream(HouduImage), "厚度曲线图")
.MoveTo(wsHouDuList.Cell(1, 6));
wsHouDuList.RowHeight = 20;
wsHouDuList.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wsHouDuList.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
wsHouDuList.Style.Font.FontName = "宋体";
rowIndex = 1;
cellIndex = 1;
wsHouDuList.Column("A").Width = 15;
wsHouDuList.Column("B").Width = 15;
wsHouDuList.Column("C").Width = 15;
wsHouDuList.Column("D").Width = 15;
2024-12-18 10:44:17 +08:00
wsHouDuList.Column("E").Width = 15;
#region
row1_cell1 = wsHouDuList.Row(rowIndex).Cell(cellIndex);
row1_cell1.Value = "测厚数据详细列表";
row1_cell1.Style.Font.Bold = true;
row1_cell1.Style.Font.FontSize = 12;
2024-12-18 10:44:17 +08:00
mergeRange_row1 = wsHouDuList.Range("A1:E1").Row(1).Merge();
mergeRange_row1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
#endregion
#region
rowIndex++;
row2_cell1 = wsHouDuList.Row(rowIndex).Cell(cellIndex);
row2_cell1.Value = "Y计米距离(m)";
row2_cell1.Style.Font.Bold = true;
row2_cell1.Style.Font.FontSize = 10;
row2_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
row2_cell2 = wsHouDuList.Row(rowIndex).Cell(cellIndex + 1);
2024-12-18 10:44:17 +08:00
row2_cell2.Value = Config.ThicknessNames.Split(',')[0];
row2_cell2.Style = row2_cell1.Style;
row2_cell3 = wsHouDuList.Row(rowIndex).Cell(cellIndex + 2);
2024-12-18 10:44:17 +08:00
row2_cell3.Value = Config.ThicknessNames.Split(',')[1];
row2_cell3.Style = row2_cell1.Style;
row2_cell4 = wsHouDuList.Row(rowIndex).Cell(cellIndex + 3);
2024-12-18 10:44:17 +08:00
row2_cell4.Value = Config.ThicknessNames.Split(',')[2];
row2_cell4.Style = row2_cell1.Style;
2024-12-18 10:44:17 +08:00
row2_cell5 = wsHouDuList.Row(rowIndex).Cell(cellIndex + 4);
row2_cell5.Value = "均值";
row2_cell5.Style = row2_cell1.Style;
#endregion
#region
//第八行之后
rowIndex++;
for (int j = 1; j <= ProductDefects.ThicknessDetail.Count; j++) // 行
{
var temprowcel1 = wsHouDuList.Row(rowIndex + j - 1).Cell(cellIndex + 0);
var temprowcel2 = wsHouDuList.Row(rowIndex + j - 1).Cell(cellIndex + 1);
var temprowcel3 = wsHouDuList.Row(rowIndex + j - 1).Cell(cellIndex + 2);
var temprowcel4 = wsHouDuList.Row(rowIndex + j - 1).Cell(cellIndex + 3);
2024-12-18 10:44:17 +08:00
var temprowcel5 = wsHouDuList.Row(rowIndex + j - 1).Cell(cellIndex + 4);
temprowcel1.Value = ProductDefects.ThicknessDetail[j - 1].Y / 100;
temprowcel1.Style.Font.Bold = true;
temprowcel1.Style.Font.FontSize = 10;
temprowcel1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel2.Value = ProductDefects.ThicknessDetail[j - 1].d1;
temprowcel2.Style.Font.Bold = true;
temprowcel2.Style.Font.FontSize = 10;
temprowcel2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel3.Value = ProductDefects.ThicknessDetail[j - 1].d2;
temprowcel3.Style.Font.Bold = true;
temprowcel3.Style.Font.FontSize = 10;
temprowcel3.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
temprowcel4.Value = ProductDefects.ThicknessDetail[j - 1].d3;
temprowcel4.Style.Font.Bold = true;
temprowcel4.Style.Font.FontSize = 10;
temprowcel4.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
2024-12-18 10:44:17 +08:00
temprowcel5.Value = Math.Round((ProductDefects.ThicknessDetail[j - 1].d1 + ProductDefects.ThicknessDetail[j - 1].d2 + ProductDefects.ThicknessDetail[j - 1].d3)/3, 2);
temprowcel5.Style.Font.Bold = true;
temprowcel5.Style.Font.FontSize = 10;
temprowcel5.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
#endregion
}
#endregion
2024-03-07 14:03:22 +08:00
workbook.SaveAs(savePath);
}
// return true;
//}
//catch (Exception ex)
//{
// return false;
//}
}
2024-05-21 14:22:10 +08:00
private double ContrastLow = 0.8;
private double ContrastTop = 1.2;
private double ContrastToPercent(double val)
{
if (val < ContrastLow)
return 0;
else if (val > ContrastTop)
return 100;
double temp = 100 / (ContrastTop - ContrastLow);
return Math.Round(temp * (val - ContrastLow), 2);
}
2024-03-07 14:03:22 +08:00
public static Image getImageBase64(string imgBase64)
{
byte[] imgByte = Convert.FromBase64String(imgBase64);
Stream stream = new MemoryStream(imgByte);
return Image.FromStream(stream);
}
public class JsonProductDefects
{
[Description("产品品名")]
public string ProName { get; set; }
[Description("产品批号")]
public string BatchId { get; set; }
[Description("产品卷号")]
public string ReelId { get; set; }
[Description("检验长度")]
public string Len { get; set; }
[Description("平均速度")]
public string Speed { get; set; }
[Description("等级")]
public string Grade { get; set; }
[Description("检验时间")]
public string DateTime { get; set; }
[Description("疵点统计")]
public List<JDefectTotal> DefectTotal = new List<JDefectTotal>();
2024-05-21 14:22:10 +08:00
public List<JDefectDetail> DefectDetail = new List<JDefectDetail>();
[Description("门幅统计")]
public List<JFaceWidthDetail> FaceWidthDetail = new List<JFaceWidthDetail>();
[Description("测厚统计")]
public List<JThicknessDetail> ThicknessDetail = new List<JThicknessDetail>();
2024-05-21 14:22:10 +08:00
[Description("检测设置")]
public Product Pdt { get; set; }
[Description("物面分辨率")]
public string xyPix { get; set; }
[Description("操作员")]
public string UserName { get; set; }
[Description("班组")]
public string WorkTeam { get; set; }
[Description("分卷信息1")]
public string PartNote1 { get; set; }
[Description("分卷信息2")]
public string PartNote2 { get; set; }
2024-03-07 14:03:22 +08:00
}
public class JDefectTotal
{
[Description("疵点名")]
public string Name { get; set; }
[Description("疵点数")]
public int Count { get; set; }
}
public class JDefectDetail
{
[Description("源图")]
public int Index { get; set; }
[Description("名称")]
public string Name { get; set; }
[Description("X(cm)")]
public double X { get; set; }
[Description("Y(米)")]
public double Y { get; set; }
[Description("宽(cm)")]
public double Width { get; set; }
[Description("高(cm)")]
public double Height { get; set; }
[Description("置信度")]
public double ZXD { get; set; }
[Description("面积cm^2)")]
public double Area { get; set; }
[Description("对比度")]
public double Contrast { get; set; }
}
public class JThicknessDetail
{
[Description("Y(米)")]
public double Y { get; set; }
[Description("数据1")]
public double d1 { get; set; }
[Description("数据2")]
public double d2 { get; set; }
[Description("数据3")]
public double d3 { get; set; }
}
public class JFaceWidthDetail
{
[Description("Y(米)")]
public double Y { get; set; }
[Description("数据")]
public double data { get; set; }
}
2024-03-07 14:03:22 +08:00
//
/// <summary>
/// 重新生成缺陷分布(cm2M在内部转换)
/// </summary>
/// <param name="lstDefectInfo">Records.DefectInfoList</param>
/// <param name="XSizeRange">幅宽</param>
/// <param name="YSizeRange">卷长度</param>
private void reDrawDefectPoints(string modelname, List<DefectInfo> lstDefectInfo, double[] XSizeRange, double[] YSizeRange)
2024-03-07 14:03:22 +08:00
{
UILineOption option;
//AddTextEvent($"绘图", $"缺陷分布, W={string.Join(", ", XSizeRange)},H={string.Join(", ", YSizeRange)}, LastData={JsonConvert.SerializeObject(lstDefectInfo[lstDefectInfo.Count - 1])}");
var lstData = lstDefectInfo.OrderBy(m => m.Code).ThenBy(m => m.Code).ToList();
if (XSizeRange == null || YSizeRange == null)
option = this.lineChartDefect.Option;
else
{
if (YSizeRange[0] == YSizeRange[1])
{
YSizeRange[0] -= YSizeRange[0] / 10f;
YSizeRange[1] += YSizeRange[1] / 10f;
}
YSizeRange[0] /= 100;
YSizeRange[1] /= 100;
option = new UILineOption();
option.XAxis.Name = "面宽(cm)";
option.YAxis.Name = "长度(米)";
//option.Grid.Top = 20;//边距
option.Grid.Right = 20;//边距
//X轴数据类型
option.XAxisType = UIAxisType.Value;
//设置X/Y轴显示范围
option.XAxis.SetRange(XSizeRange[0], XSizeRange[1]);
option.YAxis.SetRange(YSizeRange[0], YSizeRange[1]);
//坐标轴显示小数位数
option.XAxis.AxisLabel.DecimalPlaces = option.YAxis.AxisLabel.DecimalPlaces = 1;
//X/Y轴画参考线
//option.YAxisScaleLines.Add(new UIScaleLine("上限", 3.5, Color.Red));
//option.YAxisScaleLines.Add(new UIScaleLine("下限", 2.2, Color.Gold));
//option.XAxisScaleLines.Add(new UIScaleLine(dt.AddHours(3).DateTimeString(), dt.AddHours(3), Color.Red));
//option.XAxisScaleLines.Add(new UIScaleLine(dt.AddHours(6).DateTimeString(), dt.AddHours(6), Color.Red));
option.ToolTip.Visible = true;
//option.ToolTip.Formatter = "怎么自定义X,Y显示名称{X}";
option.Title = new UITitle();
option.Title.Text = "";
option.Title.SubText = "";
}
string preCode = "";
UILineSeries series = null;
foreach (var item in lstData)
{
if (preCode != item.Code)//加一组新类型及样式
{
preCode = item.Code;
var one = Config.getDefectItem(modelname, item.Code);
2024-03-07 14:03:22 +08:00
if (one == null)
{
continue;
}
JObject objItem = one as JObject;
Color color = ColorTranslator.FromHtml(objItem.Value<string>("color"));
series = option.AddSeries(new UILineSeries(objItem.Value<string>("name"), color));//加一组
series.Symbol = UILinePointSymbol.Star;
series.SymbolSize = 4;
series.SymbolLineWidth = 2;
series.ShowLine = false;
series.SymbolColor = color;
//数据点显示小数位数针对当前UILineSeries
series.XAxisDecimalPlaces = 1;
series.YAxisDecimalPlaces = 2;
//series.Smooth = false;
}
2024-08-05 09:39:58 +08:00
if(series != null)
series.Add(item.CentreX, item.CentreY / 100); //cm -> m
2024-03-07 14:03:22 +08:00
}
//====
//option.GreaterWarningArea = new UILineWarningArea(3.5);
//option.LessWarningArea = new UILineWarningArea(2.2, Color.Gold);
//this.BeginInvoke(new System.Action(() =>
//{
this.lineChartDefect.SetOption(option);
//series.UpdateYData();//按序号更新Y轴值(可设置值超出范围用于闪烁)
//}));
}
/// <summary>
/// 重新门幅宽度
/// </summary>
/// <param name="points"></param>
/// <param name="XSizeRange">卷长度</param>
/// <param name="YSizeRange">幅宽</param>
private void reDrawFaceWidth(List<float[]> points, double[] XSizeRange, double[] YSizeRange)
{
//AddTextEvent($"绘图", $"门幅宽度, W={string.Join(", ", XSizeRange)},H={string.Join(", ", YSizeRange)}, LastData={JsonConvert.SerializeObject(points[points.Count-1])}");
if (YSizeRange[0] == YSizeRange[1])
{
YSizeRange[0] -= YSizeRange[0] / 10f;
YSizeRange[1] += YSizeRange[1] / 10f;
}
XSizeRange[0] /= 100;
XSizeRange[1] /= 100;
//防止超限
XSizeRange[1] += 0.01;
YSizeRange[1] += 0.1;
UILineOption option = new UILineOption();
option.XAxis.Name = "长度(米)";
option.YAxis.Name = "面宽(cm)";
option.Grid.Top = 20;
option.Grid.Right = 20;
//X轴数据类型
option.XAxisType = UIAxisType.Value;
//设置X/Y轴显示范围
option.XAxis.SetRange(XSizeRange[0], XSizeRange[1]);
option.YAxis.SetRange(YSizeRange[0], YSizeRange[1]);
//坐标轴显示小数位数
option.XAxis.AxisLabel.DecimalPlaces = option.YAxis.AxisLabel.DecimalPlaces = 1;
//X/Y轴画参考线
//option.YAxisScaleLines.Add(new UIScaleLine("上限", 3.5, Color.Red));
//option.YAxisScaleLines.Add(new UIScaleLine("下限", 2.2, Color.Gold));
//option.XAxisScaleLines.Add(new UIScaleLine(dt.AddHours(3).DateTimeString(), dt.AddHours(3), Color.Red));
//option.XAxisScaleLines.Add(new UIScaleLine(dt.AddHours(6).DateTimeString(), dt.AddHours(6), Color.Red));
option.ToolTip.Visible = true;
//option.ToolTip.Formatter = "怎么自定义X,Y显示名称{X}";
option.Title = new UITitle();
option.Title.Text = "";
option.Title.SubText = "";
Color color = Color.Blue;
UILineSeries series = null;
series = option.AddSeries(new UILineSeries("面宽", color));
series.Symbol = UILinePointSymbol.Circle;
series.ShowLine = true;
series.SymbolSize = 4;
series.SymbolLineWidth = 2;
series.SymbolColor = color;
//数据点显示小数位数针对当前UILineSeries
series.XAxisDecimalPlaces = 2;
series.YAxisDecimalPlaces = 1;
float x;
foreach (var item in points)
{
x = item[0] / 100; //cm -> m
series.Add(x, item[1]);
}
//====
//option.GreaterWarningArea = new UILineWarningArea(3.5);
//option.LessWarningArea = new UILineWarningArea(2.2, Color.Gold);
//this.BeginInvoke(new System.Action(() =>
//{
this.lineChartFaceWidth.SetOption(option);
//}));
}
/// <summary>
/// 重新会者厚度
/// </summary>
/// <param name="HDpoints"></param>
/// <param name="XSizeRange"></param>
/// <param name="YSizeRange"></param>
private void reDrawHouDu(List<Thickness> HDpoints, double[] XSizeRange, double[] YSizeRange)
{
//AddTextEvent(DateTime.Now,$"绘图", $"门幅宽度, W={string.Join(", ", XSizeRange)},H={string.Join(", ", YSizeRange)}, LastData={JsonConvert.SerializeObject(points[points.Count-1])}");
if (YSizeRange[0] == YSizeRange[1])
{
YSizeRange[0] -= YSizeRange[0] / 10f;
YSizeRange[1] += YSizeRange[1] / 10f;
}
XSizeRange[0] /= 100;
XSizeRange[1] /= 100;
//防止超限
XSizeRange[1] += 0.01;
YSizeRange[1] += 0.1;
2024-03-07 14:03:22 +08:00
UILineOption option = new UILineOption();
2024-12-18 10:44:17 +08:00
// 设置图例
option.Legend = new UILegend();
// 图例水平布局
option.Legend.Orient = UIOrient.Horizontal;
// 图例放置在左上角
option.Legend.Top = UITopAlignment.Top;
option.Legend.Left = UILeftAlignment.Left;
// 两个图例分别是Bar1和Bar2
option.Legend.AddData(Config.ThicknessNames.Split(',')[0], Color.Blue);
option.Legend.AddData(Config.ThicknessNames.Split(',')[1], Color.Red);
option.Legend.AddData(Config.ThicknessNames.Split(',')[2], Color.Green);
option.XAxis.Name = "长度(米)";
option.YAxis.Name = "厚度(mm)";
2024-12-18 10:44:17 +08:00
option.Grid.Top = 40;
option.Grid.Right = 20;
//X轴数据类型
option.XAxisType = UIAxisType.Value;
//设置X/Y轴显示范围
option.XAxis.SetRange(XSizeRange[0], XSizeRange[1]);
option.YAxis.SetRange(YSizeRange[0], YSizeRange[1]);
//坐标轴显示小数位数
option.XAxis.AxisLabel.DecimalPlaces = option.YAxis.AxisLabel.DecimalPlaces = 1;
//X/Y轴画参考线
//option.YAxisScaleLines.Add(new UIScaleLine("上限", 3.5, Color.Red));
//option.YAxisScaleLines.Add(new UIScaleLine("下限", 2.2, Color.Gold));
//option.XAxisScaleLines.Add(new UIScaleLine(dt.AddHours(3).DateTimeString(), dt.AddHours(3), Color.Red));
//option.XAxisScaleLines.Add(new UIScaleLine(dt.AddHours(6).DateTimeString(), dt.AddHours(6), Color.Red));
option.ToolTip.Visible = true;
//option.ToolTip.Formatter = "怎么自定义X,Y显示名称{X}";
option.Title = new UITitle();
option.Title.Text = "";
option.Title.SubText = "";
Color color1 = Color.Blue;
UILineSeries series1 = null;
2024-12-18 10:44:17 +08:00
series1 = option.AddSeries(new UILineSeries(Config.ThicknessNames.Split(',')[0], color1));
series1.Symbol = UILinePointSymbol.Circle;
series1.ShowLine = true;
series1.SymbolSize = 1;//4
series1.SymbolLineWidth = 1;//2
series1.SymbolColor = color1;
series1.XAxisDecimalPlaces = 2;
series1.YAxisDecimalPlaces = 1;
UILineSeries series2 = null;
UILineSeries series3 = null;
2024-12-18 10:44:17 +08:00
//if (Config.CustomerName != "XCL" && Config.CustomerName != "MX")
{
Color color2 = Color.Red;
series2 = option.AddSeries(new UILineSeries(Config.ThicknessNames.Split(',')[1], color2));
series2.Symbol = UILinePointSymbol.Circle;
series2.ShowLine = true;
series2.SymbolSize = 1;//4
series2.SymbolLineWidth = 1;//2
series2.SymbolColor = color2;
series2.XAxisDecimalPlaces = 2;
series2.YAxisDecimalPlaces = 1;
Color color3 = Color.Green;
series3 = option.AddSeries(new UILineSeries(Config.ThicknessNames.Split(',')[2], color3));
series3.Symbol = UILinePointSymbol.Circle;
series3.ShowLine = true;
series3.SymbolSize = 1;//4
series3.SymbolLineWidth = 1;//2
series3.SymbolColor = color3;
series3.XAxisDecimalPlaces = 2;
series3.YAxisDecimalPlaces = 1;
}
double x;
foreach (var item in HDpoints)
{
x = item.Y_Dis / 100; //cm -> m
series1.Add(x, item.Value1);
2024-12-18 10:44:17 +08:00
//if (Config.CustomerName != "XCL" && Config.CustomerName != "MX")
{
series2.Add(x, item.Value2);
series3.Add(x, item.Value3);
}
}
//====
//option.GreaterWarningArea = new UILineWarningArea(3.5);
//option.LessWarningArea = new UILineWarningArea(2.2, Color.Gold);
//this.BeginInvoke(new System.Action(() =>
//{
this.lineChartHouDu.SetOption(option);
//}));
}
2024-03-07 14:03:22 +08:00
// 截图操作函数
private byte[] captureControl(Control control)
{
Bitmap bmp = new Bitmap(control.Width, control.Height);
Graphics graphics = Graphics.FromImage(bmp);
Rectangle rectangle = new Rectangle(0, 0, control.Width, control.Height);
control.DrawToBitmap(bmp, rectangle);
//bmp to jpg
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);//bmp是已经获得的bitmap数据
byte[] bytes = ms.GetBuffer();
ms.Close();
graphics.Dispose();
return bytes;
//bitmap.Save(@"C:\Images\Capture.jpg", ImageFormat.Jpeg);
//return Image.FromStream(new MemoryStream(bytes));
}
private byte[] captureControl2(Control control)
{
Bitmap bmp = new Bitmap(control.Width, control.Height);
Graphics graphics = Graphics.FromImage(bmp);
Rectangle rectangle = new Rectangle(0, 0, control.Width, control.Height);
//control.DrawToBitmap(bmp, rectangle);
foreach (Control ctr in control.Controls)
{
rectangle = new Rectangle(ctr.Top, ctr.Left, ctr.Width, ctr.Height);
ctr.DrawToBitmap(bmp, rectangle);
}
//bmp to jpg
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);//bmp是已经获得的bitmap数据
byte[] bytes = ms.GetBuffer();
ms.Close();
graphics.Dispose();
return bytes;
//bitmap.Save(@"C:\Images\Capture.jpg", ImageFormat.Jpeg);
//return Image.FromStream(new MemoryStream(bytes));
}
2024-03-07 14:03:22 +08:00
private void btnChar_Click(object sender, EventArgs e)
{
Frame.SelectPage(1004);
}
private void uiDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
2024-03-07 14:03:22 +08:00
}
}