| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.IO.Ports;
- using System.Linq.Expressions;
- using System.Linq;
- namespace FileWatcher
- {
- public partial class AutoSMTRXY : Form
- {
- DataHelper dh;
- DataTable dt;
- DataTable DB;
- /// <summary>
- /// 用户编号
- /// </summary>
- string iusercode;
- /// <summary>
- /// 岗位资源
- /// </summary>
- string isource;
- Thread InitDB;
- /// 当前工序
- /// </summary>
- string istepcode;
- StringBuilder sql = new StringBuilder();
- /// <summary>
- /// 缓存的文件
- /// </summary>
- public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
- /// <summary>
- /// 缓存的文件夹
- /// </summary>
- public static string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
- ftpOperater ftp = new ftpOperater();
- public AutoSMTRXY()
- {
- InitializeComponent();
- StartPosition = FormStartPosition.CenterScreen;
- }
- DataTable Dbfind;
- string IPAddress = "";
- private void nr_rule_DBChange(object sender, EventArgs e)
- {
- Dbfind = li_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- CheckForIllegalCrossThreadCalls = false;
- FormBorderStyle = FormBorderStyle.FixedSingle;
- InitDB = new Thread(ConnectDB);
- //添加监控事件
- SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
- stw.StartPosition = FormStartPosition.CenterScreen;
- stw.ShowDialog();
- List<string> CacheInf = new List<string>();
- IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
- for (int i = 0; i < IpEntry.AddressList.Length; i++)
- {
- if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
- IPAddress = IpEntry.AddressList[i].ToString();
- }
- //获取缓存信息
- try
- {
- Type.Text = BaseUtil.GetCacheData("Type").ToString();
- li_code.Text = BaseUtil.GetCacheData("Line").ToString();
- }
- catch (Exception ex) { MessageBox.Show(ex.Message); }
- }
- private void ConnectDB()
- {
- dh = new DataHelper();
- SystemInf.dh = dh;
- ma_code.TableName = "make";
- ma_code.SelectField = "ma_code # 工单号";
- ma_code.FormName = Name;
- ma_code.DBTitle = "工单查询";
- ma_code.SetValueField = new string[] { "ma_code" };
- ma_code.Condition = "";
- ma_code.DbChange += nr_rule_DBChange;
- li_code.TableName = "line";
- li_code.SelectField = "li_code # 线别编号,li_name # 线别名称";
- li_code.FormName = Name;
- li_code.DBTitle = "线别查询";
- li_code.SetValueField = new string[] { "li_code" };
- li_code.Condition = "";
- li_code.DbChange += nr_rule_DBChange;
- }
- SerialPort serialPort1 = new SerialPort();
- string nextLine;
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- string ExitConfirm = MessageBox.Show(this, "确认退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (ExitConfirm != "Yes")
- {
- WindowState = FormWindowState.Minimized;
- e.Cancel = true;
- }
- }
- private void AutoStart_CheckedChanged(object sender, EventArgs e)
- {
- SetAutoRun();
- }
- private void SetAutoRun()
- {
- if (AutoStart.Checked) //设置开机自启动
- {
- string path = Application.ExecutablePath;
- RegistryKey rk = Registry.LocalMachine;
- RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
- rk2.SetValue("FileWatcher.exe", path);
- rk2.Close();
- rk.Close();
- }
- else //取消开机自启动
- {
- string path = Application.ExecutablePath;
- RegistryKey rk = Registry.LocalMachine;
- RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
- rk2.DeleteValue("FileWatcher.exe", false);
- rk2.Close();
- rk.Close();
- }
- }
- private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- BaseUtil.PlaySound("站位SMT240011-1-6 当前物料数量剩余100");
- BaseUtil.PlaySound("站位SMT240011-2-5 当前物料数量剩余200");
- BaseUtil.PlaySound("站位SMT240011-3-3 当前物料数量剩余160");
- BaseUtil.PlaySound("站位SMT240011-5-6 当前物料数量剩余180");
- }
- }
- }
- }
|