版博士V2.0程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

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