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(); // 空行分隔不同的节点信息 // 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(); // 空行分隔不同的节点信息 //站位上料用站位表 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 locations = new List(); List pickups = new List(); List PMisss = new List(); List RMisss = new List(); List DMisss = new List(); List MMisss = new List(); List HMisss = new List(); List TRSMisss = new List(); List ChangeCounts = new List(); 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> GetDatFilesSortedByModificationTime(string folderPath) { var datFiles = new List>(); // 遍历指定文件夹及其所有子文件夹 foreach (var file in Directory.GetFiles(folderPath, "*.dat", SearchOption.AllDirectories)) { // 获取文件的最后修改时间 var lastWriteTime = File.GetLastWriteTime(file); // 将文件路径和修改时间添加到列表中 datFiles.Add(new Tuple(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 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); } } } }