Make_ParseLog.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. using BarTender;
  2. using DevExpress.Xpo.Logger;
  3. using DevExpress.XtraPrinting;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Security;
  12. using System.Security.AccessControl;
  13. using System.Security.Principal;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Web.Services.Description;
  17. using System.Web.UI.WebControls;
  18. using System.Windows.Forms;
  19. using System.Xml;
  20. using UAS_MES_NEW.CustomControl.ButtonUtil;
  21. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  22. using UAS_MES_NEW.DataOperate;
  23. using UAS_MES_NEW.Entity;
  24. using UAS_MES_NEW.PublicMethod;
  25. using static DevExpress.Xpo.DB.DataStoreLongrunnersWatch;
  26. namespace UAS_MES_NEW.Make
  27. {
  28. public partial class Make_ParseLog : Form
  29. {
  30. public Make_ParseLog()
  31. {
  32. InitializeComponent();
  33. }
  34. LogStringBuilder sql = new LogStringBuilder();
  35. DataTable Dbfind;
  36. DataTable dt;
  37. DataHelper dh;
  38. string currFileType = "";
  39. string SN, omakeCode, oMsid, oErrorMessage = "";
  40. string equiType = "";
  41. private void Make_ParseLog_Load(object sender, EventArgs e)
  42. {
  43. dh = SystemInf.dh;
  44. //设置锁定工单
  45. LockMakeCode.GetMakeCodeCtl(ma_code);
  46. ma_code.SetLockCheckBox(LockMakeCode);
  47. //工单号放大镜配置
  48. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  49. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
  50. ma_code.FormName = Name;
  51. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
  52. ma_code.Condition = "ma_statuscode='STARTED'";
  53. ma_code.DbChange += Ma_code_DbChange;
  54. }
  55. private void Ma_code_DbChange(object sender, EventArgs e)
  56. {
  57. Dbfind = ma_code.ReturnData;
  58. BaseUtil.SetFormValue(this.Controls, Dbfind);
  59. //获取工单的其他信息
  60. sql.Clear();
  61. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  62. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  63. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  64. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  65. if (dt.Rows.Count > 0)
  66. {
  67. BaseUtil.SetFormValue(this.Controls, dt);
  68. }
  69. }
  70. private void Device_SelectedIndexChanged(object sender, EventArgs e)
  71. {
  72. if (Device.SelectedIndex == 3)
  73. {
  74. ma_code.Enabled = false;
  75. txtPath.Focus();
  76. txtPath.SelectAll();
  77. return;
  78. }
  79. if (string.IsNullOrEmpty(ma_code.Text))
  80. {
  81. Device.SelectedIndex = -1;
  82. MessageBox.Show(this.ParentForm, "请选择工单", "提示");
  83. return;
  84. }
  85. txtPath.Focus();
  86. txtPath.SelectAll();
  87. }
  88. private void allParse_Click(object sender, EventArgs e)
  89. {
  90. if (string.IsNullOrEmpty(ma_code.Text))
  91. {
  92. MessageBox.Show(this.ParentForm, "请选择工单", "提示");
  93. return;
  94. }
  95. if (Device.SelectedIndex == -1)
  96. {
  97. Device.Focus();
  98. Device.SelectAll();
  99. MessageBox.Show(this.ParentForm, "请选择设备", "提示");
  100. return;
  101. }
  102. if (String.IsNullOrEmpty(txtPath.Text))
  103. {
  104. txtPath.Focus();
  105. txtPath.SelectAll();
  106. return;
  107. }
  108. RefreshFileList();
  109. }
  110. private void Choose_Click(object sender, EventArgs e)
  111. {
  112. if (string.IsNullOrEmpty(ma_code.Text))
  113. {
  114. MessageBox.Show(this.ParentForm, "请选择工单", "提示");
  115. return;
  116. }
  117. if (Device.SelectedIndex == -1)
  118. {
  119. Device.Focus();
  120. Device.SelectAll();
  121. MessageBox.Show(this.ParentForm, "请选择设备", "提示");
  122. return;
  123. }
  124. if (!String.IsNullOrEmpty(txtPath.Text))
  125. {
  126. txtPath.Focus();
  127. txtPath.SelectAll();
  128. }
  129. try
  130. {
  131. FolderBrowserDialog dialog = new FolderBrowserDialog();
  132. switch (Device.SelectedIndex)
  133. {
  134. case 0:
  135. dialog.Description = "请选择读取SPI设备文件夹";
  136. currFileType = "txt";
  137. equiType = "SPI";
  138. break;
  139. case 1:
  140. dialog.Description = "请选择读取AOI设备文本文件";
  141. currFileType = "txt";
  142. equiType = "AOI";
  143. break;
  144. case 2:
  145. dialog.Description = "请选择读取印刷机设备的文本文件夹";
  146. currFileType = "xml";
  147. equiType = "印刷机";
  148. break;
  149. case 3:
  150. dialog.Description = "请选择读取贴片机的文本文件夹";
  151. currFileType = "xml";
  152. equiType = "贴片机";
  153. break;
  154. }
  155. if (dialog.ShowDialog() == DialogResult.OK)
  156. {
  157. txtPath.Text = dialog.SelectedPath;
  158. txtPath.Enabled = false;
  159. Device.Enabled = false;
  160. var watcher = new FileSystemWatcher(txtPath.Text);
  161. watcher.Filter = $"*.{currFileType}";
  162. watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
  163. watcher.Created += OnFileCreated;
  164. /*watcher.Changed += OnFileChanged;
  165. watcher.Deleted += OnFileChanged;
  166. watcher.Renamed += OnFileChanged;*/
  167. watcher.EnableRaisingEvents = true;
  168. }
  169. #region
  170. /*OpenFileDialog dialog = new OpenFileDialog();
  171. dialog.Multiselect = true;//该值确定是否可以选择多个文件
  172. dialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
  173. switch (Device.SelectedIndex)
  174. {
  175. case 0:
  176. dialog.Title = "请选择读取SPI设备文件夹";
  177. dialog.Filter = "All files (*.*)|*.*";
  178. break;
  179. case 1:
  180. dialog.Title = "请选择读取AOI设备文本文件";
  181. dialog.Filter = "All files (*.*)|*.*";
  182. break;
  183. case 2:
  184. dialog.Title = "请选择读取印刷机设备的文本文件夹";
  185. dialog.Filter = "文本文件 (*.xml)|*.xml|All files (*.*)|*.*";
  186. break;
  187. }
  188. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  189. {
  190. txtPath.Text = dialog.FileName;
  191. dialog.Dispose();
  192. ListViewItem item = new ListViewItem();
  193. int count = logList.Items.Count;
  194. item.Text = (++count).ToString();
  195. item.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  196. item.SubItems.Add(txtPath.Text);
  197. logList.Items.Add(item);
  198. }
  199. if (Device.SelectedIndex == 0) // SPI
  200. {
  201. ParseLogInsert(txtPath.Text);
  202. Console.WriteLine();
  203. }
  204. else if (Device.SelectedIndex == 1) // AOI
  205. {
  206. }
  207. else if (Device.SelectedIndex == 2) // 印刷机
  208. {
  209. PrinterData xmlData = ReadWithXmlReader(txtPath.Text);
  210. Console.WriteLine();
  211. }*/
  212. #endregion
  213. }
  214. catch (Exception ex)
  215. {
  216. MessageBox.Show(this.ParentForm, ex.Message, "警告");
  217. }
  218. }
  219. private void OnFileCreated(object sender, FileSystemEventArgs e)
  220. {
  221. RefreshFileList();
  222. }
  223. private void OnFileChanged(object sender, FileSystemEventArgs e)
  224. {
  225. if (e.ChangeType == WatcherChangeTypes.Changed)
  226. {
  227. RefreshFileList();
  228. }
  229. }
  230. private void RefreshFileList()
  231. {
  232. // 在UI线程上执行更新
  233. if (lstFiles.InvokeRequired)
  234. {
  235. lstFiles.Invoke(new Action(RefreshFileList));
  236. return;
  237. }
  238. try
  239. {
  240. if (!Directory.Exists(txtPath.Text))
  241. {
  242. LogMessage($"目录不存在: {txtPath.Text}");
  243. return;
  244. }
  245. string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
  246. if (txtFiles.Length == 0)
  247. {
  248. LogMessage($"当前没有{currFileType.ToUpper()}文件");
  249. return;
  250. }
  251. else
  252. {
  253. foreach (string file in txtFiles)
  254. {
  255. LogMessage(file);
  256. if (Device.SelectedIndex == 0) // SPI
  257. {
  258. ParseLogInsert(file);
  259. Console.WriteLine();
  260. }
  261. else if (Device.SelectedIndex == 1) // AOI
  262. {
  263. ParseLogInsert(file);
  264. Console.WriteLine();
  265. }
  266. else if (Device.SelectedIndex == 2) // 印刷机
  267. {
  268. PrinterData xmlData = ReadWithXmlReader(file);
  269. Console.WriteLine();
  270. }
  271. else if (Device.SelectedIndex == 3) // 贴片机
  272. {
  273. if (!File.Exists(file))
  274. {
  275. LogMessage($"文件不存在: {file}");
  276. }
  277. string xmlContent = File.ReadAllText(file);
  278. var xmlList = ParseXml(xmlContent);
  279. if (ConsoleLog(xmlContent, file))
  280. {
  281. File.Delete(file);
  282. }
  283. List<string> param = new List<string>() { };
  284. string PS_CODE = "";
  285. LogicHandler.GetSerialNumByCaller("Make!ParseLog", out PS_CODE);
  286. List<string> MachineName = new List<string>();
  287. List<string> Part = new List<string>();
  288. List<string> Station = new List<string>();
  289. List<string> ReelNo = new List<string>();
  290. List<string> letNo = new List<string>();
  291. string Part_ = "";
  292. int letNoNum = 0;
  293. foreach (var item in xmlList)
  294. {
  295. MachineName.Add(item.MachineName);
  296. Part_ = item.Part.Split('.')[0];
  297. Station.Add(item.Station);
  298. ReelNo.Add(item.ReelNo);
  299. letNo.Add((++letNoNum).ToString());
  300. }
  301. string ps_id = "";
  302. string lineId = dh.getFieldDataByCondition("smtlocationinto", "SLI_LANE", "SLI_MCNO='" + MachineName[0] + "'").ToString();
  303. if (!dh.CheckExist("productsmt", "ps_prodcode='" + Part_ + "'"))
  304. {
  305. ps_id = dh.GetSEQ("productsmt_seq");
  306. dh.ExecuteSql("insert into productsmt(ps_id,ps_prodcode,ps_status,ps_statuscode,PS_LINECODE,PS_CODE)" +
  307. "values('" + ps_id + "','" + Part_ + "','在录入','ENTERING','"+ lineId + "','"+ PS_CODE + "')", "insert");
  308. }
  309. else
  310. {
  311. ps_id = dh.getFieldDataByCondition("productsmt", "ps_id", "ps_prodcode='"+Part_+"'").ToString();
  312. }
  313. if (dh.getRowCount("productsmtlocation", "PSL_PSID=" + ps_id) > 0)
  314. {
  315. dh.ExecuteSql("delete from productsmtlocation where PSL_PSID" + ps_id, "delete");
  316. }
  317. sql.Clear();
  318. sql.Append("insert into productsmtlocation(PSL_ID, PSL_PSID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  319. "select productsmtlocation_seq.nextval," + ps_id + ",:letArr, :ReelNo,:ReelNo,:Station,BD_BASEQTY,'' from bom@ERP " +
  320. "left join bomdetail@ERP on bo_id=bd_bomid where bo_mothercode='" + Part_ + "' and BD_SONCODE=:ReelNo");
  321. dh.BatchInsert(sql.GetString(), new string[] {"letArr", "ReelNo", "ReelNo", "Station", "ReelNo" },
  322. letNo.ToArray(),ReelNo.ToArray(), ReelNo.ToArray(), Station.ToArray(), ReelNo.ToArray());
  323. Console.WriteLine();
  324. }
  325. }
  326. LogMessage($"共找到{txtFiles.Length}个{currFileType.ToUpper()}文件");
  327. }
  328. }
  329. catch (Exception ex)
  330. {
  331. LogMessage($"刷新文件列表时出错: {ex.Message}");
  332. }
  333. }
  334. private void ParseLogInsert(string PathName)
  335. {
  336. try
  337. {
  338. StreamReader SR = File.OpenText(PathName);
  339. string restOfStream = SR.ReadToEnd();
  340. SR.Close();
  341. SR.Dispose();
  342. List<Log> logArr = new List<Log>() { };
  343. string[] lines = restOfStream.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  344. int fileNum = 0;
  345. foreach (var item in lines)
  346. {
  347. if (string.IsNullOrEmpty(item)) continue;
  348. fileNum++;
  349. string[] currItem = item.Split(',');
  350. string res = "";
  351. /*List<NgData> data = new List<NgData>();*/
  352. if(equiType == "SPI")
  353. {
  354. if (currItem[1] != "PASS")
  355. {
  356. res = "NG";
  357. #region
  358. /*string[] NgArr = currItem[1].Split(';');
  359. foreach (var ngItem in NgArr)
  360. {
  361. string[] ngItemArr = ngItem.Split('*');
  362. List<string> ngItemLocal = ngItemArr[1].Split('&').ToList();
  363. NgData ngData = new NgData {
  364. Code = ngItemArr[0],
  365. Local = ngItemLocal
  366. };
  367. data.Add(ngData);
  368. }*/
  369. #endregion
  370. }
  371. else
  372. {
  373. res = "PASS";
  374. }
  375. }else if (equiType == "AOI")
  376. {
  377. if (currItem[3] != "PASS")
  378. {
  379. res = "NG";
  380. }
  381. else
  382. {
  383. res = "PASS";
  384. }
  385. }
  386. Log itemLog = new Log()
  387. {
  388. SN = currItem[0],
  389. Result = res,
  390. Details = equiType == "SPI" ? currItem[1] : currItem[3]
  391. };
  392. logArr.Add(itemLog);
  393. LogMessage($"已解析: {currItem[0]}");
  394. }
  395. LogMessage($"文件夹{PathName},共{fileNum}条记录");
  396. InsertDb(logArr, PathName);
  397. File.WriteAllText(PathName, string.Empty);
  398. if (ConsoleLog(restOfStream, PathName))
  399. {
  400. File.Delete(PathName);
  401. }
  402. }
  403. catch (Exception ex)
  404. {
  405. MessageBox.Show(this.ParentForm, ex.Message, "警告");
  406. }
  407. }
  408. private void InsertDb(List<Log> logs, string PathName)
  409. {
  410. try
  411. {
  412. int type = Device.SelectedIndex;
  413. StringBuilder sql = new StringBuilder();
  414. List<string> param = new List<string>() { };
  415. foreach (var item in logs)
  416. {
  417. param.Add(item.SN);
  418. param.Add(ma_code.Text);
  419. if (item.Result == "PASS")
  420. {
  421. param.Add(item.Result);
  422. }
  423. else
  424. {
  425. param.Add(item.Result);
  426. }
  427. param.Add(equiType);
  428. param.Add(item.Details);
  429. param.Add(User.UserCode);
  430. param.Add(User.UserSourceCode);
  431. param.Add(User.UserLineCode);
  432. string res = "";
  433. param.Add(res);
  434. string[] paramList = param.ToArray();
  435. dh.CallProcedure("cs_insert_testrejects", ref paramList);
  436. param.Clear();
  437. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, item.SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  438. {
  439. if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, item.SN, "日志解析", "OK", User.UserCode, out oErrorMessage))
  440. {
  441. if (oErrorMessage.Contains("AFTERSUCCESS")) LogMessage(">>" + oErrorMessage + "\n");
  442. sql.Clear();
  443. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  444. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  445. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  446. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  447. BaseUtil.SetFormValue(Controls, dt);
  448. //记录日志
  449. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "日志解析", "日志解析成功", item.SN, "");
  450. LogMessage("<<解析成功\n");
  451. }
  452. else
  453. {
  454. LogMessage(">>" + oErrorMessage + "\n");
  455. }
  456. }
  457. else
  458. {
  459. LogMessage(">>" + oErrorMessage + "\n");
  460. }
  461. }
  462. }
  463. catch (Exception ex)
  464. {
  465. MessageBox.Show(this.ParentForm, ex.Message, "警告");
  466. }
  467. }
  468. private bool ConsoleLog(string Content, string PathName)
  469. {
  470. try
  471. {
  472. string sourceDir = Path.GetDirectoryName(PathName);
  473. string newFolderName = "Logs";
  474. string newFolderPath = Path.Combine(sourceDir, newFolderName);
  475. if (!Directory.Exists(newFolderPath))
  476. {
  477. Directory.CreateDirectory(newFolderPath);
  478. }
  479. string newFileName = "Log_" + Path.GetFileName(PathName);
  480. string newFilePath = Path.Combine(newFolderPath, newFileName);
  481. File.AppendAllText(newFilePath, Content + Environment.NewLine);
  482. return true;
  483. }
  484. catch (Exception ex)
  485. {
  486. MessageBox.Show(this.ParentForm, ex.Message, "警告");
  487. return false;
  488. }
  489. }
  490. private void LogMessage(string message)
  491. {
  492. if (lstFiles.InvokeRequired)
  493. {
  494. lstFiles.Invoke(new Action<string>(LogMessage), message);
  495. return;
  496. }
  497. lstFiles.Items.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
  498. lstFiles.TopIndex = lstFiles.Items.Count - 1;
  499. }
  500. private PrinterData ReadWithXmlReader(string filePath)
  501. {
  502. PrinterData data = new PrinterData();
  503. using (XmlReader reader = XmlReader.Create(filePath))
  504. {
  505. while (reader.Read())
  506. {
  507. if (reader.NodeType == XmlNodeType.Element)
  508. {
  509. switch (reader.Name)
  510. {
  511. case "SN":
  512. data.SN = reader.ReadElementContentAsString();
  513. break;
  514. case "Barcode":
  515. data.Barcode = reader.ReadElementContentAsString();
  516. break;
  517. case "Direction":
  518. data.Direction = reader.ReadElementContentAsString();
  519. break;
  520. case "PrintTime":
  521. data.PrintTime = reader.ReadElementContentAsString();
  522. break;
  523. case "PANEL":
  524. ReadPanelData(reader, data.Panel);
  525. break;
  526. case "PROCESS":
  527. ReadProcessData(reader, data.Process);
  528. break;
  529. }
  530. }
  531. }
  532. }
  533. return data;
  534. }
  535. private void ReadPanelData(XmlReader reader, Panel panel)
  536. {
  537. while (reader.Read())
  538. {
  539. if (reader.NodeType == XmlNodeType.Element)
  540. {
  541. switch (reader.Name)
  542. {
  543. case "PanelID":
  544. panel.PanelID = reader.ReadElementContentAsString();
  545. break;
  546. case "PanelName":
  547. panel.PanelName = reader.ReadElementContentAsString();
  548. break;
  549. case "PanelFirm":
  550. panel.PanelFirm = reader.ReadElementContentAsString();
  551. break;
  552. case "PanelLength":
  553. panel.PanelLength = reader.ReadElementContentAsDouble();
  554. break;
  555. case "PanelWide":
  556. panel.PanelWide = reader.ReadElementContentAsDouble();
  557. break;
  558. case "PanelThickness":
  559. panel.PanelThickness = reader.ReadElementContentAsDouble();
  560. break;
  561. }
  562. }
  563. else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "PANEL")
  564. {
  565. break;
  566. }
  567. }
  568. }
  569. private void ReadProcessData(XmlReader reader, Process process)
  570. {
  571. while (reader.Read())
  572. {
  573. if (reader.NodeType == XmlNodeType.Element)
  574. {
  575. switch (reader.Name)
  576. {
  577. case "ProcessName":
  578. process.ProcessName = reader.ReadElementContentAsString();
  579. break;
  580. case "LineNumber":
  581. process.LineNumber = reader.ReadElementContentAsString();
  582. break;
  583. case "StencilNum":
  584. process.StencilNum = reader.ReadElementContentAsString();
  585. break;
  586. }
  587. }
  588. else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "PROCESS")
  589. {
  590. break;
  591. }
  592. }
  593. }
  594. public List<MachineList> ParseXml(string xmlContent)
  595. {
  596. List<MachineList> result = new List<MachineList>();
  597. try
  598. {
  599. XmlDocument xmlDoc = new XmlDocument();
  600. xmlDoc.LoadXml(xmlContent);
  601. XmlNode machineNode = xmlDoc.SelectSingleNode("//TotalProductionInfo");
  602. string machineName = machineNode?.Attributes["MachineName"]?.Value ?? "Unknown";
  603. string part = machineNode?.Attributes["ProductionProgramName"]?.Value ?? "Unknown";
  604. XmlNodeList feederNodes = xmlDoc.SelectNodes("//FeederProductionManageInfo");
  605. foreach (XmlNode feederNode in feederNodes)
  606. {
  607. MachineList machineList = new MachineList();
  608. string feederBankPosition = feederNode.Attributes["FeederBankPosition"]?.Value ?? "Unknown";
  609. string holeNo = feederNode.Attributes["HoleNo"]?.Value ?? "Unknown";
  610. string componentName = feederNode.Attributes["ComponentName"]?.Value ?? "Unknown";
  611. machineList.MachineName = machineName;
  612. machineList.Part = part;
  613. machineList.ReelNo = componentName;
  614. machineList.Station = $"{machineName}-{feederBankPosition[0]}-{holeNo}";
  615. result.Add(machineList);
  616. }
  617. }
  618. catch (Exception ex)
  619. {
  620. LogMessage($"Error parsing XML: {ex.Message}");
  621. }
  622. return result;
  623. }
  624. private class Log
  625. {
  626. public string SN { set; get; }
  627. public string Result { set; get; }
  628. /*public List<NgData> Details { set; get; }*/
  629. public string Details { set; get; }
  630. }
  631. public class MachineList
  632. {
  633. public string MachineName { set; get; }
  634. public string Part { set; get; }
  635. public string Station { set; get; }
  636. public string ReelNo { set; get; }
  637. }
  638. private class NgData
  639. {
  640. public string Code { set; get; }
  641. public List<string> Local { set; get; }
  642. }
  643. private class PrinterData
  644. {
  645. public string SN { get; set; }
  646. public string Barcode { get; set; }
  647. public string Direction { get; set; }
  648. public string PrintTime { get; set; }
  649. public Panel Panel { get; set; } = new Panel();
  650. public Process Process { get; set; } = new Process();
  651. }
  652. private class Panel
  653. {
  654. public string PanelID { get; set; }
  655. public string PanelName { get; set; }
  656. public string PanelFirm { get; set; }
  657. public double PanelLength { get; set; }
  658. public double PanelWide { get; set; }
  659. public double PanelThickness { get; set; }
  660. }
  661. private class Process
  662. {
  663. public string ProcessName { get; set; }
  664. public string LineNumber { get; set; }
  665. public string StencilNum { get; set; }
  666. }
  667. private void claerBtn_Click(object sender, EventArgs e)
  668. {
  669. lstFiles.Items.Clear();
  670. }
  671. }
  672. }