Make_CollectNetCode.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net.Sockets;
  9. using System.Net;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using System.Xml;
  13. using UAS_MES_NEW.DataOperate;
  14. using UAS_MES_NEW.Entity;
  15. using UAS_MES_NEW.PublicMethod;
  16. using System.Speech.Synthesis;
  17. namespace UAS_MES_NEW.Make
  18. {
  19. public partial class Make_CollectNetCode : Form
  20. {
  21. DataHelper dh;
  22. AutoSizeFormClass asc = new AutoSizeFormClass();
  23. LogStringBuilder sql = new LogStringBuilder();
  24. DataTable dt;
  25. //当前序列号记录
  26. string sn_code;
  27. //制造单号
  28. string macode;
  29. //采集网标号
  30. string net_code;
  31. //网标查询条件ms_id
  32. string oMsID;
  33. //判断是否输入网标
  34. Boolean isnetcode = false;
  35. //打印计数
  36. int printcount = 0;
  37. int ma_unlimitin;
  38. private SpeechSynthesizer SpeechSynthesizer;
  39. public Make_CollectNetCode()
  40. {
  41. InitializeComponent();
  42. SpeechSynthesizer = new SpeechSynthesizer();
  43. SpeechSynthesizer.SetOutputToDefaultAudioDevice();
  44. //SpeechSynthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Teen, 0, new System.Globalization.CultureInfo("zh-CN"));
  45. SpeechSynthesizer.Rate = -2;
  46. }
  47. //FileSystemWatcher watcher;
  48. private void Make_CollectNetCode_Load(object sender, EventArgs e)
  49. {
  50. asc.controllInitializeSize(this);
  51. dh = SystemInf.dh;
  52. string sharedFolderPath = @"\\192.168.10.1\othersystem\Type2Output";
  53. sharedFolderPath = @"D:\mes";
  54. sharedFolderPath = @"\\192.168.10.1\othersystem\PickupInformation";
  55. sharedFolderPath = @"D:\标签";
  56. ////// 确保路径以反斜杠结尾,以便正确监控目录
  57. ////if (!sharedFolderPath.EndsWith("\\"))
  58. ////{
  59. //// sharedFolderPath += "\\";
  60. ////}
  61. //// 创建FileSystemWatcher实例
  62. //watcher = new FileSystemWatcher
  63. //{
  64. // Path = sharedFolderPath,
  65. // NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName,
  66. // Filter = "*.*", // 监控所有文件
  67. // IncludeSubdirectories = false, // 根据需要设置为true以监控子目录
  68. // EnableRaisingEvents = true
  69. //};
  70. // 绑定事件处理程序
  71. //fileSystemWatcher1.Created += OnCreated;
  72. //watcher.Changed += OnChanged;
  73. //watcher.Deleted += OnDeleted;
  74. //watcher.Renamed += OnRenamed;
  75. //OperateResult.AppendText(DateTime.Now+" 开始监控文件夹: " + fileSystemWatcher1.Path+ "\n");
  76. //OperateResult.AppendText(DateTime.Now + " 开始监控文件夹: " + fileSystemWatcher2.Path + "\n");
  77. }
  78. // 文件创建事件处理程序
  79. private void OnCreated(object sender, FileSystemEventArgs e)
  80. {
  81. try
  82. {
  83. OperateResult.AppendText(DateTime.Now+" 文件创建: " + e.FullPath + "\n");
  84. //第一版
  85. //if (e.FullPath.Contains("PSK"))
  86. //{
  87. // XmlDocument xmlDoc = new XmlDocument();
  88. // XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
  89. // //忽略文档里面的注释
  90. // settings.IgnoreComments = true;
  91. // XmlReader reader = XmlReader.Create(e.FullPath, settings);
  92. // xmlDoc.Load(reader);
  93. // XmlNode xMLNode = xmlDoc.SelectSingleNode("ProductDataSend");
  94. // XmlNodeList elements = xMLNode.SelectNodes("Element");
  95. // int i = 1;
  96. // string code = "";
  97. // string linecode = "";
  98. // string table = "";
  99. // string psid = "";
  100. // foreach (XmlNode element in elements)
  101. // {
  102. // // 提取并打印每个子节点的值
  103. // string date = element["Date"].InnerText;
  104. // string mcNo = element["MCNo"].InnerText;//机器号1-4
  105. // string stage = element["Stage"].InnerText;
  106. // string lane = element["Lane"].InnerText;//轨道 1 2 分别为1线2线
  107. // string mjsFileName = element["MjsFileName"].InnerText.Split('.')[0];//产品料号
  108. // string mjsGroupName = element["MjsGroupName"].InnerText;
  109. // string lotName = element["LotName"].InnerText;//程序具体名 有BOT的为B面 否则为A面
  110. // string lotNumber = element["LotNumber"].InnerText;
  111. // string fAdd = element["FAdd"].InnerText;//设备站位
  112. // string fSAdd = element["FSAdd"].InnerText;//设备左右 1左2右 如果是占多位置此为0 托盘也是1
  113. // string partsName = element["PartsName"].InnerText;//物料编号
  114. // string partsCount = element["PartsCount"].InnerText;//单位用量
  115. // string chipIni = element["ChipIni"].InnerText;
  116. // string fdrType = element["FdrType"].InnerText;
  117. // string fdrWidth = element["FdrWidth"].InnerText;
  118. // string fdrPitch = element["FdrPitch"].InnerText;
  119. // string skip = element["Skip"].InnerText;
  120. // //// 打印提取的信息,或者你可以根据需要处理这些信息
  121. // //Console.WriteLine($"Date: {date}");
  122. // //Console.WriteLine($"MCNo: {mcNo}");
  123. // //Console.WriteLine($"Stage: {stage}");
  124. // //Console.WriteLine($"Lane: {lane}");
  125. // //Console.WriteLine($"MjsFileName: {mjsFileName}");
  126. // //Console.WriteLine($"MjsGroupName: {mjsGroupName}");
  127. // //Console.WriteLine($"LotName: {lotName}");
  128. // //Console.WriteLine($"LotNumber: {lotNumber}");
  129. // //Console.WriteLine($"FAdd: {fAdd}");
  130. // //Console.WriteLine($"FSAdd: {fSAdd}");
  131. // //Console.WriteLine($"PartsName: {partsName}");
  132. // //Console.WriteLine($"ChipIni: {chipIni}");
  133. // //Console.WriteLine($"FdrType: {fdrType}");
  134. // //Console.WriteLine($"FdrWidth: {fdrWidth}");
  135. // //Console.WriteLine($"FdrPitch: {fdrPitch}");
  136. // //Console.WriteLine($"Skip: {skip}");
  137. // //Console.WriteLine(); // 空行分隔不同的<Element>节点信息
  138. // if (i == 1)
  139. // {
  140. // linecode = lane == "1" ? "SMT01" : "SMT02";
  141. // table = lotName.EndsWith("-B") ? "B" : "A";
  142. // if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileName + "' " +
  143. // "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
  144. // {
  145. // LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code);
  146. // psid = dh.GetSEQ("productsmt_seq");
  147. // dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
  148. // " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid + ",'" + code + "','" + mjsFileName + "','" + linecode + "'" +
  149. // ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
  150. // OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileName},线体:{linecode},板面:{table}\n");
  151. // }
  152. // else
  153. // {
  154. // psid = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileName + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
  155. // dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid + " " +
  156. // "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
  157. // OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileName},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
  158. // }
  159. // // Console.WriteLine("第一个");
  160. // }
  161. // if (!partsCount.Equals("0"))
  162. // {
  163. // dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  164. // " select " + psid + ",productsmtlocation_seq.nextval,sli_id,'" + partsName + "','" + partsName + "',sli_location,1,'" + table + "' from smtlocationinto where sli_mcno = '" + mcNo + "' and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fSAdd + "')>0 ", "insert");
  165. // OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  166. // }
  167. // i++;
  168. // }
  169. // reader.Close();
  170. //}
  171. //第二版
  172. if (e.FullPath.Contains("PSK"))
  173. {
  174. XmlDocument xmlDoc = new XmlDocument();
  175. XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
  176. //忽略文档里面的注释
  177. settings.IgnoreComments = true;
  178. XmlReader reader = XmlReader.Create(e.FullPath, settings);
  179. xmlDoc.Load(reader);
  180. XmlNode xMLNode = xmlDoc.SelectSingleNode("ProductDataSend");
  181. XmlNodeList elements = xMLNode.SelectNodes("Element");
  182. int i = 1;
  183. string code = "";
  184. string linecode = "";
  185. string table = "";
  186. string psid = "";
  187. string code2 = "";
  188. string psid2 = "";
  189. foreach (XmlNode element in elements)
  190. {
  191. // 提取并打印每个子节点的值
  192. string date = element["Date"].InnerText;
  193. string mcNo = element["MCNo"].InnerText;//机器号1-4
  194. string stage = element["Stage"].InnerText;
  195. string lane = element["Lane"].InnerText;//轨道 1 2 分别为1线2线
  196. string mjsFileName = element["MjsFileName"].InnerText.Split('.')[0];//产品料号
  197. string mjsFileNameZS = element["MjsFileName"].InnerText.Split('.')[0]+"-ZS";//产品料号追溯用
  198. string mjsGroupName = element["MjsGroupName"].InnerText;
  199. string lotName = element["LotName"].InnerText;//程序具体名 有BOT的为B面 否则为A面
  200. string lotNumber = element["LotNumber"].InnerText;
  201. string fAdd = element["FAdd"].InnerText;//设备站位
  202. string fSAdd = element["FSAdd"].InnerText;//设备左右 1左2右 如果是占多位置此为0 托盘也是1
  203. string partsName = element["PartsName"].InnerText;//物料编号
  204. string partsCount = element["PartsCount"].InnerText;//单位用量
  205. string chipIni = element["ChipIni"].InnerText;
  206. string fdrType = element["FdrType"].InnerText;
  207. string fdrWidth = element["FdrWidth"].InnerText;
  208. string fdrPitch = element["FdrPitch"].InnerText;
  209. string skip = element["Skip"].InnerText;
  210. //// 打印提取的信息,或者你可以根据需要处理这些信息
  211. //Console.WriteLine($"Date: {date}");
  212. //Console.WriteLine($"MCNo: {mcNo}");
  213. //Console.WriteLine($"Stage: {stage}");
  214. //Console.WriteLine($"Lane: {lane}");
  215. //Console.WriteLine($"MjsFileName: {mjsFileName}");
  216. //Console.WriteLine($"MjsGroupName: {mjsGroupName}");
  217. //Console.WriteLine($"LotName: {lotName}");
  218. //Console.WriteLine($"LotNumber: {lotNumber}");
  219. //Console.WriteLine($"FAdd: {fAdd}");
  220. //Console.WriteLine($"FSAdd: {fSAdd}");
  221. //Console.WriteLine($"PartsName: {partsName}");
  222. //Console.WriteLine($"ChipIni: {chipIni}");
  223. //Console.WriteLine($"FdrType: {fdrType}");
  224. //Console.WriteLine($"FdrWidth: {fdrWidth}");
  225. //Console.WriteLine($"FdrPitch: {fdrPitch}");
  226. //Console.WriteLine($"Skip: {skip}");
  227. //Console.WriteLine(); // 空行分隔不同的<Element>节点信息
  228. //站位上料用站位表
  229. if (i == 1)
  230. {
  231. //linecode = lane == "1" ? "SMT01" : "SMT02";
  232. linecode = "SMT03";
  233. table = lotName.EndsWith("B") ? "B" : "A";
  234. if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileName + "' " +
  235. "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
  236. {
  237. LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code);
  238. psid = dh.GetSEQ("productsmt_seq");
  239. dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
  240. " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid + ",'" + code + "','" + mjsFileName + "','" + linecode + "'" +
  241. ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
  242. OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileName},线体:{linecode},板面:{table}\n");
  243. }
  244. else
  245. {
  246. psid = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileName + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
  247. dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid + " " +
  248. "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
  249. OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileName},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
  250. }
  251. // Console.WriteLine("第一个");
  252. }
  253. if (!partsCount.Equals("0"))
  254. {
  255. dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  256. " select " + psid + ",productsmtlocation_seq.nextval,sli_id,'" + partsName + "','" + partsName + "',sli_location,'"+ partsCount + "','" + table + "' from smtlocationinto where sli_mcno = '" + mcNo + "' and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fSAdd + "')>0 ", "insert");
  257. OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  258. //dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  259. // " select " + psid + ",productsmtlocation_seq.nextval,sli_id,'" + partsName + "','" + partsName + "',sli_location,1,'" + table + "' from smtlocationinto where sli_mcno = '" + mcNo + "' and sli_lane ='" + lane + "' and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fSAdd + "')>0 ", "insert");
  260. //OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  261. }
  262. ////扣料追溯用站位表
  263. //if (i == 1)
  264. //{
  265. // //linecode = lane == "1" ? "SMT01" : "SMT02";
  266. // linecode = "SMT0" + lane;
  267. // table = lotName.EndsWith("B") ? "B" : "A";
  268. // if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileNameZS + "' " +
  269. // "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
  270. // {
  271. // LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code2);
  272. // psid2 = dh.GetSEQ("productsmt_seq");
  273. // dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
  274. // " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid2 + ",'" + code2 + "','" + mjsFileNameZS + "','" + linecode + "'" +
  275. // ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
  276. // OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileNameZS},线体:{linecode},板面:{table}\n");
  277. // }
  278. // else
  279. // {
  280. // psid2 = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileNameZS + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
  281. // dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid2 + " " +
  282. // "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
  283. // OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileNameZS},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
  284. // }
  285. // // Console.WriteLine("第一个");
  286. //}
  287. //if (!partsCount.Equals("0"))
  288. //{
  289. // dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  290. // " select " + psid2 + ",productsmtlocation_seq.nextval,sli_id,'" + partsName + "','" + partsName + "',sli_location,1,'" + table + "' from smtlocationinto where sli_mcno = '" + mcNo + "' and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fSAdd + "')>0 ", "insert");
  291. // OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  292. //}
  293. //else if(dh.CheckExist("smtlocationinto","sli_mcno = '"+mcNo+"' and sli_fadd = '"+fAdd+"' and sli_type = '托盘'")&& dh.CheckExist("productsmtlocation", "PSL_PSID = '" + psid2 + "' and psl_prodcode = '" + partsName + "'"))
  294. //{
  295. // dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  296. // " select " + psid2 + ",productsmtlocation_seq.nextval,sli_id,'" + partsName + "','" + partsName + "',sli_location,1,'" + table + "' from smtlocationinto where sli_mcno = '" + mcNo + "' and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fSAdd + "')>0 ", "insert");
  297. // OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  298. //}
  299. i++;
  300. }
  301. reader.Close();
  302. }
  303. }
  304. catch (Exception ex)
  305. {
  306. OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n");
  307. }
  308. }
  309. // 文件更改事件处理程序
  310. private void OnChanged(object sender, FileSystemEventArgs e)
  311. {
  312. // OperateResult.AppendText("文件更改: " + e.FullPath+"\n");
  313. }
  314. // 文件删除事件处理程序
  315. private void OnDeleted(object sender, FileSystemEventArgs e)
  316. {
  317. //OperateResult.AppendText("文件删除: " + e.FullPath + "\n");
  318. }
  319. // 文件重命名事件处理程序
  320. private void OnRenamed(object sender, RenamedEventArgs e)
  321. {
  322. //OperateResult.AppendText("文件重命名: 从 "+ e.OldFullPath + " 到 "+ e.FullPath + "\n");
  323. }
  324. private void sncode_KeyDown(object sender, KeyEventArgs e)
  325. {
  326. }
  327. private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
  328. {
  329. asc.controlAutoSize(this);
  330. }
  331. private void Make_CollectNetCode_Activated(object sender, EventArgs e)
  332. {
  333. }
  334. private void deleteButton1_Click(object sender, EventArgs e)
  335. {
  336. }
  337. private void Make_CollectNetCode_FormClosed(object sender, FormClosedEventArgs e)
  338. {
  339. // 释放资源
  340. fileSystemWatcher1.Dispose();
  341. timer1.Dispose();
  342. }
  343. private void fileSystemWatcher2_Created(object sender, FileSystemEventArgs e)
  344. {
  345. int i = 0;
  346. try
  347. {
  348. OperateResult.AppendText(DateTime.Now + " 文件创建: " + e.FullPath + "\n");
  349. if (e.FullPath.Contains("dat"))
  350. {
  351. // i = PLGET(e, i);
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. OperateResult.AppendText(i+" "+DateTime.Now + " " + ex.Message + "\n");
  357. }
  358. }
  359. private void PLGET(String path)
  360. {
  361. int i = 0;
  362. bool ql = false;
  363. string message = "";
  364. try
  365. {
  366. string[] lines = File.ReadAllLines(path);
  367. // 解析文件内容
  368. List<string> locations = new List<string>();
  369. List<string> pickups = new List<string>();
  370. List<string> PMisss = new List<string>();
  371. List<string> RMisss = new List<string>();
  372. List<string> DMisss = new List<string>();
  373. List<string> MMisss = new List<string>();
  374. List<string> HMisss = new List<string>();
  375. List<string> TRSMisss = new List<string>();
  376. List<string> ChangeCounts = new List<string>();
  377. foreach (string line in lines)
  378. {
  379. if (!line.StartsWith("[PlotInfo]") && !line.StartsWith("MCNo") && line.Trim() != "") // 跳过标题行
  380. {
  381. string[] fields = line.Split(' ');
  382. // 提取字段
  383. String mcNo = fields[0];
  384. String lane = fields[1];
  385. String fAdd = fields[2];
  386. String fsAdd = fields[3];
  387. string partsName = fields[4].Trim('"');
  388. string feederSerial = fields[5].Trim('"');
  389. Double pickup = Double.Parse(fields[6]);
  390. Double needpickup = Double.Parse(fields[6]);
  391. Double PMiss = Double.Parse(fields[7]);
  392. Double RMiss = Double.Parse(fields[8]);
  393. Double DMiss = Double.Parse(fields[9]);
  394. Double MMiss = Double.Parse(fields[10]);
  395. Double HMiss = Double.Parse(fields[11]);
  396. Double TRSMiss = Double.Parse(fields[12]);
  397. Double ChangeCount = Double.Parse(fields[14]);
  398. String location = "";
  399. // ... 其他字段
  400. // 处理数据
  401. if (pickup > 0)
  402. {
  403. location = dh.getFieldDataByCondition("smtlocationinto", "sli_location", "sli_mcno = '" + mcNo + "' " +
  404. "and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fsAdd + "')>0").ToString();
  405. locations.Add(location);
  406. pickups.Add(pickup.ToString());
  407. PMisss.Add(PMiss.ToString());
  408. RMisss.Add(RMiss.ToString());
  409. DMisss.Add(DMiss.ToString());
  410. MMisss.Add(MMiss.ToString());
  411. HMisss.Add(HMiss.ToString());
  412. TRSMisss.Add(TRSMiss.ToString());
  413. ChangeCounts.Add(ChangeCount.ToString());
  414. //OperateResult.AppendText(DateTime.Now + $"料号: {mcNo}, 轨道: {lane},fAdd: {fAdd} ," +
  415. // $"fsAdd: {fsAdd},站位:{location} PartsName: {partsName}, FeederSerial: {feederSerial},pickup: {pickup}" + "\n");
  416. double reaminqtysum = Double.Parse(dh.getFieldDataByCondition("DEVSMTLOCATION", "nvl(sum(DSL_REMAINQTY),0)", " dsl_location = '" + location + "' ").ToString());
  417. if (reaminqtysum < pickup)
  418. {
  419. OperateResult.AppendText(DateTime.Now + $"站位:{location}缺料 {pickup}" + "\n", Color.OrangeRed);
  420. message = message + $"站位:{location}缺料,";
  421. ql = true;
  422. }
  423. else
  424. {
  425. DataTable dt = (DataTable)dh.ExecuteSql(" select dsl_id,dsl_remainqty,dsl_barcode from DEVSMTLOCATION " +
  426. "where dsl_location = '" + location + "' and nvl(DSL_USABLE,0)<>2 and dsl_remainqty >0 order by dsl_id asc ", "select");
  427. for (int j = 0; j < dt.Rows.Count; j++)
  428. {
  429. if (needpickup > 0)
  430. {
  431. double v_v_useqty = 0;
  432. if (double.Parse(dt.Rows[j]["dsl_remainqty"].ToString()) >= needpickup || j == dt.Rows.Count - 1)
  433. {
  434. v_v_useqty = needpickup;
  435. needpickup = 0;
  436. dh.UpdateByCondition("DEVSMTLOCATION", "dsl_remainqty= dsl_remainqty - " + v_v_useqty + ",dsl_validtime=(case when dsl_validtime is null then sysdate else dsl_validtime end) ", "dsl_id=" + dt.Rows[j]["dsl_id"].ToString() + "");
  437. }
  438. else
  439. {
  440. v_v_useqty = double.Parse(dt.Rows[j]["dsl_remainqty"].ToString());
  441. needpickup = needpickup - v_v_useqty;
  442. dh.UpdateByCondition("DEVSMTLOCATION", "dsl_remainqty= dsl_remainqty - " + v_v_useqty + ",dsl_validtime=(case when dsl_validtime is null then sysdate else dsl_validtime end) ", "dsl_id=" + dt.Rows[j]["dsl_id"].ToString() + "");
  443. }
  444. }
  445. }
  446. dh.UpdateByCondition("DEVSMTLOCATION", "DSL_USABLE= 2,dsl_invalidtime=(case when dsl_invalidtime is null then sysdate else dsl_invalidtime end) ", "dsl_location='" + location + "' and nvl(dsl_remainqty,0)<=0");
  447. OperateResult.AppendText(DateTime.Now + $"站位:{location}扣料{pickup}成功" + "\n", Color.Black);
  448. }
  449. }
  450. i++;
  451. // ... 其他处理
  452. }
  453. }
  454. if (locations.Count > 0)
  455. {
  456. dh.BatchInsert("insert into PLOTDATA(PD_ID,PD_LOCATION,PD_PICKUP,PD_PMISS,PD_RMISS,PD_DMISS,PD_MMISS,PD_HMISS,PD_TRSMISS,PD_CHANGECOUNT,PD_DATE) " +
  457. "values (PLOTDATA_seq.nextval,:locations,:pickups,:PMisss,:RMisss,:DMisss,:MMisss,:HMisss,:TRSMisss,:ChangeCounts,sysdate)",
  458. new string[] { "locations", "pickups", "PMisss", "RMisss", "DMisss", "MMisss", "HMisss", "TRSMisss", "ChangeCounts" },
  459. locations.ToArray(), pickups.ToArray(), PMisss.ToArray(), RMisss.ToArray(), DMisss.ToArray(), MMisss.ToArray(), HMisss.ToArray(), TRSMisss.ToArray(), ChangeCounts.ToArray());
  460. }
  461. if (ql)
  462. {
  463. //OperateResult.AppendText(DateTime.Now + $"SMT缺料提醒" + "\n", Color.Blue);
  464. SpeechSynthesizer.SpeakAsync(message);
  465. }
  466. }
  467. catch (Exception ex)
  468. {
  469. OperateResult.AppendText(i + " " + DateTime.Now + " " + ex.Message + "\n");
  470. }
  471. }
  472. private void fileSystemWatcher2_Changed(object sender, FileSystemEventArgs e)
  473. {
  474. OperateResult.AppendText(DateTime.Now + " 文件修改: " + e.FullPath + "\n");
  475. }
  476. private void fileSystemWatcher2_Deleted(object sender, FileSystemEventArgs e)
  477. {
  478. OperateResult.AppendText(DateTime.Now + " 文件删除: " + e.FullPath + "\n");
  479. }
  480. private void fileSystemWatcher2_Renamed(object sender, RenamedEventArgs e)
  481. {
  482. OperateResult.AppendText(DateTime.Now + " 文件重命名: " + e.FullPath + "\n");
  483. }
  484. private void button1_Click(object sender, EventArgs e)
  485. {
  486. //String ttt = "站位NPM3-6R缺料,站位NPM5-14L缺料";
  487. //SpeechSynthesizer.SpeakAsync(ttt);
  488. //OperateResult.AppendText(DateTime.Now + $"SMT缺料提醒" + "\n", Color.Blue);
  489. //string folderPath = @"\\192.168.10.1\othersystem\PickupInformation"; // 替换为你的文件夹路径
  490. //var datFilesSortedByModificationTime = GetDatFilesSortedByModificationTime(folderPath);
  491. //int c = 0;
  492. //String address = "";
  493. //String path = "";
  494. //foreach (var file in datFilesSortedByModificationTime)
  495. //{
  496. // if (c == 0)
  497. // {
  498. // address = Path.GetFileName(file.Item1);
  499. // if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  500. // {
  501. // PLGET(file.Item1);
  502. // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  503. // break;
  504. // }
  505. // else
  506. // {
  507. // path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  508. // if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  509. // {
  510. // PLGET(file.Item1);
  511. // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  512. // }
  513. // }
  514. // }
  515. // else
  516. // {
  517. // path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  518. // if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  519. // {
  520. // PLGET(file.Item1);
  521. // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  522. // }
  523. // }
  524. // c++;
  525. //}
  526. //if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  527. //{
  528. // dh.ExecuteSql("insert into plot(pl_ip,pl_address,pl_date) values ('" + GetLocalIPAddress() + "','" + address + "',sysdate) ", "select");
  529. //}
  530. //else
  531. //{
  532. // dh.UpdateByCondition("plot", "pl_address = '" + address + "',pl_date = sysdate", "pl_ip = '" + GetLocalIPAddress() + "'");
  533. //}
  534. timer1_Tick(sender, e);
  535. }
  536. static string GetLocalIPAddress()
  537. {
  538. IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
  539. string IPAddress = "";
  540. for (int i = 0; i < IpEntry.AddressList.Length; i++)
  541. {
  542. if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
  543. IPAddress = IpEntry.AddressList[i].ToString();
  544. }
  545. return IPAddress;
  546. //throw new InvalidOperationException("没有找到IPv4地址。");
  547. }
  548. static List<Tuple<string, DateTime>> GetDatFilesSortedByModificationTime(string folderPath)
  549. {
  550. var datFiles = new List<Tuple<string, DateTime>>();
  551. // 遍历指定文件夹及其所有子文件夹
  552. foreach (var file in Directory.GetFiles(folderPath, "*.dat", SearchOption.AllDirectories))
  553. {
  554. // 获取文件的最后修改时间
  555. var lastWriteTime = File.GetLastWriteTime(file);
  556. // 将文件路径和修改时间添加到列表中
  557. datFiles.Add(new Tuple<string, DateTime>(file, lastWriteTime));
  558. }
  559. // 根据修改时间对文件进行排序(升序)
  560. var sortedDatFiles = datFiles.OrderByDescending(file => file.Item2).ToList();
  561. return sortedDatFiles;
  562. }
  563. private void timer1_Tick(object sender, EventArgs e)
  564. {
  565. dh = SystemInf.dh;
  566. dh.ExecuteSql("delete plot where pl_date<sysdate - 2/24", "delete");
  567. string folderPath = @"\\192.168.10.1\othersystem\PickupInformation"; // 替换为你的文件夹路径
  568. var datFilesSortedByModificationTime = GetDatFilesSortedByModificationTime(folderPath);
  569. int c = 0;
  570. String address = "";
  571. String path = "";
  572. foreach (var file in datFilesSortedByModificationTime)
  573. {
  574. if (c == 0)
  575. {
  576. address = Path.GetFileName(file.Item1);
  577. if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  578. {
  579. PLGET(file.Item1);
  580. OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  581. break;
  582. }
  583. else
  584. {
  585. path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  586. if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  587. {
  588. PLGET(file.Item1);
  589. OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  590. }
  591. }
  592. }
  593. else
  594. {
  595. path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  596. if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  597. {
  598. PLGET(file.Item1);
  599. OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  600. }
  601. }
  602. c++;
  603. }
  604. if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  605. {
  606. dh.ExecuteSql("insert into plot(pl_ip,pl_address,pl_date) values ('" + GetLocalIPAddress() + "','" + address + "',sysdate) ", "select");
  607. }
  608. else
  609. {
  610. dh.UpdateByCondition("plot", "pl_address = '" + address + "',pl_date = sysdate", "pl_ip = '" + GetLocalIPAddress() + "'");
  611. }
  612. }
  613. private void button2_Click(object sender, EventArgs e)
  614. {
  615. timer2_Tick(sender, e);
  616. }
  617. private void timer2_Tick(object sender, EventArgs e)
  618. {
  619. dh = SystemInf.dh;
  620. DataTable dt = (DataTable)dh.ExecuteSql(" select to_char(wm_concat('站位:'||dsl_location||'未校验')) mmmm from " +
  621. "( select distinct dsl_location from devsmtlocation where dsl_status=0 and dsl_ifcheck = 0 order by dsl_location asc)", "select");
  622. if (dt.Rows.Count > 0)
  623. {
  624. string message = dt.Rows[0][0].ToString();
  625. OperateResult.AppendText(DateTime.Now + message + "\n");
  626. SpeechSynthesizer.SpeakAsync(message);
  627. }
  628. }
  629. }
  630. }