版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

870 líneas
38 KiB

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