623 lines
29 KiB
C#
623 lines
29 KiB
C#
using DocumentFormat.OpenXml.EMMA;
|
||
using DocumentFormat.OpenXml.Wordprocessing;
|
||
using LeatherApp.Device;
|
||
using LeatherApp.Interface;
|
||
using Models;
|
||
using Newtonsoft.Json.Linq;
|
||
using PG_Detect;
|
||
using Sunny.UI;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace LeatherApp.Page
|
||
{
|
||
public partial class FProductInfo : UIPage
|
||
{
|
||
private Service.ProductService service=new Service.ProductService();
|
||
private Models.Product model = new Models.Product();
|
||
public FProductInfo()
|
||
{
|
||
InitializeComponent();
|
||
|
||
#region dataGridView设置
|
||
uiDataGridView1.AllowUserToAddRows = uiDataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
|
||
uiDataGridView2.AllowUserToAddRows = uiDataGridView2.AllowUserToDeleteRows = false;
|
||
uiDataGridView1.AllowUserToResizeRows = uiDataGridView2.AllowUserToResizeRows=false;//用户调整行大小
|
||
//dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
|
||
//显示行号与列宽度自动调整
|
||
uiDataGridView1.RowHeadersVisible = uiDataGridView2.RowHeadersVisible = true;
|
||
uiDataGridView1.RowHeadersWidth = uiDataGridView2.RowHeadersWidth = 50;
|
||
uiDataGridView1.ColumnHeadersHeightSizeMode = uiDataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
||
uiDataGridView1.RowHeadersWidthSizeMode = uiDataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
|
||
//dataGridView1.RowPostPaint += (sender, e) =>//序号列头
|
||
//{
|
||
// //Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
|
||
// Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
|
||
// TextRenderer.DrawText(e.Graphics, (e.RowIndex * 0.25f).ToString(), dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle, dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
|
||
//};
|
||
//for (int i = 0; i < dataGridView1.Columns.Count; i++)//禁止点击列头排序
|
||
// dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
|
||
////行列交叉处标题
|
||
//if (dataGridView1.RowHeadersVisible) dataGridView1.TopLeftHeaderCell.Value = "SPH/CYL";
|
||
#endregion
|
||
|
||
this.rbMaterial0.Text = Config.materialNameList.FirstOrDefault(x => x.Value<int>("code") == 0).Value<string>("name");
|
||
this.rbMaterial1.Text = Config.materialNameList.FirstOrDefault(x => x.Value<int>("code") == 1).Value<string>("name");
|
||
this.rbMaterial2.Text = Config.materialNameList.FirstOrDefault(x => x.Value<int>("code") == 2).Value<string>("name");
|
||
this.rbMaterial3.Text = Config.materialNameList.FirstOrDefault(x => x.Value<int>("code") == 3).Value<string>("name");
|
||
this.rbMaterial4.Text = Config.materialNameList.FirstOrDefault(x => x.Value<int>("code") == 4).Value<string>("name");
|
||
this.rbMaterial5.Text = Config.materialNameList.FirstOrDefault(x => x.Value<int>("code") == 5).Value<string>("name");
|
||
|
||
if(Config.CustomerName == "MX" || Config.CustomerName == "XCL")
|
||
{
|
||
uiLabel14.Visible = true;
|
||
uiSymbolButton1.Visible = true;
|
||
}
|
||
else
|
||
{
|
||
uiLabel14.Visible = false;
|
||
uiSymbolButton1.Visible = false;
|
||
}
|
||
|
||
initData();
|
||
}
|
||
private void initData()
|
||
{
|
||
//var lstMaterial = Config.materialNameList.Select(x => new { code = x.Value<string>("code"), name = x.Value<string>("name") }).ToList();
|
||
//cmbMaterial.ValueMember = "code";
|
||
//cmbMaterial.DisplayMember = "name";
|
||
//cmbMaterial.DataSource = lstMaterial;
|
||
//cmbMaterial.SelectedIndex = -1;
|
||
|
||
var lstColor = Config.colorNameList.Select(x => new { code = x.Value<int>("code"),name = x.Value<string>("name") }).ToList();
|
||
cmbColor.ValueMember = "code";
|
||
cmbColor.DisplayMember = "name";
|
||
cmbColor.DataSource = lstColor;
|
||
cmbColor.SelectedIndex = -1;
|
||
|
||
//
|
||
var filePathList = Directory.GetFiles(Application.StartupPath + "\\models\\", "*.trt");//*.onnx,
|
||
string[] onlyNameList=new string[filePathList.Length];
|
||
for (int i = 0; i < filePathList.Length; i++)
|
||
onlyNameList[i]=Path.GetFileName(filePathList[i]);
|
||
this.cmbModelName.Items.AddRange(onlyNameList);
|
||
|
||
//
|
||
ABSCamerCardDev devCamer1;
|
||
if (Config.Camer_Name == CamerDevNameEnum.海康)
|
||
devCamer1 = new CamerCardDev();
|
||
else
|
||
devCamer1 = new CamerCardDevIK();
|
||
var value = devCamer1.getFeatureRangeValue("ExposureTime");
|
||
if (value.Length > 0)
|
||
{
|
||
this.tcbarExposureTime.Minimum = (int)value[0];
|
||
this.tcbarExposureTime.Maximum = (int)value[1];
|
||
}
|
||
value = devCamer1.getFeatureRangeValue("Gain");
|
||
if (value.Length > 0)
|
||
{
|
||
this.tcbarGain.Minimum = (int)value[0];
|
||
this.tcbarGain.Maximum = (int)value[1];
|
||
}
|
||
//
|
||
clear(true);
|
||
}
|
||
private void loadProduct(int id,bool resetAll=false)
|
||
{
|
||
model = service.GetModelNav(id);
|
||
if(model == null)
|
||
{
|
||
clear(resetAll);
|
||
return;
|
||
}
|
||
loadProduct();
|
||
}
|
||
/// <summary>
|
||
/// 对外,生产页面不存在的CODE进行添加
|
||
/// </summary>
|
||
/// <param name="pcode"> //PX-6</param>
|
||
/// <returns></returns>
|
||
public void loadProduct(string pcode, bool resetAll = false)
|
||
{
|
||
model = service.GetModelNav(pcode);
|
||
if (model == null)
|
||
{
|
||
clear(resetAll);
|
||
string[] codes= pcode.Split('-');
|
||
if (codes[0]=="0" || Config.SuedeList1.Contains(codes[0]))
|
||
this.rbMaterial0.Checked = true;
|
||
else if (codes[0] == "1")
|
||
this.rbMaterial1.Checked = true;
|
||
else if (codes[0] == "2")
|
||
this.rbMaterial2.Checked = true;
|
||
else if (codes[0] == "3")
|
||
this.rbMaterial3.Checked = true;
|
||
else if (codes[0] == "4")
|
||
this.rbMaterial4.Checked = true;
|
||
else if (codes[0] == "5")
|
||
this.rbMaterial5.Checked = true;
|
||
else
|
||
this.rbMaterial1.Checked = true;
|
||
|
||
this.cmbColor.SelectedValue = int.Parse(codes[1]);
|
||
}
|
||
else
|
||
loadProduct();
|
||
}
|
||
|
||
private double ContrastLow = 0.8;
|
||
private double ContrastTop = 1.2;
|
||
/// <summary>
|
||
/// 获取对比度百分比 0-100 对应0.6-1.4
|
||
/// </summary>
|
||
/// <param name="val"></param>
|
||
/// <returns></returns>
|
||
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);
|
||
}
|
||
private double PercentToContrast(double val)
|
||
{
|
||
double tt = 1;
|
||
if (val > 100)
|
||
tt = 100;
|
||
else if (val < 0)
|
||
tt = 0;
|
||
else
|
||
tt = val;
|
||
double temp = tt / 100 * (ContrastTop - ContrastLow);
|
||
return temp + ContrastLow;
|
||
}
|
||
private void loadProduct()
|
||
{
|
||
if (model == null) return;
|
||
if(model.Material=="0")
|
||
this.rbMaterial0.Checked = true;
|
||
else if (model.Material == "1")
|
||
this.rbMaterial1.Checked = true;
|
||
else if (model.Material == "2")
|
||
this.rbMaterial2.Checked = true;
|
||
else if (model.Material == "3")
|
||
this.rbMaterial3.Checked = true;
|
||
else if (model.Material == "4")
|
||
this.rbMaterial4.Checked = true;
|
||
else if (model.Material == "5")
|
||
this.rbMaterial5.Checked = true;
|
||
|
||
this.cmbColor.SelectedValue = model.Color;
|
||
|
||
tcbarLightValue.Value = model.LightValue;
|
||
tcbarExposureTime.Value = (int)model.ExposureTime;
|
||
tcbarGain.Value = (int)model.Gain;
|
||
tcbarTensionValue.Value = (int)model.TensionValue;
|
||
|
||
this.cmbModelName.Text = model.ModelName;
|
||
numDefectAreaLimit.Text = model.DefectAreaLimit.ToString();
|
||
numDefectCountLimit.Text = model.DefectCountLimit.ToString();
|
||
swcDefectPauseForUser.Active = model.DefectPauseForUser;
|
||
|
||
tbClass.Text = model.ClassType;
|
||
tbAera.Text = model.HalconAreaThr.ToString();
|
||
|
||
this.uiSwitch1.Active = model.OpenThicknessDetection;
|
||
uiNumPadTextBox1.Text = model.ThicknessDetectionStopDis.ToString();
|
||
|
||
//按模型加载label
|
||
JArray defectItemList;
|
||
Config.LoadModelDefectItemList(model.ModelName, out defectItemList);
|
||
uiDataGridView1.Rows.Clear();
|
||
uiDataGridView2.Rows.Clear();
|
||
uiDataGridView1.Columns[0].Visible = false;
|
||
string code, name;
|
||
//加行
|
||
foreach (JObject item in defectItemList)
|
||
{
|
||
code = item.Value<string>("code");
|
||
name = item.Value<string>("name");
|
||
//color = item.Value<string>("color");
|
||
uiDataGridView1.Rows.Add();
|
||
uiDataGridView1.Rows[uiDataGridView1.RowCount - 1].HeaderCell.Value = name;
|
||
uiDataGridView1[0, uiDataGridView1.RowCount - 1].Value = code;
|
||
}
|
||
uiDataGridView2.Columns[0].Visible = false;
|
||
//加行
|
||
foreach (JObject item in defectItemList)
|
||
{
|
||
code = item.Value<string>("code");
|
||
name = item.Value<string>("name");
|
||
//color = item.Value<string>("color");
|
||
uiDataGridView2.Rows.Add();
|
||
uiDataGridView2.Rows[uiDataGridView2.RowCount - 1].HeaderCell.Value = name;
|
||
uiDataGridView2[0, uiDataGridView2.RowCount - 1].Value = code;
|
||
}
|
||
|
||
//uiDataGridView fill
|
||
//string code;
|
||
QualifiedLimit item1;
|
||
for (int i = 0; i < uiDataGridView1.Rows.Count; i++)
|
||
{
|
||
code = uiDataGridView1.Rows[i].Cells["col_code"].Value.ToString();
|
||
item1 = model.QualifiedLimitList.FirstOrDefault(m=>m.Code == code);
|
||
if (item1 != null)
|
||
{
|
||
uiDataGridView1.Rows[i].Cells["col_zxd"].Value=item1.ZXD;
|
||
uiDataGridView1.Rows[i].Cells["col_area"].Value = item1.Area * 100;
|
||
uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value = ContrastToPercent(item1.ContrastTop);
|
||
uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value = ContrastToPercent(item1.ContrastLower);
|
||
uiDataGridView1.Rows[i].Cells["col_IsOR"].Value = item1.IsOR;
|
||
uiDataGridView1.Rows[i].Cells["col_Len"].Value = item1.DefectWarnLength;
|
||
uiDataGridView1.Rows[i].Cells["col_Cnt"].Value = item1.DefectWarnCnt;
|
||
}
|
||
}
|
||
GradeLimit item2;
|
||
for (int i = 0; i < uiDataGridView2.Rows.Count; i++)
|
||
{
|
||
code = uiDataGridView2.Rows[i].Cells["col2_code"].Value.ToString();
|
||
item2 = model.GradeLimitList.FirstOrDefault(m => m.Code == code);
|
||
if (item2 != null)
|
||
{
|
||
uiDataGridView2.Rows[i].Cells["col2_1"].Value = item2.A;
|
||
uiDataGridView2.Rows[i].Cells["col2_2"].Value = item2.B;
|
||
uiDataGridView2.Rows[i].Cells["col2_3"].Value = item2.C;
|
||
uiDataGridView2.Rows[i].Cells["col2_4"].Value = item2.D;
|
||
uiDataGridView2.Rows[i].Cells["col2_5"].Value = item2.E;
|
||
}
|
||
}
|
||
|
||
//
|
||
this.btnSave.Visible = this.btnReload.Visible = true;
|
||
}
|
||
private void clear(bool resetAll=false)
|
||
{
|
||
model = new Models.Product();
|
||
if (resetAll)
|
||
{
|
||
rbMaterial0.Checked=rbMaterial1.Checked=false;
|
||
cmbColor.SelectedIndex = -1;
|
||
}
|
||
tcbarLightValue.Value = tcbarExposureTime.Value = tcbarGain.Value = tcbarTensionValue.Value=0;
|
||
//cmbModelName.SelectedIndex = -1;
|
||
numDefectAreaLimit.Text =numDefectCountLimit.Text= "0";
|
||
swcDefectPauseForUser.Active = true;
|
||
|
||
this.btnSave.Visible = true;
|
||
this.btnReload.Visible = false;
|
||
|
||
//
|
||
uiDataGridView1.Rows.Clear();
|
||
uiDataGridView2.Rows.Clear();
|
||
|
||
JArray defectItemList;
|
||
Config.LoadModelDefectItemList(model.ModelName, out defectItemList);
|
||
|
||
string code, name;
|
||
//===uiDataGridView1
|
||
//加列
|
||
//uiDataGridView1.Columns.Add("col_code", "code");
|
||
//uiDataGridView1.Columns.Add("col_zxd", "置信度");
|
||
//uiDataGridView1.Columns.Add("col_area", "面积");
|
||
//uiDataGridView1.Columns.Add("col_contrast", "对比度");
|
||
//禁止点击列头排序
|
||
//uiDataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
|
||
uiDataGridView1.Columns[0].Visible = false;
|
||
//加行
|
||
foreach (JObject item in defectItemList)
|
||
{
|
||
code = item.Value<string>("code");
|
||
name = item.Value<string>("name");
|
||
//color = item.Value<string>("color");
|
||
uiDataGridView1.Rows.Add();
|
||
uiDataGridView1.Rows[uiDataGridView1.RowCount - 1].HeaderCell.Value = name;
|
||
uiDataGridView1[0, uiDataGridView1.RowCount - 1].Value = code;
|
||
}
|
||
//===uiDataGridView2
|
||
//加列
|
||
//uiDataGridView2.Columns.Add("col_code", "code");
|
||
//uiDataGridView2.Columns.Add("col_1", "A");
|
||
//uiDataGridView2.Columns.Add("col_2", "B");
|
||
//uiDataGridView2.Columns.Add("col_3", "C");
|
||
//uiDataGridView2.Columns.Add("col_4", "D");
|
||
//uiDataGridView2.Columns.Add("col_5", "E");
|
||
//禁止点击列头排序
|
||
//uiDataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
|
||
uiDataGridView2.Columns[0].Visible = false;
|
||
//加行
|
||
foreach (JObject item in defectItemList)
|
||
{
|
||
code = item.Value<string>("code");
|
||
name = item.Value<string>("name");
|
||
//color = item.Value<string>("color");
|
||
uiDataGridView2.Rows.Add();
|
||
uiDataGridView2.Rows[uiDataGridView2.RowCount - 1].HeaderCell.Value = name;
|
||
uiDataGridView2[0, uiDataGridView2.RowCount - 1].Value = code;
|
||
}
|
||
}
|
||
private void FProductInfo_Initialize(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
private void btnNew_Click(object sender, EventArgs e)
|
||
{
|
||
this.clear();
|
||
}
|
||
private void btnReload_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.loadProduct(model.Id,true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UIMessageTip.ShowError(ex.Message, 2000);
|
||
}
|
||
}
|
||
private void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (!this.rbMaterial0.Checked && !rbMaterial1.Checked
|
||
&& !rbMaterial2.Checked && !rbMaterial3.Checked
|
||
&& !rbMaterial4.Checked && !rbMaterial5.Checked
|
||
) throw new Exception("请选择材质!");
|
||
if (this.cmbColor.SelectedIndex < 0) throw new Exception("请选择颜色!");
|
||
if (this.cmbModelName.SelectedIndex < 0) throw new Exception("请选择模型!");
|
||
|
||
model.Material = GetMaterialIndex();
|
||
model.Color = (int)cmbColor.SelectedValue;
|
||
model.Code = model.Material+"-"+ model.Color;
|
||
|
||
model.LightValue = tcbarLightValue.Value;
|
||
model.TensionValue = tcbarTensionValue.Value;
|
||
model.ExposureTime = tcbarExposureTime.Value;
|
||
model.Gain = tcbarGain.Value;
|
||
|
||
model.ModelName = this.cmbModelName.Text.Trim();
|
||
model.DefectAreaLimit = double.Parse(numDefectAreaLimit.Text.Trim());
|
||
model.DefectCountLimit = int.Parse(numDefectCountLimit.Text.Trim());
|
||
model.DefectPauseForUser = swcDefectPauseForUser.Active;
|
||
|
||
///halcon参数
|
||
model.ClassType = tbClass.Text;
|
||
model.HalconAreaThr = double.Parse(tbAera.Text.Trim());
|
||
|
||
model.OpenThicknessDetection = uiSwitch1.Active;
|
||
int ival;
|
||
if (int.TryParse(uiNumPadTextBox1.Text, out ival))
|
||
model.ThicknessDetectionStopDis = int.Parse(uiNumPadTextBox1.Text.Trim());
|
||
else
|
||
model.ThicknessDetectionStopDis = 0;
|
||
//datagrid
|
||
if (model.QualifiedLimitList == null)
|
||
model.QualifiedLimitList = new List<Models.QualifiedLimit>();
|
||
else
|
||
model.QualifiedLimitList.Clear();
|
||
QualifiedLimit qualifiedLimit = new QualifiedLimit();
|
||
for (int i=0;i< uiDataGridView1.Rows.Count;i++ )
|
||
{
|
||
qualifiedLimit = new Models.QualifiedLimit()
|
||
{
|
||
Code = uiDataGridView1.Rows[i].Cells["col_code"].Value.ToString(),
|
||
ZXD = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_zxd"].Value) ? Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_zxd"].Value) : 0,
|
||
Area = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_area"].Value) ? Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_area"].Value) / 100 : 0,
|
||
ContrastLower = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value) ? PercentToContrast(Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value)) : 0,
|
||
ContrastTop = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value) ? PercentToContrast(Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value)) : 0,
|
||
IsOR = Convert.ToBoolean(uiDataGridView1.Rows[i].Cells["col_IsOR"].Value),
|
||
|
||
DefectWarnLength = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_Len"].Value) ? (int)Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_Len"].Value) : 0,
|
||
DefectWarnCnt = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_Cnt"].Value) ? (int)Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_Cnt"].Value) : 0,
|
||
|
||
Name = (string)uiDataGridView1.Rows[i].HeaderCell.Value,
|
||
ModifyUserCode = Config.loginUser.Code,
|
||
CreateUserCode = Config.loginUser.Code
|
||
};
|
||
if (qualifiedLimit.ContrastLower + qualifiedLimit.ContrastTop > 0 && qualifiedLimit.ContrastTop < qualifiedLimit.ContrastLower)
|
||
throw new Exception($"检测标准中第{i+1}行中对比度上限值({ContrastToPercent(qualifiedLimit.ContrastTop)})不可小于下限值({ContrastToPercent(qualifiedLimit.ContrastLower)})!");
|
||
model.QualifiedLimitList.Add(qualifiedLimit);
|
||
}
|
||
//
|
||
if (model.GradeLimitList == null)
|
||
model.GradeLimitList = new List<Models.GradeLimit>();
|
||
else
|
||
model.GradeLimitList.Clear();
|
||
for (int i = 0; i < uiDataGridView2.Rows.Count; i++)
|
||
{
|
||
model.GradeLimitList.Add(
|
||
new Models.GradeLimit()
|
||
{
|
||
Name = (string)(string)uiDataGridView2.Rows[i].HeaderCell.Value,
|
||
Code = uiDataGridView2.Rows[i].Cells["col2_code"].Value.ToString(),
|
||
A = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_1"].Value)? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_1"].Value) : 0,
|
||
B = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_2"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_2"].Value) : 0,
|
||
C = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_3"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_3"].Value) : 0,
|
||
D = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_4"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_4"].Value) : 0,
|
||
E = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_5"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_5"].Value) : 0,
|
||
ModifyUserCode = Config.loginUser.Code,
|
||
CreateUserCode = Config.loginUser.Code
|
||
});
|
||
}
|
||
//
|
||
model.ModifyUserCode = Config.loginUser.Code;
|
||
bool result;
|
||
if (model.Id == 0)
|
||
{
|
||
model.CreateUserCode = Config.loginUser.Code;
|
||
result = service.InsertNav(model);
|
||
}
|
||
else
|
||
{
|
||
result = service.UpdateNav(model);
|
||
}
|
||
if (!result)
|
||
throw new Exception("保存失败!");
|
||
|
||
if (Config.OpenHalconDefect)
|
||
{
|
||
try
|
||
{
|
||
PGDetect pg = new PGDetect();
|
||
pg.SaveUserData(Config.HalconParamPath, model.ClassType, model.HalconAreaThr);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw new Exception($"传统算法参数保存失败!{ex.Message}");
|
||
}
|
||
}
|
||
this.btnReload.Visible = true;
|
||
UIMessageTip.ShowOk("保存成功!", 1000);
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UIMessageTip.ShowError(ex.Message, 2000);
|
||
}
|
||
}
|
||
|
||
//
|
||
private void tcbarLightValue_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
lblLightValue.Text = $"{tcbarLightValue.Value}/{tcbarLightValue.Maximum}";
|
||
}
|
||
private void tcbarExposureTime_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
lblExposureTime.Text = $"{tcbarExposureTime.Value}/{tcbarExposureTime.Maximum}";
|
||
}
|
||
private void tcbarGainValue_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
lblGain.Text = $"{tcbarGain.Value}/{tcbarGain.Maximum}";
|
||
}
|
||
private void tcbarTensionValue_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
lblTensionValue.Text = $"{tcbarTensionValue.Value}/{tcbarTensionValue.Maximum}";
|
||
}
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
this.clear(true);
|
||
}
|
||
|
||
string GetMaterialIndex()
|
||
{
|
||
if (this.rbMaterial0.Checked)
|
||
return "0";
|
||
else if (this.rbMaterial1.Checked)
|
||
return "1";
|
||
else if (this.rbMaterial2.Checked)
|
||
return "2";
|
||
else if (this.rbMaterial3.Checked)
|
||
return "3";
|
||
else if (this.rbMaterial4.Checked)
|
||
return "4";
|
||
else
|
||
return "5";
|
||
}
|
||
private void cmbMaterial_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
//if (this.cmbMaterial.SelectedIndex < 0 || this.cmbColor.SelectedIndex < 0)
|
||
// return;
|
||
if ((!this.rbMaterial0.Checked && !this.rbMaterial1.Checked && !this.rbMaterial2.Checked
|
||
&& !this.rbMaterial3.Checked && !this.rbMaterial4.Checked && !this.rbMaterial5.Checked)
|
||
|| this.cmbColor.SelectedIndex < 0)
|
||
return;
|
||
|
||
this.loadProduct(GetMaterialIndex() + "-" + this.cmbColor.SelectedValue.ToString());
|
||
}
|
||
|
||
private void btnDefectOption_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.model == null || this.model.Id==0)
|
||
return;
|
||
|
||
FSelDefect frm = new FSelDefect(model.ModelName, model.DefectPauseOption);
|
||
frm.Render();
|
||
frm.Text = "选择瑕疵";
|
||
frm.ShowDialog();
|
||
if (frm.IsOK)
|
||
{
|
||
model.DefectPauseOption = frm.lstCodes;
|
||
}
|
||
|
||
frm.Dispose();
|
||
}
|
||
|
||
private void swcDefectPauseForUser_ValueChanged(object sender, bool value)
|
||
{
|
||
btnDefectOption.Enabled = swcDefectPauseForUser.Active;
|
||
}
|
||
|
||
/// <summary>
|
||
/// MES、ERP信息输入
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void uiSymbolButton1_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.model == null || this.model.Id == 0)
|
||
return;
|
||
|
||
FErpMesEdit frm = new FErpMesEdit(model.Spec);
|
||
frm.Render();
|
||
frm.Text = "MES/ERP信息编辑";
|
||
frm.ShowDialog();
|
||
if (frm.IsOK)
|
||
{
|
||
model.Spec = frm.erpInfo;
|
||
}
|
||
|
||
frm.Dispose();
|
||
}
|
||
|
||
private void cmbModelName_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
//重新加载label
|
||
JArray defectItemList;
|
||
Config.LoadModelDefectItemList(cmbModelName.Text, out defectItemList);
|
||
uiDataGridView1.Rows.Clear();
|
||
uiDataGridView1.Columns[0].Visible = false;
|
||
string code, name;
|
||
//加行
|
||
foreach (JObject item in defectItemList)
|
||
{
|
||
code = item.Value<string>("code");
|
||
name = item.Value<string>("name");
|
||
//color = item.Value<string>("color");
|
||
uiDataGridView1.Rows.Add();
|
||
uiDataGridView1.Rows[uiDataGridView1.RowCount - 1].HeaderCell.Value = name;
|
||
uiDataGridView1[0, uiDataGridView1.RowCount - 1].Value = code;
|
||
}
|
||
if (model != null && model.QualifiedLimitList != null)
|
||
{
|
||
QualifiedLimit item1;
|
||
for (int i = 0; i < uiDataGridView1.Rows.Count; i++)
|
||
{
|
||
code = uiDataGridView1.Rows[i].Cells["col_code"].Value.ToString();
|
||
item1 = model.QualifiedLimitList.FirstOrDefault(m => m.Code == code);
|
||
if (item1 != null)
|
||
{
|
||
uiDataGridView1.Rows[i].Cells["col_zxd"].Value = item1.ZXD;
|
||
uiDataGridView1.Rows[i].Cells["col_area"].Value = item1.Area * 100;
|
||
uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value = ContrastToPercent(item1.ContrastTop);
|
||
uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value = ContrastToPercent(item1.ContrastLower);
|
||
uiDataGridView1.Rows[i].Cells["col_IsOR"].Value = item1.IsOR;
|
||
//uiDataGridView1.Rows[i].Cells["col_Len"].Value = item1.DefectWarnLength;
|
||
//uiDataGridView1.Rows[i].Cells["col_Cnt"].Value = item1.DefectWarnCnt;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|