| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- 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<MachiningRecord>(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<MachiningRecord>(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");
- }
- }
- }
- }
|