版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

875 righe
42 KiB

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