版博士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.
 
 
 
 

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