Make_CollectNetCode.cs 38 KB

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