| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net.Sockets;
- using System.Net;
- 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;
- using System.Speech.Synthesis;
- 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;
- private SpeechSynthesizer SpeechSynthesizer;
- public Make_CollectNetCode()
- {
- InitializeComponent();
- SpeechSynthesizer = new SpeechSynthesizer();
- SpeechSynthesizer.SetOutputToDefaultAudioDevice();
- //SpeechSynthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Teen, 0, new System.Globalization.CultureInfo("zh-CN"));
- SpeechSynthesizer.Rate = -2;
- }
- //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";
- sharedFolderPath = @"D:\mes";
- sharedFolderPath = @"\\192.168.10.1\othersystem\PickupInformation";
- sharedFolderPath = @"D:\标签";
- ////// 确保路径以反斜杠结尾,以便正确监控目录
- ////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");
- //OperateResult.AppendText(DateTime.Now + " 开始监控文件夹: " + fileSystemWatcher2.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 = "";
- string code2 = "";
- string psid2 = "";
- 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 mjsFileNameZS = element["MjsFileName"].InnerText.Split('.')[0]+"-ZS";//产品料号追溯用
- 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";
- linecode = "SMT03";
- 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,'"+ partsCount + "','" + 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");
- }
- ////扣料追溯用站位表
- //if (i == 1)
- //{
- // //linecode = lane == "1" ? "SMT01" : "SMT02";
- // linecode = "SMT0" + lane;
- // table = lotName.EndsWith("B") ? "B" : "A";
- // if (!dh.CheckExist("productsmt", "ps_prodcode = '" + mjsFileNameZS + "' " +
- // "and ps_linecode = '" + linecode + "' and ps_table = '" + table + "'"))
- // {
- // LogicHandler.GetSerialNumByCaller("PRODUCTSMT", out code2);
- // psid2 = 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 (" + psid2 + ",'" + code2 + "','" + mjsFileNameZS + "','" + linecode + "'" +
- // ",'" + table + "','已审核',sysdate,'管理员',sysdate,'管理员','AUDITED') ", "insert");
- // OperateResult.AppendText(DateTime.Now + $" 新增站位主表,料号:{mjsFileNameZS},线体:{linecode},板面:{table}\n");
- // }
- // else
- // {
- // psid2 = dh.getFieldDataByCondition("productsmt", "ps_id", " ps_prodcode = '" + mjsFileNameZS + "' and ps_linecode = '" + linecode + "' and ps_table = '" + table + "' ").ToString();
- // dh.ExecuteSql(" delete productsmtlocation where psl_psid = " + psid2 + " " +
- // "and psl_location in (select sli_location from SMTLOCATIONINTO where SLI_MCNO = '" + mcNo + "' ) ", "delete");
- // OperateResult.AppendText(DateTime.Now + $" 已存在站位主表,料号:{mjsFileNameZS},线体:{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 " + 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");
- // OperateResult.AppendText(DateTime.Now + $" 插入机器:{mcNo},轨道:{lane},料号:{partsName},机器站位:{fAdd},左右:{fSAdd}\n");
- //}
- //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 + "'"))
- //{
- // dh.ExecuteSql(" insert into productsmtlocation (PSL_PSID, PSL_ID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
- // " 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");
- // 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();
- timer1.Dispose();
- }
- private void fileSystemWatcher2_Created(object sender, FileSystemEventArgs e)
- {
- int i = 0;
- try
- {
- OperateResult.AppendText(DateTime.Now + " 文件创建: " + e.FullPath + "\n");
- if (e.FullPath.Contains("dat"))
- {
- // i = PLGET(e, i);
- }
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(i+" "+DateTime.Now + " " + ex.Message + "\n");
- }
- }
- private void PLGET(String path)
- {
- int i = 0;
- bool ql = false;
- string message = "";
- try
- {
- string[] lines = File.ReadAllLines(path);
- // 解析文件内容
- List<string> locations = new List<string>();
- List<string> pickups = new List<string>();
- List<string> PMisss = new List<string>();
- List<string> RMisss = new List<string>();
- List<string> DMisss = new List<string>();
- List<string> MMisss = new List<string>();
- List<string> HMisss = new List<string>();
- List<string> TRSMisss = new List<string>();
- List<string> ChangeCounts = new List<string>();
- foreach (string line in lines)
- {
- if (!line.StartsWith("[PlotInfo]") && !line.StartsWith("MCNo") && line.Trim() != "") // 跳过标题行
- {
- string[] fields = line.Split(' ');
- // 提取字段
- String mcNo = fields[0];
- String lane = fields[1];
- String fAdd = fields[2];
- String fsAdd = fields[3];
- string partsName = fields[4].Trim('"');
- string feederSerial = fields[5].Trim('"');
- Double pickup = Double.Parse(fields[6]);
- Double needpickup = Double.Parse(fields[6]);
- Double PMiss = Double.Parse(fields[7]);
- Double RMiss = Double.Parse(fields[8]);
- Double DMiss = Double.Parse(fields[9]);
- Double MMiss = Double.Parse(fields[10]);
- Double HMiss = Double.Parse(fields[11]);
- Double TRSMiss = Double.Parse(fields[12]);
- Double ChangeCount = Double.Parse(fields[14]);
- String location = "";
- // ... 其他字段
- // 处理数据
- if (pickup > 0)
- {
- location = dh.getFieldDataByCondition("smtlocationinto", "sli_location", "sli_mcno = '" + mcNo + "' " +
- "and sli_fadd ='" + fAdd + "' and instr(sli_fsadd,'" + fsAdd + "')>0").ToString();
- locations.Add(location);
- pickups.Add(pickup.ToString());
- PMisss.Add(PMiss.ToString());
- RMisss.Add(RMiss.ToString());
- DMisss.Add(DMiss.ToString());
- MMisss.Add(MMiss.ToString());
- HMisss.Add(HMiss.ToString());
- TRSMisss.Add(TRSMiss.ToString());
- ChangeCounts.Add(ChangeCount.ToString());
- //OperateResult.AppendText(DateTime.Now + $"料号: {mcNo}, 轨道: {lane},fAdd: {fAdd} ," +
- // $"fsAdd: {fsAdd},站位:{location} PartsName: {partsName}, FeederSerial: {feederSerial},pickup: {pickup}" + "\n");
- double reaminqtysum = Double.Parse(dh.getFieldDataByCondition("DEVSMTLOCATION", "nvl(sum(DSL_REMAINQTY),0)", " dsl_location = '" + location + "' ").ToString());
- if (reaminqtysum < pickup)
- {
- OperateResult.AppendText(DateTime.Now + $"站位:{location}缺料 {pickup}" + "\n", Color.OrangeRed);
- message = message + $"站位:{location}缺料,";
- ql = true;
- }
- else
- {
- DataTable dt = (DataTable)dh.ExecuteSql(" select dsl_id,dsl_remainqty,dsl_barcode from DEVSMTLOCATION " +
- "where dsl_location = '" + location + "' and nvl(DSL_USABLE,0)<>2 and dsl_remainqty >0 order by dsl_id asc ", "select");
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- if (needpickup > 0)
- {
- double v_v_useqty = 0;
- if (double.Parse(dt.Rows[j]["dsl_remainqty"].ToString()) >= needpickup || j == dt.Rows.Count - 1)
- {
- v_v_useqty = needpickup;
- needpickup = 0;
- 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() + "");
- }
- else
- {
- v_v_useqty = double.Parse(dt.Rows[j]["dsl_remainqty"].ToString());
- needpickup = needpickup - v_v_useqty;
- 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() + "");
- }
- }
- }
- 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");
- OperateResult.AppendText(DateTime.Now + $"站位:{location}扣料{pickup}成功" + "\n", Color.Black);
- }
- }
- i++;
- // ... 其他处理
- }
- }
- if (locations.Count > 0)
- {
- 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) " +
- "values (PLOTDATA_seq.nextval,:locations,:pickups,:PMisss,:RMisss,:DMisss,:MMisss,:HMisss,:TRSMisss,:ChangeCounts,sysdate)",
- new string[] { "locations", "pickups", "PMisss", "RMisss", "DMisss", "MMisss", "HMisss", "TRSMisss", "ChangeCounts" },
- locations.ToArray(), pickups.ToArray(), PMisss.ToArray(), RMisss.ToArray(), DMisss.ToArray(), MMisss.ToArray(), HMisss.ToArray(), TRSMisss.ToArray(), ChangeCounts.ToArray());
- }
- if (ql)
- {
- //OperateResult.AppendText(DateTime.Now + $"SMT缺料提醒" + "\n", Color.Blue);
- SpeechSynthesizer.SpeakAsync(message);
- }
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(i + " " + DateTime.Now + " " + ex.Message + "\n");
- }
- }
- private void fileSystemWatcher2_Changed(object sender, FileSystemEventArgs e)
- {
- OperateResult.AppendText(DateTime.Now + " 文件修改: " + e.FullPath + "\n");
- }
- private void fileSystemWatcher2_Deleted(object sender, FileSystemEventArgs e)
- {
- OperateResult.AppendText(DateTime.Now + " 文件删除: " + e.FullPath + "\n");
- }
- private void fileSystemWatcher2_Renamed(object sender, RenamedEventArgs e)
- {
- OperateResult.AppendText(DateTime.Now + " 文件重命名: " + e.FullPath + "\n");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //String ttt = "站位NPM3-6R缺料,站位NPM5-14L缺料";
- //SpeechSynthesizer.SpeakAsync(ttt);
- //OperateResult.AppendText(DateTime.Now + $"SMT缺料提醒" + "\n", Color.Blue);
- //string folderPath = @"\\192.168.10.1\othersystem\PickupInformation"; // 替换为你的文件夹路径
- //var datFilesSortedByModificationTime = GetDatFilesSortedByModificationTime(folderPath);
- //int c = 0;
- //String address = "";
- //String path = "";
- //foreach (var file in datFilesSortedByModificationTime)
- //{
- // if (c == 0)
- // {
- // address = Path.GetFileName(file.Item1);
- // if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
- // {
- // PLGET(file.Item1);
- // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
- // break;
- // }
- // else
- // {
- // path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
- // if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
- // {
- // PLGET(file.Item1);
- // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
- // }
- // }
- // }
- // else
- // {
- // path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
- // if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
- // {
- // PLGET(file.Item1);
- // OperateResult.AppendText(DateTime.Now + $"文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
- // }
- // }
- // c++;
- //}
- //if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
- //{
- // dh.ExecuteSql("insert into plot(pl_ip,pl_address,pl_date) values ('" + GetLocalIPAddress() + "','" + address + "',sysdate) ", "select");
- //}
- //else
- //{
- // dh.UpdateByCondition("plot", "pl_address = '" + address + "',pl_date = sysdate", "pl_ip = '" + GetLocalIPAddress() + "'");
- //}
- timer1_Tick(sender, e);
- }
- static string GetLocalIPAddress()
- {
- IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
- string IPAddress = "";
- for (int i = 0; i < IpEntry.AddressList.Length; i++)
- {
- if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
- IPAddress = IpEntry.AddressList[i].ToString();
- }
- return IPAddress;
- //throw new InvalidOperationException("没有找到IPv4地址。");
- }
- static List<Tuple<string, DateTime>> GetDatFilesSortedByModificationTime(string folderPath)
- {
- var datFiles = new List<Tuple<string, DateTime>>();
- // 遍历指定文件夹及其所有子文件夹
- foreach (var file in Directory.GetFiles(folderPath, "*.dat", SearchOption.AllDirectories))
- {
- // 获取文件的最后修改时间
- var lastWriteTime = File.GetLastWriteTime(file);
- // 将文件路径和修改时间添加到列表中
- datFiles.Add(new Tuple<string, DateTime>(file, lastWriteTime));
- }
- // 根据修改时间对文件进行排序(升序)
- var sortedDatFiles = datFiles.OrderByDescending(file => file.Item2).ToList();
- return sortedDatFiles;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- dh.ExecuteSql("delete plot where pl_date<sysdate - 2/24", "delete");
- string folderPath = @"\\192.168.10.1\othersystem\PickupInformation"; // 替换为你的文件夹路径
- var datFilesSortedByModificationTime = GetDatFilesSortedByModificationTime(folderPath);
- int c = 0;
- String address = "";
- String path = "";
- foreach (var file in datFilesSortedByModificationTime)
- {
- if (c == 0)
- {
- address = Path.GetFileName(file.Item1);
- if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
- {
- PLGET(file.Item1);
- OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
- break;
- }
- else
- {
- path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
- if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
- {
- PLGET(file.Item1);
- OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
- }
- }
- }
- else
- {
- path = dh.getFieldDataByCondition("plot", "pl_address", "pl_ip = '" + GetLocalIPAddress() + "'").ToString();
- if (Path.GetFileName(file.Item1).CompareTo(path) > 0)
- {
- PLGET(file.Item1);
- OperateResult.AppendText(DateTime.Now + $"抛料文件: {file.Item1},文件名:{Path.GetFileName(file.Item1)} 修改时间: {file.Item2}" + "\n");
- }
- }
- c++;
- }
- if (!dh.CheckExist("plot", "pl_ip = '" + GetLocalIPAddress() + "'"))
- {
- dh.ExecuteSql("insert into plot(pl_ip,pl_address,pl_date) values ('" + GetLocalIPAddress() + "','" + address + "',sysdate) ", "select");
- }
- else
- {
- dh.UpdateByCondition("plot", "pl_address = '" + address + "',pl_date = sysdate", "pl_ip = '" + GetLocalIPAddress() + "'");
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- timer2_Tick(sender, e);
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- DataTable dt = (DataTable)dh.ExecuteSql(" select to_char(wm_concat('站位:'||dsl_location||'未校验')) mmmm from " +
- "( select distinct dsl_location from devsmtlocation where dsl_status=0 and dsl_ifcheck = 0 order by dsl_location asc)", "select");
- if (dt.Rows.Count > 0)
- {
- string message = dt.Rows[0][0].ToString();
- OperateResult.AppendText(DateTime.Now + message + "\n");
- SpeechSynthesizer.SpeakAsync(message);
- }
- }
- }
- }
|