148 lines
7.1 KiB
C#
148 lines
7.1 KiB
C#
|
using DocumentFormat.OpenXml.EMMA;
|
|||
|
using HZH_Controls.Controls;
|
|||
|
using Models;
|
|||
|
using Newtonsoft.Json.Linq;
|
|||
|
using Sunny.UI;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Security.Cryptography.Xml;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace LeatherApp.Page
|
|||
|
{
|
|||
|
public partial class EditStandardFrm : UIEditForm
|
|||
|
{
|
|||
|
public List<QualifiedLimit> QualifiedLimits;
|
|||
|
public EditStandardFrm(Product pdt)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
#region dataGridView设置
|
|||
|
uiDataGridView1.AllowUserToAddRows = uiDataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
|
|||
|
uiDataGridView1.AllowUserToResizeRows = false;//用户调整行大小
|
|||
|
//dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
|
|||
|
//显示行号与列宽度自动调整
|
|||
|
uiDataGridView1.RowHeadersVisible = true;
|
|||
|
uiDataGridView1.RowHeadersWidth = 50;
|
|||
|
uiDataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
|||
|
uiDataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
|
|||
|
#endregion
|
|||
|
|
|||
|
QualifiedLimits = pdt.QualifiedLimitList;
|
|||
|
|
|||
|
ShowQualifiedList(pdt);
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
void ShowQualifiedList(Product pdt)
|
|||
|
{
|
|||
|
//按模型加载label
|
|||
|
JArray defectItemList;
|
|||
|
Config.LoadModelDefectItemList(pdt.ModelName, 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;
|
|||
|
}
|
|||
|
QualifiedLimit item1;
|
|||
|
for (int i = 0; i < uiDataGridView1.Rows.Count; i++)
|
|||
|
{
|
|||
|
code = uiDataGridView1.Rows[i].Cells["col_code"].Value.ToString();
|
|||
|
item1 = pdt.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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void btnCancel_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
|
|||
|
private void btnOK_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
QualifiedLimits.Clear();
|
|||
|
QualifiedLimit qualifiedLimit = new QualifiedLimit();
|
|||
|
for (int i = 0; i < uiDataGridView1.Rows.Count; i++)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
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)})!");
|
|||
|
QualifiedLimits.Add(qualifiedLimit);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
UIMessageTip.ShowWarning($"设置出错:{ex.Message}", 2000);
|
|||
|
}
|
|||
|
}
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|