using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using GcDevicePc.ProThread;
using GcDevicePc.Common;
using System.Threading;
using GcDevicePc.CK_UI;
using Ini.Net;
using System.Runtime.InteropServices;
using GcDevicePc.ConfigMethod;
using GcDevicePc.Controls;
using GcDevicePc.GCBuffer;
using GcDevicePc.IniParam;
using System.Drawing;

namespace GcDevicePc
{
    public partial class MDIBase : Form
    {
        #region 相关变量
        //private int childFormNumber = 0;
        private static FormUser  _userForm;  //用户界面
        private static Formdebug _debugForm;  //调试界面
        private static EPCTips _EPCTipsForm;  //EPC报警界面

        /// <summary>
        /// 三画图
        /// </summary>
        //CurveDisPlay curdisplay = new CurveDisPlay();
        //CurveDisPlay2 curdisplay2 = new CurveDisPlay2();
        //CurveDisPlay3 curdisplay3 = new CurveDisPlay3();

        private string Formstr;//窗口名称
        private string statestr;//状态信息
       // private Color stateColor=new Color();//状态颜色;
        private bool IsStateColor = false;
        System.DateTime startTime;  //系统启动时间
        TimeSpan timespan;

        bool inifilec = false;  //方法文件是否加载


        /// <summary>
        /// HMI控制接口
        /// </summary>
        HMIControl hmiopt;

        /// <summary>
        /// HMI数据获取接口
        /// </summary>
        GcDataTh mymodbus;

        /// <summary>
        /// NModbus Slave 变量
        /// </summary>
        //GCModbusSlave Slavetest;
        NModbusSlave nmodbusSlave;

        /// <summary>
        /// Modbus Slave 485 变量
        /// </summary>
        GCModbusSlave485 Slave485test;

        /// <summary>
        /// 数据接收
        /// </summary>
        DataRcv mytcptest = new DataRcv();

        /// <summary>
        /// 本地数据保存接口
        /// </summary>
        ChannelDataSave mydatasave = new ChannelDataSave();
        ChannelDataSave2 mydatasave2 = new ChannelDataSave2();
        ChannelDataSave3 mydatasave3 = new ChannelDataSave3();

        /// <summary>
        /// 处理数据接口
        /// </summary>
        CKvocUpdata dataVOC = new CKvocUpdata();
        CKvocUpdata2 dataVoc2 = new CKvocUpdata2();
        CKvocUpdata3 dataVoc3 = new CKvocUpdata3();

        //private DataOutput wtd624xOutput = new DataOutput();

        private SignalDataToHw signalDataTohw = new SignalDataToHw();
        private SendDataToZB signalDataTozb = new SendDataToZB();
        private CPipeCtl sendSPdata = new CPipeCtl();
        #endregion

        #region Author by zjx

        //CurveDisPlay curdisplay = new CurveDisPlay();
        /// <summary>
        /// 组件初始化
        /// </summary>
        private void DllInit()
        {
            try
            {
                if (CKVocAnalyzer.Config.Instance.ReadPath())
                {
                    CKVocAnalyzer.GlobalCKV.PcVersion = globaldata.CurrentVersion;
                    CKVocAnalyzer.VOCEntityConfig.Instance.vocinit();
                    CKVocAnalyzer.VOCEntityConfig.Instance.SetAutoAdjust();
                    CKVocAnalyzer.Config.Instance.ReadAxisRange();
                    LogOperate.LogInit.Instance.path = CKVocAnalyzer.GlobalCKV.FolderLog;
                    LogOperate.LogInit.Instance.Init();
                    CKVocAnalyzer.GlobalCKV.tcpservice.tcpStart(CKVocAnalyzer.GlobalCKV.hostadd, CKVocAnalyzer.GlobalCKV.tcpport); 
                    //自动删除
                    SpaceM.SpaceThread sthread = new SpaceM.SpaceThread(CKVocAnalyzer.GlobalCKV.HistDataPath,CKVocAnalyzer.GlobalCKV.SpaceSize,CKVocAnalyzer.GlobalCKV.SpaceTimes);
                    sthread.SpaceStart();

                    Log.Info("System Init Success");
                }
                else
                {
                    Log.Error("System Init Failed, Plesae Check Config File");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }
        #endregion


        /// <summary>
        /// 构造函数
        /// </summary>
        public MDIBase()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
        }


        #region 数据保存定时事件
        private MillisecondTimer _logTimer;
        private void InitLogTimer()
        {
            _logTimer = new MillisecondTimer();
            _logTimer.Tick += logTimer_Tick; ;
            _logTimer.Interval = 1000 * 60; //1min
            _logTimer.Start();
        }

        private void logTimer_Tick(object sender, EventArgs e)
        {
            string status_info = "";

            string other_info = "";

            string temp_info = "";

            if (globaldata.m_hmibuffer.gcinfo.hmistatus == 4)
            {
                status_info = " HMI进行单次运行 ";
            }
            else if (globaldata.m_hmibuffer.gcinfo.hmistatus == 2)
            {
                status_info = " HMI进行批处理 ";
            }
            else if (globaldata.m_hmibuffer.gcinfo.hmistatus == 0)
            {
                status_info = " HMI空闲 ";
            }
            else
            {
                status_info = " HMI状态未知 ";
            }

            if (globaldata.m_hmibuffer.gcinfo.hmistatus == 4 || globaldata.m_hmibuffer.gcinfo.hmistatus == 2)
            {
                switch (globaldata.m_hmibuffer.gcinfo.methodstatus)
                {
                    case 0:
                    case 1:
                        status_info += "方法空闲 ";
                        break;
                    case 2:
                        status_info += "方法平衡中 ";
                        break;
                    case 3:
                        status_info += "方法已就绪 ";
                        break;
                    case 4:
                    case 5:
                        status_info += "方法运行中 ";

                        break;
                    case 6:
                        status_info += "方法后处理 ";
                        break;
                    case 7:
                        status_info += "方法后处理完毕 ";
                        break;
                    case 8:
                        status_info += "信号稳定中 ";
                        break;
                    case 9:
                        status_info += "设备断开 ";
                        break;
                    case 10:
                        status_info += "EPC等待 ";
                        break;
                    default:
                        status_info += "设备连接 ";
                        break;
                }
            }

            if (globaldata.m_hmibuffer.gcinfo.hmistatus == 2)
            {
                status_info += "运行进度 " + globaldata.m_hmibuffer.gcinfo.batno.ToString() + "/" +
                               globaldata.m_hmibuffer.gcinfo.batruncount.ToString();
            }

            Log.HmiInfo(status_info);

            other_info = "点火状态:";
            switch (globaldata.m_dpbuffer.ShowList.showDet.fDetStatue)
            {
                case 0:
                    other_info += "未点火";
                    break;
                case 1:
                    other_info += "点火中";
                    break;
                case 2:
                    other_info += "点火成功";
                    break;
                case 3:
                    other_info += "点火失败";
                    break;
                case 4:
                    other_info += "火焰熄灭";
                    break;
                case 5:
                    other_info += "重新点火";
                    break;
                default:
                    other_info += "状态错误";
                    break;
            }

            other_info += " FID:" + globaldata.m_dpbuffer.ShowList.showDet.fDetValue.ToString("0.000");

            Log.HmiInfo(other_info);
            if (CProfileDevice.m_DevParam.syspara.u16InjPortFront == 1)
            {
                temp_info += "前进样口:" + globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp.ToString("#0.00") + " / " +
                             globaldata.m_dpbuffer.ShowList.showtemp.FPSetTemp.ToString("0");
            }

            if (CProfileDevice.m_DevParam.syspara.u16InjPortBehind == 1)
            {
                temp_info += "后进样口:" + globaldata.m_dpbuffer.ShowList.showtemp.BPActualTemp.ToString("#0.00") + " / " +
                             globaldata.m_dpbuffer.ShowList.showtemp.BPSetTemp.ToString("0");
            }

            if (CProfileDevice.m_DevParam.syspara.u16Col == 1)
            {
                temp_info += "柱箱:" + globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.00") + " / " +
                             globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp.ToString("0");
            }

            if (CProfileDevice.m_DevParam.syspara.u16DetNum >= 1)
            {
                if (CProfileDevice.m_DevParam.syspara.u16DetFront == 1)
                {
                    temp_info += "前检测:" + globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.00") +
                                 " / " + globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp.ToString("0");
                }

                if (CProfileDevice.m_DevParam.syspara.u16DetInter == 1)
                {
                    temp_info += "中检测:" + globaldata.m_dpbuffer.ShowList.showtemp.iDetActualTemp.ToString("#0.00") +
                                 " / " + globaldata.m_dpbuffer.ShowList.showtemp.iDetSetTemp.ToString("0");
                }

                if (CProfileDevice.m_DevParam.syspara.u16DetBehind == 1)
                {
                    temp_info += "后检测:" + globaldata.m_dpbuffer.ShowList.showtemp.bDetActualTemp.ToString("#0.00") +
                                 " / " + globaldata.m_dpbuffer.ShowList.showtemp.bDetSetTemp.ToString("0");
                }

                Log.HmiInfo(temp_info);
            }
        }

        #endregion

        GCTitle title = new GCTitle();
        /// <summary>
        /// 主窗口载入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MDIBase_Load(object sender, EventArgs e)
        {
            _userForm = new FormUser();

            DllInit();

            InitConfig();

            //系统检测日志
            InitLogTimer();

            _debugForm = new Formdebug();
            _debugForm.MdiParent = this;
            //_debugForm.Dock = DockStyle.Fill;
            _debugForm.Show();

            title.MdiParent = this;

            //title.Dock = DockStyle.Fill;
            title.Show();

            // debugForm.Hide();
            _userForm.MdiParent = this;
            _userForm.Dock = DockStyle.Fill;

            if (globaldata.CurrentVersion == 1)
            {
                _userForm.Show();
                _userForm.auto = new CKVocAnalyzer.AutoAdjust();
                _userForm.auto.Show();

                _userForm.auto.Hide();
            }

            _EPCTipsForm = new EPCTips();
            _EPCTipsForm.MdiParent = this;
            _EPCTipsForm.Location = new Point(0, ClientSize.Height- _EPCTipsForm.Height);
            _EPCTipsForm.Hide();

            // debugForm.Show();

            Formstr = "用户界面";
            startTime = DateTime.Now;
          //  toolStripStatusLabeSystme.Text = string.Format("状态：{0}", Formstr);

            timespan = DateTime.Now - startTime;
            toolStripStatusLabelusertime.Text = String.Format("运行时间：{0}", timespan.Days.ToString() + "天" + timespan.Hours.ToString() + "时" + timespan.Minutes.ToString() + "分" + timespan.Seconds.ToString() + "秒");

            //显示方法名称
            if (String.IsNullOrEmpty(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName))
            {
                SetMainFormMethodName("未加载");
            }
            else
            {
                SetMainFormMethodName(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName.Substring(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName.LastIndexOf("\\") + 1));
            }
            
            title.Width = this.ClientSize.Width - 5;
            title.Location = new Point(0, 0);

            _debugForm.Height = this.ClientSize.Height - title.Height - 65;
            _debugForm.Width = this.ClientSize.Width - 5;
            _debugForm.Location = new Point(0, title.Height);

            //_userForm.Height = this.ClientSize.Height - title.Height - 55;
            //_userForm.Width = this.ClientSize.Width - 5;
            //_userForm.Location = new Point(0, title.Height);

            SetMenu(LandIn.Island);
            autopensys();

            this.SizeChanged += new EventHandler(this.MDIBase_SizeChanged);
            
            (title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOrdBtnClicked += PictureMenu1_PMOrdBtnClicked;
            (title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptBtnClicked += PictureMenu1_PMOptBtnClicked;
            (title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMSysBtnClicked += PictureMenu1_PMSysBtnClicked;
            //pictureMenu1.PMOrdBtnClicked += PictureMenu1_PMOrdBtnClicked;
            //pictureMenu1.PMOptBtnClicked += PictureMenu1_PMOptBtnClicked;
            //pictureMenu1.PMSysBtnClicked += PictureMenu1_PMSysBtnClicked;
            //点火接口
            _userForm.autofire += new Fireport(fireupopt);
            
            epcs = false;
            timer2.Start();

        }

        private void MDIBase_SizeChanged(object sender, EventArgs e)
        {

            title.Width = this.ClientSize.Width - 5;
            title.Location = new Point(0, 0);

            _debugForm.Height = this.ClientSize.Height - title.Height - 65;
            _debugForm.Width = this.ClientSize.Width - 5;
            _debugForm.Location = new Point(0, title.Height);
        }
        //private bool a;
        private void PictureMenu1_PMSysBtnClicked(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                if (globaldata.m_hmibuffer.gcinfo.hmistatus == 0)
                {
                    hmiopt.WriteStopVal();
                    WaitHMIFree();
                    //SetTitleStatueName("系统准备中...", true);

                    //if (globaldata.CurrentVersion == "1")
                    {
                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)
                        {

                            hmiopt.WriteBatVal();
                        }

                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                        {
                            hmiopt.WriteOpenVal();
                        }

                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 1)
                        {
                            hmiopt.WriteSingleVal();
                        }
                    }
                    WaitHMIWork();

                    Thread.Sleep(500);
                    globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = true;
                    globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;


                    globaldata.starttimer = 0;

                    globaldata.startimerIsSet = true;
                    globaldata.startimerIsSet1 = true;
                    globaldata.startimerIsSet2 = true;
                    globaldata.startimerIsSet3 = true;
                }
                else
                {

                    LMessageBox dialog = new LMessageBox(this.Location, this.Size, true, "停止系统", "确定停止系统吗？", LMessageBox.MessageBoxPosition.MBP_Center);
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        //SetTitleStatueName("系统停止中...", false);
                        globaldata.OS_STOP = true;
                        hmiopt.WriteEndVal();
                        WaitHMIFree();
                        //SetTitleStatueName("系统停止...", false);

                        globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                        globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;

                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                string message = "系统处于离线状态...";
                MessageBox.Show(message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;
            }
        }

        private void PictureMenu1_PMOptBtnClicked(object sender, EventArgs e)
        {
            PictureBox picturebtn = (PictureBox)sender;
            int tagnum = Convert.ToInt32(picturebtn.Tag);

            switch (tagnum)
            {
                case 0:
                    SingleStart_Click(sender, e);  //开始
                    break;
                case 1:
                    SingleStop_Click(sender, e);  //停止
                    break;
                case 2:
                    SingleCancel_Click(sender, e);   //取消
                    break;
            }
        }

        private void PictureMenu1_PMOrdBtnClicked(object sender, EventArgs e)
        {
            PictureBox picturebtn = (PictureBox)sender;
            int tagnum = Convert.ToInt32(picturebtn.Tag);

            switch (tagnum)
            {
                case 0:
                    NewMethodMenu_Click(sender, e);   //新建方法
                    break;
                case 1:
                    OpenMethodMenu_Click(sender, e);   //打开方法 
                    break;
                case 2:
                    //  SingleAnal_Click(sender, e);  //快速运行
                    AuxToolMenu_Click(sender, e);
                    break;
                case 3:
                    //batdeal_Click(sender, e);    //智能运行
                    MethodBatMenu_Click(sender, e);
                    break;
                case 4:
                    MethodBrowseMenuItem_Click(sender, e);    //方法查询
                    break;
                case 5:
                    NetWorkMenu_Click(sender, e);    //通讯设置
                    break;
                case 6:
                    ConfigCreateSubMenuItem_Click(sender, e);   //仪器配置
                    break;
                case 7:
                    HistoryDataMenu_Click(sender, e);  //数据查询
                    break;
                case 8:
                    CalibrationMenu_Click(sender, e); //数据校准
                    break;
                case 9:
                    HistoryPicMenu_Click(sender, e);  //历史文件
                    break;
            }
        }

        //private Size GetMdiAreaSize()
        //{
        //    MdiClient client = _userForm.Parent as MdiClient;
        //    return client.ClientSize;
        //}

        /// <summary>
        /// 判断是否要开启系统
        /// </summary>
        private void autopensys()
        {
            try
            {
                int opensys = 0;
                //String tmpfile = globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.RunFolder + "\\startup.ini";
                string tmpfile = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath), "GC_Config\\GC_Set\\启动参数\\startup.ini");
                globaldata.starttimer = 0x7FFFFFFF;
                IniFile IniParser = new IniFile(tmpfile);

                if(IniParser.KeyExists("StartUp", "打开系统"))
                    opensys = IniParser.ReadInteger("StartUp", "打开系统");

                if ((opensys == 1 && globaldata.m_hmibuffer.gcinfo.methodstatus == 0) || globaldata.m_hmibuffer.gcinfo.methodstatus != 0)
                {
                    //autoopensys_Click();
                    open();
                }

                //if (globaldata.m_hmibuffer.gcinfo.methodstatus != 0)
                //{
                //    hmistatus_opensys();
                //}
            }
            catch(Exception ex)
            {
                Log.Error(ex.Message);
            }
        }

        private void SetMenu(bool isbool)
        {
            try
            {
                if (globaldata.CurrentVersion == 1)
                {
                    if (isbool)
                    {
                        NetWorkMenu.Visible = true;
                        MethodBrowseMenuItem.Visible = true;
                        NewMethodMenu.Visible = true;
                        OpenMethodMenu.Visible = true;
                        MethodBrowseMenuItem.Visible = true;
                        CalibrationMenu.Visible = true;
                        GCConfigMenuItem.Visible = true;
                        AuxToolMenu.Visible = true;
                        ParameterSettingMenu.Visible = true;
                        DebugMainMenu.Visible = true;
                        // HmiStatus.Visible = true;
                        SettingSeparator.Visible = true;
                        if (LandIn.Issa)
                        {
                            sysconfigp.Visible = true;
                        }
                        SettingMainMenu.Visible = true;

                    }
                    else
                    {
                        NetWorkMenu.Visible = false;
                        MethodBrowseMenuItem.Visible = false;
                        NewMethodMenu.Visible = false;
                        OpenMethodMenu.Visible = false;
                        MethodBrowseMenuItem.Visible = false;
                        CalibrationMenu.Visible = false;
                        GCConfigMenuItem.Visible = false;
                        AuxToolMenu.Visible = false;
                        ParameterSettingMenu.Visible = false;
                        DebugMainMenu.Visible = false;
                        sysconfigp.Visible = false;
                        // HmiStatus.Visible = false;
                        SettingSeparator.Visible = false;
                        SettingMainMenu.Visible = false;
                    }
                }
                else
                {
                    if (LandIn.Issa)
                    {
                        sysconfigp.Visible = true;

                    }
                    else
                    {
                        sysconfigp.Visible = false;

                    }

                    //UserMainMenu.Visible = false;
                    AuxToolMenu.Visible = false;
                    ParameterSettingMenu.Visible = false;
                    AutoAdjustMenu.Visible = false;
                }

            }
            catch(Exception ex)
            {
                Log.Error(ex.Message);
            }
        }
        
        /// <summary>
        /// 更新显示栏信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 1.0.2.3  添加了周期完成后，重新绘图功能
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Text = String.Format("{0}-1.5.9 {1}", globaldata.AppName,Formstr);

            HmiStatus.Text = String.Format("状态：{0}", statestr);

            timespan = System.DateTime.Now - startTime;
            toolStripStatusLabelusertime.Text = String.Format("运行时间：{0}", 
                timespan.Days.ToString() + "天" + timespan.Hours.ToString() + "时" + timespan.Minutes.ToString() + "分" + timespan.Seconds.ToString() + "秒");

            //下方状态显示
            switch (CKVocAnalyzer.GlobalCKV.adjustType)
            {
                case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Zero:
                    AdjustStat.Text = "校零中";
                    break;
                case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Biao:
                    AdjustStat.Text = "校标中";
                    break;
                case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang:
                    AdjustStat.Text = "走样中";
                    break;
            }

            //监视界面活动
            if (getIdleTick()>60*30 && LandIn.Island)
            {
                
                if (_userForm != null)
                {
                    Formstr = "用户窗口";
                    _userForm.Activate();
                    //userForm.Show();
                }
                LandIn.Island = false;
                SetMenu(LandIn.Island);
                Trace.WriteLine("进入自动销户","sys");
            }
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct LASTINPUTINFO
        {
            [MarshalAs(UnmanagedType.U4)]
            public int cbSize;
            [MarshalAs(UnmanagedType.U4)]
            public uint dwTime;
        }
        [DllImport("user32.dll")]
        public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

        /// <summary>
        /// 返回持续时间  s
        /// </summary>
        /// <returns></returns>
        public long getIdleTick()
        {
            LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
            vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
            if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
            return (Environment.TickCount - (long)vLastInputInfo.dwTime)/1000;
        }

        public void SendPCCMD(bool flag)
        {
            //if (globaldata.CurrentVersion == "1")
            {
                if (flag)  //打开运行
                {
                    hmiopt.WriteStopVal();
                    WaitHMIFree();
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue)
                    {


                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                            hmiopt.WriteOpenVal();

                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 1)
                            hmiopt.WriteSingleVal();


                    }
                    WaitHMIWork();


                }
                else   //批处理
                {
                    hmiopt.WriteStopVal();
                    WaitHMIFree();

                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue)
                    {
                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)
                        {
                            hmiopt.WriteBatVal();
                            hmiopt.WriteStartVal();
                            WaitHMIWork();
                        }

                    }
                }
            }
        }

        public void SendSTDCMD()
        {
            int ret = -1;
            int count = 3;
            hmiopt.WriteStopVal();
            WaitHMIFree();
            if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue)
            {
                ret = hmiopt.WriteSTDBatVal();
                while (ret != 0)
                {
                    ret = hmiopt.WriteSTDBatVal();
                    if (count < 0)
                    {
                        break;
                    }
                    count--;
                }
                hmiopt.WriteStartVal();
            }
        }

        private void SetMainFormMethodName(string text)
        {

            this.toolStripStatusLabelText.Text = "当前运行方法：" + text;

        }

        private void SetMainFormMethodNameTH(string text)
        {
            this.Invoke(new Action(() =>
            {
                this.toolStripStatusLabelText.Text = "当前运行方法：" + text;
            }));
        }

        #region 后台工作
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                int ret = -1;
                BackgroundWorker worker = sender as BackgroundWorker;
                Thread.Sleep(500);
                for (int i = 0; i < 100; i++)
                {
                    if (globaldata.m_hmibuffer.gcinfo.hmistatus == 0 || globaldata.m_hmibuffer.gcinfo.methodstatus == 0 || globaldata.m_hmibuffer.gcinfo.methodstatus == 7 || globaldata.m_hmibuffer.gcinfo.methodstatus == 2 || globaldata.m_hmibuffer.gcinfo.methodstatus == 3)
                    {
                        if (globaldata.OS_STOP)
                        {
                            globaldata.OS_STOP = false;
                        }
                        worker.ReportProgress(100);
                        break;
                    }
                    else
                    {
                        if (i % 10 == 0 && i != 0)
                        {
                            if (globaldata.OS_STOP)
                            {
                                ret = hmiopt.WriteEndVal();
                            }
                            else
                            {
                                ret = hmiopt.WriteStopVal();
                            }
                        }

                        if (i != 99)
                        {
                            worker.ReportProgress(i);
                        }
 
                    }

                    if (worker.CancellationPending)  // 如果用户取消则跳出处理数据代码 
                    {
                        e.Cancel = true;
                        break;
                    }

                    Thread.Sleep(100);


                }
            }
            catch
            {
            }
           
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                this.workProgress.Visible = false;
                autoResetEvent.Set();
            }
            catch 
            {
                
            }
            
        }

        private void WaitHMIFree()
        {
            if (!backgroundWorker1.IsBusy)
            {
                this.workProgress.Visible = true;
                this.workProgress.Value = 0;
                this.backgroundWorker1.RunWorkerAsync();
            }
           
        }

        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                int ret = -1;

                while (!autoResetEvent.WaitOne())
                {
                    TimeSpan.FromSeconds(1);
                }

                if (!workProgress.Visible)
                {
                    workProgress.Visible = true;
                }

                this.workProgress.Value = 0;

                BackgroundWorker worker = sender as BackgroundWorker;
                Thread.Sleep(500);
                for (int i = 0; i < 100; i++)
                {
                    if (globaldata.m_hmibuffer.gcinfo.methodstatus > 0 && globaldata.m_hmibuffer.gcinfo.methodstatus < 5)
                    {
                        worker.ReportProgress(100);
                        break;

                    }
                    else
                    {
                        if (i % 20 == 0 && i != 0)
                        {
                            if (globaldata.CurrentVersion == 1)
                            {
                                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                                    ret = hmiopt.WriteOpenVal();

                                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 1)
                                    ret = hmiopt.WriteSingleVal();

                                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)
                                {
                                    ret = hmiopt.WriteBatVal();
                                    if (ret == 0)
                                        ret = hmiopt.WriteStartVal();
                                }
                            }
                        }

                        Thread.Sleep(100);
                        if (i <= 99)
                            worker.ReportProgress(i);
                    }

                    if (worker.CancellationPending)  // 如果用户取消则跳出处理数据代码 
                    {
                        e.Cancel = true;
                        break;
                    }


                }
            }
            catch
            {
            }
            
        }

        private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                this.workProgress.Visible = false;
                autoResetEvent.Reset();
            }
            catch
            {
            }
            
        }

        private void WaitHMIWork()
        {
            if (!backgroundWorker2.IsBusy)
            {
                this.workProgress.Visible = true;
                this.workProgress.Value = 0;
                this.backgroundWorker2.RunWorkerAsync();
            }
        }
        
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.workProgress.Value = e.ProgressPercentage;
        }
    
        private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.workProgress.Value = e.ProgressPercentage;
        }
        #endregion

        private void SendStopCMD()
        {
            try
            {
                //hmiopt.WriteEndVal();
                WaitHMIFree();
                WaitHMIWork();
            }
            catch
            {
            }

        }

        #region 线程接口

        private void Start_Thread()
        {

            if (globaldata.ZbDataSave)
            {
                mydatasave.ChannelDataStart();
                mydatasave2.ChannelDataStart();
                mydatasave3.ChannelDataStart();
            }
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                mymodbus.HmiStatueStart();
                mymodbus.ChannelDataStart();
            }

            dataVOC.CKvocUpdataStart();
            dataVoc2.CKvocUpdataStart();
            dataVoc3.CKvocUpdataStart();
            //mytcptest.DataRcvStart();


            //if (!String.IsNullOrEmpty(globaldata.m_pcbuffer.gcpcinfo.moduleinfo.ip))
            //    wtd624xOutput.DataOutStart();
        }

        public void Stop_Thread()
        {
            if (globaldata.ZbDataSave)
            {
                mydatasave.ChannelDataStop();
                mydatasave2.ChannelDataStop();
                mydatasave3.ChannelDataStop();
            }
            
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                mymodbus.HmiStatueStop();
                mymodbus.ChannelDataStop();
                //ThreadMonitor.GetInstance().MonitorThStop();
                //ThreadMonitor.GetInstance().StopALLCommunication();
            }

            dataVOC.CKvocUpdataStop();
            dataVoc2.CKvocUpdataStop();
            dataVoc3.CKvocUpdataStop();
            //mytcptest.DataRcvStop();


            //if (!String.IsNullOrEmpty(globaldata.m_pcbuffer.gcpcinfo.moduleinfo.ip))
            //    wtd624xOutput.DataOutStop();
        }
        #endregion

        private void InitConfig()
        {
            string tmpname = "";
            try
            {
                if (!String.IsNullOrEmpty(globaldata.connection_ip))
                {
                    Start_ConnectStatusThread();
                    try
                    {
                        globaldata.m_profileMethod.SetStatusFullName(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_StatusName);
                        globaldata.m_profileMethod.GetDevState();
                        //if (globaldata.CurrentVersion == "1")
                        {
                            tmpname = globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2 ?
                            globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName :
                            globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName;
                        }
                        if (!String.IsNullOrEmpty(tmpname))
                        {
                            globaldata.show_MethodName = tmpname;
                            SetMainFormMethodName(tmpname);
                            globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName = Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, tmpname.ToString());

                            if(globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)
                                globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName = Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, tmpname.ToString());

                            globaldata.m_profileMethod.SetMethodFullName(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName);
                            globaldata.m_profileMethod.GetDevInjPortAllPara();
                            globaldata.m_profileMethod.GetSampleAllPara("前进样器");
                            globaldata.m_profileMethod.GetInjValveAllPara();
                            globaldata.m_profileMethod.GetChromAllPara();
                            globaldata.m_profileMethod.GetColTableElseAllPara();
                            globaldata.m_profileMethod.GetFidAllPara();
                            globaldata.m_profileMethod.GetTcdAllPara();
                            globaldata.m_profileMethod.GetAuxiliaryAllPara();  
                        }
                        else
                        {
                            Log.Error("Method is Null...");
                        }
                    }
                    catch
                    {
                        Log.Error("System Init Failed");                 
                    }

                    statestr = "设备联机";
                    IsStateColor=true;

           
                    hmiopt = new HMIControl(globaldata.connection_ip, globaldata.datamodbusport);
           
                    mymodbus = new GcDataTh(globaldata.connection_ip, globaldata.datamodbusport);


                    Start_Thread();
                    WaitHMIWork();

                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.sendtohw)
                    {
                        signalDataTohw.DataToHwStart();

                        //signalDataTozb.DataToZBStart();
                    }
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.sendtoZb)
                    {
                        //signalDataTohw.DataToHwStart();

                        signalDataTozb.DataToZBStart();
                    }
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.sendtoSP)
                    {
                        sendSPdata.DataToSPStart();
                    }
                    

                    try
                    {
                        if (globaldata.CurrentVersion == 1)
                        {
                            nmodbusSlave = new NModbusSlave();
                        }

                        //Slavetest = new GCModbusSlave();
                        //Slavetest.CModbusSlaveInit(1, 2, 3, 5);

                        if (globaldata.m_pcbuffer.gcpcinfo.outputinfo.port != 0)
                        {
                            Slave485test = new GCModbusSlave485(globaldata.m_pcbuffer.gcpcinfo.outputinfo.port, 9600);
                            Slave485test.CModbusSlave485Init(1, 2, 3, 5);
                        }
                        
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.Message);
                    }
                }
                else
                {
                    statestr = "未联机";
                    IsStateColor = false;
                }
            }
            catch(Exception ex)
            {
                Log.Error(ex.Message);
            }
        }

        //Thread gethmistaues;
        //private void Start_Thread()
        //{
        //    // mydatasave.ChannelDataStart();
        //    if (!String.IsNullOrEmpty(globaldata.connection_ip))
        //    {
        //        mymodbus.HmiStatueStart();
        //        mymodbus.ChannelDataStart();

        //        //ThreadMonitor.GetInstance().StartALLCommunication();

        //    }

        //    dataVOC.CKvocUpdataStart();
        //    mytcptest.DataRcvStart();

        //    if (!String.IsNullOrEmpty(globaldata.m_pcbuffer.gcpcinfo.moduleinfo.ip))
        //        wtd624xOutput.DataOutStart();
        //}

        //private void Stop_Thread()
        //{
        //    // mydatasave.ChannelDataStop();

        //    dataVOC.CKvocUpdataStop();
        //    mytcptest.DataRcvStop();

        //    if (!String.IsNullOrEmpty(globaldata.connection_ip))
        //    {
        //        //   mymodbus.HmiStatueStop();
        //        mymodbus.ChannelDataStop();
        //        ThreadMonitor.GetInstance().MonitorThStop();
        //        ThreadMonitor.GetInstance().StopALLCommunication();
        //    }

        //    if (!String.IsNullOrEmpty(globaldata.m_pcbuffer.gcpcinfo.moduleinfo.ip))
        //        wtd624xOutput.DataOutStop();
        //}

        /// <summary>
        /// 状态改变信号量
        /// </summary>
        ManualResetEvent datamre = new ManualResetEvent(false);
        ManualResetEvent conmre = new ManualResetEvent(false);
        ushort GCstatus = 9;
        Thread Connect_Status;


        /// <summary>
        /// HMI状态监控线程
        /// </summary>
        private void Start_ConnectStatusThread()
        {
            if (conmre != null)
            {
                conmre.Reset();
            }
            Connect_Status = new Thread(Monitor_Connect);
            Connect_Status.IsBackground = true;
            Connect_Status.Start();
        }

        //bool isone_openos = false;

        /// <summary>
        /// HMI状态监控线程实现
        /// </summary>
        private void Monitor_Connect()
        {
            UInt16[] dest = new UInt16[9];

            ushort status_flag = 10;
            ushort status_flag_old = 10;
            ushort runtype = 0;

            while (!conmre.WaitOne(500))
            {
                Thread.Sleep(500);

                if (globaldata.m_pcbuffer.gcpcinfo.pcthreadinfo.HMI_Monitor_TH == 1)
                {
                    break;
                }

                dest[0] = globaldata.m_hmibuffer.gcinfo.batno;
                dest[1] = globaldata.m_hmibuffer.gcinfo.batruncount;
                dest[2] = globaldata.m_hmibuffer.gcinfo.oneruntime;
                dest[3] = globaldata.m_hmibuffer.gcinfo.singlerun;
                dest[4] = globaldata.m_hmibuffer.gcinfo.batrun;
                dest[5] = globaldata.m_hmibuffer.gcinfo.methodstatus;
                dest[6] = globaldata.m_hmibuffer.gcinfo.waitstart;
                dest[7] = globaldata.m_hmibuffer.gcinfo.hmistatus;
                dest[8] = globaldata.m_hmibuffer.gcinfo.runtime;

                status_flag = dest[5];

                GCstatus = dest[5];
                runtype = dest[7];

                globaldata.MethodRun_Statue = dest[5];
                globaldata.RunTime_Now = dest[2];
                globaldata.RunTotal_Now = dest[8];

                if (globaldata.m_hmibuffer.gcinfo.hmioffline)
                {
                    status_flag = 9;
                }


                if ((dest[5] == 4 || dest[5] == 5) && dest[7] == 4 && globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue != 1)
                {
                    globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType = 0;
                }

                switch (runtype)
                {
                    case 0:
                        Common_HeadInfo();
                        DataControl_Status(dest[5], 0);
                        break;
                    case 2:
                        BAT_HeadInfo(dest[0], dest[1]);
                        DataControl_Status(dest[5], 2);
                        break;
                    case 3:
                        QuickRun_HeadInfo();
                        DataControl_Status(dest[5], 1);
                        break;
                    case 4:
                        SingleRun_HeadInfo();
                        DataControl_Status(dest[5], 1);
                        break;
                    default:
                        Common_HeadInfo();
                        break;
                }
                Status_Show(status_flag, ref status_flag_old);

                Menu_status();

                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)
                {

                    if (globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName != globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName)
                    {
                        string tmpFileName = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName;
                        string getFileName = "";
                        int ret;

                        FileServerClient mainclient = new FileServerClient();

                        try
                        {
                            mainclient.WtClientInit(globaldata.connection_ip, globaldata.fileserverport);
                            if (!File.Exists(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName))
                            {
                                getFileName = tmpFileName.Substring(tmpFileName.LastIndexOf("\\") + 1);
                                ret = mainclient.WtClientCopyfromServer(getFileName, globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName, globaldata.remoteFolder + "仪器方法\\");
                                Thread.Sleep(400);
                            }

                            globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName;
                            globaldata.m_profileMethod.SetMethodFullName(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName);
                            globaldata.m_profileMethod.GetDevInjPortAllPara();
                            globaldata.m_profileMethod.GetSampleAllPara("前进样器");
                            globaldata.m_profileMethod.GetInjValveAllPara();
                            globaldata.m_profileMethod.GetChromAllPara();
                            globaldata.m_profileMethod.GetColTableElseAllPara();
                            globaldata.m_profileMethod.GetFidAllPara();
                            globaldata.m_profileMethod.GetTcdAllPara();
                            globaldata.m_profileMethod.GetAuxiliaryAllPara();

                            mainclient.WtClientClose();
                        }
                        catch
                        {
                            mainclient.WtClientClose();
                        }
                    }

                }

            }
        }

        void Menu_status()
        {
            if (globaldata.m_hmibuffer.gcinfo.hmistatus != 0)//已开启系统
            {

                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = true;
                (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMSysbtnstatus = 1;

                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)//批处理
                {
                    (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 0;
                }
                else
                {
                    if (globaldata.m_hmibuffer.gcinfo.methodstatus == 3)//已就绪
                    {
                        (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 4;
                    }
                    else if(globaldata.m_hmibuffer.gcinfo.methodstatus == 4 || globaldata.m_hmibuffer.gcinfo.methodstatus == 4)
                    {
                        (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 3;
                    }
                    else
                    {
                        (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 0;
                    }
                }
            }
            else//未开启系统
            {
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMSysbtnstatus = 0;

                (this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 0;
            }




        }

        void DataControl_Status(ushort flag, ushort runtype)
        {
            switch (flag)
            {
                case 0:
                case 1:
                case 2:
                    //globaldata.work_Statue = 0;                   
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                        stopbtn();
                    break;
                case 3:   //已就绪               
                    break;
                case 4:
                case 5:
                    //if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 0)
                       // startbtn();
                    break;
                case 6:
                case 7:
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                        stopbtn();
                    break;
            }
        }

        /// <summary>
        /// 控制调试按钮权限
        /// </summary>
        /// <param name="flag"></param>
        //void ButtonControl_Status(ushort flag)
        //{
        //    this.Invoke(new Action(() =>
        //    {
        //        switch (flag)
        //        {
        //            case 0:
        //            case 1:
        //            case 2:
        //                {
        //                    SingleCancel.Enabled = false;
        //                    SingleStop.Enabled = false;
        //                    SingleStart.Enabled = false;
        //                }
        //                break;
        //            case 3: //已就绪
        //                {
        //                    SingleCancel.Enabled = false;
        //                    SingleStop.Enabled = false;
        //                    SingleStart.Enabled = true;
        //                }
        //                break;
        //            case 4:
        //            case 5:
        //                {
        //                    SingleCancel.Enabled = true;
        //                    SingleStop.Enabled = true;
        //                    SingleStart.Enabled = false;
        //                }
        //                break;
        //            case 6:
        //            case 7:
        //                {
        //                    SingleCancel.Enabled = false;
        //                    SingleStop.Enabled = false;
        //                    SingleStart.Enabled = false;
        //                }
        //                break;
        //            default:
        //                {
        //                    SingleCancel.Enabled = false;
        //                    SingleStop.Enabled = false;
        //                    SingleStart.Enabled = false;
        //                }
        //                break;
        //        }
        //    }));
        //}

        /// <summary>
        /// 显示系统连接状态和方法运行
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="oldflag"></param>
        void Status_Show(ushort flag, ref ushort oldflag)
        {
            string status_text = null;
            bool color_flag = true;
            switch (flag)
            {
                case 0:
                case 1:
                    status_text = "设备等待";
                    this.HmiStatus.BackColor = Color.LightGreen;
                    break;
                case 2:
                    status_text = "仪器平衡中...";
                    this.HmiStatus.BackColor = Color.LightGreen;

                    break;
                case 3:
                    status_text = "已就绪...";
                    this.HmiStatus.BackColor = Color.LightGreen;
                    break;
                case 4:
                case 5:
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                        status_text = "方法运行中...";
                    else if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 2)
                        status_text = "方法运行中...";
                    else if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 3)
                        status_text = "方法运行中...";
                    else
                        status_text = "方法运行中...";

                    this.HmiStatus.BackColor = Color.LightGreen;

                    break;
                case 6:
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                        stopbtn();
                    status_text = "后处理...";
                    this.HmiStatus.BackColor = Color.LightGreen;

                    break;
                case 7:
                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                        stopbtn();
                    status_text = "后处理完毕...";
                    this.HmiStatus.BackColor = Color.LightGreen;

                    break;
                case 8:
                    status_text = "点火成功后延时...";
                    this.HmiStatus.BackColor = Color.LightGreen;

                    break;
                case 9:
                    status_text = "设备断开";
                    this.HmiStatus.BackColor = Color.LightYellow;
                    color_flag = false;
                    break;
                case 10:
                    if (globaldata.m_hwconfig.hwconfiginfo.u16StartType == 2)
                    {
                        status_text = "设备等待";
                    }
                    else
                    {
                        status_text = "气路压力流量稳定中";
                    }
                    this.HmiStatus.BackColor = Color.LightGreen;

                    break;
                default:
                    //status_text = "设备连接";
                    //this.HmiStatus.BackColor = Color.LightGreen;
                    break;
            }
            statestr = status_text;
            IsStateColor = color_flag;
            //Console.WriteLine(flag.ToString());



            if (oldflag != flag)
            {
                oldflag = flag;
            }
        }

        private void tips_Show(ushort[] data)
        {
            string tips = string.Empty;

            if (data[0] == 1)
            {
                tips += "检测器通道一报警，报警码："+ data[1].ToString();
            }
            if (data[2] == 1)
            {
                tips += "检测器通道二报警，报警码：" + data[3].ToString();
            }
            if (data[4] == 1)
            {
                tips += "检测器通道三报警，报警码：" + data[5].ToString();
            }
            if (data[6] == 1)
            {
                tips += "检测器通道四报警，报警码：" + data[7].ToString();
            }
            if (data[8] == 1)
            {
                tips += "辅助通道一报警，报警码：" + data[9].ToString();
            }
            if (data[10] == 1)
            {
                tips += "辅助通道二报警，报警码：" + data[11].ToString();
            }
            if (data[12] == 1)
            {
                tips += "辅助通道三报警，报警码：" + data[13].ToString();
            }
            if (data[14] == 1)
            {
                tips += "辅助通道四报警，报警码：" + data[15].ToString();
            }

            if (!string.IsNullOrEmpty(tips))
            {
                epcs = true;
                _EPCTipsForm.MyProperty = tips;
                _EPCTipsForm.Show();
            }
           
        }

        void Common_HeadInfo()
        {
            string tmpFileName;
            tmpFileName = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName;
            SetMainFormMethodNameTH(tmpFileName.Substring(tmpFileName.LastIndexOf("\\") + 1));

        }

        void SingleRun_HeadInfo()
        {
            string tmpFileName;
            tmpFileName = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName;
            SetMainFormMethodNameTH(tmpFileName.Substring(tmpFileName.LastIndexOf("\\") + 1) + " 单次运行");
           
        }

        void QuickRun_HeadInfo()
        {
            string tmpFileName;
            tmpFileName = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName;
            SetMainFormMethodNameTH(tmpFileName.Substring(tmpFileName.LastIndexOf("\\") + 1) + " 快速运行");
        }

        void BAT_HeadInfo(ushort num, ushort count)
        {
            try
            {
                INIOperation runtable = new INIOperation(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab);
                string[] key = runtable.INIGetAllItemKeys("运行表");
                string[] runnum = runtable.INIGetAllItemKeys("循环");


                if (num < key.Length)
                {
                    if ((num != 0 || count > 0))
                    {
                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue != 0)
                        {
                            SetMainFormMethodNameTH(runtable.INIGetStringValue("运行表", key[num], "无") + "  批处理： " +
                                                    " 第" + (count + 1).ToString() + "/" +
                                                    runtable.INIGetStringValue("循环", runnum[num], "无") + "次");
                        }
                        else
                        {
                            SetMainFormMethodNameTH(runtable.INIGetStringValue("运行表", key[num], "无") + "  批处理 ");
                        }
                    }

                    globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_BATMethodName = System.IO.Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, runtable.INIGetStringValue("运行表", key[num], "无"));
                }
            }
            catch(Exception ex)
            {
                Trace.Write(ex);
            }
        }

       

        private void MDIBase_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dr = new QuitForm().ShowDialog();
           

            uint ret = 0;
            uint count = 0;

          

            if (dr == DialogResult.OK)  //停止系统并退出
            {

                CKVocAnalyzer.GlobalCKV.tcpservice.stop();
                _debugForm.CloseThread();
                Stop_Thread();
                if (!String.IsNullOrEmpty(globaldata.connection_ip))
                {
                    globaldata.OS_STOP = true;
                    hmiopt.WriteEndVal();

                    WaitHMIFree();

                    conmre.Set();
                    globaldata.m_pcbuffer.gcpcinfo.pcthreadinfo.HMI_Monitor_TH = 1;
                    Thread.Sleep(1000);


                    count = 0;
                    //ret = Slavetest.CModbusSlaveClose();
                    if (globaldata.CurrentVersion == 1)
                    {
                        nmodbusSlave.NModbusSlaveClose();

                        if (globaldata.m_pcbuffer.gcpcinfo.outputinfo.port != 0)
                        {
                            count = 0;
                            ret = Slave485test.CModbusSlave485Close();
                            while (ret != 0)
                            {
                                count++;
                                ret = Slave485test.CModbusSlave485Close();
                                Thread.Sleep(100);
                                if (count > 3)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //while (ret != 0)
                    //{
                    //    count++;
                    //    ret = Slavetest.CModbusSlaveClose();
                    //    Thread.Sleep(100);
                    //    if (count > 3)
                    //    {
                    //        break;
                    //    }
                    //}

                    
                        
                }

                try
                {
                    this.Dispose();
                    Process.GetCurrentProcess().Kill();
                }
                catch
                {

                }
            }

            if (dr == DialogResult.Yes)  //仅退出
            {
                CKVocAnalyzer.GlobalCKV.tcpservice.stop();
                _debugForm.CloseThread();
                if (!String.IsNullOrEmpty(globaldata.connection_ip))
                {
                    conmre.Set();
                    globaldata.m_pcbuffer.gcpcinfo.pcthreadinfo.HMI_Monitor_TH = 1;
                    Thread.Sleep(1500);

                    count = 0;
                    //ret = Slavetest.CModbusSlaveClose();
                    //while (ret != 0)
                    //{
                    //    count++;
                    //    ret = Slavetest.CModbusSlaveClose();
                    //    Thread.Sleep(100);
                    //    if (count > 3)
                    //    {
                    //        break;
                    //    }
                    //}
                    if (globaldata.CurrentVersion == 1)
                    {
                        nmodbusSlave.NModbusSlaveClose();

                        if (globaldata.m_pcbuffer.gcpcinfo.outputinfo.port != 0)
                        {
                            count = 0;
                            ret = Slave485test.CModbusSlave485Close();
                            while (ret != 0)
                            {
                                count++;
                                ret = Slave485test.CModbusSlave485Close();
                                Thread.Sleep(100);
                                if (count > 3)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }


                try
                {
                    this.Dispose();
                    Process.GetCurrentProcess().Kill();
                }
                catch
                {

                }
            }

            if (dr == DialogResult.Cancel)  //取消
            {
                e.Cancel = true;
            }
        }

        AutoResetEvent autoResetEvent = new AutoResetEvent(false);
        // private bool isopen = false;
        private void open()
        {
            //bool ret = false;
            try
            {

                if(globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue)
                {
                    MessageBox.Show("系统开启中......");
                    return ;
                }

                if (!String.IsNullOrEmpty(globaldata.connection_ip))
                {

                    if (globaldata.CurrentVersion == 1)
                    {
                        if (globaldata.m_hmibuffer.gcinfo.hmistatus == 0)
                        {
                            hmiopt.WriteStopVal();
                            statestr = "系统准备中...";

                            WaitHMIFree();
                            {
                                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 2)
                                {
                                    hmiopt.WriteBatVal();
                                }

                                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                                {
                                    hmiopt.WriteOpenVal();
                                }

                                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 1)
                                {
                                    hmiopt.WriteSingleVal();
                                }
                            }
                            //Console.WriteLine("WaitHMIWork ");
                            WaitHMIWork();
                            //Console.WriteLine("WaitHMIWork End");

                            globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = true;
                            globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;
                            //globaldata.starttimer = 0;
                            //globaldata.startimerIsSet = true;

                            globaldata.starttimer = 0;

                            globaldata.startimerIsSet = true;
                            globaldata.startimerIsSet1 = true;
                            globaldata.startimerIsSet2 = true;
                            globaldata.startimerIsSet3 = true;
                        }
                        else
                        {
                            //SetTitleStatueName("系统停止中...", false);
                            globaldata.OS_STOP = true;
                            hmiopt.WriteEndVal();
                            WaitHMIFree();

                            globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                            globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                Trace.Write(ex);
            }
        }

        private void fireupopt(int flag, ushort time1, ushort time2)
        {
            hmiopt.FireUPWork(flag, time1, time2);
        }

        //159
        private void fireupopt(int flag, ushort time1, ushort time2, ushort time3)
        {
            hmiopt.FireUPWork(flag, time1, time2, time3);
        }

        private void tcd_setdac(ushort port, ushort val)
        {
            hmiopt.TCD_SetDAC(port, val);
        }

        private void tcd_sw(ushort port)
        {
            hmiopt.TCD_Switch(port);
        }

        private void upMethodMain()
        {
            //hmiopt.WriteStopVal();
        }

        private void UpdateHmicfg(ushort val)
        {
            //hmiopt.WriteStopVal();
            hmiopt.UpdateHmicfg(val);
        }

        private void UpdateHmiOther(int index, ushort val)
        {
            hmiopt.UpdateHmiOther(index,val);
        }
        /// <summary>
        /// 调试运行表接口
        /// </summary>
        /// <param name="folder">批处理目录</param>
        /// <param name="runtablename">批处理文件名(带.ini)</param>
        /// <returns>0-失败 1-成功</returns>
        private int RunTableOpt(String folder, String runtablename)
        {
            int initret = 0;
            int ret = 0;

            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                FileServerClient rtclient = new FileServerClient();
                initret =  rtclient.WtClientInit(globaldata.connection_ip, globaldata.fileserverport);

                if (initret == 1)
                {
                    if (File.Exists(Path.Combine(folder, runtablename)))
                    {
                        ret = rtclient.WtClientCopytoServer("RunMethod.ini", Path.Combine(folder, runtablename), globaldata.remoteFolder + "运行表\\");
                        SendPCCMD(false);
                    }

                    rtclient.WtClientClose();
                    globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab = Path.Combine(folder, runtablename);
                }
            }

            return ret;
        }

        /// <summary>
        /// 调试运行表接口
        /// </summary>
        /// <param name="folder">批处理目录</param>
        /// <param name="runtablename">批处理文件名(带.ini)</param>
        /// <param name="count">批处理运行次数</param>
        /// <returns>0-失败 1-成功</returns>
        private int RunTableOptWithCount(String folder, String runtablename, ushort count)
        {
            int initret = 0;
            int ret = 0;

            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                FileServerClient rtclient = new FileServerClient();
                initret = rtclient.WtClientInit(globaldata.connection_ip, globaldata.fileserverport);

                if (initret == 1)
                {
                    if (File.Exists(Path.Combine(folder, runtablename)))
                    {
                        ret = rtclient.WtClientCopytoServer("RunMethodStd.ini", Path.Combine(folder, runtablename), globaldata.remoteFolder + "运行表\\");
                        hmiopt.SetBatCount(count);
                        SendSTDCMD();
                    }

                    rtclient.WtClientClose();
                    globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab = Path.Combine(folder, runtablename);
                }
                
            }
            return ret;
        }

        /// <summary>
        /// 直接执行STD批处理
        /// </summary>
        /// <param name="count">次数</param>
        private void RunTableOptWithCount(ushort count)
        {
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                hmiopt.SetBatCount(count);
                SendSTDCMD(); 
            }
        }

        /// <summary>
        /// 更新所需，关闭HMI
        /// </summary>
        public void stopforupdatefirm()
        {
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                statestr = "系统停止中...";
                globaldata.OS_STOP = true;
                hmiopt.WriteEndVal();
                WaitHMIFree();
                statestr = "系统停止中...";

                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;
            }
            else
            {
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;
            }
        }

        /// <summary>
        /// 开始更新指令
        /// </summary>
        public void startupdatefirm()
        {
            hmiopt.WriteUpdateVal();
        }
        public void hair_sw(int val)
        {
            hmiopt.HAirSwitch(val);
        }

        public void adjust_sw(int val)
        {
            hmiopt.AdjustSwitch(val);
        }

        public bool Isadmin = false;
        private void UserLoginMenu_Click(object sender, EventArgs e)
        {
            while (true)
            {
                DialogResult dr = new LandIn(globaldata.UserName, globaldata.UserPwd).ShowDialog();

                if (dr == DialogResult.OK)
                {
                    if (LandIn.Island)
                    {
                        if (_debugForm != null)
                        {
                            Formstr = "调试窗口";
                            _debugForm.Activate();
                            title.Activate();
                        }
                        Isadmin = true;
                        SetMenu(LandIn.Island);
                        Trace.WriteLine(string.Format("用户{0}，进入调试模式", "admin"), "sys");
                        return;
                    }
                    else
                    {
                        Isadmin = false;
                        MessageBox.Show("密码错误！");
                    }
                }

                if (dr == DialogResult.No)
                {
                    return;
                }
            }
        }

        private void UserLogoutMenu_Click(object sender, EventArgs e)
        {
            if (_debugForm != null)
            {
                // debugForm.Hide();
            }
            if (_userForm != null)
            {
                Formstr = "用户窗口";
                _userForm.Activate();
                //userForm.Show();
                Trace.WriteLine("注销登录，进入用户模式", "sys");
            }
            Isadmin = false;
            LandIn.Island = false;
            SetMenu(LandIn.Island);

        }

        private void SystemStartMenu_Click(object sender, EventArgs e)
        {
            open();
        }

        private void SystemStopMenu_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {

                statestr = "系统停止中...";

                globaldata.OS_STOP = true;
                hmiopt.WriteEndVal();

                WaitHMIFree();

                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;

            }
            else
            {

                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue = false;
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 0;
            }
        }
        auxtool f_auxtool;
        private void AuxToolMenu_Click(object sender, EventArgs e)
        {
            //auxtool f_auxtool = new auxtool();
            int ret = 0;
            ushort[] firetime = new ushort[2];
            ushort[] firstfiretime = new ushort[1];

            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                ret = mymodbus.GetFireUpTime(ref firetime);
                mymodbus.GetFristFireUpTime(ref firstfiretime);

            }

            if (f_auxtool == null)
            {
                f_auxtool = new auxtool(firetime[0], firetime[1], firstfiretime[0]);

                f_auxtool.auxtoolforfireup += new AUXTool(fireupopt);
                f_auxtool.hairsw += new HAir_SW(hair_sw);
                f_auxtool.adsw += new Adjust_SW(adjust_sw);
                f_auxtool.gctcd_setdac += new TCD_SetDAC(tcd_setdac);
                f_auxtool.gctcd_sw += new TCD_SW(tcd_sw);

                f_auxtool.Show();
            }
            else if (f_auxtool.IsDisposed)
            {
                f_auxtool = null;

                f_auxtool = new auxtool(firetime[0], firetime[1], firstfiretime[0]);

                f_auxtool.auxtoolforfireup += new AUXTool(fireupopt);
                f_auxtool.hairsw += new HAir_SW(hair_sw);
                f_auxtool.adsw += new Adjust_SW(adjust_sw);
                f_auxtool.gctcd_setdac += new TCD_SetDAC(tcd_setdac);
                f_auxtool.gctcd_sw += new TCD_SW(tcd_sw);

                f_auxtool.Show();
            }
            else
            {
                f_auxtool.Activate();
            }

            //if (f_auxtool == null)
            //{
            //    f_auxtool = new auxtool(firetime[0], firetime[1], firstfiretime[0]);

            //    f_auxtool.auxtoolforfireup += new AUXTool(fireupopt);
            //    f_auxtool.sfupdatefirm += new StopForUpdateFirm(stopforupdatefirm);
            //    f_auxtool.updatefirm += new UpdateFirmCMD(startupdatefirm);
            //    f_auxtool.hairsw += new HAir_SW(hair_sw);
            //    f_auxtool.Show();
            //}
            //else
            //{
            //    if (f_auxtool.IsDisposed)
            //    {
            //        f_auxtool = new auxtool(firetime[0], firetime[1], firstfiretime[0]);

            //        f_auxtool.auxtoolforfireup += new AUXTool(fireupopt);
            //        f_auxtool.sfupdatefirm += new StopForUpdateFirm(stopforupdatefirm);
            //        f_auxtool.updatefirm += new UpdateFirmCMD(startupdatefirm);
            //        f_auxtool.hairsw += new HAir_SW(hair_sw);
            //        f_auxtool.Show();

            //    }
            //    else
            //    {
            //        f_auxtool.setfireuptime(firetime[0], firetime[1], firstfiretime[0]);
            //        f_auxtool.auxtoolforfireup -= new AUXTool(fireupopt);
            //        f_auxtool.auxtoolforfireup += new AUXTool(fireupopt);
            //        f_auxtool.sfupdatefirm -= new StopForUpdateFirm(stopforupdatefirm);
            //        f_auxtool.sfupdatefirm += new StopForUpdateFirm(stopforupdatefirm);
            //        f_auxtool.updatefirm -= new UpdateFirmCMD(startupdatefirm);
            //        f_auxtool.updatefirm += new UpdateFirmCMD(startupdatefirm);
            //        f_auxtool.hairsw -= new HAir_SW(hair_sw);
            //        f_auxtool.hairsw += new HAir_SW(hair_sw);
            //        f_auxtool.Show();
            //    }
            //}
            
        }

        UserConfig confu;
        private void NetWorkMenu_Click(object sender, EventArgs e)
        {
            if (confu == null)
            {
                confu = new UserConfig();
                confu.Show();
            }
            else if (confu.IsDisposed)
            {
                confu = null;
                confu = new UserConfig();
                confu.Show();
            }
            else
            {
                confu.Activate();
            }
            
        }
        RunTables f_runtablef;
        private void MethodBatMenu_Click(object sender, EventArgs e)
        {
            try
            {
                if (f_runtablef == null)
                {
                    f_runtablef = new RunTables();
                    f_runtablef.sendupdatecmd -= new SendUpdateCMD(SendPCCMD);
                    f_runtablef.sendupdatecmd += new SendUpdateCMD(SendPCCMD);
                    f_runtablef.sendstopcmd -= new SendStopCMD(SendStopCMD);
                    f_runtablef.sendstopcmd += new SendStopCMD(SendStopCMD);
                    f_runtablef.Show();
                }
                else if (f_runtablef.IsDisposed)
                {
                    f_runtablef = null;
                    f_runtablef = new RunTables();
                    f_runtablef.sendupdatecmd -= new SendUpdateCMD(SendPCCMD);
                    f_runtablef.sendupdatecmd += new SendUpdateCMD(SendPCCMD);
                    f_runtablef.sendstopcmd -= new SendStopCMD(SendStopCMD);
                    f_runtablef.sendstopcmd += new SendStopCMD(SendStopCMD);
                    f_runtablef.Show();
                }
                else
                {
                    f_runtablef.Activate();
                }


            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);

            }
        }

        MethodMain myform;
        private void NewMethodMenu_Click(object sender, EventArgs e)
        {
            SaveDialog saveDialog = new SaveDialog(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, 0);
            DialogResult dr = saveDialog.ShowDialog();
            if (dr == DialogResult.OK)
            {
                String mfilename = Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, saveDialog.filename);
                GCMethodConfig methodconfig = new GCMethodConfig();

                if (File.Exists(mfilename) == false)
                {
                    StreamWriter sw = new StreamWriter(mfilename, false, System.Text.Encoding.Unicode);
                    sw.WriteLine("[方法名称]");
                    sw.WriteLine("名称=" + saveDialog.filename);
                    sw.Close();
                    // globaldata.createfile = true;
                }

                methodconfig.SetMethodConfigName(mfilename);
                methodconfig.SetMethodSaveName(mfilename);

                if (myform == null)
                {
                    myform = new MethodMain();
                    myform.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                    myform.Show();
                }
                else if (myform.IsDisposed)
                {
                    myform = new MethodMain();
                    myform.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                    myform.Show();
                }
                else
                {
                    myform.Activate();
                }

            }
        }

        MethodMain myformb;
        private void OpenMethodMenu_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDlg = new OpenFileDialog();
            fileDlg.Multiselect = false;
            fileDlg.InitialDirectory = globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder;
            fileDlg.RestoreDirectory = true;
            fileDlg.Title = "请选择方法文件";
            fileDlg.Filter = "配置文件(*.ini)|*.ini";
            if (fileDlg.ShowDialog() == DialogResult.OK)
            {
                string file = fileDlg.FileName;

                String mfilename = Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, file);

                globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_OpenMethodName = mfilename;
                GCMethodConfig methodconfig = new GCMethodConfig();

                methodconfig.SetMethodConfigName(mfilename);
                methodconfig.SetMethodSaveName(mfilename);


                if (myformb == null)
                {
                    myformb = new MethodMain(true);

                    myformb.sendupdatecmd += new MethodMain.SendUpdateCMD(SendPCCMD);
                    myformb.upmethod += new MethodMain.Up_MethodMain(upMethodMain);
                    myformb.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                    myformb.Show();

                }
                else if (myformb.IsDisposed)
                {
                    myformb = null;
                    myformb = new MethodMain(true);

                    myformb.sendupdatecmd += new MethodMain.SendUpdateCMD(SendPCCMD);
                    myformb.upmethod += new MethodMain.Up_MethodMain(upMethodMain);

                    myformb.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                    myformb.Show();
                }
                else
                {
                    myformb.Activate();
                }

                //MethodMain myform = new MethodMain(true);

                //myform.sendupdatecmd += new MethodMain.SendUpdateCMD(SendPCCMD);
                //myform.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                //myform.Show();

                string tmpFileName;
                tmpFileName = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_MethodName;
                SetMainFormMethodNameTH(tmpFileName.Substring(tmpFileName.LastIndexOf("\\") + 1));

                this.inifilec = true;

                
            }

        }
        

        MethodMain myformbb;
        private void MethodBrowseMenuItem_Click(object sender, EventArgs e)
        {
            if (globaldata.m_configDlg.Visible == true)
                return;

            if (inifilec)
            {
                String mfilename = globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_OpenMethodName;
                GCMethodConfig methodconfig = new GCMethodConfig();
                methodconfig.SetMethodConfigName(mfilename);
                methodconfig.SetMethodSaveName(mfilename);


                //MethodMain myform = new MethodMain(true, false);
                //myform.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                //myform.Show();
                //Console.WriteLine("前 " + globaldata.m_hmibuffer.gcinfo.methodstatus);
                if (myformbb == null)
                {
                    myformbb = new MethodMain(true, false);
                    myformbb.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                    myformbb.Show();
                }
                else if (myformbb.IsDisposed)
                {
                    myformbb = null;
                    myformbb = new MethodMain(true, false);

                    myformbb.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                    myformbb.Show();
                }
                else
                {
                    myformbb.Activate();
                }
            }
            else
            {
                OpenFileDialog fileDlg = new OpenFileDialog();
                fileDlg.Multiselect = false;
                fileDlg.InitialDirectory = globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder;
                fileDlg.RestoreDirectory = true;
                fileDlg.Title = "请选择方法文件";
                fileDlg.Filter = "配置文件(*.ini)|*.ini";
                if (fileDlg.ShowDialog() == DialogResult.OK)
                {
                    string file = fileDlg.FileName;
                    String mfilename = Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.MethodFolder, file);
                    GCMethodConfig methodconfig = new GCMethodConfig();
                    methodconfig.SetMethodConfigName(mfilename);
                    methodconfig.SetMethodSaveName(mfilename);

                    if (myformbb == null)
                    {
                        myformbb = new MethodMain(true, false);
                        myformbb.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                        myformbb.Show();
                    }
                    else if (myformbb.IsDisposed)
                    {
                        myformbb = null;
                        myformbb = new MethodMain(true, false);
                        myformbb.SetGCConfig(globaldata.m_hwconfig, methodconfig);
                        myformbb.Show();
                    }
                    else
                    {
                        myformbb.Activate();
                    }


                }
            }

            //Console.WriteLine(" 后 "+ globaldata.m_hmibuffer.gcinfo.methodstatus);
        }

        WaveTotalForm total;
        private void HistoryDataMenu_Click(object sender, EventArgs e)
        {
            try
            {
                if (total == null)
                {
                    total = new WaveTotalForm();
                    total.Show();
                }
                else if (total.IsDisposed)
                {
                    total = null;
                    total = new WaveTotalForm();
                    total.Show();
                }
                else
                {
                    total.Activate();
                }


            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }

        AdjustFrom just;
        private void CalibrationMenu_Click(object sender, EventArgs e)
        {

            try
            {
                if (just == null)
                {
                    just = new AdjustFrom();
                    just.Show();
                }
                else if (just.IsDisposed)
                {
                    just = null;
                    just = new AdjustFrom();
                    just.Show();
                }
                else
                {
                    just.Activate();
                }

            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }

        HistChartForm hist;
        private void HistoryPicMenu_Click(object sender, EventArgs e)
        {
            try
            {
                if (hist == null)
                {
                    hist = new HistChartForm(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.DataFolder);
                    hist.Show();
                }
                else if (hist.IsDisposed)
                {
                    hist = null;
                    hist = new HistChartForm(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.DataFolder);
                    hist.Show();
                }
                else
                {
                    hist.Activate();
                }
                
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }

        }
        /// <summary>
        /// 仪器配置窗口
        /// </summary>
        //InstrConfig f_showconfig;
        DeviceConfigUI.ConfigDevice f_showconfig;
        private void ConfigCreateSubMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (f_showconfig == null)
                {
                    f_showconfig = new DeviceConfigUI.ConfigDevice();
                    f_showconfig.upho += new DeviceConfigUI.UpdataHMIOP(UpdateHmicfg);
                    f_showconfig.Show();
                }
                else
                {
                    if (f_showconfig.IsDisposed)
                    {
                        f_showconfig = new DeviceConfigUI.ConfigDevice();
                        f_showconfig.upho += new DeviceConfigUI.UpdataHMIOP(UpdateHmicfg);
                        f_showconfig.Show();
                    }
                    else
                    {
                        f_showconfig.Show();
                    }
                }

            }
            catch
            {

            }


        }

        private void F_showconfig_upho(ushort val)
        {
            throw new NotImplementedException();
        }

        ShowConfig showConfig;
        private void ConfigShowSubMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (showConfig == null)
                {
                    showConfig = new ShowConfig();
                    showConfig.Show();
                }
                else if (showConfig.IsDisposed)
                {
                    showConfig = null;
                    showConfig = new ShowConfig();
                    showConfig.Show();
                }
                else
                {
                    showConfig.Activate();
                }
                
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }

        }

        private void ConfigSendSubMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                SendConfig f = new SendConfig();
                f.Show();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }
        CKVocAnalyzer.SetInfoForm sf;
        private void ParameterSettingMenu_Click(object sender, EventArgs e)
        {
            try
            {


                if (showConfig == null)
                {
                    sf = new CKVocAnalyzer.SetInfoForm();
                    sf.Show();
                }
                else if (showConfig.IsDisposed)
                {
                    sf = null;
                    sf = new CKVocAnalyzer.SetInfoForm();
                    sf.Show();
                }
                else
                {
                    sf.Activate();
                }

            }
            catch (Exception ex)
            {
                Trace.Write(ex);
            }
        }

        #region 单次处理控制
        private void startbtn()
        {
            globaldata.startflag = true;
            globaldata.stopflag = false;
            globaldata.cancelflag = false;
            globaldata.startclear = true;
            //globaldata.starttimer = 0;
            //globaldata.startimerIsSet = true;


            globaldata.starttimer = 0;

            globaldata.startimerIsSet = true;
            globaldata.startimerIsSet1 = true;
            globaldata.startimerIsSet2 = true;
            globaldata.startimerIsSet3 = true;
            globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 1;
        }

        //private int SysStatus;

        private void SingleStart_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {

                if ((globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue == true) && globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                {

                    if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                    {
                        hmiopt.WriteOpenVal();
                        //(this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 3;
                        //SysStatus = 0;
                    }
                    hmiopt.WriteStartVal();

                    startbtn();

                }
            }
        }

        Thread t_checkcmd;
        public void stopbtn()
        {
            globaldata.startflag = false;
            globaldata.stopflag = true;
            globaldata.cancelflag = false;

            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 2;
            }

            if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
            {
                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue == true)
                {
                    hmiopt.WriteOpenVal();
                    t_checkcmd = new Thread(checkcmd);
                    t_checkcmd.IsBackground = true;
                    t_checkcmd.Start();
                }
            }
        }

        private void checkcmd()
        {
            while (globaldata.m_hmibuffer.gcinfo.methodstatus != 3)
            {
                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                {
                    hmiopt.WriteOpenVal();
                }
                else if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 1)
                {
                    hmiopt.WriteSingleVal();
                }
                else
                {

                }
                Thread.Sleep(1000);
            }
        }

        private void SingleStop_Click(object sender, EventArgs e)
        {

            if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue == true)
            {

                hmiopt.WriteStopVal();

                WaitHMIFree();

                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                {
                    hmiopt.WriteOpenVal();
                    //SysStatus = 1;
                }
                stopbtn();
            }

        }

        private void cancelbtn()
        {
            globaldata.startflag = false;
            globaldata.stopflag = false;
            globaldata.cancelflag = true;
            globaldata.starttimer = 0x7FFFFFFF;
            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue = 3;
            }

            if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
            {
                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue == true)
                {
                    hmiopt.WriteOpenVal();
                    t_checkcmd = new Thread(checkcmd);
                    t_checkcmd.IsBackground = true;
                    t_checkcmd.Start();
                }

            }
        }

        private void SingleCancel_Click(object sender, EventArgs e)
        {
            if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue == true)
            {
                hmiopt.WriteCancalVal();
                WaitHMIFree();
                if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.RunType == 0)
                {
                    hmiopt.WriteOpenVal();
                    //SysStatus = 2;
                }
                cancelbtn();


            }
        }

        #endregion

        AboutForm f_showcfg;
        private void AboutMenu_Click(object sender, EventArgs e)
        {
            int ret = 0;
            ushort[] version = new ushort[12];
            ret = mymodbus.GetFireWareVersion(ref version);

            if (f_showcfg == null)
            {
                f_showcfg = new AboutForm(version);
                f_showcfg.Show();
            }
            else
            {
                if (f_showcfg.IsDisposed)
                {
                    f_showcfg = new AboutForm(version);
                    f_showcfg.Show();
                }
                else
                {
                    f_showcfg.Show();
                }

            }
        }
        /// <summary>
        /// true 开始校准   false  强制结束
        /// </summary>
        /// <param name="boolrun"></param>
        private void AutoAdjustRun(bool boolrun)
        {
            if(boolrun)
            {
                //CurveDisPlay.curdisp.SetAutoAdjust();

            }else
            {
                //CurveDisPlay.curdisp.StopAutoAdjust();
            }

        }
        /// <summary>
        /// 校准完成时间
        /// </summary>

        DateTime AutoAdjust;
        bool cancv = false;
        private void timerWorker_Tick(object sender, EventArgs e)
        {
            try
            {
                //Trace.WriteLine(string.Format("{0},{1}", SharedSpace.MControl.SetOut, SharedSpace.MControl.SetRun), "debug");

                if (SharedSpace.MControl.SetOut && SharedSpace.MControl.SetRun == false)  //准备开始校准
                {
                    SharedSpace.MControl.errstr = null;
                    SharedSpace.MControl.zhouqi = globaldata.m_dpbuffer.ShowList.showtime.alltime;
                  
                    if(SharedSpace.MControl.zhouqi*SharedSpace.MControl.runcount<=SharedSpace.MControl.dateend)
                    {
                        if (RunTableOpt(SharedSpace.MControl.path, SharedSpace.MControl.Name)==1&& SharedSpace.MControl.MethodType==1)
                        {
                            Trace.WriteLine(string.Format("开始校准{0},{1}", SharedSpace.MControl.zhouqi, SharedSpace.MControl.runcount), "sys");
                            SharedSpace.MControl.SetRun = true;//仪器进入校准环境
                            CurveDisPlay.forcePurge = true;//强制清除数据
                            AutoAdjust = DateTime.Now.AddSeconds(SharedSpace.MControl.dateend);
                            cancv = true;
                            //switch (CKVocAnalyzer.GlobalCKV.adjustType)
                            //{
                            //    case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Zero:
                            //        hmiopt.Adjust_ling_biao(0, (ushort)65280);
                            //        break;
                            //    case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Biao:
                            //        hmiopt.Adjust_ling_biao(1, (ushort)65280);
                            //        break;
                            //    case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang:
                            //        hmiopt.Adjust_ling_biao(0, 0);
                            //        break;
                            //    default:
                            //        break;
                            //}
                        }
                        if (SharedSpace.MControl.MethodType == 2)
                        {
                            Trace.WriteLine(string.Format("开始校准{0},{1}", SharedSpace.MControl.zhouqi, SharedSpace.MControl.runcount), "sys");
                            SharedSpace.MControl.SetRun = true;//仪器进入校准环境
                            CurveDisPlay.forcePurge = true;
                            AutoAdjust = DateTime.Now.AddSeconds(SharedSpace.MControl.dateend);
                            cancv = true;
                            
                        }


                    }
                    else
                    {
                        SharedSpace.MControl.errstr = "校准时间不够";
                        SharedSpace.MControl.SetOut = false;
                        SharedSpace.MControl.SetRun = false;


                    }
                }
                //else if (SharedSpace.MControl.SetRun == false)
                //{
                //    SharedSpace.MControl.errstr = "系统准备失败";
                //    SharedSpace.MControl.SetOut = false;
                //}
                //等待校准结束
                if (DateTime.Now >= AutoAdjust && SharedSpace.MControl.SetOut && SharedSpace.MControl.SetRun)
                {
                    SharedSpace.MControl.IsEnd = true;

                    if (RunTableOpt(SharedSpace.MControl.defaultPath, SharedSpace.MControl.defaultName) == 1 && SharedSpace.MControl.MethodType == 1)
                    {
                        SharedSpace.MControl.SetOut = false;
                        SharedSpace.MControl.SetRun = false;
                        if (SharedSpace.Data.typesint == 2)
                        {
                            CurveDisPlay.curdisp.ConfingAdjust();
                        }
                        cancv = true;
                        //if (CKVocAnalyzer.GlobalCKV.adjustType == CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang)
                        //{
                        //    hmiopt.Adjust_ling_biao(0, 0);
                        //}
                        Trace.WriteLine("校准结束", "sys");
                    }
                    if (SharedSpace.MControl.MethodType == 2)
                    {
                        SharedSpace.MControl.SetOut = false;
                        SharedSpace.MControl.SetRun = false;
                        if (SharedSpace.Data.typesint == 2)
                        {
                            CurveDisPlay.curdisp.ConfingAdjust();
                        }
                        cancv = true;
                        //if (CKVocAnalyzer.GlobalCKV.adjustType == CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang)
                        //{
                        //    hmiopt.Adjust_ling_biao(0, 0);
                        //}
                        Trace.WriteLine("校准结束", "sys");
                    }

                }

                if (SharedSpace.MControl.forceEnd && SharedSpace.MControl.SetOut && SharedSpace.MControl.SetRun)
                {
                    SharedSpace.MControl.IsEnd = false;
                   
                    if (RunTableOpt(SharedSpace.MControl.defaultPath, SharedSpace.MControl.defaultName) == 1&&SharedSpace.MControl.MethodType == 1)
                    {
                        SharedSpace.MControl.SetOut = false;
                        SharedSpace.MControl.SetRun = false;
                        SharedSpace.Data.typesint = 0;
                        cancv = true;

                        Trace.WriteLine("强制校准结束", "sys");
                        //if (CKVocAnalyzer.GlobalCKV.adjustType == CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang)
                        //{
                        //    hmiopt.Adjust_ling_biao(0, 0);
                        //}
                    }
                    if (SharedSpace.MControl.MethodType == 2)
                    {
                        SharedSpace.MControl.SetOut = false;
                        SharedSpace.MControl.SetRun = false;
                        SharedSpace.Data.typesint = 0;
                        cancv = true;

                        Trace.WriteLine("强制校准结束", "sys");
                        //if (CKVocAnalyzer.GlobalCKV.adjustType == CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang)
                        //{
                        //    hmiopt.Adjust_ling_biao(0, 0);
                        //}
                    }

                }

                if (cancv)
                {
                    switch (CKVocAnalyzer.GlobalCKV.adjustType)
                    {
                        case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Zero:
                            cancv = !hmiopt.Adjust_ling_biao(0, (ushort)65280);
                            break;
                        case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Biao:
                            cancv = !hmiopt.Adjust_ling_biao(1, (ushort)65280);
                            break;
                        case CKVocAnalyzer.GlobalCKV.AdjustType.AT_Yang:
                            cancv = !hmiopt.Adjust_ling_biao(0, 0);
                            break;
                        default:
                            break;
                    }
                }

            }
            catch (Exception ex)
            {
                SharedSpace.MControl.SetOut = false;
                SharedSpace.MControl.SetRun = false;
                Trace.Write(ex);
            }
        }
        private int epct;
        private bool epcs;
        private Process[] MyProcesses;
        private bool Zbexe = false;
        private void timer2_Tick(object sender, EventArgs e)
        {
            epct++;
            if (epct>20)
            {
                if (epcs == true)
                {
                    epcs = false;
                    _EPCTipsForm.Hide();
                }
                epct = 0;
            }
            else
            {
                if (epcs == false)
                {
                    tips_Show(globaldata.m_hmibuffer.gcinfo.EPCStatus);
                }
            }
            if (!Zbexe)
            {
                MyProcesses = Process.GetProcessesByName("通用5.2");//需要监控的程序名，该方法带出该程序所有用到的进程 
                foreach (Process myprocess in MyProcesses)
                {
                    //textBox1.Text += myprocess.ProcessName + "\r\n";
                    if (myprocess.ProcessName.ToLower() == "通用5.2")
                    {
                        Zbexe = true;
                        //MessageBox.Show("通用5.2");
                        myprocess.EnableRaisingEvents = true;//设置进程终止时触发的时间 
                        myprocess.Exited += new EventHandler(myprocess_Exited);//发现外部程序关闭即触发方法myprocess_Exited 
                    }
                }
            }

        }
        private void myprocess_Exited(object sender, EventArgs e)//被触发的程序 
        {
            Zbexe = false;
            MessageBox.Show("后处理软件已退出，请重启本软件和后处理软件");
        }
        private void changeVsi_Click(object sender, EventArgs e)
        {
            DialogResult dl = MessageBox.Show("是否切换", "版本切换", MessageBoxButtons.OKCancel);
            if (dl == DialogResult.OK)
            {
                string file = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath), "GC_Config\\GC_Set\\启动参数\\startup.ini");
                IniFile iniFile = new IniFile(file);

                //iniFile.ReadSection("").
                if (iniFile.ReadString("Version", "VersionType") == "0")
                {
                    iniFile.WriteInteger("Version", "VersionType", 1);//实验室
                }
                else
                {
                    iniFile.WriteInteger("Version", "VersionType", 0);//在线
                }
                Application.ExitThread();
                Application.Exit();
                Application.Restart();
                Process.GetCurrentProcess().Kill();
            }
        }
        CKVocAnalyzer.FormulaTips ft;
        private void 单位换算ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ft == null)
            {
                ft = new CKVocAnalyzer.FormulaTips();
                ft.Show();
            }
            else if (ft.IsDisposed)
            {
                ft = null;
                ft = new CKVocAnalyzer.FormulaTips();
                ft.Show();
            }
            else
            {
                ft.Activate();
            }
        }
        //CKVocAnalyzer.AutoAdjust auto;
        private void 自动校准ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_userForm.auto == null)
            {
                _userForm.auto = new CKVocAnalyzer.AutoAdjust();
                //_userForm.auto
                _userForm.auto.Isadmin = Isadmin;
                _userForm.auto.Show();
                
            }
            else if (_userForm.auto.IsDisposed)
            {
                _userForm.auto = null;
                _userForm.auto = new CKVocAnalyzer.AutoAdjust();
                _userForm.auto.Isadmin = Isadmin;
                _userForm.auto.Show();
            }
            else
            {
                if (!_userForm.auto.Visible)
                {
                    _userForm.auto.Isadmin = Isadmin;
                    _userForm.auto.Show();
                    _userForm.auto.IsinitShow();

                    //_userForm.auto.ShowKB();
                }
            }
        }

        private void TestToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CKVocAnalyzer.testsjshow testsjshow = new CKVocAnalyzer.testsjshow();
            testsjshow.Show();
        }

        SysConfig sysc;
        private void 系统配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int ret = 0;
            ushort[] other = new ushort[2];

            if (!String.IsNullOrEmpty(globaldata.connection_ip))
            {
                ret = mymodbus.GetOtherset(ref other);
            }
            if (sysc == null)
            {
                sysc = new SysConfig(other);
                sysc.uphos += new UpdataHMIOS(UpdateHmiOther);
                sysc.uphops += new UpdataHMIOpS(UpdateHmicfg);
                sysc.sfupdatefirm += new StopForUpdateFirm(stopforupdatefirm);
                sysc.updatefirm += new UpdateFirmCMD(startupdatefirm);
                sysc.Show();
            }
            else if (sysc.IsDisposed)
            {
                sysc = null;
                sysc = new SysConfig(other);
                sysc.uphos += new UpdataHMIOS(UpdateHmiOther);
                sysc.uphops += new UpdataHMIOpS(UpdateHmicfg);
                sysc.sfupdatefirm += new StopForUpdateFirm(stopforupdatefirm);
                sysc.updatefirm += new UpdateFirmCMD(startupdatefirm);
                sysc.Show();
            }
            else
            {
                sysc.Activate();
            }
        }

        VisionLogs vl;
        private void 版本日志ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (vl == null)
            {
                vl = new VisionLogs();
                vl.Show();
            }
            else if (vl.IsDisposed)
            {
                vl = null;
                vl = new VisionLogs();
                vl.Show();
            }
            else
            {
                vl.Activate();
            }
        }

        private void 说明ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string files = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "软件说明.chm";

                if (File.Exists(files))
                {
                    System.Diagnostics.Process.Start(files);
                }
                else
                {
                    MessageBox.Show("文件缺失。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {

            }
        }

        Compound compound;
        private void 化合物列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (compound == null)
            {
                compound = new Compound();
                compound.Show();
            }
            else if (compound.IsDisposed)
            {
                compound = null;
                compound = new Compound();
                compound.Show();
            }
            else
            {
                compound.Activate();
            }
        }

        //private void debugSubMenu_Click(object sender, EventArgs e)        
        //    try
        //    {
        //        _424XTest test = new _424XTest()；
        //        test.Show();
        //    }
        //    catch (Exception ex)
        //    {
        //        Log.Error(ex.Message);
        //    }
        //}
    }
}
