AutoSMTRXY.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using System.Text;
  9. using System.Net;
  10. using System.Net.Sockets;
  11. using System.IO.Ports;
  12. using System.Linq.Expressions;
  13. using System.Linq;
  14. namespace FileWatcher
  15. {
  16. public partial class AutoSMTRXY : Form
  17. {
  18. DataHelper dh;
  19. DataTable dt;
  20. DataTable DB;
  21. /// <summary>
  22. /// 用户编号
  23. /// </summary>
  24. string iusercode;
  25. /// <summary>
  26. /// 岗位资源
  27. /// </summary>
  28. string isource;
  29. Thread InitDB;
  30. /// 当前工序
  31. /// </summary>
  32. string istepcode;
  33. StringBuilder sql = new StringBuilder();
  34. /// <summary>
  35. /// 缓存的文件
  36. /// </summary>
  37. public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
  38. /// <summary>
  39. /// 缓存的文件夹
  40. /// </summary>
  41. public static string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
  42. ftpOperater ftp = new ftpOperater();
  43. public AutoSMTRXY()
  44. {
  45. InitializeComponent();
  46. StartPosition = FormStartPosition.CenterScreen;
  47. }
  48. DataTable Dbfind;
  49. string IPAddress = "";
  50. private void nr_rule_DBChange(object sender, EventArgs e)
  51. {
  52. Dbfind = li_code.ReturnData;
  53. BaseUtil.SetFormValue(this.Controls, Dbfind);
  54. }
  55. private void Form1_Load(object sender, EventArgs e)
  56. {
  57. CheckForIllegalCrossThreadCalls = false;
  58. FormBorderStyle = FormBorderStyle.FixedSingle;
  59. InitDB = new Thread(ConnectDB);
  60. //添加监控事件
  61. SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
  62. stw.StartPosition = FormStartPosition.CenterScreen;
  63. stw.ShowDialog();
  64. List<string> CacheInf = new List<string>();
  65. IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
  66. for (int i = 0; i < IpEntry.AddressList.Length; i++)
  67. {
  68. if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
  69. IPAddress = IpEntry.AddressList[i].ToString();
  70. }
  71. //获取缓存信息
  72. try
  73. {
  74. Type.Text = BaseUtil.GetCacheData("Type").ToString();
  75. li_code.Text = BaseUtil.GetCacheData("Line").ToString();
  76. }
  77. catch (Exception ex) { MessageBox.Show(ex.Message); }
  78. }
  79. private void ConnectDB()
  80. {
  81. dh = new DataHelper();
  82. SystemInf.dh = dh;
  83. ma_code.TableName = "make";
  84. ma_code.SelectField = "ma_code # 工单号";
  85. ma_code.FormName = Name;
  86. ma_code.DBTitle = "工单查询";
  87. ma_code.SetValueField = new string[] { "ma_code" };
  88. ma_code.Condition = "";
  89. ma_code.DbChange += nr_rule_DBChange;
  90. li_code.TableName = "line";
  91. li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
  92. li_code.FormName = Name;
  93. li_code.DBTitle = "线别查询";
  94. li_code.SetValueField = new string[] { "li_code" };
  95. li_code.Condition = "";
  96. li_code.DbChange += nr_rule_DBChange;
  97. }
  98. SerialPort serialPort1 = new SerialPort();
  99. string nextLine;
  100. private void Clean_Click(object sender, EventArgs e)
  101. {
  102. OperateResult.Clear();
  103. }
  104. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  105. {
  106. string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  107. if (ExitConfirm != "Yes")
  108. {
  109. WindowState = FormWindowState.Minimized;
  110. e.Cancel = true;
  111. }
  112. }
  113. private void AutoStart_CheckedChanged(object sender, EventArgs e)
  114. {
  115. SetAutoRun();
  116. }
  117. private void SetAutoRun()
  118. {
  119. if (AutoStart.Checked) //设置开机自启动
  120. {
  121. string path = Application.ExecutablePath;
  122. RegistryKey rk = Registry.LocalMachine;
  123. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  124. rk2.SetValue("FileWatcher.exe", path);
  125. rk2.Close();
  126. rk.Close();
  127. }
  128. else //取消开机自启动
  129. {
  130. string path = Application.ExecutablePath;
  131. RegistryKey rk = Registry.LocalMachine;
  132. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  133. rk2.DeleteValue("FileWatcher.exe", false);
  134. rk2.Close();
  135. rk.Close();
  136. }
  137. }
  138. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  139. {
  140. if (e.KeyCode == Keys.Enter)
  141. {
  142. BaseUtil.PlaySound("站位SMT240011-1-6 当前物料数量剩余100");
  143. BaseUtil.PlaySound("站位SMT240011-2-5 当前物料数量剩余200");
  144. BaseUtil.PlaySound("站位SMT240011-3-3 当前物料数量剩余160");
  145. BaseUtil.PlaySound("站位SMT240011-5-6 当前物料数量剩余180");
  146. }
  147. }
  148. }
  149. }