142 lines
5.5 KiB
C#
142 lines
5.5 KiB
C#
|
using GeBoShi.SysCtrl;
|
|||
|
using HZH_Controls.Controls;
|
|||
|
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 GeBoShi.UI.Product
|
|||
|
{
|
|||
|
public partial class ProductInfoFrm : Form
|
|||
|
{
|
|||
|
Service.ProductService service = new Service.ProductService();
|
|||
|
Models.Product model = new Models.Product();
|
|||
|
|
|||
|
public ProductInfoFrm(Models.Product m = null)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
UIStyle.SetUIStyle(this);
|
|||
|
this.uiTitel1.FatherForm = this;
|
|||
|
|
|||
|
#region dataGridView设置
|
|||
|
dataGridView1.AllowUserToAddRows = dataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
|
|||
|
dataGridView2.AllowUserToAddRows = dataGridView2.AllowUserToDeleteRows = false;
|
|||
|
dataGridView1.AllowUserToResizeRows = dataGridView2.AllowUserToResizeRows = false;//用户调整行大小
|
|||
|
//dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
|
|||
|
//显示行号与列宽度自动调整
|
|||
|
dataGridView1.RowHeadersVisible = dataGridView2.RowHeadersVisible = true;
|
|||
|
dataGridView1.RowHeadersWidth = dataGridView2.RowHeadersWidth = 50;
|
|||
|
//dataGridView1.ColumnHeadersHeightSizeMode = dataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
|
|||
|
dataGridView1.RowHeadersWidthSizeMode = dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
|
|||
|
|
|||
|
#endregion
|
|||
|
initData();
|
|||
|
|
|||
|
if (m != null)
|
|||
|
{
|
|||
|
model = m;
|
|||
|
//显示模型
|
|||
|
foreach (string onnxFile in this.cmbDefectModelFile.Items)
|
|||
|
if (!string.IsNullOrWhiteSpace(model.ModelName) && onnxFile.ToLower() == model.ModelName.ToLower())
|
|||
|
this.cmbDefectModelFile.SelectedItem = model.ModelName;
|
|||
|
|
|||
|
txtName.Text = model.Name;
|
|||
|
cmbClasses.Text = model.Material;
|
|||
|
tbColorName.Text = model.ColorName;
|
|||
|
int[] rgb = new int[3];
|
|||
|
for (int i = 0; i < rgb.Length; i++)
|
|||
|
rgb[i] = Convert.ToInt32(model.ColorValue.Split(',')[i]);
|
|||
|
tbColorName.ForeColor = Color.FromArgb(rgb[0], rgb[1], rgb[2]);
|
|||
|
|
|||
|
tbSpec.Text = model.Spec;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void initData()
|
|||
|
{
|
|||
|
//模型文件
|
|||
|
string strDefectModelFile = ConfMgr.Instance.SysConfigParams.AIModelPath;
|
|||
|
if(!Directory.Exists(strDefectModelFile))
|
|||
|
{
|
|||
|
MessageBox.Show("模型路径错误:" + strDefectModelFile, "警告");
|
|||
|
return;
|
|||
|
}
|
|||
|
string[] onnxFiles = Directory.GetFiles(strDefectModelFile, "*.trt");
|
|||
|
//标签文件
|
|||
|
string[] labelFiles = Directory.GetFiles(strDefectModelFile, "*.json");
|
|||
|
string errorStr = "";
|
|||
|
foreach (string onnxFile in onnxFiles)
|
|||
|
{
|
|||
|
string onlyName;
|
|||
|
onlyName = Path.GetFileName(onnxFile);
|
|||
|
cmbDefectModelFile.Items.Add(onlyName);
|
|||
|
string findname = onlyName.Replace(".trt", ".json");
|
|||
|
//存在对应label文件
|
|||
|
if (labelFiles.Count(p => Path.GetFileName(p) == findname) <= 0)
|
|||
|
{
|
|||
|
errorStr += $"{onlyName},";
|
|||
|
}
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(errorStr))
|
|||
|
MessageBox.Show("模型缺少词典文件:" + errorStr, "警告");
|
|||
|
}
|
|||
|
|
|||
|
private void cmbClasses_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void ProductInfoFrm_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void ProductInfoFrm_SizeChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (this.WindowState == FormWindowState.Maximized)
|
|||
|
{
|
|||
|
this.WindowState = FormWindowState.Normal;
|
|||
|
this.Top = 0;
|
|||
|
this.Left = 0;
|
|||
|
this.Width = SystemInformation.WorkingArea.Width;
|
|||
|
this.Height = SystemInformation.WorkingArea.Height;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void tsbtnExit_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
|
|||
|
private void tsbtnSave_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void cmbDefectModelFile_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
tbLabelFile.Text = cmbDefectModelFile.Text.Replace(".trt", ".json");
|
|||
|
}
|
|||
|
|
|||
|
private void btnColor_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
ColorDialog dlg = new ColorDialog();
|
|||
|
DialogResult result = dlg.ShowDialog();
|
|||
|
if(result == DialogResult.OK)
|
|||
|
{
|
|||
|
// 获取用户所选颜色
|
|||
|
Color selectedColor = dlg.Color;
|
|||
|
// 在 label1 中显示所选颜色的 RGB 值
|
|||
|
tbColorName.ForeColor = selectedColor;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|