版博士V2.0程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

996 行
47 KiB

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