AutoSMTRXY.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7. using System.Text;
  8. using System.Net;
  9. using System.Net.Sockets;
  10. using System.IO.Ports;
  11. namespace FileWatcher
  12. {
  13. public partial class AutoSMTRXY : Form
  14. {
  15. DataHelper dh;
  16. DataTable dt;
  17. DataTable DB;
  18. /// <summary>
  19. /// 用户编号
  20. /// </summary>
  21. string iusercode;
  22. /// <summary>
  23. /// 岗位资源
  24. /// </summary>
  25. string isource;
  26. Thread InitDB;
  27. /// 当前工序
  28. /// </summary>
  29. string istepcode;
  30. StringBuilder sql = new StringBuilder();
  31. /// <summary>
  32. /// 缓存的文件
  33. /// </summary>
  34. public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
  35. /// <summary>
  36. /// 缓存的文件夹
  37. /// </summary>
  38. public static string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
  39. ftpOperater ftp = new ftpOperater();
  40. public AutoSMTRXY()
  41. {
  42. InitializeComponent();
  43. StartPosition = FormStartPosition.CenterScreen;
  44. }
  45. DataTable Dbfind;
  46. string IPAddress = "";
  47. private void nr_rule_DBChange(object sender, EventArgs e)
  48. {
  49. Dbfind = li_code.ReturnData;
  50. BaseUtil.SetFormValue(this.Controls, Dbfind);
  51. }
  52. private void Form1_Load(object sender, EventArgs e)
  53. {
  54. CheckForIllegalCrossThreadCalls = false;
  55. FormBorderStyle = FormBorderStyle.FixedSingle;
  56. InitDB = new Thread(ConnectDB);
  57. //添加监控事件
  58. SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
  59. stw.StartPosition = FormStartPosition.CenterScreen;
  60. stw.ShowDialog();
  61. List<string> CacheInf = new List<string>();
  62. IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
  63. for (int i = 0; i < IpEntry.AddressList.Length; i++)
  64. {
  65. if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
  66. IPAddress = IpEntry.AddressList[i].ToString();
  67. }
  68. //获取缓存信息
  69. try
  70. {
  71. Type.Text = BaseUtil.GetCacheData("Type").ToString();
  72. li_code.Text = BaseUtil.GetCacheData("Line").ToString();
  73. }
  74. catch (Exception ex) { MessageBox.Show(ex.Message); }
  75. RemindTimer.Start();
  76. }
  77. private void ConnectDB()
  78. {
  79. dh = new DataHelper();
  80. SystemInf.dh = dh;
  81. ma_code.TableName = "make";
  82. ma_code.SelectField = "ma_code # 工单号";
  83. ma_code.FormName = Name;
  84. ma_code.DBTitle = "工单查询";
  85. ma_code.SetValueField = new string[] { "ma_code" };
  86. ma_code.Condition = "";
  87. ma_code.DbChange += nr_rule_DBChange;
  88. li_code.TableName = "line";
  89. li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
  90. li_code.FormName = Name;
  91. li_code.DBTitle = "线别查询";
  92. li_code.SetValueField = new string[] { "li_code" };
  93. li_code.Condition = "";
  94. li_code.DbChange += nr_rule_DBChange;
  95. }
  96. SerialPort serialPort1 = new SerialPort();
  97. string nextLine;
  98. private void Clean_Click(object sender, EventArgs e)
  99. {
  100. OperateResult.Clear();
  101. }
  102. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  103. {
  104. string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  105. if (ExitConfirm != "Yes")
  106. {
  107. WindowState = FormWindowState.Minimized;
  108. e.Cancel = true;
  109. }
  110. }
  111. private void AutoStart_CheckedChanged(object sender, EventArgs e)
  112. {
  113. SetAutoRun();
  114. }
  115. //音频提示站位,料号,剩余数量信息
  116. private void Remind()
  117. {
  118. if (RemindVoice.Checked)
  119. {
  120. sql.Clear();
  121. sql.Append("SELECT 总需求数,余数,站位,料号 from(select bar_batchqty,dsl_barcode,dsl_prodcode 料号, " +
  122. "dsl_location 站位,dsl_baseqty 用量,(select sum(case when dsl_getqty=0 then 1 else dsl_getqty end)" +
  123. " from devsmtlocation T where T.dsl_location=devsmtlocation.dsl_location and dsl_invalidtime is null) " +
  124. "上料数, (select max(to_char(dsl_indate ,'MM-DD hh24:mi:ss')) from devsmtlocation T where " +
  125. "T.dsl_location=devsmtlocation.dsl_location and dsl_usable>0)接料时间,dsl_madeqty 料卷产出数, allmadeqty " +
  126. " 站位产出数,DSL_VALIDTIME, dsl_remainqty,(select sum(dsl_remainqty)from devsmtlocation T where " +
  127. "T.dsl_location=devsmtlocation.dsl_location and dsl_invalidtime is null)余数,dsl_needqty 总需求数 " +
  128. " from devsmtlocation left join (select DSL_LINECODE alllincode,Dsl_Location allLocation, " +
  129. " sum(dsl_madeqty)allmadeqty from devsmtlocation group by DSL_LINECODE,Dsl_Location)A on " +
  130. " alllincode=devsmtlocation.dsl_linecode and allLocation=dsl_location left join barcode " +
  131. " on dsl_barcode = bar_code where dsl_status=0 and dsl_usable=1) ");
  132. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  133. for (int i = 0; i < dt.Rows.Count; i++)
  134. {
  135. string 站位 = dt.Rows[i]["站位"].ToString();
  136. string 余数 = dt.Rows[i]["余数"].ToString();
  137. string 料号 = dt.Rows[i]["料号"].ToString();
  138. BaseUtil.PlaySound("站位" + 站位 + "物料" + 料号 + "数量剩余" + 余数 + "请及时接料");
  139. }
  140. }
  141. }
  142. private void SetAutoRun()
  143. {
  144. if (AutoStart.Checked) //设置开机自启动
  145. {
  146. string path = Application.ExecutablePath;
  147. RegistryKey rk = Registry.LocalMachine;
  148. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  149. rk2.SetValue("FileWatcher.exe", path);
  150. rk2.Close();
  151. rk.Close();
  152. }
  153. else //取消开机自启动
  154. {
  155. string path = Application.ExecutablePath;
  156. RegistryKey rk = Registry.LocalMachine;
  157. RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  158. rk2.DeleteValue("FileWatcher.exe", false);
  159. rk2.Close();
  160. rk.Close();
  161. }
  162. }
  163. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  164. {
  165. if (e.KeyCode == Keys.Enter)
  166. {
  167. if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  168. {
  169. MessageBox.Show("工单号不存在");
  170. return;
  171. }
  172. if (dh.CheckExist("line", "li_code='" + li_code.Text + "'"))
  173. {
  174. MessageBox.Show("线别不存在");
  175. return;
  176. }
  177. }
  178. string error = "";
  179. if (SN.Checked)
  180. {
  181. System.Data.DataTable dt = (System.Data.DataTable)dh.ExecuteSql("select MSL_MAINSN from makesnlist where msl_sncode='" + ms_sncode.Text + "'", "select");
  182. if (dt.Rows.Count > 0)
  183. {
  184. string MainSN = dt.Rows[0]["MSL_MAINS"].ToString();
  185. LogicHandler.CS_SetResult(ma_code.Text, li_code.Text, MainSN, li_code.Text, "OK", out error);
  186. }
  187. }
  188. else
  189. {
  190. LogicHandler.CS_SetResult(ma_code.Text, li_code.Text, "", li_code.Text, "OK", out error);
  191. }
  192. }
  193. private void RemindTimer_Tick(object sender, EventArgs e)
  194. {
  195. Remind();
  196. }
  197. }
  198. }