Make_CollectNetCode.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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.Text;
  10. using System.Windows.Forms;
  11. using System.Xml;
  12. using UAS_MES_NEW.DataOperate;
  13. using UAS_MES_NEW.Entity;
  14. using UAS_MES_NEW.PublicMethod;
  15. namespace UAS_MES_NEW.Make
  16. {
  17. public partial class Make_CollectNetCode : Form
  18. {
  19. DataHelper dh;
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. LogStringBuilder sql = new LogStringBuilder();
  22. DataTable dt;
  23. //当前序列号记录
  24. string sn_code;
  25. //制造单号
  26. string macode;
  27. //采集网标号
  28. string net_code;
  29. //网标查询条件ms_id
  30. string oMsID;
  31. //判断是否输入网标
  32. Boolean isnetcode = false;
  33. //打印计数
  34. int printcount = 0;
  35. int ma_unlimitin;
  36. public Make_CollectNetCode()
  37. {
  38. InitializeComponent();
  39. }
  40. //FileSystemWatcher watcher;
  41. private void Make_CollectNetCode_Load(object sender, EventArgs e)
  42. {
  43. asc.controllInitializeSize(this);
  44. dh = SystemInf.dh;
  45. //string sharedFolderPath = @"\\192.168.10.1\othersystem\Type2Output";
  46. //// 确保路径以反斜杠结尾,以便正确监控目录
  47. //if (!sharedFolderPath.EndsWith("\\"))
  48. //{
  49. // sharedFolderPath += "\\";
  50. //}
  51. ////string sharedFolderPath = @"D:\mes";
  52. ////// 确保路径以反斜杠结尾,以便正确监控目录
  53. ////if (!sharedFolderPath.EndsWith("\\"))
  54. ////{
  55. //// sharedFolderPath += "\\";
  56. ////}
  57. //// 创建FileSystemWatcher实例
  58. //watcher = new FileSystemWatcher
  59. //{
  60. // Path = sharedFolderPath,
  61. // NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName,
  62. // Filter = "*.*", // 监控所有文件
  63. // IncludeSubdirectories = false, // 根据需要设置为true以监控子目录
  64. // EnableRaisingEvents = true
  65. //};
  66. // 绑定事件处理程序
  67. //fileSystemWatcher1.Created += OnCreated;
  68. //watcher.Changed += OnChanged;
  69. //watcher.Deleted += OnDeleted;
  70. //watcher.Renamed += OnRenamed;
  71. OperateResult.AppendText(DateTime.Now+" 开始监控文件夹: " + fileSystemWatcher1.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. foreach (XmlNode element in elements)
  183. {
  184. // 提取并打印每个子节点的值
  185. string date = element["Date"].InnerText;
  186. string mcNo = element["MCNo"].InnerText;//机器号1-4
  187. string stage = element["Stage"].InnerText;
  188. string lane = element["Lane"].InnerText;//轨道 1 2 分别为1线2线
  189. string mjsFileName = element["MjsFileName"].InnerText.Split('.')[0];//产品料号
  190. string mjsGroupName = element["MjsGroupName"].InnerText;
  191. string lotName = element["LotName"].InnerText;//程序具体名 有BOT的为B面 否则为A面
  192. string lotNumber = element["LotNumber"].InnerText;
  193. string fAdd = element["FAdd"].InnerText;//设备站位
  194. string fSAdd = element["FSAdd"].InnerText;//设备左右 1左2右 如果是占多位置此为0 托盘也是1
  195. string partsName = element["PartsName"].InnerText;//物料编号
  196. string partsCount = element["PartsCount"].InnerText;//单位用量
  197. string chipIni = element["ChipIni"].InnerText;
  198. string fdrType = element["FdrType"].InnerText;
  199. string fdrWidth = element["FdrWidth"].InnerText;
  200. string fdrPitch = element["FdrPitch"].InnerText;
  201. string skip = element["Skip"].InnerText;
  202. //// 打印提取的信息,或者你可以根据需要处理这些信息
  203. //Console.WriteLine($"Date: {date}");
  204. //Console.WriteLine($"MCNo: {mcNo}");
  205. //Console.WriteLine($"Stage: {stage}");
  206. //Console.WriteLine($"Lane: {lane}");
  207. //Console.WriteLine($"MjsFileName: {mjsFileName}");
  208. //Console.WriteLine($"MjsGroupName: {mjsGroupName}");
  209. //Console.WriteLine($"LotName: {lotName}");
  210. //Console.WriteLine($"LotNumber: {lotNumber}");
  211. //Console.WriteLine($"FAdd: {fAdd}");
  212. //Console.WriteLine($"FSAdd: {fSAdd}");
  213. //Console.WriteLine($"PartsName: {partsName}");
  214. //Console.WriteLine($"ChipIni: {chipIni}");
  215. //Console.WriteLine($"FdrType: {fdrType}");
  216. //Console.WriteLine($"FdrWidth: {fdrWidth}");
  217. //Console.WriteLine($"FdrPitch: {fdrPitch}");
  218. //Console.WriteLine($"Skip: {skip}");
  219. //Console.WriteLine(); // 空行分隔不同的<Element>节点信息
  220. if (i == 1)
  221. {
  222. linecode = lane == "1" ? "SMT01" : "SMT02";
  223. table = lotName.EndsWith("-B") ? "B" : "A";
  224. if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileName + "' " +
  225. "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
  226. {
  227. LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code);
  228. psid = dh.GetSEQ("productsmt_seq");
  229. dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
  230. " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid + ",'" + code + "','" + mjsFileName + "','" + linecode + "'" +
  231. ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
  232. OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileName},线体:{linecode},板面:{table}\n");
  233. }
  234. else
  235. {
  236. psid = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileName + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
  237. dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid + " " +
  238. "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
  239. OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileName},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
  240. }
  241. // Console.WriteLine("第一个");
  242. }
  243. if (!partsCount.Equals("0"))
  244. {
  245. dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  246. " 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");
  247. OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  248. //dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
  249. // " 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");
  250. //OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
  251. }
  252. i++;
  253. }
  254. reader.Close();
  255. }
  256. }
  257. catch (Exception ex)
  258. {
  259. OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n");
  260. }
  261. }
  262. // 文件更改事件处理程序
  263. private void OnChanged(object sender, FileSystemEventArgs e)
  264. {
  265. // OperateResult.AppendText("文件更改: " + e.FullPath+"\n");
  266. }
  267. // 文件删除事件处理程序
  268. private void OnDeleted(object sender, FileSystemEventArgs e)
  269. {
  270. //OperateResult.AppendText("文件删除: " + e.FullPath + "\n");
  271. }
  272. // 文件重命名事件处理程序
  273. private void OnRenamed(object sender, RenamedEventArgs e)
  274. {
  275. //OperateResult.AppendText("文件重命名: 从 "+ e.OldFullPath + " 到 "+ e.FullPath + "\n");
  276. }
  277. private void sncode_KeyDown(object sender, KeyEventArgs e)
  278. {
  279. }
  280. private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
  281. {
  282. asc.controlAutoSize(this);
  283. }
  284. private void Make_CollectNetCode_Activated(object sender, EventArgs e)
  285. {
  286. }
  287. private void deleteButton1_Click(object sender, EventArgs e)
  288. {
  289. }
  290. private void Make_CollectNetCode_FormClosed(object sender, FormClosedEventArgs e)
  291. {
  292. // 释放资源
  293. fileSystemWatcher1.Dispose();
  294. }
  295. }
  296. }