MetroDynamicTesting.cs 10.4 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 MetroFramework.Forms;
using Dal;

namespace App
{
    using FrmTestManageSwitch = FrmTestManage2;
    public partial class MetroDynamicTesting : FrmBase
    {
        private bool isTest = true;//判断上一个状态是否为暂停测试
        FrmTestManageSwitch newForm;
        private LoginManager _loginManager;

        public MetroDynamicTesting(LoginManager loginManager)
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
            this.SetLanguage(this);
            this._loginManager = loginManager;
            Init();
            this.label1.Text = getMsg("FrmTestNoData");
            
        }
        private void Init()
        {
            if (Fuction.m_Language == Const.LANGUAGE_ENGLISH)
            {
                this.Text = getMsg("FrmMDItsmi_Dynamic") +" " + getMsg("FrmMDItabTest");
            }
            else
            {
                this.Text = getMsg("FrmMDItsmi_Dynamic") + 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 AddToDynamicPanel(FrmTestManageSwitch form)
        {
            try
            {

                this.DynamicTestingShow.Location = new Point(12, -50);
                this.DynamicTestingShow.Size = new System.Drawing.Size(this.mdiPanel.Width - 24, this.mdiPanel.Height-20);
                this.DynamicTestingShow.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.DynamicTestingShow;//指定子窗体的父容器为
                newForm.FormBorderStyle = FormBorderStyle.None;// 无边框
                newForm.Dock = System.Windows.Forms.DockStyle.Fill;
                this.DynamicTestingShow.Controls.Add(newForm);// 添加到 Panel中
                newForm.Show();     // 显示
                this.label1.SendToBack();
                newForm.Activate();//激活
            }
            catch (Exception ex)
            {
                LOGGER.Error("AddToDynamicPanel", ex);
            }

        }
        /**
         * 开始测试
         */
        private void startTestingButton_Click(object sender, EventArgs e)
        {
            this.DynamicTestingShow.Location = new Point(113, 10);
            this.DynamicTestingShow.Size = new System.Drawing.Size(this.mdiPanel.Width - 120, this.mdiPanel.Height - 20);
            this.DynamicTestingShow.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.IsMdiContainer = true;
            this.label1.Visible = false;
            chooseProduct();
        }
        private MetroProduct mp;
        public void chooseProduct()
        {
            try
            {
                gobackButton.Visible = true;
                btnNext.Visible = true;
                stopTestingButton.Visible = false;
                gobackButton.Enabled = true;
                btnNext.Enabled = false;
                MetroProduct.returnValue = -100;
                mp = new MetroProduct(Const.OPERATION_CHOOSE, "testModeItemDYNAMIC", _loginManager);
                //newForm.Owner = this;
                mp.Movable = false;
                mp.ControlBox = false;
                //newForm.ShowInTaskbar = false;
                mp.MdiParent = this;//指定当前窗体为顶级Mdi窗体
                mp.Parent = this.DynamicTestingShow;//指定子窗体的父容器为
                mp.FormBorderStyle = FormBorderStyle.None; // 无边框
                mp.Dock = System.Windows.Forms.DockStyle.Fill;
                this.DynamicTestingShow.Controls.Add(mp);  // 添加到 Panel中
                mp.checkMachineState();
                mp.Show();     // 显示
                mp.Activate();//激活

            }
            catch (Exception ex)
            {
                LOGGER.Error("chooseProduct", ex);
            }
        }
        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 FrmTestManageSwitch)
            {
                ((FrmTestManageSwitch)newForm).CutOffTest();
                return;
            }
        }

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

        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");//按钮文字改为继续测试
                        //((FrmTestManage)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");//按钮文字改为暂停测试
                        //((FrmTestManage)newForm).GoOnTest();
                        return;
                    }
                //}
            }
        }
        


        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.label5.Location.X - 40, this.label5.Location.Y);
            this.label6.Location = new Point(this.label6.Location.X - 65, this.label6.Location.Y);
            this.label7.Location = new Point(this.label7.Location.X - 65, this.label7.Location.Y);
            this.label8.Location = new Point(this.label8.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 MetroDynamicTesting_Load(object sender, EventArgs e)
        {
            chooseProduct();
            this.label1.SendToBack();
            this.label1.Left = (this.DynamicTestingShow.Width - this.label1.Width) / 2;
            this.label1.Top = (this.DynamicTestingShow.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 void btnNext_Click(object sender, EventArgs e)
        {
            //mp.checkMachineState();
            if (this.btnNext.Enabled)
            {
                this.stopTestingButton.Location = this.btnNext.Location;
                this.DynamicTestingShow.Height = this.mdiPanel.Height;
                this.gobackButton.Visible = false;
                this.btnNext.Visible = false;
                mp.Next();
            }
        }
        public void showNextButton()
        {
            this.btnNext.Enabled = true;

        }
        public void hideNextButton()
        {
            this.btnNext.Enabled = false;
        }
    }
}