using Autofac;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Bro.Common.Model;
|
using Bro.M135.Common;
|
using Bro.Process;
|
using Bro.UI.Model.Winform;
|
using System.Data;
|
using Bro.M141.Process;
|
using Windows.Gaming.Input;
|
|
namespace Bro.M141.Process.UI
|
{
|
//[MenuNode("ProductList", "产品列表", 2, EnumHelper.TopMenu.SystemInfo, MenuNodeType.Form)]
|
public partial class FrmProductList : MenuFormBase
|
{
|
M141Process M141Process => Process as M141Process;
|
M141Config M141Config => Process.IConfig as M141Config;
|
|
bool IsSetTableHead = true;
|
List<string> InitializeDataText = new List<string>();
|
List<string> HeadText = new List<string>();
|
List<List<string>> DataText = new List<List<string>>();
|
|
|
List<ProductModel> DisplayProductList = new List<ProductModel>();
|
|
|
public FrmProductList()
|
{
|
InitializeComponent();
|
dataGridView1_ProductDisplayList.AutoGenerateColumns = false;
|
|
this.Load += (s, e) =>
|
{
|
checkBox1_IsAutoRefresh.Checked = true;
|
checkBox1_IsAutoRefresh.CheckedChanged -= AutoRefresh_ProductDisplayList;
|
checkBox1_IsAutoRefresh.CheckedChanged += AutoRefresh_ProductDisplayList;
|
|
timerRefresh.Enabled = true;
|
timerRefresh.Interval = 1000;
|
timerRefresh.Tick -= timerRefresh_Tick;
|
timerRefresh.Tick += timerRefresh_Tick;
|
};
|
}
|
|
protected override void Dispose(bool disposing)
|
{
|
if (M141Process != null)
|
{
|
M141Process.OnNewProductEnqueued -= Process_OnNewProductEnqueued;
|
M141Process.OnProductDequeued -= Process_OnProductDequeued;
|
}
|
|
if (disposing && (components != null))
|
{
|
components.Dispose();
|
}
|
base.Dispose(disposing);
|
}
|
|
public override void OnProcessUpdated()
|
{
|
base.OnProcessUpdated();
|
|
//初始化表头
|
InitialTableHead();
|
|
M141Process.OnNewProductEnqueued -= Process_OnNewProductEnqueued;
|
M141Process.OnProductDequeued -= Process_OnProductDequeued;
|
M141Process.OnNewProductEnqueued += Process_OnNewProductEnqueued;
|
M141Process.OnProductDequeued += Process_OnProductDequeued;
|
}
|
|
private void button1_ClearProductDisplayList_Click(object sender, EventArgs e)
|
{
|
IsSetTableHead = false;
|
DisplayProductList.Clear();
|
DataText.Clear();
|
RefreshProductView();
|
}
|
|
//初始化表格
|
#region 初始化DataGridView表格
|
public void InitialTableHead()
|
{
|
//根据内容自动调节所有单元格的行的高度
|
//dataGridView1_ProductDisplayList.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
|
//获取标准检测项和ML检测项
|
var specCollection = (((GlobalVar.Container.BeginLifetimeScope()).Resolve<IProcessConfig>()) as ProcessConfigBase).SpecCollection;
|
|
//计算所有检测项的数量,确定表格列数
|
int num_SpecCollection = specCollection.Count();
|
//添加列
|
for (int i = 0; i < num_SpecCollection + 4; i++)
|
{
|
InitializeDataText.Add("-");
|
}
|
//确定表头并添加
|
HeadText.Add("PID");
|
HeadText.Add("SN");
|
HeadText.Add("Result");
|
//添加网络检测项名称
|
HeadText.Add("NetResults");
|
//添加标准检测项的名称
|
foreach (var item in specCollection)
|
{
|
HeadText.Add(item.Code);
|
}
|
|
RefreshProductView();
|
}
|
#endregion
|
|
//设置是否自动刷新表格
|
public void AutoRefresh_ProductDisplayList(object? sender, EventArgs e)
|
{
|
timerRefresh.Enabled = checkBox1_IsAutoRefresh.Checked;
|
}
|
|
//加入新的产品数据
|
private async void Process_OnNewProductEnqueued(ProductModel pRecord)
|
{
|
await Task.Run(() =>
|
{
|
lock (_dataViewLock)
|
{
|
DisplayProductList.Insert(0, pRecord);
|
|
//筛选检测项
|
List<string> tempDataString = new List<string>(InitializeDataText);
|
var specsList = (pRecord.Details.SelectMany(p => p.ResultList).ToList()).SelectMany(d => d.Specs).ToList();
|
var defects = string.Join(",", (pRecord.Details.SelectMany(p => p.ResultList.SelectMany(r => r.NetResults.SelectMany(n => n.DetectDetails.Select(t => t.ClassName))).Distinct().SkipWhile(u => string.Equals(u, "ok", StringComparison.OrdinalIgnoreCase)))));
|
|
tempDataString[0] = pRecord.PID;
|
tempDataString[1] = pRecord.SN;
|
tempDataString[2] = pRecord.Result;
|
tempDataString[3] = defects;
|
for (int i = 4; i < HeadText.Count(); i++)
|
{
|
//tempDataString[i] = specsList.FirstOrDefault(s => s.Code == HeadText[i] ? s.ActualValue.ToString() : "-");
|
|
tempDataString[i] = specsList.FirstOrDefault(s => s.Code == HeadText[i])?.GetMeasureValueStr() ?? "-";
|
}
|
|
DataText.Insert(0, tempDataString);
|
}
|
});
|
}
|
|
//如果当前产品已存在,更新数据并出队操作
|
private void Process_OnProductDequeued(ProductModel pRecord)
|
{
|
lock (_dataViewLock)
|
{
|
var p = DisplayProductList.FirstOrDefault(u => u.PID == pRecord.PID);
|
if (p != null)
|
{
|
int index = DisplayProductList.IndexOf(p);
|
DisplayProductList[index] = pRecord;
|
|
//筛选检测项
|
var tempDataString = InitializeDataText;
|
var specsList = (pRecord.Details.SelectMany(p => p.ResultList).ToList()).SelectMany(d => d.Specs).ToList();
|
var defects = string.Join(",", (pRecord.Details.SelectMany(p => p.ResultList.SelectMany(r => r.NetResults.SelectMany(n => n.DetectDetails.Select(t => t.ClassName))).Distinct().SkipWhile(u => string.Equals(u, "ok", StringComparison.OrdinalIgnoreCase)))));
|
|
tempDataString[0] = pRecord.PID;
|
tempDataString[1] = pRecord.SN;
|
tempDataString[2] = pRecord.Result;
|
tempDataString[3] = defects;
|
for (int i = 4; i < HeadText.Count(); i++)
|
{
|
//tempDataString[i] = specsList.FirstOrDefault(s => s.Code == HeadText[i] ? s.ActualValue.ToString() : "-");
|
|
tempDataString[i] = specsList.FirstOrDefault(s => s.Code == HeadText[i])?.GetMeasureValueStr() ?? "-";
|
}
|
|
DataText[index] = tempDataString;
|
}
|
}
|
}
|
|
//时间刷新
|
private void timerRefresh_Tick(object sender, EventArgs e)
|
{
|
timerRefresh.Interval = M141Config.DataViewRefreshTime;
|
timerRefresh.Enabled = false;
|
this.Invoke(() =>
|
{
|
RefreshProductView();
|
});
|
|
timerRefresh.Enabled = true;
|
}
|
|
//刷新数据(将收集的数据显示到界面表格中)
|
static object _dataViewLock = new object();
|
private void RefreshProductView()
|
{
|
lock (_dataViewLock)
|
{
|
DataText = DataText.Take(M141Config.DataViewCount).ToList();
|
}
|
this.Invoke(() =>
|
{
|
//按行刷新显示
|
if (M141Config.RefreshModeSelect == RefreshMode.行)
|
{
|
//添加列,并加入列头
|
if (IsSetTableHead)
|
{
|
int countColumn = 0;
|
HeadText.ForEach(h =>
|
{
|
dataGridView1_ProductDisplayList.Columns.Add(new DataGridViewTextBoxColumn());
|
dataGridView1_ProductDisplayList.Columns[countColumn].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
dataGridView1_ProductDisplayList.Columns[countColumn++].HeaderText = h;
|
});
|
|
IsSetTableHead = false;
|
}
|
|
//添加行
|
dataGridView1_ProductDisplayList.Rows.Clear();
|
if (DataText.Count() != 0)
|
{
|
int countRow = 0;
|
DataText.ForEach(d1 =>
|
{
|
int countColumn = 0;
|
dataGridView1_ProductDisplayList.Rows.Add();
|
d1.ForEach(d2 =>
|
{
|
dataGridView1_ProductDisplayList.Rows[countRow].Cells[countColumn++].Value = d2;
|
});
|
countRow++;
|
});
|
}
|
}
|
//按列刷新显示
|
else
|
{
|
|
}
|
});
|
}
|
}
|
}
|