MetroStaticTesting.cs 11.0 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Comm;
using Common.Logging;
using System.Reflection;
using Dal;

namespace App
{
    public partial class MetroStaticTesting : FrmBase
    {
        private bool isTest = true;//上一个状态是否在测试测试,默认为是
        private LoginManager _loginManager;
        FrmTestManage newForm;
        public MetroStaticTesting(LoginManager loginManager)
        {
            //Control.CheckForIllegalCrossThreadCalls = false;
            LOGGER.Debug("start into Static Test"+DateTime.Now);
            InitializeComponent();
            this.SetLanguage(this);
            this.WindowState = FormWindowState.Maximized;
            this._loginManager = loginManager;
            Init();
            this.label1.Text = getMsg("FrmTestNoData");
            LOGGER.Debug("Start Load Static Test Form" + DateTime.Now);
            chooseProduct();
            
        }
        private void Init()
        {
            if (Fuction.m_Language == Const.LANGUAGE_ENGLISH)
            {
                this.Text = getMsg("FrmMDItsmi_Static") + " " + getMsg("FrmMDItabTest");
            }
            else
            {
                this.Text = getMsg("FrmMDItsmi_Static") + getMsg("FrmMDItabTest");
            }
            //this.startTestingButton.Text = getMsg("FrmMDIAuth_2010");
            this.stopTestingButton.Text = getMsg("FrmMDIAuth_2020");
            this.gobackButton.Text = getMsg("back");
            this.btnNext.Text = getMsg("frmProductbtn_Choose");

            this.lbl_temp.Text = getMsg("FrmMDIRightNavigateBarlbl_SolventTemp") + ":";
            this.lbl_pattern.Text = getMsg("FrmMDIRightNavigateBarlbl_TestMode") + ":";
            this.lbl_solvent.Text = getMsg("FrmMDIRightNavigateBarlbl_TestSolvent") + ":";
            this.lbl_time.Text = getMsg("FrmMDIRightNavigateBarlbl_Date") + ":";

        }
        public void AddToStaticPanel(FrmTestManage form)
        {
            this.staticTestingShow.Location = new Point(12, -50);
            this.staticTestingShow.Size = new System.Drawing.Size(this.mdiPanel.Width - 24, this.mdiPanel.Height-20);
            this.staticTestingShow.BorderStyle = System.Windows.Forms.BorderStyle.None;
            newForm = form;
            this.IsMdiContainer = true;
            newForm.Movable = false;
            newForm.ControlBox = false;
            newForm.ShowInTaskbar = false;
            newForm.MdiParent = this;//指定当前窗体为顶级Mdi窗体
            newForm.Parent = this.staticTestingShow;//指定子窗体的父容器为
            newForm.FormBorderStyle = FormBorderStyle.None; // 无边框
            newForm.Dock = System.Windows.Forms.DockStyle.Fill;
            this.staticTestingShow.Controls.Add(newForm);  // 添加到 Panel中
            newForm.Show();     // 显示
            this.label1.SendToBack();
            newForm.Activate();//激活
        }

        

        /**
         * 开始测试
         */
        private void startTestingButton_Click(object sender, EventArgs e)
        {
            this.staticTestingShow.Location = new Point(113, 10);
            this.staticTestingShow.Size = new System.Drawing.Size(this.mdiPanel.Width - 120, this.mdiPanel.Height - 20);
            this.staticTestingShow.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.label1.Visible = false;
            chooseProduct();
        }
        private MetroProduct frm;
        public void chooseProduct()
        {
            gobackButton.Visible = true;
            btnNext.Visible = true;
            stopTestingButton.Visible = false;
            gobackButton.Enabled = true;
            btnNext.Enabled = false;
            MetroProduct.returnValue = -100;
            frm = new MetroProduct(Const.OPERATION_CHOOSE, "testModeItemSTATIC", _loginManager);
            frm.Movable = false;
            frm.ControlBox = false;
            frm.MdiParent = this;//指定当前窗体为顶级Mdi窗体
            frm.Parent = this.staticTestingShow;//指定子窗体的父容器为
            frm.FormBorderStyle = FormBorderStyle.None; // 无边框
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            this.staticTestingShow.Controls.Add(frm);  // 添加到 Panel中
            //LOGGER.Debug("finish Add Product Form and Start Check Machine State"+DateTime.Now);
            //LOGGER.Debug("Finish Check Machine State"+DateTime.Now);
            frm.Show();// 显示
            frm.Activate(); 
            frm.checkMachineState();
        }

        private void stopTestingButton_Click(object sender, EventArgs e)
        {
            if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.Cut_Off_Test))
            {
                CutOffTest();//中止测试
                this.label1.SendToBack();
            }
        }
        private void CutOffTest()
        {
            if (newForm is FrmTestManage)
            {
                ((FrmTestManage)newForm).CutOffTest();
                return;
            }
        }

        private void goBackButton_Click(object sender, EventArgs e)
        {
            this.Close();
            MetroMDI mm = new MetroMDI(_loginManager);
            //this.ShowInTaskbar = false;
            //mm.ShowInTaskbar = true;
            mm.Show();
            //PauseTest();//暂停测试
        }
        private void PauseTest()
        {
            if (newForm is FrmTestManage)
            {
                //if (((FrmTestManage)newForm).IsRealStart)
                //{
                    //如果之前为暂停测试,点击按钮后名字变为继续测试
                    //如果之前为继续测试,点击按钮后名字变为暂停测试
                    if (this.isTest)
                    {
                        //////tn.Text = getMsg("FrmMDIAuth_" + Const.TREE_GOONTEST);//继续测试 国际化
                        //(Fuction.m_Language == Const.LANGUAGE_CHINESE) ? "继续测试" : "GoOn Test";
                        this.isTest = false;//按下暂停键
                        gobackButton.Text = getMsg("FrmMDIAuth_2031");//按钮文字改为继续测试
                        //((FrmTestFunction)newForm).PauseTest();
                        return;
                    }
                    else
                    {
                        //////tn.Text = getMsg("FrmMDIAuth_" + Const.TREE_PAUSETEST);////暂停测试 国际化
                        //(Fuction.m_Language == Const.LANGUAGE_CHINESE) ? "暂停测试" : "Pause Test";
                        this.isTest = true;//按下继续测试
                        gobackButton.Text = getMsg("FrmMDIAuth_2030");//按钮文字改为暂停测试
                        //((FrmTestFunction)newForm).GoOnTest();
                        return;
                    }
                //}
            }
        }

        private void MetroStaticTesting_FormClosed(object sender, EventArgs e)
        {
            //this.Close();
            //MetroMDI mm = new MetroMDI(_loginManager);
            //mm.Show();
        }

        private void panel1_MouseHover(object sender, EventArgs e)
        {
            //showInfo();
        }
        private void showInfo()
        {
            //this.label5.Location = new Point(this.label5.Location.X + 40, this.label5.Location.Y);
            //this.label6.Location = new Point(this.label6.Location.X + 196, this.label6.Location.Y);
            //this.label7.Location = new Point(this.label7.Location.X + 196, this.label7.Location.Y);
            //this.label8.Location = new Point(this.label8.Location.X + 196, this.label8.Location.Y);
            this.lbl_time.Visible = true;
            this.lbl_temp.Visible = true;
            this.lbl_solvent.Visible = true;
            this.lbl_pattern.Visible = true;
        }
        private void hideInfo()
        {
            this.label5.Location = new Point(this.lbl_time.Location.X - 40, this.label5.Location.Y);
            this.label6.Location = new Point(this.lbl_solvent.Location.X - 65, this.label6.Location.Y);
            this.label7.Location = new Point(this.lbl_pattern.Location.X - 65, this.label7.Location.Y);
            this.label8.Location = new Point(this.lbl_temp.Location.X - 65, this.label8.Location.Y);
            this.lbl_time.Visible = false;
            this.lbl_temp.Visible = false;
            this.lbl_solvent.Visible = false;
            this.lbl_pattern.Visible = false;
        }

        private void panel1_MouseLeave(object sender, EventArgs e)
        {
            //hideInfo();
        }

        public void showInfo(int para, string data)
        {
            int count = this.panel1.Controls.Count;
            for (int i = 0; i < count; i++)
            {
                if (this.panel1.Controls[i] is Label && Convert.ToInt32(this.panel1.Controls[i].Tag) == para)
                {
                    this.panel1.Controls[i].Text = data;
                    return;
                }
            }
        }
        public void showControls()
        {
            this.stopTestingButton.Visible = true;
            //this.pauseTestingButton.Visible = true;
            //this.panel1.Visible = true;
        }

        private void MetroStaticTesting_Load(object sender, EventArgs e)
        {
            this.label1.SendToBack();
            this.label1.Left = (this.staticTestingShow.Width - this.label1.Width) / 2;
            this.label1.Top = (this.staticTestingShow.Height - this.label1.Height) / 2;
        }


        private bool isShow = true;
        private void panel1_Click(object sender, EventArgs e)
        {
            if (isShow)
            {
                showInfo();
                isShow = false;
            }
            else
            {
                hideInfo();
                isShow = true;
            }
        }
        //private System.Timers.Timer checkReturnValueTimer;
        /**
         * 下一步
         */
        private void button1_Click(object sender, EventArgs e)
        {
            //frm.checkMachineState();
            //checkReturnValueTimer = new System.Timers.Timer();
            //checkReturnValueTimer.Elapsed += new System.Timers.ElapsedEventHandler(CheckNext);//两秒后检测是否有数据读入
            //checkReturnValueTimer.Interval = 2500;
            //checkReturnValueTimer.Start();
            if (this.btnNext.Enabled)
            {
                this.stopTestingButton.Location = this.btnNext.Location;
                this.staticTestingShow.Height = this.mdiPanel.Height;
                this.gobackButton.Visible = false;
                this.btnNext.Visible = false;
                frm.Next();
            }
        }
        //public void CheckNext(object source, System.Timers.ElapsedEventArgs e)
        //{
        //    checkReturnValueTimer.Stop();
            
        //}
        public void showNextButton()
        {
            this.btnNext.Enabled = true;
        }
        public void hideNextButton()
        {
            this.btnNext.Enabled = false;
        }
    }
}