Make_CollectFb.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using DevExpress.XtraRichEdit.API.Word;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net.Sockets;
  10. using System.Net;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. using UAS_MES_NEW.DataOperate;
  15. using UAS_MES_NEW.Entity;
  16. using UAS_MES_NEW.PublicMethod;
  17. using System.Speech.Synthesis;
  18. using Newtonsoft.Json;
  19. namespace UAS_MES_NEW.Make
  20. {
  21. public partial class Make_CollectFb : Form
  22. {
  23. DataHelper dh;
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. LogStringBuilder sql = new LogStringBuilder();
  26. DataTable dt;
  27. //当前序列号记录
  28. string sn_code;
  29. //制造单号
  30. string macode;
  31. //采集网标号
  32. string net_code;
  33. //网标查询条件ms_id
  34. string oMsID;
  35. //判断是否输入网标
  36. Boolean isnetcode = false;
  37. //打印计数
  38. int printcount = 0;
  39. int ma_unlimitin;
  40. private SpeechSynthesizer SpeechSynthesizer;
  41. public Make_CollectFb()
  42. {
  43. InitializeComponent();
  44. SpeechSynthesizer = new SpeechSynthesizer();
  45. SpeechSynthesizer.SetOutputToDefaultAudioDevice();
  46. //SpeechSynthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Teen, 0, new System.Globalization.CultureInfo("zh-CN"));
  47. SpeechSynthesizer.Rate = -2;
  48. }
  49. //FileSystemWatcher watcher;
  50. private void Make_CollectNetCode_Load(object sender, EventArgs e)
  51. {
  52. asc.controllInitializeSize(this);
  53. dh = SystemInf.dh;
  54. //string sharedFolderPath = @"\\192.168.10.1\othersystem\Type2Output";
  55. //sharedFolderPath = @"D:\mes";
  56. //sharedFolderPath = @"\\192.168.10.1\othersystem\PickupInformation";
  57. //sharedFolderPath = @"D:\标签";
  58. ////// 确保路径以反斜杠结尾,以便正确监控目录
  59. ////if (!sharedFolderPath.EndsWith("\\"))
  60. ////{
  61. //// sharedFolderPath += "\\";
  62. ////}
  63. //// 创建FileSystemWatcher实例
  64. //watcher = new FileSystemWatcher
  65. //{
  66. // Path = sharedFolderPath,
  67. // NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName,
  68. // Filter = "*.*", // 监控所有文件
  69. // IncludeSubdirectories = false, // 根据需要设置为true以监控子目录
  70. // EnableRaisingEvents = true
  71. //};
  72. // 绑定事件处理程序
  73. //fileSystemWatcher1.Created += OnCreated;
  74. //watcher.Changed += OnChanged;
  75. //watcher.Deleted += OnDeleted;
  76. //watcher.Renamed += OnRenamed;
  77. //OperateResult.AppendText(DateTime.Now+" 开始监控文件夹: " + fileSystemWatcher1.Path+ "\n");
  78. //OperateResult.AppendText(DateTime.Now + " 开始监控文件夹: " + fileSystemWatcher2.Path + "\n");
  79. }
  80. public class MachiningRecord
  81. {
  82. public string SN { get; set; }
  83. public string LorR { get; set; }
  84. public string OPDateTime { get; set; }
  85. public string BeginTime { get; set; }
  86. public string EndTime { get; set; }
  87. public decimal MillSegment { get; set; }
  88. public decimal TotalMillSegments { get; set; }
  89. public decimal MillDis { get; set; }
  90. public decimal MillDiameter { get; set; }
  91. public string FixtureSN { get; set; }
  92. public string ProductCount { get; set; }
  93. public decimal BoardThickness { get; set; }
  94. public int LiftingKnifeHeight { get; set; }
  95. public decimal OverZ { get; set; }
  96. public decimal WorkHeight { get; set; }
  97. public int CutSpeed { get; set; }
  98. public int SpindleSpeed { get; set; }
  99. public string OPNo { get; set; }
  100. }
  101. // 文件创建事件处理程序
  102. private void OnCreated(object sender, FileSystemEventArgs e)
  103. {
  104. try
  105. {
  106. OperateResult.AppendText(DateTime.Now+" 文件创建: " + e.FullPath + "\n");
  107. //第二版
  108. if (e.FullPath.Contains("txt"))
  109. {
  110. string jsonFilePath = e.FullPath;
  111. string jsonContent = File.ReadLines(jsonFilePath).Last().Replace("[", "\"").Replace("]", "\"");
  112. Console.WriteLine(jsonContent);
  113. MachiningRecord record = JsonConvert.DeserializeObject<MachiningRecord>(jsonContent);
  114. if (!dh.CheckExist("MACHINING_RECORDS", "OP_DATE_TIME=to_date('" + record.OPDateTime + "','yyyy/MM/dd hh24:mi:ss')"))
  115. {
  116. dh.ExecuteSql(" INSERT INTO MACHINING_RECORDS (RECORD_ID, SN, LOR_R, OP_DATE_TIME, BEGIN_TIME, END_TIME, MILL_SEGMENT," +
  117. " TOTAL_MILL_SEGMENTS, MILL_DIS, MILL_DIAMETER, FIXTURE_SN, PRODUCT_COUNT, BOARD_THINNESS, LIFTING_KNIFE_HEIGHT, OVER_Z," +
  118. " 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')" +
  119. ",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 + "'," +
  120. "'" + record.MillDiameter + "','" + record.FixtureSN + "','" + record.ProductCount + "','" + record.BoardThickness + "','" + record.LiftingKnifeHeight + "','" + record.OverZ + "'," +
  121. "'" + record.WorkHeight + "','" + record.CutSpeed + "','" + record.SpindleSpeed + "','" + record.OPNo + "') ", "insert");
  122. }
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n");
  128. }
  129. }
  130. // 文件更改事件处理程序
  131. private void OnChanged(object sender, FileSystemEventArgs e)
  132. {
  133. // OperateResult.AppendText("文件更改: " + e.FullPath+"\n");
  134. }
  135. // 文件删除事件处理程序
  136. private void OnDeleted(object sender, FileSystemEventArgs e)
  137. {
  138. //OperateResult.AppendText("文件删除: " + e.FullPath + "\n");
  139. }
  140. // 文件重命名事件处理程序
  141. private void OnRenamed(object sender, RenamedEventArgs e)
  142. {
  143. //OperateResult.AppendText("文件重命名: 从 "+ e.OldFullPath + " 到 "+ e.FullPath + "\n");
  144. }
  145. private void sncode_KeyDown(object sender, KeyEventArgs e)
  146. {
  147. }
  148. private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
  149. {
  150. asc.controlAutoSize(this);
  151. }
  152. private void Make_CollectNetCode_Activated(object sender, EventArgs e)
  153. {
  154. }
  155. private void deleteButton1_Click(object sender, EventArgs e)
  156. {
  157. }
  158. private void Make_CollectNetCode_FormClosed(object sender, FormClosedEventArgs e)
  159. {
  160. // 释放资源
  161. fileSystemWatcher1.Dispose();
  162. }
  163. private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
  164. {
  165. try
  166. {
  167. OperateResult.AppendText(DateTime.Now + " 文件变更: " + e.FullPath + "\n");
  168. //第二版
  169. if (e.FullPath.Contains("txt"))
  170. {
  171. string jsonFilePath = e.FullPath;
  172. string jsonContent = File.ReadLines(jsonFilePath).Last().Replace("[", "\"").Replace("]", "\"");
  173. MachiningRecord record = JsonConvert.DeserializeObject<MachiningRecord>(jsonContent);
  174. if (!dh.CheckExist("MACHINING_RECORDS", "OP_DATE_TIME=to_date('" + record.OPDateTime + "','yyyy/MM/dd hh24:mi:ss')"))
  175. {
  176. dh.ExecuteSql(" INSERT INTO MACHINING_RECORDS (RECORD_ID, SN, LOR_R, OP_DATE_TIME, BEGIN_TIME, END_TIME, MILL_SEGMENT," +
  177. " TOTAL_MILL_SEGMENTS, MILL_DIS, MILL_DIAMETER, FIXTURE_SN, PRODUCT_COUNT, BOARD_THINNESS, LIFTING_KNIFE_HEIGHT, OVER_Z," +
  178. " 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')" +
  179. ",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 + "'," +
  180. "'" + record.MillDiameter + "','" + record.FixtureSN + "','" + record.ProductCount + "','" + record.BoardThickness + "','" + record.LiftingKnifeHeight + "','" + record.OverZ + "'," +
  181. "'" + record.WorkHeight + "','" + record.CutSpeed + "','" + record.SpindleSpeed + "','" + record.OPNo + "') ", "insert");
  182. }
  183. }
  184. }
  185. catch (Exception ex)
  186. {
  187. OperateResult.AppendText(DateTime.Now + " " + ex.Message + "\n");
  188. }
  189. }
  190. }
  191. }