版博士V2.0程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

976 lignes
44 KiB

  1. using MaiMuAOI.SysCtrl;
  2. using MaiMuAOI.SysUI.ProcessStep;
  3. using MaiMuControl.Utils;
  4. using Models;
  5. using Newtonsoft.Json;
  6. using OpenCvSharp;
  7. using OpenCvSharp.Flann;
  8. using ProductionControl.UI;
  9. using ProductionControl.UIExtend;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using System.Drawing.Imaging;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Linq.Expressions;
  21. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. using System.Windows.Forms;
  25. using ToolKits.EnumTool;
  26. using ToolKits.mAPI;
  27. namespace MaiMuAOI.SysUI.ProductAndStep
  28. {
  29. public partial class ProductInfoFrm : Form
  30. {
  31. Service.ClassesService svcClasses = new Service.ClassesService();
  32. Service.ProductService service = new Service.ProductService();
  33. Models.Product model = new Models.Product();
  34. public ProductInfoFrm(Models.Product m = null)
  35. {
  36. InitializeComponent();
  37. UIStyle.SetUIStyle(this);
  38. this.uiTitel1.FatherForm = this;
  39. this.dgvBatchList.AutoGenerateColumns = false;
  40. dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
  41. dataGridView2.DefaultCellStyle.ForeColor = Color.Black;
  42. dataGridView3.DefaultCellStyle.ForeColor = Color.Black;
  43. this.Cursor = Cursors.WaitCursor;
  44. skinTabControl1.SelectedIndex = 0;
  45. //显示打印内容
  46. DataGridViewComboBoxColumn cbxColumn = (DataGridViewComboBoxColumn)dataGridView1.Columns["DataType"];
  47. DataGridViewComboBoxColumn cbxColumn2 = (DataGridViewComboBoxColumn)dataGridView2.Columns["DataType2"];
  48. DataGridViewComboBoxColumn cbxColumn3 = (DataGridViewComboBoxColumn)dataGridView3.Columns["DataType3"];
  49. foreach (var s in System.Enum.GetValues(typeof(PrintDataPdtEnum)))
  50. {
  51. PrintDataPdtEnum dataEnum = (PrintDataPdtEnum)s;
  52. cbxColumn.Items.Add(dataEnum.GetDescription());
  53. cbxColumn2.Items.Add(dataEnum.GetDescription());
  54. cbxColumn3.Items.Add(dataEnum.GetDescription());
  55. }
  56. if (m != null)
  57. {
  58. model = m;
  59. this.Text += $" (ID:{m.Id})";
  60. this.txtCode.Text = m.Code;
  61. this.txtName.Text = m.Name;
  62. this.txtSpec.Text = m.Spec;
  63. this.cmbHoleCount.Text = m.HoleCount.ToString();
  64. this.txtBatchId.Text = m.BatchId;
  65. this.numTargetCount.Value = m.TargetCount;
  66. this.toolTip1.SetToolTip(this.numTargetCount, "已完成:" + m.CompleteCount);
  67. this.numTensionBaseValue.Value = (decimal)m.TensionBaseValue;
  68. this.numTensionUpFloatValue.Value = (decimal)m.TensionUpFloatValue;
  69. this.numTensionDownFloatValue.Value = (decimal)m.TensionDownFloatValue;
  70. this.numHeightBaseValue.Value = (decimal)m.HeightBaseValue;
  71. this.numHeightUpFloatValue.Value = (decimal)m.HeightUpFloatValue;
  72. this.numHeightDownFloatValue.Value = (decimal)m.HeightDownFloatValue;
  73. this.txtHeightBaseDec.Text = m.HeightBaseDec;
  74. this.numLineWidthBaseValue.Value = (decimal)m.LineWidthBaseValue;
  75. this.numLineWidthUpFloatValue.Value = (decimal)m.LineWidthUpFloatValue;
  76. this.numLineWidthDownFloatValue.Value = (decimal)m.LineWidthDownFloatValue;
  77. this.numPTBaseValue.Value = (decimal)m.PTBaseValue;
  78. this.numPTUpFloatValue.Value = (decimal)m.PTUpFloatValue;
  79. this.numPTDownFloatValue.Value = (decimal)m.PTDownFloatValue;
  80. this.numPTXBaseValue.Value = (decimal)m.PTXBaseValue;
  81. this.numPTXUpFloatValue.Value = (decimal)m.PTXUpFloatValue;
  82. this.numPTXDownFloatValue.Value = (decimal)m.PTXDownFloatValue;
  83. //if (m.Type > 0)
  84. //{
  85. // this.txtCode.Enabled = false;
  86. // this.txtName.Width = this.txtCode.Width;
  87. // this.txtSpec.Enabled = false;
  88. //}
  89. this.tsbtnAddFile.Enabled = true;
  90. this.tsbtnNewBatchId.Enabled = true;
  91. this.dgvBatchList.DataSource = new BindingSource(m.BatchHistoryList, null);
  92. //2023-11-2 mark
  93. this.cbMarkType.SelectedIndex = m.MarkType;
  94. this.numMarkSize.Value = (decimal)m.MarkSize;
  95. //2023-12-18 主栅
  96. this.cbMarkDisturb.Checked = (m.MarkDisturb == 1);
  97. this.cbMainGrid.Checked = (m.MainGrid == 1);
  98. //2024-1-24 pad
  99. this.cbHavePad.Checked = (m.HavePad == 1);
  100. //2024-5-10 网节
  101. this.cbWangJie.Checked = (m.HaveWJ == 1);
  102. this.cbWBType.SelectedIndex = m.WBType;
  103. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
  104. if (attachmentFile != null)
  105. {
  106. this.btnOpenFile.Text = attachmentFile.Name;
  107. this.btnOpenFile.Visible = true;
  108. if ((this.groupBox5.Width - this.btnOpenFile.Width) > 0)
  109. {
  110. this.btnOpenFile.Left = (this.groupBox5.Width - this.btnOpenFile.Width) / 2;
  111. }
  112. else
  113. this.btnOpenFile.Left = 20;
  114. this.textBoxPath.Text = ConfMgr.Instance.ProjectDir+ $"\\{model.Id}\\" + attachmentFile.Name;
  115. }
  116. //是否显示上传功能
  117. if(ConfMgr.Instance.SysConfigParams.OpenPdtServer)
  118. tsbPdtPush.Visible = true;
  119. else
  120. tsbPdtPush.Visible = false;
  121. /////////////Print////////////////
  122. this.cbOrderPrint.Checked = m.EnableOrderPrint;
  123. this.tbOrderTempPath.Text = m.OrderTempPath;
  124. this.cbOpenBarTenderPrint.Checked = m.EnableLabelPrint;
  125. this.tbBarTenderTempPath.Text = m.LabelTempPath;
  126. this.cbOpenExcelPrint.Checked = m.EnableExcelPrint;
  127. this.tbExcelTempPath.Text = m.ExcelTempPath;
  128. if (m.PrintInfoList != null)
  129. foreach (var item in m.PrintInfoList)
  130. {
  131. if (item.Type == 1 && !item.IsValue)
  132. {
  133. int index = this.dataGridView1.Rows.Add();
  134. this.dataGridView1.Rows[index].Cells[0].Value = item.PrintKey;
  135. this.dataGridView1.Rows[index].Cells[1].Value = item.PrintCode;
  136. }
  137. else if (item.Type == 0 && !item.IsValue)
  138. {
  139. int index = this.dataGridView2.Rows.Add();
  140. this.dataGridView2.Rows[index].Cells[0].Value = item.PrintKey;
  141. this.dataGridView2.Rows[index].Cells[1].Value = item.PrintCode;
  142. }
  143. else if (item.Type == 3 && !item.IsValue)
  144. {
  145. int index = this.dataGridView3.Rows.Add();
  146. this.dataGridView3.Rows[index].Cells[0].Value = item.PrintKey;
  147. this.dataGridView3.Rows[index].Cells[1].Value = item.PrintCode;
  148. }
  149. }
  150. ////////////////////////////////
  151. this.cbOrderSave.Checked = m.EnableOrderSave;
  152. this.tbSavePath.Text = m.OrderSavePath;
  153. }
  154. else
  155. {
  156. cbWBType.SelectedIndex = 0;
  157. cbMarkType.SelectedIndex = 2;
  158. numMarkSize.Value = (decimal)0.5;
  159. this.textBoxPath.Text = "";
  160. }
  161. InitDataView();
  162. this.Cursor = Cursors.Default;
  163. }
  164. ArrayList GetArrayList<T>()
  165. {
  166. ArrayList list = new ArrayList();
  167. Type type = typeof(T);
  168. //list.Add(new DictionaryEntry("start", "启动按钮"));
  169. foreach (int value in Enum.GetValues(type))
  170. {
  171. string strName = Enum.GetName(type, value);//获取名称
  172. list.Add(new DictionaryEntry(value, strName));
  173. }
  174. return list;
  175. }
  176. private void InitDataView()
  177. {
  178. try
  179. {
  180. //显示的数据
  181. this.cmbClasses.DisplayMember = "Name";
  182. this.cmbClasses.ValueMember = "Id";
  183. var list = svcClasses.GetListNav(0);
  184. this.cmbClasses.DataSource = list;
  185. if (model !=null && model.ClassesId > 0)
  186. this.cmbClasses.SelectedValue = model.ClassesId;
  187. //缺陷项
  188. //ArrayList lstDefect = new ArrayList();
  189. //List<string> DefectNames = new List<string>();
  190. //foreach (var item in Enum.GetValues(typeof(DefectCodeEnum)))
  191. //{
  192. // DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  193. // userCon.Code = item.ToString();
  194. // userCon.Title = EnumExtension.GetEnumDescription((DefectCodeEnum)item);
  195. // if (model != null && model.QualifiedCriterionList != null)
  196. // {
  197. // var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  198. // if (qalifiedItem != null)
  199. // {
  200. // userCon.Checked = true;
  201. // userCon.SizeValue = (decimal)qalifiedItem.Size;
  202. // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  203. // }
  204. // }
  205. // this.flpQualifiedPannel.Controls.Add(userCon);
  206. //}
  207. //获取所有缺陷项
  208. //var lstDefect = GetArrayList<DefectCodeEnum>();
  209. //判断是rj还是pt
  210. if (model != null && model.ClassesId > 0)
  211. {
  212. Classes tClasses = svcClasses.GetById(model.ClassesId);
  213. //lstDefect.RemoveAt(10);
  214. //lstDefect.RemoveAt(11);
  215. //lstDefect.RemoveAt(11);
  216. //lstDefect.RemoveAt(11);
  217. //if (tClasses.Name == "乳剂")
  218. //{
  219. // lstDefect.RemoveAt(11);
  220. // lstDefect.RemoveAt(11);
  221. // lstDefect.RemoveAt(11);
  222. //}
  223. //else
  224. // lstDefect.RemoveAt(14);
  225. }
  226. this.flpQualifiedPannel.Controls.Clear();
  227. foreach (var item in ConfMgr.Instance.DefectItemParamsList)
  228. {
  229. string mdname = "rj.onnx";
  230. if (model != null && !string.IsNullOrEmpty(model.DefectModelFile))
  231. mdname = model.DefectModelFile;
  232. if ((item.Type.Split(',').Count(p => p == "-1") > 0 ) ||
  233. (item.Type.Split(',').Count(p => p == mdname.Replace(".onnx", "")) > 0))
  234. {
  235. DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  236. userCon.Code = item.Code;
  237. userCon.Title = item.Name;
  238. userCon.Threshold = (decimal)item.Threshold;
  239. //不显示,是有默认值
  240. if (item.Show == 0)
  241. {
  242. userCon.Checked = true;
  243. userCon.Threshold = (decimal)item.Threshold;
  244. userCon.SizeValue = (decimal)item.Size;
  245. userCon.MaxDefectCount = item.MaxDefectCount;
  246. userCon.Visible = false;
  247. }
  248. else
  249. {
  250. if (model != null && model.QualifiedCriterionList != null)
  251. {
  252. var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  253. if (qalifiedItem != null)
  254. {
  255. userCon.Checked = true;
  256. userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold;
  257. userCon.SizeValue = (decimal)qalifiedItem.Size;
  258. userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  259. }
  260. }
  261. }
  262. this.flpQualifiedPannel.Controls.Add(userCon);
  263. }
  264. }
  265. //模型文件
  266. string strDefectModelFile = ConfMgr.Instance.SysConfigParams.AIModelPath;
  267. string[] onnxFiles = Directory.GetFiles(strDefectModelFile, "*.onnx");
  268. string onlyName;
  269. foreach (string onnxFile in onnxFiles)
  270. {
  271. onlyName = Path.GetFileName(onnxFile);
  272. cmbDefectModelFile.Items.Add(onlyName);
  273. if (!string.IsNullOrWhiteSpace(model.DefectModelFile) && onlyName.ToLower() == model.DefectModelFile.ToLower())
  274. this.cmbDefectModelFile.SelectedItem = model.DefectModelFile;
  275. }
  276. }
  277. catch(Exception e)
  278. {
  279. MessageBox.Show("数据&模型载入出错:"+ e.Message,"报警", MessageBoxButtons.OK,MessageBoxIcon.Error);
  280. }
  281. }
  282. private void ProductInfoFrm_Load(object sender, EventArgs e)
  283. {
  284. }
  285. /// <summary>
  286. /// 保存产品信息
  287. /// </summary>
  288. private void savePdt()
  289. {
  290. string szCode = this.txtCode.Text.Trim();
  291. string szName = this.txtName.Text.Trim();
  292. string szSpec = this.txtSpec.Text.Trim();
  293. string szHoleCount = this.cmbHoleCount.Text.Trim();
  294. string szBatchId = this.txtBatchId.Text.Trim();
  295. int liTargetCount = (int)this.numTargetCount.Value;
  296. string szHeightBaseDec = this.txtHeightBaseDec.Text.Trim().Trim(new char[] { ';', ',' });
  297. if (szCode == "" || szName == "")
  298. throw new Exception("请填写料号和名称!");
  299. if (this.cmbClasses.SelectedIndex < 0)
  300. throw new Exception("请选择产品类型!");
  301. if (szHoleCount == "" || !Util.IsNumber(szHoleCount))
  302. throw new Exception("请正确填写产品目数!");
  303. if (this.cmbDefectModelFile.SelectedIndex < 0)
  304. throw new Exception("请选择检测模型文件!");
  305. if (this.cbMarkType.SelectedIndex < 0)
  306. throw new Exception("请选择Mark!");
  307. //if (szBatchId == "")// || liTargetCount < 1
  308. // throw new Exception("请填写批次号");// 和批次目标数量!");
  309. if (szHeightBaseDec != "")
  310. {
  311. double num;
  312. string[] szs = szHeightBaseDec.Split(new char[] { ';', ',' });
  313. foreach (string s in szs)
  314. {
  315. if (!double.TryParse(s, out num))
  316. throw new Exception(s + " 非数值!");
  317. }
  318. }
  319. model.Code = szCode;
  320. model.Name = szName;
  321. model.Spec = szSpec;
  322. model.ClassesId = (int)this.cmbClasses.SelectedValue;
  323. model.HoleCount = Convert.ToInt32(szHoleCount);
  324. model.DefectModelFile = this.cmbDefectModelFile.Text.Trim();
  325. model.TensionBaseValue = (double)this.numTensionBaseValue.Value;
  326. model.TensionUpFloatValue = (double)this.numTensionUpFloatValue.Value;
  327. model.TensionDownFloatValue = (double)this.numTensionDownFloatValue.Value;
  328. model.HeightBaseValue = (double)this.numHeightBaseValue.Value;
  329. model.HeightUpFloatValue = (double)this.numHeightUpFloatValue.Value;
  330. model.HeightDownFloatValue = (double)this.numHeightDownFloatValue.Value;
  331. model.HeightBaseDec = szHeightBaseDec;
  332. model.LineWidthBaseValue = (double)this.numLineWidthBaseValue.Value;
  333. model.LineWidthUpFloatValue = (double)this.numLineWidthUpFloatValue.Value;
  334. model.LineWidthDownFloatValue = (double)this.numLineWidthDownFloatValue.Value;
  335. model.PTBaseValue = (double)this.numPTBaseValue.Value;
  336. model.PTUpFloatValue = (double)this.numPTUpFloatValue.Value;
  337. model.PTDownFloatValue = (double)this.numPTDownFloatValue.Value;
  338. model.PTXBaseValue = (double)this.numPTXBaseValue.Value;
  339. model.PTXUpFloatValue = (double)this.numPTXUpFloatValue.Value;
  340. model.PTXDownFloatValue = (double)this.numPTXDownFloatValue.Value;
  341. if (model.QualifiedCriterionList == null)
  342. model.QualifiedCriterionList = new List<Models.QualifiedCriterion>();
  343. else
  344. model.QualifiedCriterionList.Clear();
  345. foreach (DefectCountOfSizeControl defectControl in this.flpQualifiedPannel.Controls)
  346. {
  347. if (defectControl.Checked)
  348. {
  349. model.QualifiedCriterionList.Add(
  350. new Models.QualifiedCriterion()
  351. {
  352. DefectCode = defectControl.Code,
  353. Size = (float)defectControl.SizeValue,
  354. MaxDefectCount = (int)defectControl.MaxDefectCount,
  355. Threshold = (double)defectControl.Threshold,
  356. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  357. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  358. });
  359. }
  360. }
  361. model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  362. //2023-11-2 mark
  363. model.MarkType = this.cbMarkType.SelectedIndex;
  364. model.MarkSize = (double)this.numMarkSize.Value;
  365. //2023-12-18 主栅
  366. model.MarkDisturb = this.cbMarkDisturb.Checked ? 1 : 0;
  367. model.MainGrid = this.cbMainGrid.Checked ? 1 : 0;
  368. //2024-1-24 是否存在pad
  369. model.HavePad = this.cbHavePad.Checked ? 1 : 0;
  370. //2024-5-10 是否存在网节
  371. model.HaveWJ = this.cbWangJie.Checked ? 1 : 0;
  372. //2024-9-7 网版规格
  373. model.WBType = this.cbWBType.SelectedIndex;
  374. ////////////////////Print//////////////////////////
  375. model.EnableOrderPrint = this.cbOrderPrint.Checked;
  376. model.OrderTempPath = this.tbOrderTempPath.Text;
  377. model.EnableLabelPrint = this.cbOpenBarTenderPrint.Checked;
  378. model.LabelTempPath = this.tbBarTenderTempPath.Text;
  379. model.EnableExcelPrint = this.cbOpenExcelPrint.Checked;
  380. model.ExcelTempPath = this.tbExcelTempPath.Text;
  381. List<PrintInfo> labeldata = new List<PrintInfo>();
  382. for (int i = 0; i < this.dataGridView1.RowCount; i++)
  383. {
  384. if (this.dataGridView1.Rows[i].Cells[0].Value != null)
  385. labeldata.Add(new PrintInfo()
  386. {
  387. Type = 1,
  388. IsValue = false,
  389. PrintKey = this.dataGridView1.Rows[i].Cells[0].Value.ToString(),
  390. PrintCode = this.dataGridView1.Rows[i].Cells[1].Value.ToString(),
  391. PrintName = "",
  392. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  393. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  394. });
  395. }
  396. for (int i = 0; i < this.dataGridView2.RowCount; i++)
  397. {
  398. if (this.dataGridView2.Rows[i].Cells[0].Value != null)
  399. labeldata.Add(new PrintInfo()
  400. {
  401. Type = 0,
  402. IsValue = false,
  403. PrintKey = this.dataGridView2.Rows[i].Cells[0].Value.ToString(),
  404. PrintCode = this.dataGridView2.Rows[i].Cells[1].Value.ToString(),
  405. PrintName = "",
  406. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  407. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  408. });
  409. }
  410. for (int i = 0; i < this.dataGridView3.RowCount; i++)
  411. {
  412. if (this.dataGridView3.Rows[i].Cells[0].Value != null)
  413. labeldata.Add(new PrintInfo()
  414. {
  415. Type = 3,
  416. IsValue = false,
  417. PrintKey = this.dataGridView3.Rows[i].Cells[0].Value.ToString(),
  418. PrintCode = this.dataGridView3.Rows[i].Cells[1].Value.ToString(),
  419. PrintName = "",
  420. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  421. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  422. });
  423. }
  424. model.PrintInfoList = labeldata;
  425. /////////////////////////////////////////////////
  426. model.EnableOrderSave = cbOrderSave.Checked;
  427. model.OrderSavePath = tbSavePath.Text;
  428. ///
  429. bool result;
  430. if (model.Id == 0)
  431. {
  432. model.BatchId = szBatchId;
  433. model.TargetCount = liTargetCount;
  434. model.CompleteCount = 0;
  435. model.CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  436. result = service.InsertNav(model);
  437. }
  438. else
  439. {
  440. if (model.BatchId != szBatchId && !string.IsNullOrWhiteSpace(model.BatchId))
  441. {
  442. if (model.CompleteCount < model.TargetCount
  443. && MessageBox.Show($"本批次完成数量未达到目标数量,确定更换批次号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  444. return;
  445. if (model.BatchHistoryList.FirstOrDefault(m => m.BatchId == szBatchId) != null)
  446. throw new Exception("当前批次号与历史中所用批次号重复,请重新填写!");
  447. model.BatchHistoryList.Add(new Models.BatchHistory()
  448. {
  449. BatchId = model.BatchId,
  450. TargetCount = model.TargetCount,
  451. CompleteCount = model.CompleteCount,
  452. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  453. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  454. });
  455. model.CompleteCount = 0;
  456. }
  457. model.BatchId = szBatchId;
  458. model.TargetCount = liTargetCount;
  459. result = service.UpdateNav(model);
  460. }
  461. SysMgr.Instance.WriteSysEditLog("产品信息修改", JsonConvert.SerializeObject(model));
  462. if (!result)
  463. throw new Exception("保存失败!");
  464. }
  465. private void tsbtnSave_Click(object sender, EventArgs e)
  466. {
  467. try
  468. {
  469. tsbtnSave.Select();
  470. savePdt();
  471. this.tsbtnAddFile.Enabled = true;
  472. this.tsbtnNewBatchId.Enabled = true;
  473. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  474. this.DialogResult = DialogResult.OK;
  475. this.Close();
  476. }
  477. catch (Exception ex)
  478. {
  479. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  480. }
  481. }
  482. private void tsbtnExit_Click(object sender, EventArgs e)
  483. {
  484. this.Close();
  485. }
  486. private void tsbtnNewBatchId_Click(object sender, EventArgs e)
  487. {
  488. }
  489. private void tsbtnAddFile_Click(object sender, EventArgs e)
  490. {
  491. this.Cursor = Cursors.WaitCursor;
  492. System.Windows.Forms.Application.DoEvents();
  493. try
  494. {
  495. if (this.cbMarkType.SelectedIndex < 0)
  496. throw new Exception("请选择Mark!");
  497. //.dwg /.dxf /.dws /.dwt
  498. string filePath = ConfMgr.SelectFile("gbx,gbr文件|*.gb?");
  499. if (string.IsNullOrWhiteSpace(filePath))
  500. return;
  501. //后台线程转BMP与JPG
  502. string tempClass = this.cmbDefectModelFile.Text;
  503. int tempIndex = this.cbMarkType.SelectedIndex;
  504. double tempSize = (double)this.numMarkSize.Value;
  505. //2023-12-18
  506. int tMarkDistrub = this.cbMarkDisturb.Checked ? 1 : 0;
  507. int tMainGrid = this.cbMainGrid.Checked ? 1 : 0;
  508. //2024-1-24
  509. int tHavePad = this.cbHavePad.Checked ? 1 : 0;
  510. //2024-5-10
  511. int tHaveWJ = this.cbWangJie.Checked ? 1 : 0;
  512. int wbtp = this.cbWBType.SelectedIndex;
  513. string fileName = Path.GetFileName(filePath);
  514. string fileExtend = Path.GetExtension(filePath);
  515. string fileOnlyName = fileName.Substring(0, fileName.Length - fileExtend.Length);
  516. //判断是否已经保存产品信息
  517. if (string.IsNullOrEmpty(model.Name))
  518. {
  519. //产品信息未保存,保存产品信息
  520. savePdt();
  521. }
  522. //显示等待弹窗
  523. WaitFrm waitingBox = new WaitFrm((obj, args) =>
  524. {
  525. try
  526. {
  527. string targFilePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
  528. if (!Directory.Exists(targFilePath))
  529. Directory.CreateDirectory(targFilePath);
  530. else//删除原文件
  531. ConfMgr.DelFilesInFolder(targFilePath);
  532. targFilePath += fileName;
  533. //File.Copy(res.file_path, defectFileName + ".bmp", true);
  534. bool result = API.CopyFile(filePath, targFilePath, false);//更快 //false-覆盖
  535. if (!result)
  536. throw new Exception("移动文件失败!");
  537. Yolo5.Yolo_Class yolo = new Yolo5.Yolo_Class();
  538. string bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".bmp";
  539. //2023-11-3 mark
  540. //yolo.gerber2image(targFilePath, bmpPath);
  541. double[] markParam = new double[9];
  542. if (tempClass.IndexOf("rj") >= 0)
  543. markParam[0] = 2;
  544. else if (tempClass.IndexOf("pi") >= 0)
  545. markParam[0] = 1;
  546. else if (tempClass.IndexOf("best") >= 0)
  547. markParam[0] = 1;
  548. else
  549. markParam[0] = 0;
  550. //if (tempClass.Contains("乳剂"))
  551. // markParam[0] = 2;
  552. //else if (tempClass.Contains("PI"))
  553. // markParam[0] = 1;
  554. //else
  555. // markParam[0] = 0;
  556. if (tempIndex == 0)
  557. {
  558. //默认情况 实心圆,0.5mm
  559. markParam[1] = 2;
  560. markParam[2] = 0.5;
  561. markParam[3] = 1;
  562. markParam[4] = 0;
  563. markParam[5] = 0;
  564. markParam[6] = 0;
  565. markParam[7] = 0;
  566. markParam[8] = 0;
  567. }
  568. else
  569. {
  570. markParam[1] = tempIndex - 1;
  571. markParam[2] = tempSize;
  572. markParam[3] = tempIndex == 1 ? 0 : 1;
  573. markParam[4] = tMarkDistrub;
  574. markParam[5] = tMainGrid;
  575. markParam[6] = tHavePad;
  576. markParam[7] = tHaveWJ;
  577. markParam[8] = wbtp;
  578. }
  579. yolo.gerber2image(targFilePath, bmpPath, markParam);
  580. //换背景JPG
  581. Mat mat = Cv2.ImRead(bmpPath);
  582. Cv2.CvtColor(mat, mat, ColorConversionCodes.RGB2GRAY);//转灰度图
  583. for (int i = 0; i < mat.Height; i++)
  584. {
  585. for (int j = 0; j < mat.Width; j++)
  586. {
  587. if (mat.At<byte>(i, j) == 255)//白色
  588. mat.Set<byte>(i, j, 0);
  589. else
  590. mat.Set<byte>(i, j, 255);
  591. }
  592. }
  593. model.MapPath = bmpPath;
  594. //灰转彩
  595. //Cv2.CvtColor(mat, mat, ColorConversionCodes.GRAY2RGB);
  596. //for (int i = 0; i < mat.Height; i++)
  597. //{
  598. // for (int j = 0; j < mat.Width; j++)
  599. // {
  600. // if (mat.At<byte>(i, j) == 255)//白色
  601. // mat.Set<byte>(i, j, 0); //黄色
  602. // }
  603. //}
  604. bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".jpg";
  605. OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat).Save(bmpPath, ImageFormat.Jpeg);
  606. //});//不能加.Start();
  607. if (model.AttachmentList == null)
  608. model.AttachmentList = new List<Attachment>();
  609. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
  610. if (attachmentFile != null)
  611. {
  612. attachmentFile.Type = 0;//图纸
  613. attachmentFile.NameTimestamp = $"{model.Id}\\{fileOnlyName}";
  614. attachmentFile.Name = fileName;
  615. attachmentFile.ExtendName = fileExtend;
  616. }
  617. else
  618. {
  619. model.AttachmentList.Add(new Models.Attachment()
  620. {
  621. TBName = "product",
  622. Type = 0,
  623. NameTimestamp = $"{model.Id}\\{fileOnlyName}",
  624. Name = fileName,
  625. ExtendName = fileExtend,
  626. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  627. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  628. });
  629. }
  630. if (!service.UpdateNav(model))
  631. throw new Exception("保存文件失败!");
  632. model = service.GetModelNav(model.Code);
  633. }
  634. catch (Exception ex)
  635. {
  636. MessageBox.Show($"图纸解析失败-请检查图纸:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  637. }
  638. }, "图纸解析上传...");
  639. waitingBox.ShowDialog(this);
  640. this.btnOpenFile.Text = fileName;
  641. this.textBoxPath.Text = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + fileName;
  642. this.btnOpenFile.Visible = true;
  643. }
  644. catch (Exception ex)
  645. {
  646. MessageBox.Show($"图纸上传失败-请检查图纸:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  647. }
  648. finally
  649. {
  650. this.Cursor = Cursors.Default;
  651. }
  652. }
  653. private void btnOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  654. {
  655. if (model == null || model.AttachmentList == null)
  656. {
  657. MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  658. return;
  659. }
  660. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
  661. if (attachmentFile == null)
  662. {
  663. MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  664. return;
  665. }
  666. string filePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + attachmentFile.Name;
  667. if (File.Exists(filePath))
  668. Process.Start(filePath);
  669. }
  670. private void tbtnGetPos_Click(object sender, EventArgs e)
  671. {
  672. if ((model.MapPath == null) || (string.IsNullOrEmpty(model.MapPath)))
  673. {
  674. MessageBox.Show("还未上传图纸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  675. return;
  676. }
  677. List<double> dList = new List<double>();
  678. if (model.GetPointList != null)
  679. {
  680. var list = model.GetPointList.Split(',');
  681. dList = new List<double>();
  682. if (list.Length < 28)
  683. {
  684. for (int i = 0; i < 28; i++)
  685. {
  686. dList.Add(0);
  687. }
  688. }
  689. else
  690. {
  691. for (int i = 0; i < list.Length; i++)
  692. {
  693. dList.Add(double.Parse(list[i]));
  694. }
  695. }
  696. }
  697. FrmGetPosByPic frm = new FrmGetPosByPic(model, model.MapPath, dList.ToArray());
  698. frm.ShowDialog();
  699. model.GetPointList = string.Join(",", frm.GetPoints()); ;
  700. model.MapPath = frm.GetMapPath();
  701. if (!service.UpdateNav(model))
  702. throw new Exception("保存文件失败!");
  703. model = service.GetModelNav(model.Code);
  704. }
  705. private void textBoxPath_DoubleClick(object sender, EventArgs e)
  706. {
  707. if (File.Exists(this.textBoxPath.Text))
  708. {
  709. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
  710. if (attachmentFile != null)
  711. {
  712. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  713. psi.Arguments = "/e,/select," + ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
  714. System.Diagnostics.Process.Start(psi);
  715. }
  716. }
  717. }
  718. #region 发送产品数据
  719. private void tsbPdtPush_Click(object sender, EventArgs e)
  720. {
  721. try
  722. {
  723. this.Cursor = Cursors.WaitCursor;
  724. System.Windows.Forms.Application.DoEvents();
  725. SysMgr.Instance.SendPdtData(model);
  726. this.Cursor = Cursors.Default;
  727. }
  728. catch (Exception ex)
  729. {
  730. ;
  731. }
  732. }
  733. #endregion
  734. #region 打印设置
  735. private void tbBarTenderTempPath_DoubleClick(object sender, EventArgs e)
  736. {
  737. TextBox bt = (TextBox)sender;
  738. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  739. DialogResult result = openFileDialog1.ShowDialog();
  740. if (result == DialogResult.OK)
  741. {
  742. bt.Text = openFileDialog1.FileName;
  743. }
  744. }
  745. #endregion
  746. #region 流程管理
  747. private void tsbStep_Click(object sender, EventArgs e)
  748. {
  749. try
  750. {
  751. if (model.StepId != null && model.StepInfo != null)
  752. {
  753. //存在流程,直接打开
  754. //新老流程判断
  755. if (model.StepInfo.ProcessType == "快速流程")
  756. {
  757. StepProcessFrm frm = new StepProcessFrm(model.StepInfo);
  758. frm.ShowDialog(this);
  759. }
  760. else
  761. {
  762. StepInfoFrm frm = new StepInfoFrm(model.StepInfo);
  763. frm.ShowDialog(this);
  764. }
  765. }
  766. else
  767. {
  768. //新建流程
  769. StepSelectFrm stepSelectFrm = new StepSelectFrm();
  770. stepSelectFrm.ShowDialog();
  771. if (stepSelectFrm.ProcessSelect == 200)
  772. {
  773. //老流程
  774. StepInfoFrm frm = new StepInfoFrm();
  775. frm.ShowDialog();
  776. model.StepId = frm.StepID;
  777. }
  778. else if (stepSelectFrm.ProcessSelect == 100)
  779. {
  780. //新流程
  781. StepProcessFrm frm = new StepProcessFrm();
  782. frm.ShowDialog();
  783. model.StepId = frm.StepID;
  784. }
  785. model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  786. bool result = service.UpdateNav(model);
  787. if (!result)
  788. throw new Exception("保存失败!");
  789. model = service.GetModelNav(model.Id);
  790. }
  791. }
  792. catch (Exception ex)
  793. {
  794. MessageBox.Show($"{ex.Message}!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  795. }
  796. }
  797. #endregion
  798. #region 保存设置
  799. private void tbSavePath_DoubleClick(object sender, EventArgs e)
  800. {
  801. TextBox bt = (TextBox)sender;
  802. string path = ConfMgr.SelectFolder(Application.StartupPath);
  803. if (!string.IsNullOrWhiteSpace(path))
  804. {
  805. bt.Text = path;
  806. }
  807. }
  808. #endregion
  809. private void cmbClasses_SelectedIndexChanged(object sender, EventArgs e)
  810. {
  811. //int ClassesId = (int)this.cmbClasses.SelectedValue;
  812. //this.flpQualifiedPannel.Controls.Clear();
  813. //foreach (var item in ConfMgr.Instance.DefectItemParamsList)
  814. //{
  815. // if ((item.Type.Split(',').Count(p => p == "-1") > 0) ||
  816. // (item.Type.Split(',').Count(p => p == ClassesId.ToString()) > 0))
  817. // {
  818. // DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  819. // userCon.Code = item.Code;
  820. // userCon.Title = item.Name;
  821. // userCon.Threshold = (decimal)item.Threshold;
  822. // if (model != null && model.QualifiedCriterionList != null)
  823. // {
  824. // var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  825. // if (qalifiedItem != null)
  826. // {
  827. // userCon.Checked = true;
  828. // userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold;
  829. // userCon.SizeValue = (decimal)qalifiedItem.Size;
  830. // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  831. // }
  832. // }
  833. // this.flpQualifiedPannel.Controls.Add(userCon);
  834. // }
  835. //}
  836. }
  837. private void cmbDefectModelFile_SelectedIndexChanged(object sender, EventArgs e)
  838. {
  839. //int ClassesId = (int)this.cmbDefectModelFile.SelectedValue;
  840. this.flpQualifiedPannel.Controls.Clear();
  841. foreach (var item in ConfMgr.Instance.DefectItemParamsList)
  842. {
  843. bool st = false;
  844. foreach (var name in item.Type.Split(',')) {
  845. st = cmbDefectModelFile.Text.Replace(".onnx", "").IndexOf(name) >=0;
  846. if (st)
  847. {
  848. break;
  849. }
  850. }
  851. if ((item.Type.Split(',').Count(p => p == "-1") > 0) ||
  852. st)
  853. {
  854. DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  855. userCon.Code = item.Code;
  856. userCon.Title = item.Name;
  857. userCon.Threshold = (decimal)item.Threshold;
  858. if (model != null && model.QualifiedCriterionList != null)
  859. {
  860. //不显示,是有默认值
  861. if (item.Show == 0)
  862. {
  863. userCon.Checked = true;
  864. userCon.Threshold = (decimal)item.Threshold;
  865. userCon.SizeValue = (decimal)item.Size;
  866. userCon.MaxDefectCount = item.MaxDefectCount;
  867. userCon.Visible = false;
  868. }
  869. else
  870. {
  871. if (model != null && model.QualifiedCriterionList != null)
  872. {
  873. var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  874. if (qalifiedItem != null)
  875. {
  876. userCon.Checked = true;
  877. userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold;
  878. userCon.SizeValue = (decimal)qalifiedItem.Size;
  879. userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  880. }
  881. }
  882. }
  883. //var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  884. //if (qalifiedItem != null)
  885. //{
  886. // userCon.Checked = true;
  887. // userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold;
  888. // userCon.SizeValue = (decimal)qalifiedItem.Size;
  889. // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  890. //}
  891. }
  892. this.flpQualifiedPannel.Controls.Add(userCon);
  893. }
  894. }
  895. }
  896. }
  897. }