AutoSMTRXY.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. RemindTimer.Start();
  79. }
  80. private void ConnectDB()
  81. {
  82. dh = new DataHelper();
  83. SystemInf.dh = dh;
  84. ma_code.TableName = "make";
  85. ma_code.SelectField = "ma_code # 工单号";
  86. ma_code.FormName = Name;
  87. ma_code.DBTitle = "工单查询";
  88. ma_code.SetValueField = new string[] { "ma_code" };
  89. ma_code.Condition = "";
  90. ma_code.DbChange += nr_rule_DBChange;
  91. li_code.TableName = "line";
  92. li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
  93. li_code.FormName = Name;
  94. li_code.DBTitle = "线别查询";
  95. li_code.SetValueField = new string[] { "li_code" };
  96. li_code.Condition = "";
  97. li_code.DbChange += nr_rule_DBChange;
  98. }
  99. SerialPort serialPort1 = new SerialPort();
  100. string nextLine;
  101. private void Clean_Click(object sender, EventArgs e)
  102. {
  103. OperateResult.Clear();
  104. }
  105. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  106. {
  107. string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  108. if (ExitConfirm != "Yes")
  109. {
  110. WindowState = FormWindowState.Minimized;
  111. e.Cancel = true;
  112. }
  113. }
  114. private void AutoStart_CheckedChanged(object sender, EventArgs e)
  115. {
  116. SetAutoRun();
  117. }
  118. //音频提示站位,料号,剩余数量信息
  119. private void Remind()
  120. {
  121. if (RemindVoice.Checked)
  122. {
  123. sql.Clear();
  124. sql.Append("SELECT 总需求数,余数,站位,料号 from(select bar_batchqty,dsl_barcode,dsl_prodcode 料号, " +
  125. "dsl_location 站位,dsl_baseqty 用量,(select sum(case when dsl_getqty=0 then 1 else dsl_getqty end)" +
  126. " from devsmtlocation T where T.dsl_location=devsmtlocation.dsl_location and dsl_invalidtime is null) " +
  127. "上料数, (select max(to_char(dsl_indate ,'MM-DD hh24:mi:ss')) from devsmtlocation T where " +
  128. "T.dsl_location=devsmtlocation.dsl_location and dsl_usable>0)接料时间,dsl_madeqty 料卷产出数, allmadeqty " +
  129. " 站位产出数,DSL_VALIDTIME, dsl_remainqty,(select sum(dsl_remainqty)from devsmtlocation T where " +
  130. "T.dsl_location=devsmtlocation.dsl_location and dsl_invalidtime is null)余数,dsl_needqty 总需求数 " +
  131. " from devsmtlocation left join (select DSL_LINECODE alllincode,Dsl_Location allLocation, " +
  132. " sum(dsl_madeqty)allmadeqty from devsmtlocation group by DSL_LINECODE,Dsl_Location)A on " +
  133. " alllincode=devsmtlocation.dsl_linecode and allLocation=dsl_location left join barcode " +
  134. " on dsl_barcode = bar_code where dsl_status=0 and dsl_usable=1) ");
  135. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  136. for (int i = 0; i < dt.Rows.Count; i++)
  137. {
  138. string 站位 = dt.Rows[i]["站位"].ToString();
  139. string 余数 = dt.Rows[i]["余数"].ToString();
  140. string 料号 = dt.Rows[i]["料号"].ToString();
  141. BaseUtil.PlaySound("站位" + 站位 + "物料" + 料号 + "数量剩余" + 余数 + "请及时接料");
  142. }
  143. }
  144. }
  145. private void SetAutoRun()
  146. {
  147. if (AutoStart.Checked) //设置开机自启动
  148. {
  149. string path = Application.ExecutablePath;
  150. RegistryKey rk = Registry.LocalMachine;
  151. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  152. rk2.SetValue("FileWatcher.exe", path);
  153. rk2.Close();
  154. rk.Close();
  155. }
  156. else //取消开机自启动
  157. {
  158. string path = Application.ExecutablePath;
  159. RegistryKey rk = Registry.LocalMachine;
  160. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  161. rk2.DeleteValue("FileWatcher.exe", false);
  162. rk2.Close();
  163. rk.Close();
  164. }
  165. }
  166. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  167. {
  168. if (e.KeyCode == Keys.Enter)
  169. {
  170. BaseUtil.PlaySound("站位SMT240011-1-6 当前物料数量剩余100");
  171. BaseUtil.PlaySound("站位SMT240011-2-5 当前物料数量剩余200");
  172. BaseUtil.PlaySound("站位SMT240011-3-3 当前物料数量剩余160");
  173. BaseUtil.PlaySound("站位SMT240011-5-6 当前物料数量剩余180");
  174. }
  175. }
  176. private void RemindTimer_Tick(object sender, EventArgs e)
  177. {
  178. Remind();
  179. }
  180. }
  181. }