using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;//.Tasks;
using System.Windows.Forms;
using GcDevicePc.DevParam;
using GcDevicePc.IniParam;

namespace GcDevicePc.ConfigDlg
{
    public partial class ChromeDlg : Form
    {
       // private int indexOld = 0;

        public ChromeDlg()
        {
            InitializeComponent();
        }

        public void reflashContent()
        {
            globaldata.m_profileMethod.GetDevState();
            globaldata.m_profileMethod.GetChromAllPara();


            int FrontNo = 0;
            int BehindNo = 1;


            if(CProfileDevice.m_DevParam.syspara.u16ChromNum >= 1)
            {

                ChromeSelect.Items.Clear();
                ChromeType.Items.Clear();
                ChromeType.Items.Insert(0, "毛细孔柱");
                ChromeType.Items.Insert(1, "填充柱");

                if (CProfileDevice.m_DevParam.syspara.u16ChromFront == 1)
                {
                    ChromeSelect.Items.Insert(FrontNo, "前色谱柱");
                    //if (CProfileDevice.m_DevParam.syspara.u16ChromFrontType == 0)
                    //{
                    //    ChromeType.Items.Insert(FrontNo, "毛细孔柱");
                    //}
                    //else if (CProfileDevice.m_DevParam.syspara.u16ChromFrontType == 1)
                    //{
                    //    ChromeType.Items.Insert(FrontNo, "填充柱");
                    //}else
                    //{
                    //    ChromeType.Items.Insert(FrontNo, "未知");
                    //}
                }
                else
                {
                    BehindNo = 0;
                }

                if (CProfileDevice.m_DevParam.syspara.u16ChromBehind == 1)
                {
                    ChromeSelect.Items.Insert(BehindNo, "后色谱柱");
                    //if (CProfileDevice.m_DevParam.syspara.u16ChromBehindType == 0)
                    //{
                    //    ChromeType.Items.Insert(BehindNo, "毛细孔柱");
                    //}
                    //else if (CProfileDevice.m_DevParam.syspara.u16ChromBehindType == 1)
                    //{
                    //    ChromeType.Items.Insert(BehindNo, "填充柱");
                    //}
                    //else
                    //{
                    //    ChromeType.Items.Insert(BehindNo, "未知");
                    //}
                    ChromeType.Enabled = false;
                }
                if(ChromeSelect.Items.Count >= 1)
                    ChromeSelect.SelectedIndex = 0;
            }
            else
            {
                ChromeSelect.Enabled = false;
                ChromeType.Enabled = false;

            }

            //if (CProfileDevice.m_DevParam.syspara.u16ChromFront == 1 )
            //{
            //    ChromeMaxTemp.Text = CProfileDevice.m_DevParam.chrom[cFront].fHigestTempSet.ToString();
            //    ChromeLen.Text = CProfileDevice.m_DevParam.chrom[cFront].fLengthSet.ToString();
            //    ChromeCal.Text = CProfileDevice.m_DevParam.chrom[cFront].fCalSet.ToString();
            //    ChromeMem.Text = CProfileDevice.m_DevParam.chrom[cFront].fFilmThicknessSet.ToString();
            //    tb柱前压.Text = CProfileDevice.m_DevParam.chrom[cFront].fPreSetValue.ToString();
            //    tb柱流量.Text = CProfileDevice.m_DevParam.chrom[cFront].fFlowSetValue.ToString();
            //    tb线速度.Text = CProfileDevice.m_DevParam.chrom[cFront].fActualAverageLineSpeed.ToString();
            //    description.Text = CProfileDevice.m_DevParam.chrom[cFront].sDescribe;
            //}

            //if (CProfileDevice.m_DevParam.syspara.u16ChromBehind == 1)
            //{
            //    ChromeMaxTemp.Text = CProfileDevice.m_DevParam.chrom[cBehind].fHigestTempSet.ToString();
            //    ChromeLen.Text = CProfileDevice.m_DevParam.chrom[cBehind].fLengthSet.ToString();
            //    ChromeCal.Text = CProfileDevice.m_DevParam.chrom[cBehind].fCalSet.ToString();
            //    ChromeMem.Text = CProfileDevice.m_DevParam.chrom[cBehind].fFilmThicknessSet.ToString();
            //    tb柱前压.Text = CProfileDevice.m_DevParam.chrom[cBehind].fPreSetValue.ToString();
            //    tb柱流量.Text = CProfileDevice.m_DevParam.chrom[cBehind].fFlowSetValue.ToString();
            //    tb线速度.Text = CProfileDevice.m_DevParam.chrom[cBehind].fActualAverageLineSpeed.ToString();
            //    description.Text = CProfileDevice.m_DevParam.chrom[cBehind].sDescribe;
            //}

            if (CProfileDevice.m_DevParam.syspara.u16StartType == 3)
            {
                this.epcgroup.Enabled = true;
            }else
            {
                this.epcgroup.Enabled = false;
            }


        }

        public void recordCurData()
        {
            int index;
            index = this.ChromeSelect.SelectedIndex;

            if (index < 0)
                return;

            if (CProfileDevice.m_DevParam.syspara.u16ChromNum == 2 && ChromeMaxTemp.Text != "")
            {
                if(index == 1)
                {
                    CProfileDevice.m_DevParam.chrom[index-1].fHigestTempSet = float.Parse(ChromeMaxTemp.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].fLengthSet = float.Parse(ChromeLen.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].fCalSet = float.Parse(ChromeCal.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].fFilmThicknessSet = float.Parse(ChromeMem.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].fPreSetValue = float.Parse(tb柱前压.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].fFlowSetValue = float.Parse(tb柱流量.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].fActualAverageLineSpeed = float.Parse(tb线速度.Text);
                    CProfileDevice.m_DevParam.chrom[index-1].sDescribe = description.Text;
                }
                if (index == 0)
                {
                    CProfileDevice.m_DevParam.chrom[index + 1].fHigestTempSet = float.Parse(ChromeMaxTemp.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].fLengthSet = float.Parse(ChromeLen.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].fCalSet = float.Parse(ChromeCal.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].fFilmThicknessSet = float.Parse(ChromeMem.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].fPreSetValue = float.Parse(tb柱前压.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].fFlowSetValue = float.Parse(tb柱流量.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].fActualAverageLineSpeed = float.Parse(tb线速度.Text);
                    CProfileDevice.m_DevParam.chrom[index + 1].sDescribe = description.Text;
                }
               
                
            }
            else if (CProfileDevice.m_DevParam.syspara.u16ChromNum == 1 && ChromeMaxTemp.Text != "")
            {
                if(CProfileDevice.m_DevParam.syspara.u16ChromFront == 1)
                {
                    CProfileDevice.m_DevParam.chrom[index].fHigestTempSet = float.Parse(ChromeMaxTemp.Text);
                    CProfileDevice.m_DevParam.chrom[index].fLengthSet = float.Parse(ChromeLen.Text);
                    CProfileDevice.m_DevParam.chrom[index].fCalSet = float.Parse(ChromeCal.Text);
                    CProfileDevice.m_DevParam.chrom[index].fFilmThicknessSet = float.Parse(ChromeMem.Text);
                    CProfileDevice.m_DevParam.chrom[index].fPreSetValue = float.Parse(tb柱前压.Text);
                    CProfileDevice.m_DevParam.chrom[index].fFlowSetValue = float.Parse(tb柱流量.Text);
                    CProfileDevice.m_DevParam.chrom[index].fActualAverageLineSpeed = float.Parse(tb线速度.Text);
                    CProfileDevice.m_DevParam.chrom[index].sDescribe = description.Text;
                }else
                {
                    CProfileDevice.m_DevParam.chrom[index+1].fHigestTempSet = float.Parse(ChromeMaxTemp.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].fLengthSet = float.Parse(ChromeLen.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].fCalSet = float.Parse(ChromeCal.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].fFilmThicknessSet = float.Parse(ChromeMem.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].fPreSetValue = float.Parse(tb柱前压.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].fFlowSetValue = float.Parse(tb柱流量.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].fActualAverageLineSpeed = float.Parse(tb线速度.Text);
                    CProfileDevice.m_DevParam.chrom[index+1].sDescribe = description.Text;
                }
            }else
            {

            }      
        }

        private void TextBoxDec_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.')
            {
                e.Handled = true;
            }
        }

        private void ChromeSel_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            recordCurData();
            const int cFront = 0;
            const int cBehind = 1;
            int index;
            index = this.ChromeSelect.SelectedIndex;
          
            if(CProfileDevice.m_DevParam.syspara.u16ChromNum >= 1)
            {
                if(CProfileDevice.m_DevParam.syspara.u16ChromFront == 1)
                {
                    if(index == 0)
                    {
                        ChromeType.SelectedIndex =Convert.ToInt32(CProfileDevice.m_DevParam.chrom[cFront].u16ChromType);
                        ChromeMaxTemp.Text = CProfileDevice.m_DevParam.chrom[cFront].fHigestTempSet.ToString();
                        ChromeLen.Text = CProfileDevice.m_DevParam.chrom[cFront].fLengthSet.ToString();
                        ChromeCal.Text = CProfileDevice.m_DevParam.chrom[cFront].fCalSet.ToString();
                        ChromeMem.Text = CProfileDevice.m_DevParam.chrom[cFront].fFilmThicknessSet.ToString();
                        tb柱前压.Text = CProfileDevice.m_DevParam.chrom[cFront].fPreSetValue.ToString();
                        tb柱流量.Text = CProfileDevice.m_DevParam.chrom[cFront].fFlowSetValue.ToString();
                        tb线速度.Text = CProfileDevice.m_DevParam.chrom[cFront].fActualAverageLineSpeed.ToString();
                        description.Text = CProfileDevice.m_DevParam.chrom[cFront].sDescribe;
                    }else
                    {
                        ChromeType.SelectedIndex = Convert.ToInt32(CProfileDevice.m_DevParam.chrom[cBehind].u16ChromType);
                        ChromeMaxTemp.Text = CProfileDevice.m_DevParam.chrom[cBehind].fHigestTempSet.ToString();
                        ChromeLen.Text = CProfileDevice.m_DevParam.chrom[cBehind].fLengthSet.ToString();
                        ChromeCal.Text = CProfileDevice.m_DevParam.chrom[cBehind].fCalSet.ToString();
                        ChromeMem.Text = CProfileDevice.m_DevParam.chrom[cBehind].fFilmThicknessSet.ToString();
                        tb柱前压.Text = CProfileDevice.m_DevParam.chrom[cBehind].fPreSetValue.ToString();
                        tb柱流量.Text = CProfileDevice.m_DevParam.chrom[cBehind].fFlowSetValue.ToString();
                        tb线速度.Text = CProfileDevice.m_DevParam.chrom[cBehind].fActualAverageLineSpeed.ToString();
                        description.Text = CProfileDevice.m_DevParam.chrom[cBehind].sDescribe;
                    }                       
                }else
                {
                     if(CProfileDevice.m_DevParam.syspara.u16ChromBehind == 1)
                     {
                         if(index == 0)
                         {
                             ChromeType.SelectedIndex = Convert.ToInt32(CProfileDevice.m_DevParam.chrom[cBehind].u16ChromType);
                            ChromeMaxTemp.Text = CProfileDevice.m_DevParam.chrom[cBehind].fHigestTempSet.ToString();
                            ChromeLen.Text = CProfileDevice.m_DevParam.chrom[cBehind].fLengthSet.ToString();
                            ChromeCal.Text = CProfileDevice.m_DevParam.chrom[cBehind].fCalSet.ToString();
                            ChromeMem.Text = CProfileDevice.m_DevParam.chrom[cBehind].fFilmThicknessSet.ToString();
                            tb柱前压.Text = CProfileDevice.m_DevParam.chrom[cBehind].fPreSetValue.ToString();
                            tb柱流量.Text = CProfileDevice.m_DevParam.chrom[cBehind].fFlowSetValue.ToString();
                            tb线速度.Text = CProfileDevice.m_DevParam.chrom[cBehind].fActualAverageLineSpeed.ToString();
                            description.Text = CProfileDevice.m_DevParam.chrom[cBehind].sDescribe;
                         }else
                         {
    
                         }        
                     }
                }            
            }                  
        }
    }
}
