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

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