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;
///
/// 用户编号
///
string iusercode;
///
/// 岗位资源
///
string isource;
Thread InitDB;
/// 当前工序
///
string istepcode;
StringBuilder sql = new StringBuilder();
///
/// 缓存的文件
///
public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
///
/// 缓存的文件夹
///
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 CacheInf = new List();
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");
}
}
}
}