FrmPara.cs 9.1 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;

namespace App
{
    public partial class FrmPara : App.FrmBase
    {
        readonly bool isInit;
        readonly Fuction fuction = new Fuction();
        private string para_Height;
        private string operation;//判断是静态测试还是动态测试
        private string testingKind;
        private Control parentControl;
        private LoginManager _loginManager;
        public FrmPara(string o, Control parentControl, LoginManager loginManager)
        {
            isInit = true;
            InitializeComponent();
            this._loginManager = loginManager;
            this.SetLanguage(this);
            this.operation = o;
            this.parentControl = parentControl;
            isInit = false;
            Init();
            this.lbl_TestSolvent.Text = getMsg("FrmParalbl_TestSolvent");
            this.btn_OK1.Text = getMsg("FrmParabtn_OK1");
            this.btn_Cancel1.Text = getMsg("FrmParabtn_Cancel1");
        }
        private void Init()
        {
            cmb_TestSolvent.Items.Clear();
            cmb_TestSolvent.Items.Add(Const.TESTSOLVENT_50IPA);
            cmb_TestSolvent.Items.Add(Const.TESTSOLVENT_75IPA);
            cmb_TestSolvent.SelectedIndex = 1;
            
            /**
             * 该段代码是添加测试方式:静态测试和动态测试
             */
            ////cmb_TestMode.Items.Clear();
            
            if("testModeItemDYNAMIC".Equals(this.operation))
            {
                switch (Fuction.m_Language)
                {
                    case Const.LANGUAGE_ENGLISH:
                        testingKind = Const.TESTMETHOD_DYNAMIC_EN;
                        break;
                    case Const.LANGUAGE_JAPANESE:
                        testingKind = Const.TESTMETHOD_DYNAMIC_JP;
                        break;
                    case Const.LANGUAGE_CHINESE:
                        testingKind = Const.TESTMETHOD_DYNAMIC_CH;
                        break;
                    default:
                        break;
                }
            }
            else if("testModeItemSTATIC".Equals(this.operation))
            {
                switch (Fuction.m_Language)
                {
                    case Const.LANGUAGE_ENGLISH:
                        testingKind = Const.TESTMETHOD_STATIC_EN;
                        break;
                    case Const.LANGUAGE_JAPANESE:
                        testingKind = Const.TESTMETHOD_STATIC_JP;
                        break;
                    case Const.LANGUAGE_CHINESE:
                        testingKind = Const.TESTMETHOD_STATIC_CH;
                        break;
                    default:
                        break;
                }
            }
            
            ////cmb_TestMode.Items.Add(testModeItemDYNAMIC);
            ////cmb_TestMode.Items.Add(testModeItemSTATIC);
            ////cmb_TestMode.SelectedIndex = 1;

            lbl_TempUnit.Text = Fuction.m_UserTempUnit;
            //lbl_LengthUnit.Text = Fuction.m_UserLengthUnit;
            para_Height = fuction.GetParameterByParaName(Const.PARA_Height, "currency");
            SetHeightVisible(para_Height == "");
        }
        private void SetHeightVisible(bool visible)
        {
            //txt_Height.Visible = visible;
            //lbl_Height.Visible = visible;
            //lbl_LengthUnit.Visible = visible;
        }

        private void btn_OK1_Click(object sender, EventArgs e)
        {
            #region checkValid
            if (ckb_IfHeat.Checked)
            {
                if (!CheckNull(this.lbl_HeatTemp.Text, txt_HeatTemp))
                    return;
                try
                {
                    if (Fuction.m_UserTempUnit==Const.TEMPUNIT_C &&
                        (Convert.ToDecimal(txt_HeatTemp.Text.Trim())<30 ||
                        Convert.ToDecimal(txt_HeatTemp.Text.Trim()) > 45) ||
                        Fuction.m_UserTempUnit == Const.TEMPUNIT_F &&
                        (Convert.ToDecimal(txt_HeatTemp.Text.Trim()) < 86 ||
                        Convert.ToDecimal(txt_HeatTemp.Text.Trim()) > 113))
                    {
                        ShowMessageBox.ShowError(
    Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_HEAT_TEMPERATURE);
                        txt_HeatTemp.Focus();
                        return;
                    }
                }
                catch(Exception ex)
                {
                    LOGGER.Info(ex.StackTrace);
                    ShowMessageBox.ShowError(
                        Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_HEAT_TEMPERATURE);
                    txt_HeatTemp.Focus();
                    return;
                }
            }
            if (!CheckNull(lbl_TestSolvent.Text, cmb_TestSolvent))
                return;

            if (para_Height=="")
            {
                //if (!CheckNull(lbl_Height.Text, txt_Height) ||
                //!CheckNumber(lbl_Height.Text, txt_Height))
                //    return;
                //para_Height = fuction.ChangeLUnit(txt_Height.Text);
            }
            #endregion

            
            string ifHeat = ckb_IfHeat.Checked ? Const.ISHEAT_HEAT : Const.ISHEAT_NOTHEAT;
            string HeatTemp = ckb_IfHeat.Checked ? 
                (Fuction.m_UserTempUnit==Const.TEMPUNIT_C? txt_HeatTemp.Text.Trim() :fuction.ChangeTempUnit(txt_HeatTemp.Text.Trim())):
                "";
             

            if (fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_HEATTEMP, HeatTemp) && 
                fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_ISHEAT, ifHeat) &&
                fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_Height, para_Height) &&
                fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_TESTSOLVENT, cmb_TestSolvent.Text) &&
                fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_TESTMODE, testingKind)
                )
            {
                //////((FrmMDI)this.ParentForm).GetRightInfo(Const.TREE_TESTTEMP, HeatTemp + Fuction.m_UserTempUnit);
                //////((FrmMDI)this.ParentForm).GetRightInfo(Const.TREE_TESTSOLVENT, cmb_TestSolvent.Text);
                //////((FrmMDI)this.ParentForm).GetRightInfo(Const.TREE_TESTMODE, cmb_TestMode.Text);
                
                //2009年后加功能:选择加热后,提示用户打开加热器加热,如果不选择之后的流程和之前没有变化
                if (ckb_IfHeat.Checked)
                {
                    ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.OPEN_HEATER);
                }
                try
                {
                    //FrmTestManage frmTestManage = new FrmTestManage(HeatTemp, ifHeat, cmb_TestSolvent.Text, testingKind, _loginManager);
                    //if (this.parentControl.TopLevelControl is MetroDynamicTesting)
                    //{
                    //    MetroDynamicTesting parentForm = (MetroDynamicTesting)this.parentControl.TopLevelControl;
                    //    parentForm.AddToDynamicPanel(frmTestManage);
                    //}
                    //else if (this.parentControl.TopLevelControl is MetroStaticTesting)
                    //{
                    //    MetroStaticTesting parentForm = (MetroStaticTesting)this.parentControl.TopLevelControl;
                    //    parentForm.AddToStaticPanel(frmTestManage);
                    //}
                }
                catch (Exception ex)
                {
                    Console.WriteLine("FrmParaClickOk:" + ex.StackTrace);
                }
                
                //try
                //{
                //    frmTestManage.Show();
                //    frmTestManage.StartPosition = FormStartPosition.CenterParent;
                //    frmTestManage.Activate();//激活
                //}
                //catch (Exception ex)
                //{
                //    Console.WriteLine(ex.StackTrace);
                //}
            }
            else
            {
                ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);
            }
            this.Close();
        }

        private void btn_Cancel1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ckb_IfHeat_CheckedChanged(object sender, EventArgs e)
        {
            if (ckb_IfHeat.Checked)
            {
                lbl_HeatTemp.Visible = true;
                txt_HeatTemp.Visible = true;
                lbl_TempUnit.Visible = true;
            }
            else
            {
                lbl_HeatTemp.Visible = false;
                txt_HeatTemp.Visible = false;
                lbl_TempUnit.Visible = false;
            }
        }

        private void FrmPara_Shown(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterParent;

            //ResizeForm();
        }
        
        private void FrmPara_LocationChanged(object sender, EventArgs e)
        {
            if (isInit)
            {
                this.Location = new Point(0, 0);
            }
        }


    }
}