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

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