123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- using DevExpress.XtraRichEdit.API.Word;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_CollectNetCode : Form
- {
- DataHelper dh;
- AutoSizeFormClass asc = new AutoSizeFormClass();
- LogStringBuilder sql = new LogStringBuilder();
- DataTable dt;
- //当前序列号记录
- string sn_code;
- //制造单号
- string macode;
- //采集网标号
- string net_code;
- //网标查询条件ms_id
- string oMsID;
- //判断是否输入网标
- Boolean isnetcode = false;
- //打印计数
- int printcount = 0;
- int ma_unlimitin;
- public Make_CollectNetCode()
- {
- InitializeComponent();
- }
- //FileSystemWatcher watcher;
- private void Make_CollectNetCode_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- dh = SystemInf.dh;
- //string sharedFolderPath = @"\\192.168.10.1\othersystem\Type2Output";
- //// 确保路径以反斜杠结尾,以便正确监控目录
- //if (!sharedFolderPath.EndsWith("\\"))
- //{
- // sharedFolderPath += "\\";
- //}
- ////string sharedFolderPath = @"D:\mes";
- ////// 确保路径以反斜杠结尾,以便正确监控目录
- ////if (!sharedFolderPath.EndsWith("\\"))
- ////{
- //// sharedFolderPath += "\\";
- ////}
- //// 创建FileSystemWatcher实例
- //watcher = new FileSystemWatcher
- //{
- // Path = sharedFolderPath,
- // NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName,
- // Filter = "*.*", // 监控所有文件
- // IncludeSubdirectories = false, // 根据需要设置为true以监控子目录
- // EnableRaisingEvents = true
- //};
- // 绑定事件处理程序
- //fileSystemWatcher1.Created += OnCreated;
- //watcher.Changed += OnChanged;
- //watcher.Deleted += OnDeleted;
- //watcher.Renamed += OnRenamed;
- OperateResult.AppendText(DateTime.Now+" 开始监控文件夹: " + fileSystemWatcher1.Path+ "\n");
- }
- // 文件创建事件处理程序
- private void OnCreated(object sender, FileSystemEventArgs e)
- {
- try
- {
- OperateResult.AppendText(DateTime.Now+" 文件创建: " + e.FullPath + "\n");
- //第一版
- //if (e.FullPath.Contains("PSK"))
- //{
- // XmlDocument xmlDoc = new XmlDocument();
- // XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
- // //忽略文档里面的注释
- // settings.IgnoreComments = true;
- // XmlReader reader = XmlReader.Create(e.FullPath, settings);
- // xmlDoc.Load(reader);
- // XmlNode xMLNode = xmlDoc.SelectSingleNode("ProductDataSend");
- // XmlNodeList elements = xMLNode.SelectNodes("Element");
- // int i = 1;
- // string code = "";
- // string linecode = "";
- // string table = "";
- // string psid = "";
- // foreach (XmlNode element in elements)
- // {
- // // 提取并打印每个子节点的值
- // string date = element["Date"].InnerText;
- // string mcNo = element["MCNo"].InnerText;//机器号1-4
- // string stage = element["Stage"].InnerText;
- // string lane = element["Lane"].InnerText;//轨道 1 2 分别为1线2线
- // string mjsFileName = element["MjsFileName"].InnerText.Split('.')[0];//产品料号
- // string mjsGroupName = element["MjsGroupName"].InnerText;
- // string lotName = element["LotName"].InnerText;//程序具体名 有BOT的为B面 否则为A面
- // string lotNumber = element["LotNumber"].InnerText;
- // string fAdd = element["FAdd"].InnerText;//设备站位
- // string fSAdd = element["FSAdd"].InnerText;//设备左右 1左2右 如果是占多位置此为0 托盘也是1
- // string partsName = element["PartsName"].InnerText;//物料编号
- // string partsCount = element["PartsCount"].InnerText;//单位用量
- // string chipIni = element["ChipIni"].InnerText;
- // string fdrType = element["FdrType"].InnerText;
- // string fdrWidth = element["FdrWidth"].InnerText;
- // string fdrPitch = element["FdrPitch"].InnerText;
- // string skip = element["Skip"].InnerText;
- // //// 打印提取的信息,或者你可以根据需要处理这些信息
- // //Console.WriteLine($"Date: {date}");
- // //Console.WriteLine($"MCNo: {mcNo}");
- // //Console.WriteLine($"Stage: {stage}");
- // //Console.WriteLine($"Lane: {lane}");
- // //Console.WriteLine($"MjsFileName: {mjsFileName}");
- // //Console.WriteLine($"MjsGroupName: {mjsGroupName}");
- // //Console.WriteLine($"LotName: {lotName}");
- // //Console.WriteLine($"LotNumber: {lotNumber}");
- // //Console.WriteLine($"FAdd: {fAdd}");
- // //Console.WriteLine($"FSAdd: {fSAdd}");
- // //Console.WriteLine($"PartsName: {partsName}");
- // //Console.WriteLine($"ChipIni: {chipIni}");
- // //Console.WriteLine($"FdrType: {fdrType}");
- // //Console.WriteLine($"FdrWidth: {fdrWidth}");
- // //Console.WriteLine($"FdrPitch: {fdrPitch}");
- // //Console.WriteLine($"Skip: {skip}");
- // //Console.WriteLine(); // 空行分隔不同的<Element>节点信息
- // if (i == 1)
- // {
- // linecode = lane == "1" ? "SMT01" : "SMT02";
- // table = lotName.EndsWith("-B") ? "B" : "A";
- // if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileName + "' " +
- // "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
- // {
- // LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code);
- // psid = dh.GetSEQ("productsmt_seq");
- // dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
- // " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid + ",'" + code + "','" + mjsFileName + "','" + linecode + "'" +
- // ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
- // OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileName},线体:{linecode},板面:{table}\n");
- // }
- // else
- // {
- // psid = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileName + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
- // dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid + " " +
- // "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
- // OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileName},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
- // }
- // // Console.WriteLine("第一个");
- // }
- // if (!partsCount.Equals("0"))
- // {
- // dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
- // " 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");
- // OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
- // }
- // i++;
- // }
- // reader.Close();
- //}
- //第二版
- if (e.FullPath.Contains("PSK"))
- {
- XmlDocument xmlDoc = new XmlDocument();
- XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
- //忽略文档里面的注释
- settings.IgnoreComments = true;
- XmlReader reader = XmlReader.Create(e.FullPath, settings);
- xmlDoc.Load(reader);
- XmlNode xMLNode = xmlDoc.SelectSingleNode("ProductDataSend");
- XmlNodeList elements = xMLNode.SelectNodes("Element");
- int i = 1;
- string code = "";
- string linecode = "";
- string table = "";
- string psid = "";
- foreach (XmlNode element in elements)
- {
- // 提取并打印每个子节点的值
- string date = element["Date"].InnerText;
- string mcNo = element["MCNo"].InnerText;//机器号1-4
- string stage = element["Stage"].InnerText;
- string lane = element["Lane"].InnerText;//轨道 1 2 分别为1线2线
- string mjsFileName = element["MjsFileName"].InnerText.Split('.')[0];//产品料号
- string mjsGroupName = element["MjsGroupName"].InnerText;
- string lotName = element["LotName"].InnerText;//程序具体名 有BOT的为B面 否则为A面
- string lotNumber = element["LotNumber"].InnerText;
- string fAdd = element["FAdd"].InnerText;//设备站位
- string fSAdd = element["FSAdd"].InnerText;//设备左右 1左2右 如果是占多位置此为0 托盘也是1
- string partsName = element["PartsName"].InnerText;//物料编号
- string partsCount = element["PartsCount"].InnerText;//单位用量
- string chipIni = element["ChipIni"].InnerText;
- string fdrType = element["FdrType"].InnerText;
- string fdrWidth = element["FdrWidth"].InnerText;
- string fdrPitch = element["FdrPitch"].InnerText;
- string skip = element["Skip"].InnerText;
- //// 打印提取的信息,或者你可以根据需要处理这些信息
- //Console.WriteLine($"Date: {date}");
- //Console.WriteLine($"MCNo: {mcNo}");
- //Console.WriteLine($"Stage: {stage}");
- //Console.WriteLine($"Lane: {lane}");
- //Console.WriteLine($"MjsFileName: {mjsFileName}");
- //Console.WriteLine($"MjsGroupName: {mjsGroupName}");
- //Console.WriteLine($"LotName: {lotName}");
- //Console.WriteLine($"LotNumber: {lotNumber}");
- //Console.WriteLine($"FAdd: {fAdd}");
- //Console.WriteLine($"FSAdd: {fSAdd}");
- //Console.WriteLine($"PartsName: {partsName}");
- //Console.WriteLine($"ChipIni: {chipIni}");
- //Console.WriteLine($"FdrType: {fdrType}");
- //Console.WriteLine($"FdrWidth: {fdrWidth}");
- //Console.WriteLine($"FdrPitch: {fdrPitch}");
- //Console.WriteLine($"Skip: {skip}");
- //Console.WriteLine(); // 空行分隔不同的<Element>节点信息
- if (i == 1)
- {
- linecode = lane == "1" ? "SMT01" : "SMT02";
- table = lotName.EndsWith("-B") ? "B" : "A";
- if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileName + "' " +
- "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
- {
- LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code);
- psid = dh.GetSEQ("productsmt_seq");
- dh.ExecuteSql(" insert into productsmt(PS_ID, PS_CODE, PS_PRODCODE, PS_LINECODE, PS_TABLE, PS_STATUS, PS_INDATE," +
- " PS_INMAN, PS_AUDITDATE, PS_AUDITMAN, PS_STATUSCODE) values (" + psid + ",'" + code + "','" + mjsFileName + "','" + linecode + "'" +
- ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
- OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileName},线体:{linecode},板面:{table}\n");
- }
- else
- {
- psid = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileName + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
- dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid + " " +
- "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
- OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileName},线体:{linecode},板面:{table},删除机器:{mcNo}站位\n");
- }
- // Console.WriteLine("第一个");
- }
- if (!partsCount.Equals("0"))
- {
- dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
- " 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");
- OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
- //dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
- // " 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");
- //OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
- }
- i++;
- }
- reader.Close();
- }
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n");
- }
- }
- // 文件更改事件处理程序
- private void OnChanged(object sender, FileSystemEventArgs e)
- {
- // OperateResult.AppendText("文件更改: " + e.FullPath+"\n");
- }
- // 文件删除事件处理程序
- private void OnDeleted(object sender, FileSystemEventArgs e)
- {
- //OperateResult.AppendText("文件删除: " + e.FullPath + "\n");
- }
- // 文件重命名事件处理程序
- private void OnRenamed(object sender, RenamedEventArgs e)
- {
- //OperateResult.AppendText("文件重命名: 从 "+ e.OldFullPath + " 到 "+ e.FullPath + "\n");
- }
- private void sncode_KeyDown(object sender, KeyEventArgs e)
- {
-
- }
- private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Make_CollectNetCode_Activated(object sender, EventArgs e)
- {
- }
-
- private void deleteButton1_Click(object sender, EventArgs e)
- {
- }
- private void Make_CollectNetCode_FormClosed(object sender, FormClosedEventArgs e)
- {
- // 释放资源
- fileSystemWatcher1.Dispose();
- }
- }
- }
|