geboshi_V1/LeatherProject/ServerApp/ServerFrm.cs

1197 lines
58 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Models;
using Newtonsoft.Json.Linq;
using Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using ClosedXML.Excel;
using ServerApp.WebServer;
namespace ServerApp
{
public partial class ServerFrm : Form
{
public ServerFrm()
{
InitializeComponent();
//设置图标大小
this.lineChartDefect.Size = new System.Drawing.Size(600, 800);
this.lineChartFaceWidth.Size = new System.Drawing.Size(1000, 300);
}
private void ServerFrm_Load(object sender, EventArgs e)
{
this.lstboxLog.Items.Clear();
WebService web = new WebService();
//web.dbConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
web.dbConStr = "server=localhost;Database=LeatherDB;Uid=root;Pwd=Maimu888; AllowLoadLocalInfile=true";
web.LogEvent = (warning, msg) =>
{
try
{
this.BeginInvoke(new Action(() =>
{
msg = DateTime.Now.ToString("HH:mm:ss fff") + "Http" + " - " + msg;
msg = (warning == "正常" ? "" : warning == "警告" ? "Y" : "R") + msg;
if (this.lstboxLog.Items.Count > 1000)
this.lstboxLog.Items.Clear();
lstboxLog.Items.Insert(0, msg);
}));
}
catch (Exception ex)
{
}
};
web.GetReportEvent = (data) =>
{
try
{
GetDataReport(data);
}
catch (Exception ex)
{
MessageBox.Show($"数据报表生成失败:{ex.Message}");
}
};
web.start("172.16.21.210", 10086); //172.16.21.210 172.30.8.2
}
private void lstboxLog_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0) return;
string text = lstboxLog.GetItemText(e.Index);
switch (text[0])
{
case 'R':
e.DrawBackground();
e.Graphics.DrawString(text.Substring(1), e.Font,
new SolidBrush(Color.Red),
e.Bounds);
//e.Graphics.DrawString(text.Substring(1), e.Font, Color.Red, e.Bounds, ContentAlignment.MiddleLeft);
break;
case 'Y':
e.DrawBackground();
e.Graphics.DrawString(text.Substring(1), e.Font,
new SolidBrush(Color.Orange),
e.Bounds);
//e.Graphics.DrawString(text.Substring(1), e.Font, Color.Orange, e.Bounds, ContentAlignment.MiddleLeft);
break;
}
}
private bool GetDataReport(UploadDataRecords data)
{
int err = 0;
string path = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\Report";
if (string.IsNullOrWhiteSpace(path))
return false;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var list = data.DefectInfoList;
//绘图1
double len = Math.Round(data.Len * 100, 2);//cm
this.reDrawDefectPoints(data, new double[] { 0, Math.Round(data.FaceWidthMax + 0.005f, 2) }, new double[] { 0, len });
err = 1;
//绘图2
this.reDrawFaceWidth(data.FacePointList,
new double[] { 0, Math.Round(len + 0.005f, 2) },
new double[] { 130, 160 });
err = 2;
if (data.ThicknessList != null && data.ThicknessList.Count > 0)
{
List<double> hdMax = new List<double>(){
data.ThicknessList.Select(t=> t.Value1).ToList().Max(),
data.ThicknessList.Select(t => t.Value2).ToList().Max(),
data.ThicknessList.Select(t => t.Value3).ToList().Max(),
};
List<double> hdMin = new List<double>(){
data.ThicknessList.Select(t=> t.Value1).ToList().Min(),
data.ThicknessList.Select(t => t.Value2).ToList().Min(),
data.ThicknessList.Select(t => t.Value3).ToList().Min(),
};
reDrawHouDu(data.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) });
}
err = 2;
foreach (var item in list)
{
if (string.IsNullOrEmpty(item.Name))
item.Name = item.Code;
}
//
string Grade = "";
if (data.Grade < 1) Grade = "";
else if (data.Grade <= 5) Grade = (char)(data.Grade + 64) + "";
else Grade = "不合格";
JsonProductDefects jdata = new JsonProductDefects()
{
ProName = data.BarCodeName,
BatchId = data.BatchId,
ReelId = string.IsNullOrEmpty(data.PartReelId) ? "'" + data.ReelId : $"{data.ReelId}-{data.PartReelId}",
Len = data.Len.ToString(),
Speed = Math.Round(data.Len / data.TimeLen, 2).ToString(),
Grade = Grade,
DateTime = data.CreateTime.ToString("yyyy年MM月dd日 HH:mm"),
UserName = data.UserName,
WorkTeam = data.WorkTeam,
PartNote1 = data.PartReelNote,
PartNote2 = data.PartReelNote2,
};
err = 5;
if (data.DefectInfoList != null)
{
jdata.DefectTotal = data.DefectInfoList.GroupBy(x => x.Name).Select(g => new JDefectTotal { Name = g.Key, Count = g.Count() }).ToList();
jdata.DefectDetail = data.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
})
.OrderBy(x => x.Index).ThenBy(x => x.Y).ToList();
}
if (data.FacePointList != null)
{
jdata.FaceWidthDetail = data.FacePointList.Select(x => new JFaceWidthDetail
{
Y = x[0],
data = x[1],
}).OrderBy(x => x.Y).ThenBy(x => x.Y).ToList();
}
if (data.ThicknessList != null)
{
jdata.ThicknessDetail = data.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();
}
err = 6;
Product pd = new Product();
pd.ExposureTime = data.ExposureTime;
pd.Gain = data.Gain;
pd.LightValue = data.LightValue;
pd.QualifiedLimitList = data.QualifiedLimitList;
pd.ModelName = data.ModelName;
jdata.Pdt = pd;
jdata.xyPix = $"X:{data.cm2px_x},Y:{data.cm2px_y}";
err = 7;
var image1 = captureControl(this.lineChartDefect);
var image2 = captureControl(this.lineChartFaceWidth);
var image3 = captureControl(this.lineChartHouDu);
var filePath = $"{path}\\缺陷列表_{data.BatchId}_{data.ReelId}.xlsx";
err = 8;
filePath = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\temp.xlsx";
exportTabel(jdata, image1, image2, image3, filePath);
//if (!res)
// throw new Exception("导出失败!");
//System.Diagnostics.Process.Start(filePath);
return true;
}
public void exportTabel(JsonProductDefects ProductDefects, byte[] defectImage, byte[] faceWidthImage, byte[] HouduImage, string savePath)
{
//try
//{
if (ProductDefects == null)
throw new Exception("传入的参数为空");
using (var workbook = new XLWorkbook())
{
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;
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;
//NULL
var row2_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row2_cell9.Value = "操作员";
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;
row3_cell9.Style = row2_cell2.Style;
#endregion
#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 = "班组";
row4_cell9.Style = row2_cell1.Style;
rowIndex++;
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;
row5_cell9.Style = row2_cell1.Style;
#endregion
#region
rowIndex++;
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;
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
rowIndex++;
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);
row8_cell1.Value = "检测参数";
row8_cell1.Style.Font.Bold = true;
row8_cell1.Style.Font.FontSize = 10;
row8_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
string cellstr = $"A8:A{9 + ProductDefects.DefectTotal.Count}";
var mergeRange_row8 = wsDefectsDetail.Range(cellstr).Column(1).Merge();
mergeRange_row8.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row8_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row8_cell2.Value = "筛选标准";
row8_cell2.Style.Font.Bold = true;
row8_cell2.Style.Font.FontSize = 10;
row8_cell2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var mergeRange_row8_2 = wsDefectsDetail.Range($"B8:I8").Row(1).Merge();
mergeRange_row8_2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
//第九行
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;
//第十行之后
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 => x.Name == tempItemDefectTotal.Name || 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;
}
temprowcel9.Value = tempItemDefectTotal.Count;
temprowcel9.Style.Font.FontSize = 10;
temprowcel9.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
//更新行号
rowIndex = rowIndex + ProductDefects.DefectTotal.Count;
}
#endregion
#if false //不用
#region
rowIndex++;
if (ProductDefects.DefectTotal != null && ProductDefects.DefectTotal.Count > 0)
{
cellIndex = 1;
int DefectTotalCount = ProductDefects.DefectTotal.Count;
//最少5行固定4列
var row6_cell1 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex);
row6_cell1.Value = "检测参数";
row6_cell1.Style.Font.Bold = true;
row6_cell1.Style.Font.FontSize = 10;
row6_cell1.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
string cellstr = $"A6:A{7 + ProductDefects.DefectTotal.Count}";
var mergeRange_row6 = wsDefectsDetail.Range(cellstr).Column(1).Merge();
mergeRange_row6.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var row6_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row6_cell2.Value = "筛选标准";
row6_cell2.Style.Font.Bold = true;
row6_cell2.Style.Font.FontSize = 10;
row6_cell2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
var mergeRange_row6_2 = wsDefectsDetail.Range($"B6:I6").Row(1).Merge();
mergeRange_row6_2.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
//第七行
rowIndex++;
var row7_cell2 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 1);
row7_cell2.Value = "缺陷类型";
row7_cell2.Style = row2_cell1.Style;
var row7_cell3 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 2);
row7_cell3.Value = "置信度";
row7_cell3.Style = row2_cell1.Style;
var row7_cell4 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 3);
row7_cell4.Value = "面积";
row7_cell4.Style = row2_cell1.Style;
var row7_cell5 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 4);
row7_cell5.Value = "对比度下限";
row7_cell5.Style = row2_cell1.Style;
var row7_cell6 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 5);
row7_cell6.Value = "对比度上限";
row7_cell6.Style = row2_cell1.Style;
var row7_cell7 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 6);
row7_cell7.Value = "所用模型版本";
row7_cell7.Style = row2_cell1.Style;
var row7_cell8 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 7);
row7_cell8.Value = "或向选择";
row7_cell8.Style = row2_cell1.Style;
var row7_cell9 = wsDefectsDetail.Row(rowIndex).Cell(cellIndex + 8);
row7_cell9.Value = "本次检出数量";
row7_cell9.Style = row2_cell1.Style;
//第八行之后
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 => x.Name == tempItemDefectTotal.Name || 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;
temprowcel9.Value = tempItemDefectTotal.Count;
temprowcel9.Style.Font.FontSize = 10;
temprowcel9.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
}
}
//更新行号
rowIndex = rowIndex + ProductDefects.DefectTotal.Count;
}
#endregion
#endif
#region
//rowIndex++;
if (ProductDefects.DefectDetail != null && ProductDefects.DefectDetail.Count > 0)
{
List<string> lstRow5str = new List<string>() { "源图", "名称", "X(cm)", "Y(米)", "宽(mm)", "高(mm)", "置信度", "面积mm^2)", "对比度" };
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;
case "宽(mm)":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Width;
break;
case "高(mm)":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].Height;
break;
case "置信度":
temp_row6_cell.Value = ProductDefects.DefectDetail[i].ZXD;
break;
case "面积mm^2)":
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
#region
var wsDefectsImg = workbook.Worksheets.Add("正面疵点分布图");
wsDefectsImg.AddPicture(new MemoryStream(defectImage), "纵向计算")
.MoveTo(wsDefectsImg.Cell(1, 1));
#endregion
#region 线
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;
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("测厚数据列表");
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;
#region
row1_cell1 = wsHouDuList.Row(rowIndex).Cell(cellIndex);
row1_cell1.Value = "测厚数据详细列表";
row1_cell1.Style.Font.Bold = true;
row1_cell1.Style.Font.FontSize = 12;
mergeRange_row1 = wsHouDuList.Range("A1:D1").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);
row2_cell2.Value = "数据1";
row2_cell2.Style = row2_cell1.Style;
row2_cell3 = wsHouDuList.Row(rowIndex).Cell(cellIndex + 2);
row2_cell3.Value = "数据2";
row2_cell3.Style = row2_cell1.Style;
row2_cell4 = wsHouDuList.Row(rowIndex).Cell(cellIndex + 3);
row2_cell4.Value = "数据3";
row2_cell4.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);
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;
}
#endregion
#endregion
workbook.SaveAs(savePath);
}
// return true;
//}
//catch (Exception ex)
//{
// return false;
//}
}
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);
}
/// <summary>
/// 显示颜色现在对应30色确保label在30个以内
/// </summary>
Color[] ChartColor = new Color[30] { Color.Red, Color.Blue, Color.Green, Color.YellowGreen, Color.Orange,
Color.Peru, Color.DarkRed,Color.GreenYellow, Color.Pink , Color.Brown,
Color.CadetBlue, Color.OrangeRed, Color.Cyan, Color.Lime, Color.Magenta, Color.Tan, Color.Sienna,
Color.DarkGray, Color.SaddleBrown, Color.DarkBlue, Color.Firebrick,Color.Gainsboro,Color.Honeydew,Color.Khaki,Color.Lavender,
Color.LightGoldenrodYellow,Color.Navy, Color.Khaki, Color.IndianRed,Color.Lavender};
/// <summary>
/// 重新生成缺陷分布(cm2M在内部转换)
/// </summary>
/// <param name="lstDefectInfo">Records.DefectInfoList</param>
/// <param name="XSizeRange">幅宽</param>
/// <param name="YSizeRange">卷长度</param>
private void reDrawDefectPoints(UploadDataRecords records, double[] XSizeRange, double[] YSizeRange)
{
//AddTextEvent($"绘图", $"缺陷分布, W={string.Join(", ", XSizeRange)},H={string.Join(", ", YSizeRange)}, LastData={JsonConvert.SerializeObject(lstDefectInfo[lstDefectInfo.Count - 1])}");
var lstData = records.DefectInfoList.OrderBy(m => m.Code).ThenBy(m => m.Code).ToList();
if (XSizeRange == null || YSizeRange == null)
return;
else
{
if (YSizeRange[0] == YSizeRange[1])
{
YSizeRange[0] -= YSizeRange[0] / 10f;
YSizeRange[1] += YSizeRange[1] / 10f;
}
YSizeRange[0] /= 100;
YSizeRange[1] /= 100;
lineChartDefect.Series.Clear();
lineChartDefect.ChartAreas[0].AxisX.Title = "宽度(cm)";
lineChartDefect.ChartAreas[0].AxisY.Title = "长度(m)";
Dictionary<string,int> indexlist = new Dictionary<string, int>();
int indexcolor = 0;
DateTime dt = DateTime.Now;
foreach (var rowItem in lstData)
{
string name = rowItem.Name;
if (lineChartDefect.Series.FindByName(name) == null)//rowItem[3] 为name
{
indexlist.Add(name, indexcolor);
lineChartDefect.Series.Add(name);
int labelIndex = indexcolor;
lineChartDefect.Series[name].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
lineChartDefect.Series[name].MarkerSize = 5;
lineChartDefect.Series[name].MarkerColor = ChartColor[labelIndex];
lineChartDefect.Series[name].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
indexcolor++;
}
lineChartDefect.Series[name].Points.AddXY(rowItem.CentreX, rowItem.CentreY / 100);
if ((DateTime.Now - dt).Seconds > 1)
{
break;
}
}
lineChartDefect.ChartAreas[0].AxisX.Minimum = XSizeRange[0];
lineChartDefect.ChartAreas[0].AxisX.Maximum = XSizeRange[1];
lineChartDefect.ChartAreas[0].AxisY.Minimum = YSizeRange[0];
lineChartDefect.ChartAreas[0].AxisY.Maximum = YSizeRange[1];
}
}
/// <summary>
/// 重新门幅宽度
/// </summary>
/// <param name="points"></param>
/// <param name="XSizeRange">卷长度</param>
/// <param name="YSizeRange">幅宽</param>
private void reDrawFaceWidth(List<float[]> points, double[] XSizeRange, double[] YSizeRange)
{
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;
lineChartFaceWidth.Series.Clear();
lineChartFaceWidth.Series.Add("面宽");
lineChartFaceWidth.ChartAreas[0].AxisX.Title = "长度(m)";
lineChartFaceWidth.ChartAreas[0].AxisY.Title = "宽度(cm)";
lineChartFaceWidth.Series["面宽"].ChartType = SeriesChartType.Line;
lineChartFaceWidth.Series["面宽"].MarkerSize = 5;
lineChartFaceWidth.Series["面宽"].MarkerColor = Color.Blue;
lineChartFaceWidth.Series["面宽"].MarkerStyle = MarkerStyle.Circle;
lineChartFaceWidth.ChartAreas[0].AxisY.Maximum = YSizeRange[1];
lineChartFaceWidth.ChartAreas[0].AxisY.Minimum = YSizeRange[0];
lineChartFaceWidth.ChartAreas[0].AxisX.Maximum = XSizeRange[1];
lineChartFaceWidth.ChartAreas[0].AxisX.Minimum = XSizeRange[0];
float x;
foreach (var item in points)
{
x = item[0] / 100; //cm -> m
//series.Add(x, item[1]);
this.lineChartFaceWidth.Series["面宽"].Points.AddXY((float)Math.Round(x, 2), (float)Math.Round(item[1], 2));
}
}
/// <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;
lineChartHouDu.Series.Clear();
lineChartHouDu.Series.Add("厚度1");
lineChartHouDu.Series.Add("厚度2");
lineChartHouDu.Series.Add("厚度3");
lineChartHouDu.ChartAreas[0].AxisX.Title = "长度(m)";
lineChartHouDu.ChartAreas[0].AxisY.Title = "宽度(cm)";
lineChartHouDu.Series["厚度1"].ChartType = SeriesChartType.Line;
lineChartHouDu.Series["厚度1"].MarkerSize = 5;
lineChartHouDu.Series["厚度1"].MarkerColor = Color.Blue;
lineChartHouDu.Series["厚度1"].MarkerStyle = MarkerStyle.Circle;
lineChartHouDu.Series["厚度2"].ChartType = SeriesChartType.Line;
lineChartHouDu.Series["厚度2"].MarkerSize = 5;
lineChartHouDu.Series["厚度2"].MarkerColor = Color.Red;
lineChartHouDu.Series["厚度2"].MarkerStyle = MarkerStyle.Circle;
lineChartHouDu.Series["厚度3"].ChartType = SeriesChartType.Line;
lineChartHouDu.Series["厚度3"].MarkerSize = 5;
lineChartHouDu.Series["厚度3"].MarkerColor = Color.Green;
lineChartHouDu.Series["厚度3"].MarkerStyle = MarkerStyle.Circle;
lineChartHouDu.ChartAreas[0].AxisY.Maximum = YSizeRange[1];
lineChartHouDu.ChartAreas[0].AxisY.Minimum = YSizeRange[0];
lineChartHouDu.ChartAreas[0].AxisX.Maximum = XSizeRange[1];
lineChartHouDu.ChartAreas[0].AxisX.Minimum = XSizeRange[0];
double x;
foreach (var item in HDpoints)
{
x = item.Y_Dis / 100; //cm -> m
this.lineChartFaceWidth.Series["厚度1"].Points.AddXY((float)Math.Round(x, 2), (float)Math.Round(item.Value1, 2));
this.lineChartFaceWidth.Series["厚度2"].Points.AddXY((float)Math.Round(x, 2), (float)Math.Round(item.Value2, 2));
this.lineChartFaceWidth.Series["厚度3"].Points.AddXY((float)Math.Round(x, 2), (float)Math.Round(item.Value3, 2));
}
}
// 截图操作函数
private byte[] captureControl(System.Windows.Forms.Control control)
{
byte[] bytes = null;
this.Invoke(new System.Action(() =>
{
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数据
bytes = ms.GetBuffer();
ms.Close();
graphics.Dispose();
}));
return bytes;
//bitmap.Save(@"C:\Images\Capture.jpg", ImageFormat.Jpeg);
//return Image.FromStream(new MemoryStream(bytes));
}
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>();
public List<JDefectDetail> DefectDetail = new List<JDefectDetail>();
[Description("门幅统计")]
public List<JFaceWidthDetail> FaceWidthDetail = new List<JFaceWidthDetail>();
[Description("测厚统计")]
public List<JThicknessDetail> ThicknessDetail = new List<JThicknessDetail>();
[Description("检测设置")]
public Models.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; }
}
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; }
}
}
}