MetroTestResult.cs 9.9 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 Dal;
using Comm;
using log4net;
using System.Reflection;

namespace App
{
    public partial class MetroTestResult : FrmBase
    {
        FrmTestResult newForm;
        FrmTestManage newForm2;
        private LoginManager _loginManager;
        private string FileName;
        public bool isOpen = true;//判断该窗口是否打开状态

        public MetroTestResult(LoginManager loginManager,string fileName)
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
            this.SetLanguage(this);
            this._loginManager = loginManager;
            Init();
            this.FileName = fileName;
            OpenTest();
        }
        private void Init()
        {
            this.Text = getMsg("FrmTestResult");
            this.btnGoBack.Text = getMsg("back");
            this.checkBoxEC1.Text = fuction.GetParameterByParaName(Const.PARA_ECName1,"currency");
            this.checkBoxEC2.Text = fuction.GetParameterByParaName(Const.PARA_ECName2, "currency");
        }

        /**
         * 
         * 鼠标放在三个按钮上做出相应提示
         */
        private void openFileBtn_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.openFileBtn, getMsg("FrmMDIrb_Open.InfoTitle"));
        }

        private void printFileBtn_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.printFileBtn, getMsg("FrmMDIrb_Print"));
        }

        private void printViewBtn_MouseHover(object sender, EventArgs e)
        {
            //ToolTip tt = new ToolTip();
            //tt.SetToolTip(this.printViewBtn, getMsg("FrmMDIrb_PrintPreview"));
        }

        /**
         * 打开文件
         */
        private void openFileBtn_Click(object sender, EventArgs e)
        {
            OpenTest();
        }
        private void OpenTest()
        {
            string directory = Fuction.m_CurrentDirectory + Const.TestDataDataRoot;
            openFileDialog1.InitialDirectory = directory;
            if (this.FileName != "")//测试结束跳转
            {
                this.resultShowPanel.Controls.Clear();
                openFile(this.FileName);
                this.FileName = "";
            }
            else
            {
                
                if (openFileDialog1.ShowDialog() == DialogResult.OK)//自行打开测试结果
                {
                    this.resultShowPanel.Controls.Clear();
                    openFile(openFileDialog1.FileName);
                }
                else
                {
                    int count = this.resultShowPanel.Controls.Count;

                    if (count == 2 || count == 0)
                    {
                        this.Close();
                        this.isOpen = false;
                        MetroMDI mm = new MetroMDI(_loginManager);
                        mm.Show();
                    }
                }
            }

        }
        private void openFile(string fileName)
        {
            try
            {
                string XMLFile = fileName;
                newForm = new FrmTestResult(XMLFile);
                if (newForm is FrmTestResult)
                {
                    try
                    {
                        newForm.Movable = false;
                        newForm.ControlBox = false;
                        newForm.MdiParent = this;
                        newForm.ShowInTaskbar = true;
                        newForm.StartPosition = FormStartPosition.CenterScreen;
                        newForm.Parent = this.resultShowPanel;
                        newForm.Text = "";
                        newForm.FormBorderStyle = FormBorderStyle.None;
                        newForm.Dock = System.Windows.Forms.DockStyle.Fill;
                        this.resultShowPanel.Controls.Add(newForm);
                        newForm.Show();
                        newForm.Activate();//激活
                        //readEndData();
                        endData = newForm.ReadEndData;
                    }
                    catch (Exception ex)
                    {
                        newForm.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LOGGER.Debug(ex.StackTrace);
            }
        }
        /**
         * 打印预览
         */
        private void printViewBtn_Click(object sender, EventArgs e)
        {
            //if (newForm2.GetType().FullName == "App.FrmTestManage")
            //{
            //    string directory = Fuction.m_CurrentDirectory + Const.TestDataRoot + Const.TEMPWORD;
            //    int if_Export = ((FrmTestManage)newForm2).SaveAsWord(directory, Const.OPERATION_PRINTPREVIEW);
            //    return;
            //}else 
            if (newForm is FrmTestResult)
            {
                try
                {
                    string directory = Fuction.m_CurrentDirectory + Const.TestDataRoot + Const.TEMPWORD;
                    int if_Export = ((FrmTestResult)newForm).SaveAsWord(directory, Const.OPERATION_PRINTPREVIEW);
                    return;
                }
                catch (Exception ex)
                {
                    LOGGER.Info("打印预览" + ex.StackTrace);
                }
            }
        }

        /**
         * 打印
         */
        private void printFileBtn_Click(object sender, EventArgs e)
        {
            //if (newForm2.GetType().FullName == "App.FrmTestManage")
            //{
            //    string directory = Fuction.m_CurrentDirectory + Const.TestDataRoot + Const.TEMPWORD;
            //    int if_Export = ((FrmTestManage)newForm2).SaveAsWord(directory, Const.OPERATION_PRINT);
            //    return;
            //}
            LOGGER.Debug("Start Into Export Report" + DateTime.Now);
            if (newForm is FrmTestResult)
            {
                string directory = Fuction.m_CurrentDirectory + Const.TestDataRoot + Const.TEMPWORD;
                try
                {
                    int if_Export = ((FrmTestResult)newForm).SaveAsWord(directory, Const.OPERATION_PRINT);
                }
                catch (Exception ex)
                {
                    LOGGER.Info("导出PDF:"+ex.StackTrace);
                }
                return;
            }
        }

        private void MetroTestResult_FormClosed(object sender, EventArgs e)
        {
            //this.Close();
            //MetroMDI mm = new MetroMDI(_loginManager);
            //mm.Show();
        }
        bool isCheck1 = false;
        /**
         * 等效系数1
         */
        private void checkBoxEC_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxEC1.Checked)
            {
                DataColumnCollection columns = ((FrmTestResult)newForm).table2.Columns;
                columns.Add(fuction.GetParameterByParaName(Const.PARA_ECName1, "currency"), typeof(System.Double));
                ((FrmTestResult)newForm).table2.Rows[0][fuction.GetParameterByParaName(Const.PARA_ECName1, "currency")] = fuction.GetParameterByParaName(Const.PARA_EC1, "currency");
                ((FrmTestResult)newForm).GetDataGrideValue(((FrmTestResult)newForm).dgvTestResult, ((FrmTestResult)newForm).table2);
            }
            else
            {
                DataColumnCollection columns = ((FrmTestResult)newForm).table2.Columns;
                columns.Remove(fuction.GetParameterByParaName(Const.PARA_ECName1, "currency"));
            }
        }

        private double endData = 0;
        /**
         * 
         * removeEC
         */
        private void removeEC()
        {
            ((FrmTestResult)newForm).removeEC();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            double EC = 0;
            string ECKind = "";
            //if (this.comboBox1.Text.Equals(getMsg("EC1")))
            //{
            //    EC = double.Parse(fuction.GetParameterByParaName(Const.PARA_EC1));
            //    ECKind = getMsg("EC1");
            //}
            //else if (this.comboBox1.Text.Equals(getMsg("EC2")))
            //{

            //    EC = double.Parse(fuction.GetParameterByParaName(Const.PARA_EC2));
            //    ECKind = getMsg("EC2");
            //}
            EC *= endData;
            ((FrmTestResult)newForm).AddEC(EC, ECKind);
            
        }
        /**
         * 等效系数2
         */
        private void checkBoxEC2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxEC2.Checked)
            {
                DataColumnCollection columns = ((FrmTestResult)newForm).table2.Columns;
                columns.Add(fuction.GetParameterByParaName(Const.PARA_ECName2, "currency"), typeof(System.Double));
                ((FrmTestResult)newForm).table2.Rows[0][fuction.GetParameterByParaName(Const.PARA_ECName2, "currency")] = fuction.GetParameterByParaName(Const.PARA_EC2, "currency");
                ((FrmTestResult)newForm).GetDataGrideValue(((FrmTestResult)newForm).dgvTestResult, ((FrmTestResult)newForm).table2);
            }
            else
            {
                DataColumnCollection columns = ((FrmTestResult)newForm).table2.Columns;
                columns.Remove(fuction.GetParameterByParaName(Const.PARA_ECName2, "currency"));
            }
        }
        /**
         * 返回上一步菜单
         */
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            MetroMDI mm = new MetroMDI(_loginManager);
            mm.ShowInTaskbar = true;
            mm.Show();
        }

        private void MetroTestResult_Load(object sender, EventArgs e)
        {
            this.testResultPanel.Height = this.Height - 59;
        }


    }
}