using Autofac;
|
using Bro.Common.Interface;
|
using Bro.Common.Model;
|
using Bro.M135.Common;
|
using Bro.M135.DBManager;
|
using Bro.UI.Model.Winform;
|
using Sunny.UI;
|
using System.Data;
|
|
namespace Bro.M141.Process.UI
|
{
|
//[MenuNode("产品检测记录", "产品检测记录", 3, Bro.Common.Helper.EnumHelper.TopMenu.SystemInfo, MenuNodeType.Form)]
|
public partial class FrmProductSpec : MenuFormBase
|
{
|
M141Process Process_M141 => Process as M141Process;
|
M141Config Config_M141 => Process.IConfig as M141Config;
|
|
public FrmProductSpec()
|
{
|
InitializeComponent();
|
dgvProductSpecs.AutoGenerateColumns = false;
|
dgvProductSpecs.AllowUserToAddRows = false;
|
dgvProductSpecs.AllowUserToDeleteRows = false;
|
dgvProductSpecs.RowHeadersVisible = false;
|
dgvProductSpecs.ShowEditingIcon = false;
|
|
this.Load += (s, e) =>
|
{
|
chkAutoRefresh.Checked = true;
|
};
|
}
|
|
List<ISpec> _defineSpecs = new List<ISpec>();
|
public override void OnProcessUpdated()
|
{
|
base.OnProcessUpdated();
|
|
dgvProductSpecs.Columns.Clear();
|
|
var specList = new List<ISpec>
|
{
|
new Spec { Code = "NO"},
|
new Spec { Code = "PID"},
|
new Spec { Code = "SN" }
|
};
|
|
// 从 检测标准集合 中获取 缺陷列表
|
//var temps = Config_M084.SpecCollection.Where(x => x.IsEnabled).Select(x => x as Spec);
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
var config = scope.Resolve<IProcessConfig>();
|
if (config is ISpecCollector sc)
|
{
|
_defineSpecs = sc.GetSpecList();
|
}
|
}
|
|
if (_defineSpecs.Any())
|
{
|
specList.AddRange(_defineSpecs.OrderBy(x => x.Code));
|
}
|
|
specList.ForEach(x =>
|
{
|
var col = new DataGridViewColumn(new DataGridViewTextBoxCell())
|
{
|
HeaderText = x.Code,
|
Name = x.Code,
|
AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells,
|
MinimumWidth = x.Code == "NO" ? 60 : 100,
|
//DataPropertyName = nameof(x.ActualValue),
|
};
|
dgvProductSpecs.Columns.Add(col);
|
});
|
}
|
|
//每隔4秒自动刷新一次
|
int _refreshTimes = 0;
|
public override void RefreshUIIn100()
|
{
|
if (!chkAutoRefresh.Checked)
|
return;
|
|
_refreshTimes++;
|
if (_refreshTimes == 40)
|
{
|
_refreshTimes = 0;
|
RefreshProductView();
|
}
|
}
|
|
static object _dataViewLock = new object();
|
private void RefreshProductView()
|
{
|
lock (_dataViewLock)
|
{
|
this.Invoke(() =>
|
{
|
SetDgvProductSpecsData();
|
//dgvProductSpecs.DataSource = GetSource();
|
});
|
}
|
}
|
|
/// <summary>
|
/// 填充产品检测列表记录
|
/// </summary>
|
private void SetDgvProductSpecsData()
|
{
|
dgvProductSpecs.Rows.Clear();
|
var productModels = Process_M141.ProductSpecResultList;
|
//var productModels = GetProductModelTest();
|
var rowNo = 0;
|
foreach (var product in productModels)
|
{
|
//var detectResultLists = product.Details.SelectMany(u => u.Value.DetectResults.Values).ToList();
|
//List<DetectResult> defectList = detectResultLists.SelectMany(u => u.SelectMany(t => t)).ToList();
|
|
int rowIndex = dgvProductSpecs.Rows.Add(); // 添加新行并获取其索引
|
dgvProductSpecs.Rows[rowIndex].Cells["NO"].Value = ++rowNo;
|
dgvProductSpecs.Rows[rowIndex].Cells["PID"].Value = product.PID;
|
dgvProductSpecs.Rows[rowIndex].Cells["SN"].Value = product.SN;
|
|
//var specs = defectList.SelectMany(x => x.Specs).ToList();
|
List<ISpec> specs = new List<ISpec>();
|
specs.AddRange(product.Details.SelectMany(u => u.SpecList).ToList().ConvertAll(u => (ISpec)u));
|
specs.AddRange(product.Details.SelectMany(u => u.ResultList.SelectMany(d => d.Specs)));
|
|
foreach (var defineSpec in _defineSpecs)
|
{
|
var curCell = dgvProductSpecs.Rows[rowIndex].Cells[defineSpec.Code];
|
var actualSpec = specs.FirstOrDefault(x => x.Code == defineSpec.Code);
|
if (actualSpec == null)
|
{
|
curCell.Value = "";
|
continue;
|
}
|
|
//dr[i++] = temp.GetMeasureValueStr;
|
|
// 自行计算
|
if (actualSpec.ActualValue == null)
|
{
|
curCell.Value = "--";
|
curCell.Style.ForeColor = Color.Yellow; // TBD
|
}
|
else
|
{
|
curCell.Value = actualSpec.ActualValue;
|
if (defineSpec.StandardValue - defineSpec.Tolrenance_Negative <= actualSpec.ActualValue &&
|
actualSpec.ActualValue <= defineSpec.StandardValue + defineSpec.Tolrenance_Positive)
|
{
|
curCell.Style.ForeColor = Color.Green;// OK
|
}
|
else
|
{
|
curCell.Style.ForeColor = Color.Red;// NG
|
}
|
}
|
|
//// 另一种处理方式,不确定MeasureResult 业务是否已进行处理
|
//if (actualSpec.MeasureResult == null)
|
//{
|
// curCell.Value = "--";
|
// curCell.Style.ForeColor = Color.Yellow;
|
//}
|
//else
|
//{
|
// curCell.Value = actualSpec.ActualValue;
|
// curCell.Style.ForeColor = actualSpec.MeasureResult.Value ? Color.Green : Color.Red;
|
//}
|
}
|
}
|
|
// DataGridView 自动滚动到未行
|
if (dgvProductSpecs.RowCount >= 1)
|
{
|
dgvProductSpecs.FirstDisplayedScrollingRowIndex = dgvProductSpecs.RowCount - 1;
|
}
|
}
|
|
/// <summary>
|
/// 测试记录
|
/// </summary>
|
/// <returns></returns>
|
private static List<ProductModel> GetProductModelTest()
|
{
|
var productSpecResultList = new List<ProductModel>();
|
productSpecResultList.Add(new ProductModel
|
{
|
PID = "2024081117100955",
|
SN = "SN1",
|
Details = new List<P_PRODUCT_DETAIL>()
|
{
|
{ new P_PRODUCT_DETAIL()
|
{
|
SpecList = new List<Spec>
|
{
|
|
new Spec { Code="FAI91A_X", ActualValue=1, MeasureResult = true, IsEnabled=true},
|
new Spec { Code="FAI91A_Y", ActualValue=2},
|
new Spec { Code="FAI91B_X", ActualValue=3},
|
new Spec { Code="FAI91B_Y", ActualValue=4},
|
new Spec { Code="FAI91_A", ActualValue=5},
|
new Spec { Code="FAI91_B", ActualValue=6}
|
}
|
}
|
}
|
}
|
});
|
|
productSpecResultList.Add(new ProductModel
|
{
|
PID = "2024081117100958",
|
SN = "SN2",
|
Details = new List<P_PRODUCT_DETAIL>()
|
{
|
{ new P_PRODUCT_DETAIL()
|
{
|
SpecList = new List<Spec>
|
{
|
|
new Spec { Code="FAI91A_X", ActualValue=1, MeasureResult = true, IsEnabled=true},
|
new Spec { Code="FAI91A_Y", ActualValue=2},
|
new Spec { Code="FAI91B_X", ActualValue=3},
|
new Spec { Code="FAI91B_Y", ActualValue=4},
|
new Spec { Code="FAI91_A", ActualValue=5},
|
new Spec { Code="FAI91_B", ActualValue=6}
|
}
|
}
|
}
|
}
|
});
|
return productSpecResultList;
|
}
|
}
|
}
|