版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

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