Make_CollectNetCode.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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 innerText = element["MjsFileName"].InnerText;
  200. int idx = innerText.LastIndexOf('.');
  201. string mjsFileName = idx > 0 ? innerText.Substring(0, idx) : innerText;
  202. string mjsFileNameZS = (idx > 0 ? innerText.Substring(0, idx) : innerText) + "-ZS";
  203. string mjsGroupName = element["MjsGroupName"].InnerText;
  204. string lotName = element["LotName"].InnerText;//程序具体名 有BOT的为B面 否则为A面
  205. string lotNumber = element["LotNumber"].InnerText;
  206. string fAdd = element["FAdd"].InnerText;//设备站位
  207. string fSAdd = element["FSAdd"].InnerText;//设备左右 1左2右 如果是占多位置此为0 托盘也是1
  208. string partsName = element["PartsName"].InnerText;//物料编号
  209. string partsCount = element["PartsCount"].InnerText;//单位用量
  210. string chipIni = element["ChipIni"].InnerText;
  211. string fdrType = element["FdrType"].InnerText;
  212. string fdrWidth = element["FdrWidth"].InnerText;
  213. string fdrPitch = element["FdrPitch"].InnerText;
  214. string skip = element["Skip"].InnerText;
  215. //// 打印提取的信息,或者你可以根据需要处理这些信息
  216. //Console.WriteLine($"Date: {date}");
  217. //Console.WriteLine($"MCNo: {mcNo}");
  218. //Console.WriteLine($"Stage: {stage}");
  219. //Console.WriteLine($"Lane: {lane}");
  220. //Console.WriteLine($"MjsFileName: {mjsFileName}");
  221. //Console.WriteLine($"MjsGroupName: {mjsGroupName}");
  222. //Console.WriteLine($"LotName: {lotName}");
  223. //Console.WriteLine($"LotNumber: {lotNumber}");
  224. //Console.WriteLine($"FAdd: {fAdd}");
  225. //Console.WriteLine($"FSAdd: {fSAdd}");
  226. //Console.WriteLine($"PartsName: {partsName}");
  227. //Console.WriteLine($"ChipIni: {chipIni}");
  228. //Console.WriteLine($"FdrType: {fdrType}");
  229. //Console.WriteLine($"FdrWidth: {fdrWidth}");
  230. //Console.WriteLine($"FdrPitch: {fdrPitch}");
  231. //Console.WriteLine($"Skip: {skip}");
  232. //Console.WriteLine(); // 空行分隔不同的<Element>节点信息
  233. //站位上料用站位表
  234. if (i == 1)
  235. {
  236. //linecode = lane == "1" ? "SMT01" : "SMT02";
  237. linecode = "SMT0" + lane;
  238. table = lotName.EndsWith("-B") ? "B" : "A";
  239. if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileName + "' " +
  240. "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
  241. {
  242. LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code);
  243. psid = dh.GetSEQ("productsmt_seq");
  244. dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
  245. " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid + ",'" + code + "','" + mjsFileName + "','" + linecode + "'" +
  246. ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
  247. OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileName},线体:{linecode},板面:{table}\n");
  248. }
  249. else
  250. {
  251. psid = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileName + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
  252. dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid + " " +
  253. "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
  254. OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileName},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
  255. }
  256. // Console.WriteLine("第一个");
  257. }
  258. //if (!partsCount.Equals("0"))
  259. //{
  260. //dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  261. // " 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");
  262. //OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  263. dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  264. " 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");
  265. OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  266. //}
  267. //扣料追溯用站位表
  268. if (i == 1)
  269. {
  270. //linecode = lane == "1" ? "SMT01" : "SMT02";
  271. linecode = "SMT0" + lane;
  272. table = lotName.EndsWith("-B") ? "B" : "A";
  273. if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileNameZS + "' " +
  274. "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
  275. {
  276. LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code2);
  277. psid2 = dh.GetSEQ("productsmt_seq");
  278. dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
  279. " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid2 + ",'" + code2 + "','" + mjsFileNameZS + "','" + linecode + "'" +
  280. ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
  281. OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileNameZS},线体:{linecode},板面:{table}\n");
  282. }
  283. else
  284. {
  285. psid2 = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileNameZS + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
  286. dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid2 + " " +
  287. "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
  288. OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileNameZS},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
  289. }
  290. // Console.WriteLine("第一个");
  291. }
  292. if (!partsCount.Equals("0"))
  293. {
  294. dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  295. " 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");
  296. OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  297. }
  298. 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 + "'"))
  299. {
  300. dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  301. " 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");
  302. OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  303. }
  304. i++;
  305. }
  306. reader.Close();
  307. }
  308. }
  309. catch (Exception ex)
  310. {
  311. OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n");
  312. }
  313. }
  314. // 文件更改事件处理程序
  315. private void OnChanged(object sender, FileSystemEventArgs e)
  316. {
  317. // OperateResult.AppendText("文件更改: " + e.FullPath+"\n");
  318. }
  319. // 文件删除事件处理程序
  320. private void OnDeleted(object sender, FileSystemEventArgs e)
  321. {
  322. //OperateResult.AppendText("文件删除: " + e.FullPath + "\n");
  323. }
  324. // 文件重命名事件处理程序
  325. private void OnRenamed(object sender, RenamedEventArgs e)
  326. {
  327. //OperateResult.AppendText("文件重命名: 从 "+ e.OldFullPath + " 到 "+ e.FullPath + "\n");
  328. }
  329. private void sncode_KeyDown(object sender, KeyEventArgs e)
  330. {
  331. }
  332. private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
  333. {
  334. asc.controlAutoSize(this);
  335. }
  336. private void Make_CollectNetCode_Activated(object sender, EventArgs e)
  337. {
  338. }
  339. private void deleteButton1_Click(object sender, EventArgs e)
  340. {
  341. }
  342. private void Make_CollectNetCode_FormClosed(object sender, FormClosedEventArgs e)
  343. {
  344. // 释放资源
  345. fileSystemWatcher1.Dispose();
  346. timer1.Dispose();
  347. }
  348. private void fileSystemWatcher2_Created(object sender, FileSystemEventArgs e)
  349. {
  350. int i = 0;
  351. try
  352. {
  353. OperateResult.AppendText(DateTime.Now + " 文件创建: " + e.FullPath + "\n");
  354. if (e.FullPath.Contains("dat"))
  355. {
  356. // i = PLGET(e, i);
  357. }
  358. }
  359. catch (Exception ex)
  360. {
  361. OperateResult.AppendText(i+" "+DateTime.Now + " " + ex.Message + "\n");
  362. }
  363. }
  364. private void PLGET(String path)
  365. {
  366. int i = 0;
  367. bool ql = false;
  368. string message = "";
  369. try
  370. {
  371. string[] lines = File.ReadAllLines(path);
  372. // 解析文件内容
  373. List<string> locations = new List<string>();
  374. List<string> pickups = new List<string>();
  375. List<string> PMisss = new List<string>();
  376. List<string> RMisss = new List<string>();
  377. List<string> DMisss = new List<string>();
  378. List<string> MMisss = new List<string>();
  379. List<string> HMisss = new List<string>();
  380. List<string> TRSMisss = new List<string>();
  381. List<string> ChangeCounts = new List<string>();
  382. foreach (string line in lines)
  383. {
  384. if (!line.StartsWith("[PlotInfo]") && !line.StartsWith("MCNo") && line.Trim() != "") // 跳过标题行
  385. {
  386. string[] fields = line.Split(' ');
  387. // 提取字段
  388. String mcNo = fields[0];
  389. String lane = fields[1];
  390. String fAdd = fields[2];
  391. String fsAdd = fields[3];
  392. string partsName = fields[4].Trim('"');
  393. string feederSerial = fields[5].Trim('"');
  394. Double pickup = Double.Parse(fields[6]);
  395. Double needpickup = Double.Parse(fields[6]);
  396. Double PMiss = Double.Parse(fields[7]);
  397. Double RMiss = Double.Parse(fields[8]);
  398. Double DMiss = Double.Parse(fields[9]);
  399. Double MMiss = Double.Parse(fields[10]);
  400. Double HMiss = Double.Parse(fields[11]);
  401. Double TRSMiss = Double.Parse(fields[12]);
  402. Double ChangeCount = Double.Parse(fields[14]);
  403. String location = "";
  404. // ... 其他字段
  405. // 处理数据
  406. if (pickup > 0)
  407. {
  408. location = dh.getFieldDataByCondition("smtlocationinto", "sli_location", "sli_mcno = '" + mcNo + "' " +
  409. "and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fsAdd + "')>0").ToString();
  410. locations.Add(location);
  411. pickups.Add(pickup.ToString());
  412. PMisss.Add(PMiss.ToString());
  413. RMisss.Add(RMiss.ToString());
  414. DMisss.Add(DMiss.ToString());
  415. MMisss.Add(MMiss.ToString());
  416. HMisss.Add(HMiss.ToString());
  417. TRSMisss.Add(TRSMiss.ToString());
  418. ChangeCounts.Add(ChangeCount.ToString());
  419. //OperateResult.AppendText(DateTime.Now + $"料号: {mcNo}, 轨道: {lane},fAdd: {fAdd} ," +
  420. // $"fsAdd: {fsAdd},站位:{location} PartsName: {partsName}, FeederSerial: {feederSerial},pickup: {pickup}" + "\n");
  421. double reaminqtysum = Double.Parse(dh.getFieldDataByCondition("DEVSMTLOCATION", "nvl(sum(DSL_REMAINQTY),0)", " dsl_location = '" + location + "' ").ToString());
  422. if (reaminqtysum < pickup)
  423. {
  424. OperateResult.AppendText(DateTime.Now + $"站位:{location}缺料 {pickup}" + "\n", Color.OrangeRed);
  425. message = message + $"站位:{location}缺料,";
  426. ql = true;
  427. }
  428. else
  429. {
  430. DataTable dt = (DataTable)dh.ExecuteSql(" select dsl_id,dsl_remainqty,dsl_barcode from DEVSMTLOCATION " +
  431. "where dsl_location = '" + location + "' and nvl(DSL_USABLE,0)<>2 and dsl_remainqty >0 order by dsl_id asc ", "select");
  432. for (int j = 0; j < dt.Rows.Count; j++)
  433. {
  434. if (needpickup > 0)
  435. {
  436. double v_v_useqty = 0;
  437. if (double.Parse(dt.Rows[j]["dsl_remainqty"].ToString()) >= needpickup || j == dt.Rows.Count - 1)
  438. {
  439. v_v_useqty = needpickup;
  440. needpickup = 0;
  441. 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() + "");
  442. }
  443. else
  444. {
  445. v_v_useqty = double.Parse(dt.Rows[j]["dsl_remainqty"].ToString());
  446. needpickup = needpickup - v_v_useqty;
  447. 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() + "");
  448. }
  449. }
  450. }
  451. 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");
  452. OperateResult.AppendText(DateTime.Now + $"站位:{location}扣料{pickup}成功" + "\n", Color.Black);
  453. }
  454. }
  455. i++;
  456. // ... 其他处理
  457. }
  458. }
  459. if (locations.Count > 0)
  460. {
  461. 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) " +
  462. "values (PLOTDATA_seq.nextval,:locations,:pickups,:PMisss,:RMisss,:DMisss,:MMisss,:HMisss,:TRSMisss,:ChangeCounts,sysdate)",
  463. new string[] { "locations", "pickups", "PMisss", "RMisss", "DMisss", "MMisss", "HMisss", "TRSMisss", "ChangeCounts" },
  464. locations.ToArray(), pickups.ToArray(), PMisss.ToArray(), RMisss.ToArray(), DMisss.ToArray(), MMisss.ToArray(), HMisss.ToArray(), TRSMisss.ToArray(), ChangeCounts.ToArray());
  465. }
  466. if (ql)
  467. {
  468. //OperateResult.AppendText(DateTime.Now + $"SMT缺料提醒" + "\n", Color.Blue);
  469. SpeechSynthesizer.SpeakAsync(message);
  470. }
  471. }
  472. catch (Exception ex)
  473. {
  474. OperateResult.AppendText(i + " " + DateTime.Now + " " + ex.Message + "\n");
  475. }
  476. }
  477. private void fileSystemWatcher2_Changed(object sender, FileSystemEventArgs e)
  478. {
  479. OperateResult.AppendText(DateTime.Now + " 文件修改: " + e.FullPath + "\n");
  480. }
  481. private void fileSystemWatcher2_Deleted(object sender, FileSystemEventArgs e)
  482. {
  483. OperateResult.AppendText(DateTime.Now + " 文件删除: " + e.FullPath + "\n");
  484. }
  485. private void fileSystemWatcher2_Renamed(object sender, RenamedEventArgs e)
  486. {
  487. OperateResult.AppendText(DateTime.Now + " 文件重命名: " + e.FullPath + "\n");
  488. }
  489. private void button1_Click(object sender, EventArgs e)
  490. {
  491. //String ttt = "站位NPM3-6R缺料,站位NPM5-14L缺料";
  492. //SpeechSynthesizer.SpeakAsync(ttt);
  493. //OperateResult.AppendText(DateTime.Now + $"SMT缺料提醒" + "\n", Color.Blue);
  494. //string folderPath = @"\\192.168.10.1\othersystem\PickupInformation"; // 替换为你的文件夹路径
  495. //var datFilesSortedByModificationTime = GetDatFilesSortedByModificationTime(folderPath);
  496. //int c = 0;
  497. //String address = "";
  498. //String path = "";
  499. //foreach (var file in datFilesSortedByModificationTime)
  500. //{
  501. // if (c == 0)
  502. // {
  503. // address = Path.GetFileName(file.Item1);
  504. // if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  505. // {
  506. // PLGET(file.Item1);
  507. // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  508. // break;
  509. // }
  510. // else
  511. // {
  512. // path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  513. // if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  514. // {
  515. // PLGET(file.Item1);
  516. // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  517. // }
  518. // }
  519. // }
  520. // else
  521. // {
  522. // path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  523. // if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  524. // {
  525. // PLGET(file.Item1);
  526. // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  527. // }
  528. // }
  529. // c++;
  530. //}
  531. //if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  532. //{
  533. // dh.ExecuteSql("insert into plot(pl_ip,pl_address,pl_date) values ('" + GetLocalIPAddress() + "','" + address + "',sysdate) ", "select");
  534. //}
  535. //else
  536. //{
  537. // dh.UpdateByCondition("plot", "pl_address = '" + address + "',pl_date = sysdate", "pl_ip = '" + GetLocalIPAddress() + "'");
  538. //}
  539. timer1_Tick(sender, e);
  540. }
  541. static string GetLocalIPAddress()
  542. {
  543. IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
  544. string IPAddress = "";
  545. for (int i = 0; i < IpEntry.AddressList.Length; i++)
  546. {
  547. if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
  548. IPAddress = IpEntry.AddressList[i].ToString();
  549. }
  550. return IPAddress;
  551. //throw new InvalidOperationException("没有找到IPv4地址。");
  552. }
  553. static List<Tuple<string, DateTime>> GetDatFilesSortedByModificationTime(string folderPath)
  554. {
  555. var datFiles = new List<Tuple<string, DateTime>>();
  556. // 遍历指定文件夹及其所有子文件夹
  557. foreach (var file in Directory.GetFiles(folderPath, "*.dat", SearchOption.AllDirectories))
  558. {
  559. // 获取文件的最后修改时间
  560. var lastWriteTime = File.GetLastWriteTime(file);
  561. // 将文件路径和修改时间添加到列表中
  562. datFiles.Add(new Tuple<string, DateTime>(file, lastWriteTime));
  563. }
  564. // 根据修改时间对文件进行排序(升序)
  565. var sortedDatFiles = datFiles.OrderByDescending(file => file.Item2).ToList();
  566. return sortedDatFiles;
  567. }
  568. private void timer1_Tick(object sender, EventArgs e)
  569. {
  570. dh = SystemInf.dh;
  571. dh.ExecuteSql("delete plot where pl_date<sysdate - 2/24", "delete");
  572. string folderPath = @"\\192.168.10.1\othersystem\PickupInformation"; // 替换为你的文件夹路径
  573. var datFilesSortedByModificationTime = GetDatFilesSortedByModificationTime(folderPath);
  574. int c = 0;
  575. String address = "";
  576. String path = "";
  577. foreach (var file in datFilesSortedByModificationTime)
  578. {
  579. if (c == 0)
  580. {
  581. address = Path.GetFileName(file.Item1);
  582. if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  583. {
  584. PLGET(file.Item1);
  585. OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  586. break;
  587. }
  588. else
  589. {
  590. path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  591. if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  592. {
  593. PLGET(file.Item1);
  594. OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  595. }
  596. }
  597. }
  598. else
  599. {
  600. path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
  601. if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
  602. {
  603. PLGET(file.Item1);
  604. OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
  605. }
  606. }
  607. c++;
  608. }
  609. if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
  610. {
  611. dh.ExecuteSql("insert into plot(pl_ip,pl_address,pl_date) values ('" + GetLocalIPAddress() + "','" + address + "',sysdate) ", "select");
  612. }
  613. else
  614. {
  615. dh.UpdateByCondition("plot", "pl_address = '" + address + "',pl_date = sysdate", "pl_ip = '" + GetLocalIPAddress() + "'");
  616. }
  617. }
  618. private void button2_Click(object sender, EventArgs e)
  619. {
  620. timer2_Tick(sender, e);
  621. }
  622. private void timer2_Tick(object sender, EventArgs e)
  623. {
  624. dh = SystemInf.dh;
  625. DataTable dt = (DataTable)dh.ExecuteSql(" select to_char(wm_concat('站位:'||dsl_location||'未校验')) mmmm from " +
  626. "( select distinct dsl_location from devsmtlocation where dsl_status=0 and dsl_ifcheck = 0 order by dsl_location asc)", "select");
  627. if (dt.Rows.Count > 0)
  628. {
  629. string message = dt.Rows[0][0].ToString();
  630. OperateResult.AppendText(DateTime.Now + message + "\n");
  631. SpeechSynthesizer.SpeakAsync(message);
  632. }
  633. }
  634. }
  635. }