Make_CollectNetCode.cs 37 KB

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