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 GcDevicePc;
using GcDevicePc.DevParam;
using GcDevicePc.IniParam;

namespace GcDevicePc
{

    public partial class InjSample : Form
    {
        const int cFront = 0;
        const int cBehind = 1;
        private int indexOld = 0;

        public InjSample()
        {
            InitializeComponent();
        }

        public void reflashContent()
        {
            if(CProfileDevice.m_DevParam.syspara.u16SampleNum < 1)
            {
                this.groupBox1.Enabled = false;
                this.InjSampleBox.Enabled = false;
            }else
            {
                this.groupBox1.Enabled = true;
                this.InjSampleBox.Enabled = true;
            }

            int index;
            globaldata.m_profileMethod.GetDevState();
            globaldata.m_profileMethod.GetSampleAllPara("前进样器"); //可以没有参数

            InjSampleBox.Items.Clear();
            InjSampleBox.Items.Add("前进样器");
            InjSampleBox.Items.Add("后进样器");
            
            //for (int i = 0; i < this.InjSampleBox.Items.Count; i++)
            //{
            //    this.InjSampleBox.Items.Remove(this.InjSampleBox.Items[i]);
            //}
                   
            if (CProfileDevice.m_DevParam.syspara.u16SampleFront == 1)
            {
                indexOld = 0;
            }
            else if (CProfileDevice.m_DevParam.syspara.u16SampleBehind == 1)
            {
                indexOld = 1;
            }
            else 
            {
                indexOld = -1;
            }

            index = indexOld;

            if(index >= 0)
            {
                 tb进样后溶剂A.Text = CProfileDevice.m_DevParam.sample[index].sASSolventA;
                tb进样后溶剂B.Text = CProfileDevice.m_DevParam.sample[index].sASSolventB;
                tb进样前溶剂A.Text = CProfileDevice.m_DevParam.sample[index].sBSSolventA;
                tb进样前溶剂B.Text = CProfileDevice.m_DevParam.sample[index].sBSSolventB;
                tb进样前样品.Text = CProfileDevice.m_DevParam.sample[index].sFrontSample;
                tb进样器尺寸.Text = CProfileDevice.m_DevParam.sample[index].fInjectorSize.ToString();
                tb进样量.Text = CProfileDevice.m_DevParam.sample[index].fSampleQuantity.ToString();
                tb进样前针芯次数.Text = CProfileDevice.m_DevParam.sample[index].u16PushPullTimes.ToString();
            }
           

            this.InjSampleBox.SelectedIndex = indexOld;
        }

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

        private void cb进样器_SelectedIndexChanged(object sender, EventArgs e)
        {
            recordCurData();

            int index;
            indexOld = this.InjSampleBox.SelectedIndex;
            index = indexOld;

            if (index < 0)
                return;

            tb进样后溶剂A.Text = CProfileDevice.m_DevParam.sample[index].sASSolventA;
            tb进样后溶剂B.Text = CProfileDevice.m_DevParam.sample[index].sASSolventB;
            tb进样前溶剂A.Text = CProfileDevice.m_DevParam.sample[index].sBSSolventA;
            tb进样前溶剂B.Text = CProfileDevice.m_DevParam.sample[index].sBSSolventB;
            tb进样前样品.Text = CProfileDevice.m_DevParam.sample[index].sFrontSample;
            tb进样器尺寸.Text = CProfileDevice.m_DevParam.sample[index].fInjectorSize.ToString();
            tb进样量.Text = CProfileDevice.m_DevParam.sample[index].fSampleQuantity.ToString();
            tb进样前针芯次数.Text = CProfileDevice.m_DevParam.sample[index].u16PushPullTimes.ToString();
        }

        public void recordCurData()
        {
            int index;
            index = indexOld;

            if (index < 0)
                return;

            if (CProfileDevice.m_DevParam.syspara.u16SampleFront == 1 && index == 0)
            {
                //this.cb进样口.SelectedIndex = 0;
            }
            else if (CProfileDevice.m_DevParam.syspara.u16SampleBehind == 1 && index == 1)
            {
                //this.cb进样口.SelectedIndex = 1;
            }
            else
            {
                //this.cb进样口.SelectedIndex = -1;
                return;
            }

            CProfileDevice.m_DevParam.sample[index].sASSolventA = tb进样后溶剂A.Text;
            CProfileDevice.m_DevParam.sample[index].sASSolventB = tb进样后溶剂B.Text;
            CProfileDevice.m_DevParam.sample[index].sBSSolventA = tb进样前溶剂A.Text;
            CProfileDevice.m_DevParam.sample[index].sBSSolventB = tb进样前溶剂B.Text;
            CProfileDevice.m_DevParam.sample[index].sFrontSample = tb进样前样品.Text;
            CProfileDevice.m_DevParam.sample[index].fInjectorSize = float.Parse(tb进样器尺寸.Text);
            CProfileDevice.m_DevParam.sample[index].fSampleQuantity = float.Parse(tb进样量.Text);
            CProfileDevice.m_DevParam.sample[index].u16PushPullTimes = System.UInt16.Parse(tb进样前针芯次数.Text);
        }
    }
}
