|
- #define TZJD
-
- using MaiMuAOI.SysCtrl;
- using MaiMuControl.Utils;
- using Models;
- using OpenCvSharp;
- using ProductionControl.UI;
- using ProductionControl.UIExtend;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using ToolKits.EnumTool;
- using ToolKits.mAPI;
- using Yolo5;
-
- namespace MaiMuAOI.SysUI.ProductAndStep
- {
- public partial class ProductInfoFrm : Form
- {
- Service.ClassesService svcClasses = new Service.ClassesService();
- 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;
-
- this.dgvBatchList.AutoGenerateColumns = false;
-
- dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
- dataGridView2.DefaultCellStyle.ForeColor = Color.Black;
- dataGridView3.DefaultCellStyle.ForeColor = Color.Black;
-
- this.Cursor = Cursors.WaitCursor;
- skinTabControl1.SelectedIndex = 0;
- //去除PT线宽等
- //tabControl1.TabPages.RemoveAt(2);
- //this.cbMarkType.SelectedIndex = -1;
- //去除不用的上下限界面4-10
- for (int i = 0; i < 7; i++)
- skinTabControl1.TabPages.RemoveAt(4);
-
- //显示打印内容
- DataGridViewComboBoxColumn cbxColumn = (DataGridViewComboBoxColumn)dataGridView1.Columns["DataType"];
- DataGridViewComboBoxColumn cbxColumn2 = (DataGridViewComboBoxColumn)dataGridView2.Columns["DataType2"];
- DataGridViewComboBoxColumn cbxColumn3 = (DataGridViewComboBoxColumn)dataGridView3.Columns["DataType3"];
- foreach (var s in System.Enum.GetValues(typeof(PrintDataPdtEnum)))
- {
- PrintDataPdtEnum dataEnum = (PrintDataPdtEnum)s;
- cbxColumn.Items.Add(dataEnum.GetDescription());
- cbxColumn2.Items.Add(dataEnum.GetDescription());
- cbxColumn3.Items.Add(dataEnum.GetDescription());
- }
-
- if (m != null)
- {
- model = m;
- this.Text += $" (ID:{m.Id})";
- this.txtCode.Text = m.Code;
- this.txtName.Text = m.Name;
- this.txtSpec.Text = m.Spec;
-
- this.cmbHoleCount.Text = m.HoleCount.ToString();
-
- this.txtBatchId.Text = m.BatchId;
- this.numTargetCount.Value = m.TargetCount;
- this.toolTip1.SetToolTip(this.numTargetCount, "已完成:" + m.CompleteCount);
-
- this.numTensionBaseValue.Value = (decimal)m.TensionBaseValue;
- this.numTensionUpFloatValue.Value = (decimal)m.TensionUpFloatValue;
- this.numTensionDownFloatValue.Value = (decimal)m.TensionDownFloatValue;
- this.numHeightBaseValue.Value = (decimal)m.HeightBaseValue;
- this.numHeightUpFloatValue.Value = (decimal)m.HeightUpFloatValue;
- this.numHeightDownFloatValue.Value = (decimal)m.HeightDownFloatValue;
- this.txtHeightBaseDec.Text = m.HeightBaseDec;
- this.numLineWidthBaseValue.Value = (decimal)m.LineWidthBaseValue;
- this.numLineWidthUpFloatValue.Value = (decimal)m.LineWidthUpFloatValue;
- this.numLineWidthDownFloatValue.Value = (decimal)m.LineWidthDownFloatValue;
- this.numPTBaseValue.Value = (decimal)m.PTBaseValue;
- this.numPTUpFloatValue.Value = (decimal)m.PTUpFloatValue;
- this.numPTDownFloatValue.Value = (decimal)m.PTDownFloatValue;
-
- this.numPTXBaseValue.Value = (decimal)m.PTXBaseValue;
- this.numPTXUpFloatValue.Value = (decimal)m.PTXUpFloatValue;
- this.numPTXDownFloatValue.Value = (decimal)m.PTXDownFloatValue;
-
- //新增判断2024-2-20
- this.numericUpDown3.Value = (decimal)m.FLineWidthBaseValue;
- this.numericUpDown2.Value = (decimal)m.FLineWidthUpFloatValue;
- this.numericUpDown1.Value = (decimal)m.FLineWidthDownFloatValue;
-
- this.numericUpDown6.Value = (decimal)m.MGridIntervalBaseValue;
- this.numericUpDown5.Value = (decimal)m.MGridIntervalUpFloatValue;
- this.numericUpDown4.Value = (decimal)m.MGridIntervalDownFloatValue;
-
- this.numericUpDown9.Value = (decimal)m.MGridWidthBaseValue;
- this.numericUpDown8.Value = (decimal)m.MGridWidthUpFloatValue;
- this.numericUpDown7.Value = (decimal)m.MGridWidthDownFloatValue ;
-
- this.numericUpDown12.Value = (decimal)m.MGridSpreadBaseValue;
- this.numericUpDown11.Value = (decimal)m.MGridSpreadUpFloatValue;
- this.numericUpDown10.Value = (decimal)m.MGridSpreadDownFloatValue;
-
- this.numericUpDown15.Value = (decimal)m.FGridSpreadBaseValue;
- this.numericUpDown14.Value = (decimal)m.FGridSpreadUpFloatValue;
- this.numericUpDown13.Value = (decimal)m.FGridSpreadDownFloatValue;
-
- this.numericUpDown18.Value = (decimal)m.BackPoleWidthBaseValue;
- this.numericUpDown17.Value = (decimal)m.BackPoleWidthUpFloatValue;
- this.numericUpDown16.Value = (decimal)m.BackPoleWidthDownFloatValue;
-
- this.numericUpDown21.Value = (decimal)m.MGridLengthBaseValue;
- this.numericUpDown20.Value = (decimal)m.MGridLengthUpFloatValue;
- this.numericUpDown19.Value = (decimal)m.MGridLengthDownFloatValue;
-
- this.numericUpDown24.Value = (decimal)m.MarkXDisBaseValue;
- this.numericUpDown23.Value = (decimal)m.MarkXDisUpFloatValue;
- this.numericUpDown22.Value = (decimal)m.MarkXDisDownFloatValue;
-
- this.numericUpDown27.Value = (decimal)m.MarkYDisBaseValue;
- this.numericUpDown26.Value = (decimal)m.MarkYDisUpFloatValue;
- this.numericUpDown25.Value = (decimal)m.MarkYDisDownFloatValue;
-
- this.numericUpDown30.Value = (decimal)m.ForkLengthBaseValue;
- this.numericUpDown29.Value = (decimal)m.ForkLengthUpFloatValue;
- this.numericUpDown28.Value = (decimal)m.ForkLengthDownFloatValue;
-
- this.numericUpDown33.Value = (decimal)m.ForkWidthBaseValue;
- this.numericUpDown32.Value = (decimal)m.ForkWidthUpFloatValue;
- this.numericUpDown31.Value = (decimal)m.ForkWidthDownFloatValue;
-
- this.numericUpDown36.Value = (decimal)m.ForkDisBaseValue;
- this.numericUpDown35.Value = (decimal)m.ForkDisUpFloatValue;
- this.numericUpDown34.Value = (decimal)m.ForkDisDownFloatValue;
-
- this.numericUpDown39.Value = (decimal)m.ChilopodLengthBaseValue;
- this.numericUpDown38.Value = (decimal)m.ChilopodLengthUpFloatValue;
- this.numericUpDown37.Value = (decimal)m.ChilopodLengthDownFloatValue;
-
- this.numericUpDown42.Value = (decimal)m.ChilopodWidthBaseValue;
- this.numericUpDown41.Value = (decimal)m.ChilopodWidthUpFloatValue;
- this.numericUpDown40.Value = (decimal)m.ChilopodWidthDownFloatValue;
-
- this.numericUpDown45.Value = (decimal)m.WeldingSpotDisBaseValue;
- this.numericUpDown44.Value = (decimal)m.WeldingSpotDisUpFloatValue;
- this.numericUpDown43.Value = (decimal)m.WeldingSpotDisDownFloatValue;
-
- this.numericUpDown48.Value = (decimal)m.WeldingSpotWidthBaseValue;
- this.numericUpDown47.Value = (decimal)m.WeldingSpotWidthUpFloatValue;
- this.numericUpDown46.Value = (decimal)m.WeldingSpotWidthDownFloatValue;
-
- this.numericUpDown51.Value = (decimal)m.WeldingSpotLengthBaseValue;
- this.numericUpDown50.Value = (decimal)m.WeldingSpotLengthUpFloatValue;
- this.numericUpDown49.Value = (decimal)m.WeldingSpotLengthDownFloatValue;
-
- this.numericUpDown54.Value = (decimal)m.ShardingDisBaseValue;
- this.numericUpDown53.Value = (decimal)m.ShardingDisUpFloatValue;
- this.numericUpDown52.Value = (decimal)m.ShardingDisDownFloatValue;
- //if (m.Type > 0)
- //{
- // this.txtCode.Enabled = false;
- // this.txtName.Width = this.txtCode.Width;
- // this.txtSpec.Enabled = false;
- //}
-
- this.tsbtnAddFile.Enabled = true;
- this.tsbtnNewBatchId.Enabled = true;
- this.dgvBatchList.DataSource = new BindingSource(m.BatchHistoryList, null);
- //2023-11-2 mark
- this.cbMarkType.SelectedIndex = m.MarkType;
- this.numMarkSize.Value = (decimal)m.MarkSize;
- //2023-12-18 主栅
- this.cbMarkDisturb.Checked = (m.MarkDisturb == 1);
- this.cbMainGrid.Checked = (m.MainGrid == 1);
- //2024-1-24 pad
- this.cbHavePad.Checked = (m.HavePad == 1);
- //2024-5-10 网节
- this.cbWangJie.Checked = (m.HaveWJ == 1);
-
- //this.cbOpenWM.Checked = m.OpenWM;
- this.numWM.Value = (decimal)m.WangMuThresh;
-
- Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
- if (attachmentFile != null)
- {
- this.btnOpenFile.Text = attachmentFile.Name;
- this.btnOpenFile.Visible = true;
-
- if ((this.groupBox5.Width - this.btnOpenFile.Width) > 0)
- {
- this.btnOpenFile.Left = (this.groupBox5.Width - this.btnOpenFile.Width) / 2;
- }
- else
- this.btnOpenFile.Left = 20;
-
- this.textBoxPath.Text = ConfMgr.Instance.ProjectDir+ $"\\{model.Id}\\" + attachmentFile.Name;
- }
- //是否显示上传功能
- if(ConfMgr.Instance.SysConfigParams.OpenPdtServer)
- tsbPdtPush.Visible = true;
- else
- tsbPdtPush.Visible = false;
-
- /////////////Print////////////////
- this.cbOrderPrint.Checked = m.EnableOrderPrint;
- this.tbOrderTempPath.Text = m.OrderTempPath;
- this.cbOpenBarTenderPrint.Checked = m.EnableLabelPrint;
- this.tbBarTenderTempPath.Text = m.LabelTempPath;
- this.cbOpenExcelPrint.Checked = m.EnableExcelPrint;
- this.tbExcelTempPath.Text = m.ExcelTempPath;
- if (m.PrintInfoList != null)
- foreach (var item in m.PrintInfoList)
- {
- if (item.Type == 1 && !item.IsValue)
- {
- int index = this.dataGridView1.Rows.Add();
- this.dataGridView1.Rows[index].Cells[0].Value = item.PrintKey;
- this.dataGridView1.Rows[index].Cells[1].Value = item.PrintCode;
- }
- else if (item.Type == 0 && !item.IsValue)
- {
- int index = this.dataGridView2.Rows.Add();
- this.dataGridView2.Rows[index].Cells[0].Value = item.PrintKey;
- this.dataGridView2.Rows[index].Cells[1].Value = item.PrintCode;
- }
- else if (item.Type == 3 && !item.IsValue)
- {
- int index = this.dataGridView3.Rows.Add();
- this.dataGridView3.Rows[index].Cells[0].Value = item.PrintKey;
- this.dataGridView3.Rows[index].Cells[1].Value = item.PrintCode;
- }
- }
-
- this.cbOrderSave.Checked = m.EnableOrderSave;
- this.tbSavePath.Text = m.OrderSavePath;
- ////////////////////////////////
-
- }
- else
- {
- cbMarkType.SelectedIndex = 2;
- numMarkSize.Value = (decimal)0.5;
- this.textBoxPath.Text = "";
- }
- InitDataView();
- this.Cursor = Cursors.Default;
- }
- ArrayList GetArrayList<T>()
- {
- ArrayList list = new ArrayList();
- Type type = typeof(T);
- //list.Add(new DictionaryEntry("start", "启动按钮"));
- foreach (int value in Enum.GetValues(type))
- {
- string strName = Enum.GetName(type, value);//获取名称
- list.Add(new DictionaryEntry(value, strName));
- }
-
- return list;
- }
-
- private void InitDataView()
- {
- try
- {
- //显示的数据
- this.cmbClasses.DisplayMember = "Name";
- this.cmbClasses.ValueMember = "Id";
- var list = svcClasses.GetListNav(0);
- this.cmbClasses.DataSource = list;
- if (model.ClassesId > 0)
- this.cmbClasses.SelectedValue = model.ClassesId;
-
- //缺陷项
- //ArrayList lstDefect = new ArrayList();
- //List<string> DefectNames = new List<string>();
- //foreach (var item in Enum.GetValues(typeof(DefectCodeEnum)))
- //{
- // DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
- // userCon.Code = item.ToString();
- // userCon.Title = EnumExtension.GetEnumDescription((DefectCodeEnum)item);
-
- // if (model != null && model.QualifiedCriterionList != null)
- // {
- // var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
- // if (qalifiedItem != null)
- // {
- // userCon.Checked = true;
- // userCon.SizeValue = (decimal)qalifiedItem.Size;
- // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
- // }
- // }
-
- // this.flpQualifiedPannel.Controls.Add(userCon);
- //}
-
- //获取所有缺陷项
- var lstDefect = GetArrayList<DefectCodeEnum>();
-
- //判断是rj还是pt
- if (model != null && model.ClassesId > 0)
- {
- Classes tClasses = svcClasses.GetById(model.ClassesId);
- if (tClasses.Name == "乳剂")
- {
- lstDefect.RemoveAt(13);
- lstDefect.RemoveAt(13);
- lstDefect.RemoveAt(13);
- lstDefect.RemoveAt(13);
- }
- else
- {
- lstDefect.RemoveAt(14);
- lstDefect.RemoveAt(14);
- lstDefect.RemoveAt(14);
- }
- }
- else
- {
- lstDefect.RemoveAt(14);
- lstDefect.RemoveAt(14);
- lstDefect.RemoveAt(14);
- }
- this.flpQualifiedPannel.Controls.Clear();
- foreach (DictionaryEntry item in lstDefect)
- {
- DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
- userCon.Code = item.Value.ToString();
- userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
- if (model != null && model.QualifiedCriterionList != null)
- {
- var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
- if (qalifiedItem != null)
- {
- userCon.Checked = true;
- userCon.SizeValue = (decimal)qalifiedItem.Size;
- userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
- }
- }
-
- this.flpQualifiedPannel.Controls.Add(userCon);
- }
-
-
- //模型文件
- string strDefectModelFile = ConfMgr.Instance.SysConfigParams.AIModelPath;
- string[] onnxFiles = Directory.GetFiles(strDefectModelFile, "*.onnx");
- string onlyName;
- foreach (string onnxFile in onnxFiles)
- {
- onlyName = Path.GetFileName(onnxFile);
- cmbDefectModelFile.Items.Add(onlyName);
- if (!string.IsNullOrWhiteSpace(model.DefectModelFile) && onlyName.ToLower() == model.DefectModelFile.ToLower())
- this.cmbDefectModelFile.SelectedItem = model.DefectModelFile;
- }
- }
- catch(Exception e)
- {
- MessageBox.Show("数据&模型载入出错:"+ e.Message,"报警", MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- }
-
- private void ProductInfoFrm_Load(object sender, EventArgs e)
- {
-
- }
-
- private void tsbtnSave_Click(object sender, EventArgs e)
- {
- try
- {
- tsbtnSave.Select();
- string szCode = this.txtCode.Text.Trim();
- string szName = this.txtName.Text.Trim();
- string szSpec = this.txtSpec.Text.Trim();
- string szHoleCount = this.cmbHoleCount.Text.Trim();
- string szBatchId = this.txtBatchId.Text.Trim();
- int liTargetCount = (int)this.numTargetCount.Value;
- string szHeightBaseDec = this.txtHeightBaseDec.Text.Trim().Trim(new char[] { ';', ',' });
- if (szCode == "" || szName == "")
- throw new Exception("请填写料号和名称!");
- if (this.cmbClasses.SelectedIndex < 0)
- throw new Exception("请选择产品类型!");
- if (szHoleCount == "" || !Util.IsNumber(szHoleCount))
- throw new Exception("请正确填写产品目数!");
- if (this.cmbDefectModelFile.SelectedIndex < 0)
- throw new Exception("请选择检测模型文件!");
-
- if (this.cbMarkType.SelectedIndex < 0)
- throw new Exception("请选择Mark!");
- //if (szBatchId == "")// || liTargetCount < 1
- // throw new Exception("请填写批次号");// 和批次目标数量!");
- if (szHeightBaseDec != "")
- {
- double num;
- string[] szs = szHeightBaseDec.Split(new char[] { ';', ',' });
- foreach (string s in szs)
- {
- if (!double.TryParse(s, out num))
- throw new Exception(s + " 非数值!");
- }
- }
-
- model.Code = szCode;
- model.Name = szName;
- model.Spec = szSpec;
- model.ClassesId = (int)this.cmbClasses.SelectedValue;
- model.HoleCount = Convert.ToInt32(szHoleCount);
- model.DefectModelFile = this.cmbDefectModelFile.Text.Trim();
-
- model.TensionBaseValue = (double)this.numTensionBaseValue.Value;
- model.TensionUpFloatValue = (double)this.numTensionUpFloatValue.Value;
- model.TensionDownFloatValue = (double)this.numTensionDownFloatValue.Value;
- model.HeightBaseValue = (double)this.numHeightBaseValue.Value;
- model.HeightUpFloatValue = (double)this.numHeightUpFloatValue.Value;
- model.HeightDownFloatValue = (double)this.numHeightDownFloatValue.Value;
- model.HeightBaseDec = szHeightBaseDec;
- model.LineWidthBaseValue = (double)this.numLineWidthBaseValue.Value;
- model.LineWidthUpFloatValue = (double)this.numLineWidthUpFloatValue.Value;
- model.LineWidthDownFloatValue = (double)this.numLineWidthDownFloatValue.Value;
- model.PTBaseValue = (double)this.numPTBaseValue.Value;
- model.PTUpFloatValue = (double)this.numPTUpFloatValue.Value;
- model.PTDownFloatValue = (double)this.numPTDownFloatValue.Value;
-
- model.PTXBaseValue = (double)this.numPTXBaseValue.Value;
- model.PTXUpFloatValue = (double)this.numPTXUpFloatValue.Value;
- model.PTXDownFloatValue = (double)this.numPTXDownFloatValue.Value;
-
- //新增判断2024-2-20
- model.FLineWidthBaseValue = (double)this.numericUpDown3.Value;
- model.FLineWidthUpFloatValue = (double)this.numericUpDown2.Value;
- model.FLineWidthDownFloatValue = (double)this.numericUpDown1.Value;
-
- model.MGridIntervalBaseValue = (double)this.numericUpDown6.Value;
- model.MGridIntervalUpFloatValue = (double)this.numericUpDown5.Value;
- model.MGridIntervalDownFloatValue = (double)this.numericUpDown4.Value;
-
- model.MGridWidthBaseValue = (double)this.numericUpDown9.Value;
- model.MGridWidthUpFloatValue = (double)this.numericUpDown8.Value;
- model.MGridWidthDownFloatValue = (double)this.numericUpDown7.Value;
-
- model.MGridSpreadBaseValue = (double)this.numericUpDown12.Value;
- model.MGridSpreadUpFloatValue = (double)this.numericUpDown11.Value;
- model.MGridSpreadDownFloatValue = (double)this.numericUpDown10.Value;
-
- model.FGridSpreadBaseValue = (double)this.numericUpDown15.Value;
- model.FGridSpreadUpFloatValue = (double)this.numericUpDown14.Value;
- model.FGridSpreadDownFloatValue = (double)this.numericUpDown13.Value;
-
- model.BackPoleWidthBaseValue = (double)this.numericUpDown18.Value;
- model.BackPoleWidthUpFloatValue = (double)this.numericUpDown17.Value;
- model.BackPoleWidthDownFloatValue = (double)this.numericUpDown16.Value;
-
- model.MGridLengthBaseValue = (double)this.numericUpDown21.Value;
- model.MGridLengthUpFloatValue = (double)this.numericUpDown20.Value;
- model.MGridLengthDownFloatValue = (double)this.numericUpDown19.Value;
-
- model.MarkXDisBaseValue = (double)this.numericUpDown24.Value;
- model.MarkXDisUpFloatValue = (double)this.numericUpDown23.Value;
- model.MarkXDisDownFloatValue = (double)this.numericUpDown22.Value;
-
- model.MarkYDisBaseValue = (double)this.numericUpDown27.Value;
- model.MarkYDisUpFloatValue = (double)this.numericUpDown26.Value;
- model.MarkYDisDownFloatValue = (double)this.numericUpDown25.Value;
-
- model.ForkLengthBaseValue = (double)this.numericUpDown30.Value;
- model.ForkLengthUpFloatValue = (double)this.numericUpDown29.Value;
- model.ForkLengthDownFloatValue = (double)this.numericUpDown28.Value;
-
- model.ForkWidthBaseValue = (double)this.numericUpDown33.Value;
- model.ForkWidthUpFloatValue = (double)this.numericUpDown32.Value;
- model.ForkWidthDownFloatValue = (double)this.numericUpDown31.Value;
-
- model.ForkDisBaseValue = (double)this.numericUpDown36.Value;
- model.ForkDisUpFloatValue = (double)this.numericUpDown35.Value;
- model.ForkDisDownFloatValue = (double)this.numericUpDown34.Value;
-
- model.ChilopodLengthBaseValue = (double)this.numericUpDown39.Value;
- model.ChilopodLengthUpFloatValue = (double)this.numericUpDown38.Value;
- model.ChilopodLengthDownFloatValue = (double)this.numericUpDown37.Value;
-
- model.ChilopodWidthBaseValue = (double)this.numericUpDown42.Value;
- model.ChilopodWidthUpFloatValue = (double)this.numericUpDown41.Value;
- model.ChilopodWidthDownFloatValue = (double)this.numericUpDown40.Value;
-
- model.WeldingSpotDisBaseValue = (double)this.numericUpDown45.Value;
- model.WeldingSpotDisUpFloatValue = (double)this.numericUpDown44.Value;
- model.WeldingSpotDisDownFloatValue = (double)this.numericUpDown43.Value;
-
- model.WeldingSpotWidthBaseValue = (double)this.numericUpDown48.Value;
- model.WeldingSpotWidthUpFloatValue = (double)this.numericUpDown47.Value;
- model.WeldingSpotWidthDownFloatValue = (double)this.numericUpDown46.Value;
-
- model.WeldingSpotLengthBaseValue = (double)this.numericUpDown51.Value;
- model.WeldingSpotLengthUpFloatValue = (double)this.numericUpDown50.Value;
- model.WeldingSpotLengthDownFloatValue = (double)this.numericUpDown49.Value;
-
- model.ShardingDisBaseValue = (double)this.numericUpDown54.Value;
- model.ShardingDisUpFloatValue = (double)this.numericUpDown53.Value;
- model.ShardingDisDownFloatValue = (double)this.numericUpDown52.Value;
-
- if (model.QualifiedCriterionList == null)
- model.QualifiedCriterionList = new List<Models.QualifiedCriterion>();
- else
- model.QualifiedCriterionList.Clear();
- foreach (DefectCountOfSizeControl defectControl in this.flpQualifiedPannel.Controls)
- {
- if (defectControl.Checked)
- {
- model.QualifiedCriterionList.Add(
- new Models.QualifiedCriterion()
- {
- DefectCode = defectControl.Code,
- Size = (float)defectControl.SizeValue,
- MaxDefectCount = (int)defectControl.MaxDefectCount,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- });
- }
- }
-
- model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
-
- //2023-11-2 mark
- model.MarkType = this.cbMarkType.SelectedIndex;
- model.MarkSize = (double)this.numMarkSize.Value;
- //2023-12-18 主栅
- model.MarkDisturb = this.cbMarkDisturb.Checked ? 1 : 0;
- model.MainGrid = this.cbMainGrid.Checked ? 1 : 0;
- //2024-1-24 是否存在pad
- model.HavePad = this.cbHavePad.Checked ? 1 : 0;
- //2024-5-10 是否存在网节
- model.HaveWJ = this.cbWangJie.Checked ? 1 : 0;
- ////////////////////Print//////////////////////////
- model.EnableOrderPrint = this.cbOrderPrint.Checked;
- model.OrderTempPath = this.tbOrderTempPath.Text;
- model.EnableLabelPrint = this.cbOpenBarTenderPrint.Checked;
- model.LabelTempPath = this.tbBarTenderTempPath.Text;
- model.EnableExcelPrint = this.cbOpenExcelPrint.Checked;
- model.ExcelTempPath = this.tbExcelTempPath.Text;
- List<PrintInfo> labeldata = new List<PrintInfo>();
- for (int i = 0; i < this.dataGridView1.RowCount; i++)
- {
- if (this.dataGridView1.Rows[i].Cells[0].Value != null)
- labeldata.Add(new PrintInfo()
- {
- Type = 1,
- IsValue = false,
- PrintKey = this.dataGridView1.Rows[i].Cells[0].Value.ToString(),
- PrintCode = this.dataGridView1.Rows[i].Cells[1].Value.ToString(),
- PrintName = "",
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- }) ;
- }
- for (int i = 0; i < this.dataGridView2.RowCount; i++)
- {
- if (this.dataGridView2.Rows[i].Cells[0].Value != null)
- labeldata.Add(new PrintInfo()
- {
- Type = 0,
- IsValue = false,
- PrintKey = this.dataGridView2.Rows[i].Cells[0].Value.ToString(),
- PrintCode = this.dataGridView2.Rows[i].Cells[1].Value.ToString(),
- PrintName = "",
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- });
- }
- for (int i = 0; i < this.dataGridView3.RowCount; i++)
- {
- if (this.dataGridView3.Rows[i].Cells[0].Value != null)
- labeldata.Add(new PrintInfo()
- {
- Type = 3,
- IsValue = false,
- PrintKey = this.dataGridView3.Rows[i].Cells[0].Value.ToString(),
- PrintCode = this.dataGridView3.Rows[i].Cells[1].Value.ToString(),
- PrintName = "",
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- });
- }
- model.PrintInfoList = labeldata;
-
- model.EnableOrderSave = cbOrderSave.Checked;
- model.OrderSavePath = tbSavePath.Text;
-
- #if TZJD
- //设置比对参数
- Yolo_Class yolo_Class = new Yolo_Class();
- if (model.AttachmentList == null || model.AttachmentList.Count == 0)
- {
- MessageBox.Show("图纸未上传,跳过图纸比对参数设置!");
- }
- else
- {
- var attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
- string gbxBmpPath = ConfMgr.Instance.ProjectDir + $"\\{attachmentFile.NameTimestamp}";
- if (!yolo_Class.WriteCustomThresh(gbxBmpPath, (double)numWM.Value))
- {
- MessageBox.Show($"比对精度设置失败!请检测 {gbxBmpPath} 图纸是否存在!");
- }
- else
- {
- //model.OpenWM = cbOpenWM.Checked;
- model.WangMuThresh = (double)numWM.Value;
- }
- }
- #endif
- /////////////////////////////////////////////////
- ///
- bool result;
- if (model.Id == 0)
- {
- model.BatchId = szBatchId;
- model.TargetCount = liTargetCount;
- model.CompleteCount = 0;
- model.CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
- result = service.InsertNav(model);
- }
- else
- {
- if (model.BatchId != szBatchId && !string.IsNullOrWhiteSpace(model.BatchId))
- {
- if (model.CompleteCount < model.TargetCount
- && MessageBox.Show($"本批次完成数量未达到目标数量,确定更换批次号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
- return;
- if (model.BatchHistoryList.FirstOrDefault(m => m.BatchId == szBatchId) != null)
- throw new Exception("当前批次号与历史中所用批次号重复,请重新填写!");
-
- model.BatchHistoryList.Add(new Models.BatchHistory()
- {
- BatchId = model.BatchId,
- TargetCount = model.TargetCount,
- CompleteCount = model.CompleteCount,
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- });
- model.CompleteCount = 0;
- }
-
- model.BatchId = szBatchId;
- model.TargetCount = liTargetCount;
- result = service.UpdateNav(model);
- }
- if (!result)
- throw new Exception("保存失败!");
-
- this.tsbtnAddFile.Enabled = true;
- this.tsbtnNewBatchId.Enabled = true;
- MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- private void tsbtnExit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void tsbtnNewBatchId_Click(object sender, EventArgs e)
- {
-
- }
-
- private void tsbtnAddFile_Click(object sender, EventArgs e)
- {
- this.Cursor = Cursors.WaitCursor;
- System.Windows.Forms.Application.DoEvents();
- try
- {
- if (this.cbMarkType.SelectedIndex < 0)
- throw new Exception("请选择Mark!");
- //.dwg /.dxf /.dws /.dwt
- string filePath = ConfMgr.SelectFile("gbx,gbr文件|*.gb?");
- if (string.IsNullOrWhiteSpace(filePath))
- return;
-
- string fileName = Path.GetFileName(filePath);
- string fileExtend = Path.GetExtension(filePath);
- string fileOnlyName = fileName.Substring(0, fileName.Length - fileExtend.Length);
-
- //
- string targFilePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
- if (!Directory.Exists(targFilePath))
- Directory.CreateDirectory(targFilePath);
- else//删除原文件
- ConfMgr.DelFilesInFolder(targFilePath);
-
- targFilePath += fileName;
- //File.Copy(res.file_path, defectFileName + ".bmp", true);
- bool result = API.CopyFile(filePath, targFilePath, false);//更快 //false-覆盖
- if (!result)
- throw new Exception("移动文件失败!");
-
- //后台线程转BMP与JPG
- string tempClass = this.cmbClasses.Text;
- int tempIndex = this.cbMarkType.SelectedIndex;
- double tempSize = (double)this.numMarkSize.Value;
-
- //2023-12-18
- int tMarkDistrub = this.cbMarkDisturb.Checked ? 1 : 0;
- int tMainGrid = this.cbMainGrid.Checked ? 1 : 0;
- //2024-1-24
- int tHavePad = this.cbHavePad.Checked ? 1 : 0;
- //2024-5-10
- int tHaveWJ = this.cbWangJie.Checked ? 1 : 0;
- //Task.Run(() =>
- {
- Yolo5.Yolo_Class yolo = new Yolo5.Yolo_Class();
- string bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".bmp";
- //2023-11-3 mark
- //yolo.gerber2image(targFilePath, bmpPath);
- double[] markParam = new double[8];
- if (tempClass.Contains("乳剂"))
- markParam[0] = 2;
- else if (tempClass.Contains("PI"))
- markParam[0] = 1;
- else
- markParam[0] = 0;
- if (tempIndex == 0)
- {
- //默认情况 实心圆,0.5mm
- markParam[1] = 2;
- markParam[2] = 0.5;
- markParam[3] = 1;
- markParam[4] = 0;
- markParam[5] = 0;
- markParam[6] = 0;
- markParam[7] = 1;
- }
- else
- {
- markParam[1] = tempIndex - 1;
- markParam[2] = tempSize;
- markParam[3] = tempIndex == 1 ? 0 : 1;
- markParam[4] = tMarkDistrub;
- markParam[5] = tMainGrid;
- markParam[6] = tHavePad;
- }
- yolo.gerber2image(targFilePath, bmpPath, markParam);
-
- //换背景JPG
- Mat mat = Cv2.ImRead(bmpPath);
- Cv2.CvtColor(mat, mat, ColorConversionCodes.RGB2GRAY);//转灰度图
- for (int i = 0; i < mat.Height; i++)
- {
- for (int j = 0; j < mat.Width; j++)
- {
- if (mat.At<byte>(i, j) == 255)//白色
- mat.Set<byte>(i, j, 0);
- else
- mat.Set<byte>(i, j, 255);
- }
- }
- model.MapPath = bmpPath;
- //灰转彩
- //Cv2.CvtColor(mat, mat, ColorConversionCodes.GRAY2RGB);
- //for (int i = 0; i < mat.Height; i++)
- //{
- // for (int j = 0; j < mat.Width; j++)
- // {
- // if (mat.At<byte>(i, j) == 255)//白色
- // mat.Set<byte>(i, j, 0); //黄色
- // }
- //}
- bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".jpg";
- OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat).Save(bmpPath, ImageFormat.Jpeg);
- //});//不能加.Start();
- }
- Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
- if (attachmentFile != null)
- {
- attachmentFile.Type = 0;//图纸
- attachmentFile.NameTimestamp = $"{model.Id}\\{fileOnlyName}";
- attachmentFile.Name = fileName;
- attachmentFile.ExtendName = fileExtend;
- }
- else
- {
- model.AttachmentList.Add(new Models.Attachment()
- {
- TBName = "product",
- Type = 0,
- NameTimestamp = $"{model.Id}\\{fileOnlyName}",
- Name = fileName,
- ExtendName = fileExtend,
- CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
- ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
- });
- }
- if (!service.UpdateNav(model))
- throw new Exception("保存文件失败!");
-
- model = service.GetModelNav(model.Code);
- this.btnOpenFile.Text = fileName;
- this.btnOpenFile.Visible = true;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- this.Cursor = Cursors.Default;
- }
- }
-
- private void btnOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
- if (attachmentFile == null)
- MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- string filePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + attachmentFile.Name;
- if (File.Exists(filePath))
- Process.Start(filePath);
- }
-
- private void tbtnGetPos_Click(object sender, EventArgs e)
- {
- if ((model.MapPath == null) || (string.IsNullOrEmpty(model.MapPath)))
- {
- MessageBox.Show("还未上传图纸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- List<double> dList = new List<double>();
- if (model.GetPointList != null)
- {
- var list = model.GetPointList.Split(',');
- dList = new List<double>();
- if (list.Length < 28)
- {
- for (int i = 0; i < 28; i++)
- {
- dList.Add(0);
- }
- }
- else
- {
- for (int i = 0; i < list.Length; i++)
- {
- dList.Add(double.Parse(list[i]));
- }
- }
- }
- FrmGetPosByPic frm = new FrmGetPosByPic(model, model.MapPath, dList.ToArray());
- frm.ShowDialog();
- model.GetPointList = string.Join(",", frm.GetPoints()); ;
- model.MapPath = frm.GetMapPath();
-
- if (!service.UpdateNav(model))
- throw new Exception("保存文件失败!");
-
- model = service.GetModelNav(model.Code);
- }
-
- private void textBoxPath_DoubleClick(object sender, EventArgs e)
- {
- if (File.Exists(this.textBoxPath.Text))
- {
- Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
- if (attachmentFile != null)
- {
- System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
- psi.Arguments = "/e,/select," + ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
- System.Diagnostics.Process.Start(psi);
- }
- }
- }
-
- #region 发送产品数据
- private void tsbPdtPush_Click(object sender, EventArgs e)
- {
- try
- {
- this.Cursor = Cursors.WaitCursor;
- System.Windows.Forms.Application.DoEvents();
- SysMgr.Instance.SendPdtData(model);
- this.Cursor = Cursors.Default;
- }
- catch (Exception ex)
- {
- ;
- }
- }
- #endregion
-
-
- #region 打印设置
- private void tbBarTenderTempPath_DoubleClick(object sender, EventArgs e)
- {
- TextBox bt = (TextBox)sender;
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- DialogResult result = openFileDialog1.ShowDialog();
- if (result == DialogResult.OK)
- {
- bt.Text = openFileDialog1.FileName;
- }
- }
- #endregion
-
- #region 保存设置
- private void tbSavePath_DoubleClick(object sender, EventArgs e)
- {
- TextBox bt = (TextBox)sender;
- string path = ConfMgr.SelectFolder(Application.StartupPath);
- if (!string.IsNullOrWhiteSpace(path))
- {
- bt.Text = path;
- }
- }
- #endregion
-
- private void cmbClasses_TextChanged(object sender, EventArgs e)
- {
- if(cmbClasses.Text == "乳剂")
- {
- //获取所有缺陷项
- var lstDefect = GetArrayList<DefectCodeEnum>();
- lstDefect.RemoveAt(13);
- lstDefect.RemoveAt(13);
- lstDefect.RemoveAt(13);
- lstDefect.RemoveAt(13);
- this.flpQualifiedPannel.Controls.Clear();
- foreach (DictionaryEntry item in lstDefect)
- {
- DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
- userCon.Code = item.Value.ToString();
- userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
- if (model != null && model.QualifiedCriterionList != null)
- {
- var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
- if (qalifiedItem != null)
- {
- userCon.Checked = true;
- userCon.SizeValue = (decimal)qalifiedItem.Size;
- userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
- }
- }
-
- this.flpQualifiedPannel.Controls.Add(userCon);
- }
- }
- else
- {
- //获取所有缺陷项
- var lstDefect = GetArrayList<DefectCodeEnum>();
- lstDefect.RemoveAt(14);
- lstDefect.RemoveAt(14);
- lstDefect.RemoveAt(14);
- this.flpQualifiedPannel.Controls.Clear();
- foreach (DictionaryEntry item in lstDefect)
- {
- DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
- userCon.Code = item.Value.ToString();
- userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
- if (model != null && model.QualifiedCriterionList != null)
- {
- var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
- if (qalifiedItem != null)
- {
- userCon.Checked = true;
- userCon.SizeValue = (decimal)qalifiedItem.Size;
- userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
- }
- }
-
- this.flpQualifiedPannel.Controls.Add(userCon);
- }
- }
- }
- }
- }
|