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); } RemindTimer.Start(); } 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 Remind() { if (RemindVoice.Checked) { sql.Clear(); sql.Append("SELECT 总需求数,余数,站位,料号 from(select bar_batchqty,dsl_barcode,dsl_prodcode 料号, " + "dsl_location 站位,dsl_baseqty 用量,(select sum(case when dsl_getqty=0 then 1 else dsl_getqty end)" + " from devsmtlocation T where T.dsl_location=devsmtlocation.dsl_location and dsl_invalidtime is null) " + "上料数, (select max(to_char(dsl_indate ,'MM-DD hh24:mi:ss')) from devsmtlocation T where " + "T.dsl_location=devsmtlocation.dsl_location and dsl_usable>0)接料时间,dsl_madeqty 料卷产出数, allmadeqty " + " 站位产出数,DSL_VALIDTIME, dsl_remainqty,(select sum(dsl_remainqty)from devsmtlocation T where " + "T.dsl_location=devsmtlocation.dsl_location and dsl_invalidtime is null)余数,dsl_needqty 总需求数 " + " from devsmtlocation left join (select DSL_LINECODE alllincode,Dsl_Location allLocation, " + " sum(dsl_madeqty)allmadeqty from devsmtlocation group by DSL_LINECODE,Dsl_Location)A on " + " alllincode=devsmtlocation.dsl_linecode and allLocation=dsl_location left join barcode " + " on dsl_barcode = bar_code where dsl_status=0 and dsl_usable=1) "); DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select"); for (int i = 0; i < dt.Rows.Count; i++) { string 站位 = dt.Rows[i]["站位"].ToString(); string 余数 = dt.Rows[i]["余数"].ToString(); string 料号 = dt.Rows[i]["料号"].ToString(); BaseUtil.PlaySound("站位" + 站位 + "物料" + 料号 + "数量剩余" + 余数 + "请及时接料"); } } } 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) { if (dh.CheckExist("make", "ma_code='" + ma_code.Text + "'")) { MessageBox.Show("工单号不存在"); return; } if (dh.CheckExist("line", "li_code='" + li_code.Text + "'")) { MessageBox.Show("线别不存在"); return; } } DataTable dt = (DataTable)dh.ExecuteSql("select MSL_MAINSN from makesnlist where msl_sncode='" + ms_sncode.Text + "'", "select"); if (dt.Rows.Count > 0) { string MainSN = dt.Rows[0]["MSL_MAINS"].ToString(); } } private void RemindTimer_Tick(object sender, EventArgs e) { Remind(); } } }