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.
 
 
 
 

966 rindas
43 KiB

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