版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

992 lines
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. }
  278. else
  279. {
  280. lstDefect.RemoveAt(14);
  281. lstDefect.RemoveAt(14);
  282. lstDefect.RemoveAt(14);
  283. }
  284. }
  285. else
  286. {
  287. lstDefect.RemoveAt(14);
  288. lstDefect.RemoveAt(14);
  289. lstDefect.RemoveAt(14);
  290. }
  291. this.flpQualifiedPannel.Controls.Clear();
  292. foreach (DictionaryEntry item in lstDefect)
  293. {
  294. DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  295. userCon.Code = item.Value.ToString();
  296. userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
  297. if (model != null && model.QualifiedCriterionList != null)
  298. {
  299. var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  300. if (qalifiedItem != null)
  301. {
  302. userCon.Checked = true;
  303. userCon.SizeValue = (decimal)qalifiedItem.Size;
  304. userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  305. }
  306. }
  307. this.flpQualifiedPannel.Controls.Add(userCon);
  308. }
  309. //模型文件
  310. string strDefectModelFile = ConfMgr.Instance.SysConfigParams.AIModelPath;
  311. string[] onnxFiles = Directory.GetFiles(strDefectModelFile, "*.onnx");
  312. string onlyName;
  313. foreach (string onnxFile in onnxFiles)
  314. {
  315. onlyName = Path.GetFileName(onnxFile);
  316. cmbDefectModelFile.Items.Add(onlyName);
  317. if (!string.IsNullOrWhiteSpace(model.DefectModelFile) && onlyName.ToLower() == model.DefectModelFile.ToLower())
  318. this.cmbDefectModelFile.SelectedItem = model.DefectModelFile;
  319. }
  320. }
  321. catch(Exception e)
  322. {
  323. MessageBox.Show("数据&模型载入出错:"+ e.Message,"报警", MessageBoxButtons.OK,MessageBoxIcon.Error);
  324. }
  325. }
  326. private void ProductInfoFrm_Load(object sender, EventArgs e)
  327. {
  328. }
  329. private void tsbtnSave_Click(object sender, EventArgs e)
  330. {
  331. try
  332. {
  333. tsbtnSave.Select();
  334. string szCode = this.txtCode.Text.Trim();
  335. string szName = this.txtName.Text.Trim();
  336. string szSpec = this.txtSpec.Text.Trim();
  337. string szHoleCount = this.cmbHoleCount.Text.Trim();
  338. string szBatchId = this.txtBatchId.Text.Trim();
  339. int liTargetCount = (int)this.numTargetCount.Value;
  340. string szHeightBaseDec = this.txtHeightBaseDec.Text.Trim().Trim(new char[] { ';', ',' });
  341. if (szCode == "" || szName == "")
  342. throw new Exception("请填写料号和名称!");
  343. if (this.cmbClasses.SelectedIndex < 0)
  344. throw new Exception("请选择产品类型!");
  345. if (szHoleCount == "" || !Util.IsNumber(szHoleCount))
  346. throw new Exception("请正确填写产品目数!");
  347. if (this.cmbDefectModelFile.SelectedIndex < 0)
  348. throw new Exception("请选择检测模型文件!");
  349. if (this.cbMarkType.SelectedIndex < 0)
  350. throw new Exception("请选择Mark!");
  351. //if (szBatchId == "")// || liTargetCount < 1
  352. // throw new Exception("请填写批次号");// 和批次目标数量!");
  353. if (szHeightBaseDec != "")
  354. {
  355. double num;
  356. string[] szs = szHeightBaseDec.Split(new char[] { ';', ',' });
  357. foreach (string s in szs)
  358. {
  359. if (!double.TryParse(s, out num))
  360. throw new Exception(s + " 非数值!");
  361. }
  362. }
  363. model.Code = szCode;
  364. model.Name = szName;
  365. model.Spec = szSpec;
  366. model.ClassesId = (int)this.cmbClasses.SelectedValue;
  367. model.HoleCount = Convert.ToInt32(szHoleCount);
  368. model.DefectModelFile = this.cmbDefectModelFile.Text.Trim();
  369. model.TensionBaseValue = (double)this.numTensionBaseValue.Value;
  370. model.TensionUpFloatValue = (double)this.numTensionUpFloatValue.Value;
  371. model.TensionDownFloatValue = (double)this.numTensionDownFloatValue.Value;
  372. model.HeightBaseValue = (double)this.numHeightBaseValue.Value;
  373. model.HeightUpFloatValue = (double)this.numHeightUpFloatValue.Value;
  374. model.HeightDownFloatValue = (double)this.numHeightDownFloatValue.Value;
  375. model.HeightBaseDec = szHeightBaseDec;
  376. model.LineWidthBaseValue = (double)this.numLineWidthBaseValue.Value;
  377. model.LineWidthUpFloatValue = (double)this.numLineWidthUpFloatValue.Value;
  378. model.LineWidthDownFloatValue = (double)this.numLineWidthDownFloatValue.Value;
  379. model.PTBaseValue = (double)this.numPTBaseValue.Value;
  380. model.PTUpFloatValue = (double)this.numPTUpFloatValue.Value;
  381. model.PTDownFloatValue = (double)this.numPTDownFloatValue.Value;
  382. model.PTXBaseValue = (double)this.numPTXBaseValue.Value;
  383. model.PTXUpFloatValue = (double)this.numPTXUpFloatValue.Value;
  384. model.PTXDownFloatValue = (double)this.numPTXDownFloatValue.Value;
  385. //新增判断2024-2-20
  386. model.FLineWidthBaseValue = (double)this.numericUpDown3.Value;
  387. model.FLineWidthUpFloatValue = (double)this.numericUpDown2.Value;
  388. model.FLineWidthDownFloatValue = (double)this.numericUpDown1.Value;
  389. model.MGridIntervalBaseValue = (double)this.numericUpDown6.Value;
  390. model.MGridIntervalUpFloatValue = (double)this.numericUpDown5.Value;
  391. model.MGridIntervalDownFloatValue = (double)this.numericUpDown4.Value;
  392. model.MGridWidthBaseValue = (double)this.numericUpDown9.Value;
  393. model.MGridWidthUpFloatValue = (double)this.numericUpDown8.Value;
  394. model.MGridWidthDownFloatValue = (double)this.numericUpDown7.Value;
  395. model.MGridSpreadBaseValue = (double)this.numericUpDown12.Value;
  396. model.MGridSpreadUpFloatValue = (double)this.numericUpDown11.Value;
  397. model.MGridSpreadDownFloatValue = (double)this.numericUpDown10.Value;
  398. model.FGridSpreadBaseValue = (double)this.numericUpDown15.Value;
  399. model.FGridSpreadUpFloatValue = (double)this.numericUpDown14.Value;
  400. model.FGridSpreadDownFloatValue = (double)this.numericUpDown13.Value;
  401. model.BackPoleWidthBaseValue = (double)this.numericUpDown18.Value;
  402. model.BackPoleWidthUpFloatValue = (double)this.numericUpDown17.Value;
  403. model.BackPoleWidthDownFloatValue = (double)this.numericUpDown16.Value;
  404. model.MGridLengthBaseValue = (double)this.numericUpDown21.Value;
  405. model.MGridLengthUpFloatValue = (double)this.numericUpDown20.Value;
  406. model.MGridLengthDownFloatValue = (double)this.numericUpDown19.Value;
  407. model.MarkXDisBaseValue = (double)this.numericUpDown24.Value;
  408. model.MarkXDisUpFloatValue = (double)this.numericUpDown23.Value;
  409. model.MarkXDisDownFloatValue = (double)this.numericUpDown22.Value;
  410. model.MarkYDisBaseValue = (double)this.numericUpDown27.Value;
  411. model.MarkYDisUpFloatValue = (double)this.numericUpDown26.Value;
  412. model.MarkYDisDownFloatValue = (double)this.numericUpDown25.Value;
  413. model.ForkLengthBaseValue = (double)this.numericUpDown30.Value;
  414. model.ForkLengthUpFloatValue = (double)this.numericUpDown29.Value;
  415. model.ForkLengthDownFloatValue = (double)this.numericUpDown28.Value;
  416. model.ForkWidthBaseValue = (double)this.numericUpDown33.Value;
  417. model.ForkWidthUpFloatValue = (double)this.numericUpDown32.Value;
  418. model.ForkWidthDownFloatValue = (double)this.numericUpDown31.Value;
  419. model.ForkDisBaseValue = (double)this.numericUpDown36.Value;
  420. model.ForkDisUpFloatValue = (double)this.numericUpDown35.Value;
  421. model.ForkDisDownFloatValue = (double)this.numericUpDown34.Value;
  422. model.ChilopodLengthBaseValue = (double)this.numericUpDown39.Value;
  423. model.ChilopodLengthUpFloatValue = (double)this.numericUpDown38.Value;
  424. model.ChilopodLengthDownFloatValue = (double)this.numericUpDown37.Value;
  425. model.ChilopodWidthBaseValue = (double)this.numericUpDown42.Value;
  426. model.ChilopodWidthUpFloatValue = (double)this.numericUpDown41.Value;
  427. model.ChilopodWidthDownFloatValue = (double)this.numericUpDown40.Value;
  428. model.WeldingSpotDisBaseValue = (double)this.numericUpDown45.Value;
  429. model.WeldingSpotDisUpFloatValue = (double)this.numericUpDown44.Value;
  430. model.WeldingSpotDisDownFloatValue = (double)this.numericUpDown43.Value;
  431. model.WeldingSpotWidthBaseValue = (double)this.numericUpDown48.Value;
  432. model.WeldingSpotWidthUpFloatValue = (double)this.numericUpDown47.Value;
  433. model.WeldingSpotWidthDownFloatValue = (double)this.numericUpDown46.Value;
  434. model.WeldingSpotLengthBaseValue = (double)this.numericUpDown51.Value;
  435. model.WeldingSpotLengthUpFloatValue = (double)this.numericUpDown50.Value;
  436. model.WeldingSpotLengthDownFloatValue = (double)this.numericUpDown49.Value;
  437. model.ShardingDisBaseValue = (double)this.numericUpDown54.Value;
  438. model.ShardingDisUpFloatValue = (double)this.numericUpDown53.Value;
  439. model.ShardingDisDownFloatValue = (double)this.numericUpDown52.Value;
  440. if (model.QualifiedCriterionList == null)
  441. model.QualifiedCriterionList = new List<Models.QualifiedCriterion>();
  442. else
  443. model.QualifiedCriterionList.Clear();
  444. foreach (DefectCountOfSizeControl defectControl in this.flpQualifiedPannel.Controls)
  445. {
  446. if (defectControl.Checked)
  447. {
  448. model.QualifiedCriterionList.Add(
  449. new Models.QualifiedCriterion()
  450. {
  451. DefectCode = defectControl.Code,
  452. Size = (float)defectControl.SizeValue,
  453. MaxDefectCount = (int)defectControl.MaxDefectCount,
  454. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  455. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  456. });
  457. }
  458. }
  459. model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  460. //2023-11-2 mark
  461. model.MarkType = this.cbMarkType.SelectedIndex;
  462. model.MarkSize = (double)this.numMarkSize.Value;
  463. //2023-12-18 主栅
  464. model.MarkDisturb = this.cbMarkDisturb.Checked ? 1 : 0;
  465. model.MainGrid = this.cbMainGrid.Checked ? 1 : 0;
  466. //2024-1-24 是否存在pad
  467. model.HavePad = this.cbHavePad.Checked ? 1 : 0;
  468. //2024-5-10 是否存在网节
  469. model.HaveWJ = this.cbWangJie.Checked ? 1 : 0;
  470. ////////////////////Print//////////////////////////
  471. model.EnableOrderPrint = this.cbOrderPrint.Checked;
  472. model.OrderTempPath = this.tbOrderTempPath.Text;
  473. model.EnableLabelPrint = this.cbOpenBarTenderPrint.Checked;
  474. model.LabelTempPath = this.tbBarTenderTempPath.Text;
  475. model.EnableExcelPrint = this.cbOpenExcelPrint.Checked;
  476. model.ExcelTempPath = this.tbExcelTempPath.Text;
  477. List<PrintInfo> labeldata = new List<PrintInfo>();
  478. for (int i = 0; i < this.dataGridView1.RowCount; i++)
  479. {
  480. if (this.dataGridView1.Rows[i].Cells[0].Value != null)
  481. labeldata.Add(new PrintInfo()
  482. {
  483. Type = 1,
  484. IsValue = false,
  485. PrintKey = this.dataGridView1.Rows[i].Cells[0].Value.ToString(),
  486. PrintCode = this.dataGridView1.Rows[i].Cells[1].Value.ToString(),
  487. PrintName = "",
  488. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  489. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  490. }) ;
  491. }
  492. for (int i = 0; i < this.dataGridView2.RowCount; i++)
  493. {
  494. if (this.dataGridView2.Rows[i].Cells[0].Value != null)
  495. labeldata.Add(new PrintInfo()
  496. {
  497. Type = 0,
  498. IsValue = false,
  499. PrintKey = this.dataGridView2.Rows[i].Cells[0].Value.ToString(),
  500. PrintCode = this.dataGridView2.Rows[i].Cells[1].Value.ToString(),
  501. PrintName = "",
  502. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  503. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  504. });
  505. }
  506. for (int i = 0; i < this.dataGridView3.RowCount; i++)
  507. {
  508. if (this.dataGridView3.Rows[i].Cells[0].Value != null)
  509. labeldata.Add(new PrintInfo()
  510. {
  511. Type = 3,
  512. IsValue = false,
  513. PrintKey = this.dataGridView3.Rows[i].Cells[0].Value.ToString(),
  514. PrintCode = this.dataGridView3.Rows[i].Cells[1].Value.ToString(),
  515. PrintName = "",
  516. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  517. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  518. });
  519. }
  520. model.PrintInfoList = labeldata;
  521. model.EnableOrderSave = cbOrderSave.Checked;
  522. model.OrderSavePath = tbSavePath.Text;
  523. #if TZJD
  524. //设置比对参数
  525. Yolo_Class yolo_Class = new Yolo_Class();
  526. if (model.AttachmentList == null || model.AttachmentList.Count == 0)
  527. {
  528. MessageBox.Show("图纸未上传,跳过图纸比对参数设置!");
  529. }
  530. else
  531. {
  532. var attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
  533. string gbxBmpPath = ConfMgr.Instance.ProjectDir + $"\\{attachmentFile.NameTimestamp}";
  534. if (!yolo_Class.WriteCustomThresh(gbxBmpPath, (double)numWM.Value))
  535. {
  536. MessageBox.Show($"比对精度设置失败!请检测 {gbxBmpPath} 图纸是否存在!");
  537. }
  538. else
  539. {
  540. //model.OpenWM = cbOpenWM.Checked;
  541. model.WangMuThresh = (double)numWM.Value;
  542. }
  543. }
  544. #endif
  545. /////////////////////////////////////////////////
  546. ///
  547. bool result;
  548. if (model.Id == 0)
  549. {
  550. model.BatchId = szBatchId;
  551. model.TargetCount = liTargetCount;
  552. model.CompleteCount = 0;
  553. model.CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  554. result = service.InsertNav(model);
  555. }
  556. else
  557. {
  558. if (model.BatchId != szBatchId && !string.IsNullOrWhiteSpace(model.BatchId))
  559. {
  560. if (model.CompleteCount < model.TargetCount
  561. && MessageBox.Show($"本批次完成数量未达到目标数量,确定更换批次号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  562. return;
  563. if (model.BatchHistoryList.FirstOrDefault(m => m.BatchId == szBatchId) != null)
  564. throw new Exception("当前批次号与历史中所用批次号重复,请重新填写!");
  565. model.BatchHistoryList.Add(new Models.BatchHistory()
  566. {
  567. BatchId = model.BatchId,
  568. TargetCount = model.TargetCount,
  569. CompleteCount = model.CompleteCount,
  570. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  571. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  572. });
  573. model.CompleteCount = 0;
  574. }
  575. model.BatchId = szBatchId;
  576. model.TargetCount = liTargetCount;
  577. result = service.UpdateNav(model);
  578. }
  579. if (!result)
  580. throw new Exception("保存失败!");
  581. this.tsbtnAddFile.Enabled = true;
  582. this.tsbtnNewBatchId.Enabled = true;
  583. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  584. this.DialogResult = DialogResult.OK;
  585. this.Close();
  586. }
  587. catch (Exception ex)
  588. {
  589. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  590. }
  591. }
  592. private void tsbtnExit_Click(object sender, EventArgs e)
  593. {
  594. this.Close();
  595. }
  596. private void tsbtnNewBatchId_Click(object sender, EventArgs e)
  597. {
  598. }
  599. private void tsbtnAddFile_Click(object sender, EventArgs e)
  600. {
  601. this.Cursor = Cursors.WaitCursor;
  602. System.Windows.Forms.Application.DoEvents();
  603. try
  604. {
  605. if (this.cbMarkType.SelectedIndex < 0)
  606. throw new Exception("请选择Mark!");
  607. //.dwg /.dxf /.dws /.dwt
  608. string filePath = ConfMgr.SelectFile("gbx,gbr文件|*.gb?");
  609. if (string.IsNullOrWhiteSpace(filePath))
  610. return;
  611. string fileName = Path.GetFileName(filePath);
  612. string fileExtend = Path.GetExtension(filePath);
  613. string fileOnlyName = fileName.Substring(0, fileName.Length - fileExtend.Length);
  614. //
  615. string targFilePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
  616. if (!Directory.Exists(targFilePath))
  617. Directory.CreateDirectory(targFilePath);
  618. else//删除原文件
  619. ConfMgr.DelFilesInFolder(targFilePath);
  620. targFilePath += fileName;
  621. //File.Copy(res.file_path, defectFileName + ".bmp", true);
  622. bool result = API.CopyFile(filePath, targFilePath, false);//更快 //false-覆盖
  623. if (!result)
  624. throw new Exception("移动文件失败!");
  625. //后台线程转BMP与JPG
  626. string tempClass = this.cmbClasses.Text;
  627. int tempIndex = this.cbMarkType.SelectedIndex;
  628. double tempSize = (double)this.numMarkSize.Value;
  629. //2023-12-18
  630. int tMarkDistrub = this.cbMarkDisturb.Checked ? 1 : 0;
  631. int tMainGrid = this.cbMainGrid.Checked ? 1 : 0;
  632. //2024-1-24
  633. int tHavePad = this.cbHavePad.Checked ? 1 : 0;
  634. //2024-5-10
  635. int tHaveWJ = this.cbWangJie.Checked ? 1 : 0;
  636. //Task.Run(() =>
  637. {
  638. Yolo5.Yolo_Class yolo = new Yolo5.Yolo_Class();
  639. string bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".bmp";
  640. //2023-11-3 mark
  641. //yolo.gerber2image(targFilePath, bmpPath);
  642. double[] markParam = new double[8];
  643. if (tempClass.Contains("乳剂"))
  644. markParam[0] = 2;
  645. else if (tempClass.Contains("PI"))
  646. markParam[0] = 1;
  647. else
  648. markParam[0] = 0;
  649. if (tempIndex == 0)
  650. {
  651. //默认情况 实心圆,0.5mm
  652. markParam[1] = 2;
  653. markParam[2] = 0.5;
  654. markParam[3] = 1;
  655. markParam[4] = 0;
  656. markParam[5] = 0;
  657. markParam[6] = 0;
  658. markParam[7] = 1;
  659. }
  660. else
  661. {
  662. markParam[1] = tempIndex - 1;
  663. markParam[2] = tempSize;
  664. markParam[3] = tempIndex == 1 ? 0 : 1;
  665. markParam[4] = tMarkDistrub;
  666. markParam[5] = tMainGrid;
  667. markParam[6] = tHavePad;
  668. }
  669. yolo.gerber2image(targFilePath, bmpPath, markParam);
  670. //换背景JPG
  671. Mat mat = Cv2.ImRead(bmpPath);
  672. Cv2.CvtColor(mat, mat, ColorConversionCodes.RGB2GRAY);//转灰度图
  673. for (int i = 0; i < mat.Height; i++)
  674. {
  675. for (int j = 0; j < mat.Width; j++)
  676. {
  677. if (mat.At<byte>(i, j) == 255)//白色
  678. mat.Set<byte>(i, j, 0);
  679. else
  680. mat.Set<byte>(i, j, 255);
  681. }
  682. }
  683. model.MapPath = bmpPath;
  684. //灰转彩
  685. //Cv2.CvtColor(mat, mat, ColorConversionCodes.GRAY2RGB);
  686. //for (int i = 0; i < mat.Height; i++)
  687. //{
  688. // for (int j = 0; j < mat.Width; j++)
  689. // {
  690. // if (mat.At<byte>(i, j) == 255)//白色
  691. // mat.Set<byte>(i, j, 0); //黄色
  692. // }
  693. //}
  694. bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".jpg";
  695. OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat).Save(bmpPath, ImageFormat.Jpeg);
  696. //});//不能加.Start();
  697. }
  698. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
  699. if (attachmentFile != null)
  700. {
  701. attachmentFile.Type = 0;//图纸
  702. attachmentFile.NameTimestamp = $"{model.Id}\\{fileOnlyName}";
  703. attachmentFile.Name = fileName;
  704. attachmentFile.ExtendName = fileExtend;
  705. }
  706. else
  707. {
  708. model.AttachmentList.Add(new Models.Attachment()
  709. {
  710. TBName = "product",
  711. Type = 0,
  712. NameTimestamp = $"{model.Id}\\{fileOnlyName}",
  713. Name = fileName,
  714. ExtendName = fileExtend,
  715. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  716. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  717. });
  718. }
  719. if (!service.UpdateNav(model))
  720. throw new Exception("保存文件失败!");
  721. model = service.GetModelNav(model.Code);
  722. this.btnOpenFile.Text = fileName;
  723. this.btnOpenFile.Visible = true;
  724. }
  725. catch (Exception ex)
  726. {
  727. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  728. }
  729. finally
  730. {
  731. this.Cursor = Cursors.Default;
  732. }
  733. }
  734. private void btnOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  735. {
  736. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
  737. if (attachmentFile == null)
  738. MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  739. string filePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + attachmentFile.Name;
  740. if (File.Exists(filePath))
  741. Process.Start(filePath);
  742. }
  743. private void tbtnGetPos_Click(object sender, EventArgs e)
  744. {
  745. if ((model.MapPath == null) || (string.IsNullOrEmpty(model.MapPath)))
  746. {
  747. MessageBox.Show("还未上传图纸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  748. return;
  749. }
  750. List<double> dList = new List<double>();
  751. if (model.GetPointList != null)
  752. {
  753. var list = model.GetPointList.Split(',');
  754. dList = new List<double>();
  755. if (list.Length < 28)
  756. {
  757. for (int i = 0; i < 28; i++)
  758. {
  759. dList.Add(0);
  760. }
  761. }
  762. else
  763. {
  764. for (int i = 0; i < list.Length; i++)
  765. {
  766. dList.Add(double.Parse(list[i]));
  767. }
  768. }
  769. }
  770. FrmGetPosByPic frm = new FrmGetPosByPic(model, model.MapPath, dList.ToArray());
  771. frm.ShowDialog();
  772. model.GetPointList = string.Join(",", frm.GetPoints()); ;
  773. model.MapPath = frm.GetMapPath();
  774. if (!service.UpdateNav(model))
  775. throw new Exception("保存文件失败!");
  776. model = service.GetModelNav(model.Code);
  777. }
  778. private void textBoxPath_DoubleClick(object sender, EventArgs e)
  779. {
  780. if (File.Exists(this.textBoxPath.Text))
  781. {
  782. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
  783. if (attachmentFile != null)
  784. {
  785. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  786. psi.Arguments = "/e,/select," + ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
  787. System.Diagnostics.Process.Start(psi);
  788. }
  789. }
  790. }
  791. #region 发送产品数据
  792. private void tsbPdtPush_Click(object sender, EventArgs e)
  793. {
  794. try
  795. {
  796. this.Cursor = Cursors.WaitCursor;
  797. System.Windows.Forms.Application.DoEvents();
  798. SysMgr.Instance.SendPdtData(model);
  799. this.Cursor = Cursors.Default;
  800. }
  801. catch (Exception ex)
  802. {
  803. ;
  804. }
  805. }
  806. #endregion
  807. #region 打印设置
  808. private void tbBarTenderTempPath_DoubleClick(object sender, EventArgs e)
  809. {
  810. TextBox bt = (TextBox)sender;
  811. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  812. DialogResult result = openFileDialog1.ShowDialog();
  813. if (result == DialogResult.OK)
  814. {
  815. bt.Text = openFileDialog1.FileName;
  816. }
  817. }
  818. #endregion
  819. #region 保存设置
  820. private void tbSavePath_DoubleClick(object sender, EventArgs e)
  821. {
  822. TextBox bt = (TextBox)sender;
  823. string path = ConfMgr.SelectFolder(Application.StartupPath);
  824. if (!string.IsNullOrWhiteSpace(path))
  825. {
  826. bt.Text = path;
  827. }
  828. }
  829. #endregion
  830. private void cmbClasses_TextChanged(object sender, EventArgs e)
  831. {
  832. if(cmbClasses.Text == "乳剂")
  833. {
  834. //获取所有缺陷项
  835. var lstDefect = GetArrayList<DefectCodeEnum>();
  836. lstDefect.RemoveAt(13);
  837. lstDefect.RemoveAt(13);
  838. lstDefect.RemoveAt(13);
  839. lstDefect.RemoveAt(13);
  840. this.flpQualifiedPannel.Controls.Clear();
  841. foreach (DictionaryEntry item in lstDefect)
  842. {
  843. DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  844. userCon.Code = item.Value.ToString();
  845. userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
  846. if (model != null && model.QualifiedCriterionList != null)
  847. {
  848. var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  849. if (qalifiedItem != null)
  850. {
  851. userCon.Checked = true;
  852. userCon.SizeValue = (decimal)qalifiedItem.Size;
  853. userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  854. }
  855. }
  856. this.flpQualifiedPannel.Controls.Add(userCon);
  857. }
  858. }
  859. else
  860. {
  861. //获取所有缺陷项
  862. var lstDefect = GetArrayList<DefectCodeEnum>();
  863. lstDefect.RemoveAt(14);
  864. lstDefect.RemoveAt(14);
  865. lstDefect.RemoveAt(14);
  866. this.flpQualifiedPannel.Controls.Clear();
  867. foreach (DictionaryEntry item in lstDefect)
  868. {
  869. DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  870. userCon.Code = item.Value.ToString();
  871. userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
  872. if (model != null && model.QualifiedCriterionList != null)
  873. {
  874. var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  875. if (qalifiedItem != null)
  876. {
  877. userCon.Checked = true;
  878. userCon.SizeValue = (decimal)qalifiedItem.Size;
  879. userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  880. }
  881. }
  882. this.flpQualifiedPannel.Controls.Add(userCon);
  883. }
  884. }
  885. }
  886. }
  887. }