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.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; using Newtonsoft.Json; namespace UAS_MES_NEW.Make { public partial class Make_CollectFb : 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_CollectFb() { 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"); } public class MachiningRecord { public string SN { get; set; } public string LorR { get; set; } public string OPDateTime { get; set; } public string BeginTime { get; set; } public string EndTime { get; set; } public decimal MillSegment { get; set; } public decimal TotalMillSegments { get; set; } public decimal MillDis { get; set; } public decimal MillDiameter { get; set; } public string FixtureSN { get; set; } public string ProductCount { get; set; } public decimal BoardThickness { get; set; } public int LiftingKnifeHeight { get; set; } public decimal OverZ { get; set; } public decimal WorkHeight { get; set; } public int CutSpeed { get; set; } public int SpindleSpeed { get; set; } public string OPNo { get; set; } } // 文件创建事件处理程序 private void OnCreated(object sender, FileSystemEventArgs e) { try { OperateResult.AppendText(DateTime.Now+" 文件创建: " + e.FullPath + "\n"); //第二版 if (e.FullPath.Contains("txt")) { string jsonFilePath = e.FullPath; string jsonContent = File.ReadLines(jsonFilePath).Last().Replace("[", "\"").Replace("]", "\""); Console.WriteLine(jsonContent); MachiningRecord record = JsonConvert.DeserializeObject(jsonContent); if (!dh.CheckExist("MACHINING_RECORDS", "OP_DATE_TIME=to_date('" + record.OPDateTime + "','yyyy/MM/dd hh24:mi:ss')")) { dh.ExecuteSql(" INSERT INTO MACHINING_RECORDS (RECORD_ID, SN, LOR_R, OP_DATE_TIME, BEGIN_TIME, END_TIME, MILL_SEGMENT," + " TOTAL_MILL_SEGMENTS, MILL_DIS, MILL_DIAMETER, FIXTURE_SN, PRODUCT_COUNT, BOARD_THINNESS, LIFTING_KNIFE_HEIGHT, OVER_Z," + " WORK_HEIGHT,CUT_SPEED, SPINDLE_SPEED, OP_NO) VALUES (MACHINING_RECORDS_seq.nextval,'" + record.SN + "','" + record.LorR + "',to_date('" + record.OPDateTime + "','yyyy/MM/dd hh24:mi:ss')" + ",to_date('" + record.BeginTime + "','yyyy/MM/dd hh24:mi:ss'),to_date('" + record.EndTime + "','yyyy/MM/dd hh24:mi:ss'),'" + record.MillSegment + "','" + record.TotalMillSegments + "','" + record.MillDis + "'," + "'" + record.MillDiameter + "','" + record.FixtureSN + "','" + record.ProductCount + "','" + record.BoardThickness + "','" + record.LiftingKnifeHeight + "','" + record.OverZ + "'," + "'" + record.WorkHeight + "','" + record.CutSpeed + "','" + record.SpindleSpeed + "','" + record.OPNo + "') ", "insert"); } } } 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(); } private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e) { try { OperateResult.AppendText(DateTime.Now + " 文件变更: " + e.FullPath + "\n"); //第二版 if (e.FullPath.Contains("txt")) { string jsonFilePath = e.FullPath; string jsonContent = File.ReadLines(jsonFilePath).Last().Replace("[", "\"").Replace("]", "\""); MachiningRecord record = JsonConvert.DeserializeObject(jsonContent); if (!dh.CheckExist("MACHINING_RECORDS", "OP_DATE_TIME=to_date('" + record.OPDateTime + "','yyyy/MM/dd hh24:mi:ss')")) { dh.ExecuteSql(" INSERT INTO MACHINING_RECORDS (RECORD_ID, SN, LOR_R, OP_DATE_TIME, BEGIN_TIME, END_TIME, MILL_SEGMENT," + " TOTAL_MILL_SEGMENTS, MILL_DIS, MILL_DIAMETER, FIXTURE_SN, PRODUCT_COUNT, BOARD_THINNESS, LIFTING_KNIFE_HEIGHT, OVER_Z," + " WORK_HEIGHT,CUT_SPEED, SPINDLE_SPEED, OP_NO) VALUES (MACHINING_RECORDS_seq.nextval,'" + record.SN + "','" + record.LorR + "',to_date('" + record.OPDateTime + "','yyyy/MM/dd hh24:mi:ss')" + ",to_date('" + record.BeginTime + "','yyyy/MM/dd hh24:mi:ss'),to_date('" + record.EndTime + "','yyyy/MM/dd hh24:mi:ss'),'" + record.MillSegment + "','" + record.TotalMillSegments + "','" + record.MillDis + "'," + "'" + record.MillDiameter + "','" + record.FixtureSN + "','" + record.ProductCount + "','" + record.BoardThickness + "','" + record.LiftingKnifeHeight + "','" + record.OverZ + "'," + "'" + record.WorkHeight + "','" + record.CutSpeed + "','" + record.SpindleSpeed + "','" + record.OPNo + "') ", "insert"); } } } catch (Exception ex) { OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n"); } } } }