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.GCBuffer;


namespace GcDevicePc.ConfigMethod
{

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

        HWConfig hwconfig;
        GCMethodConfig methodconfig;

        public SampleTab(HWConfig hwconfig, ref GCMethodConfig methodconfig)
        {
            InitializeComponent();

            this.hwconfig = hwconfig;
            this.methodconfig = methodconfig;
        }

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

            int index;

            this.methodconfig.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 (this.hwconfig.hwconfiginfo.u16SampleFront == 1)
            {
                indexOld = 0;
            }
            else if (this.hwconfig.hwconfiginfo.u16SampleBehind == 1)
            {
                indexOld = 1;
            }
            else
            {
                indexOld = -1;
            }

            index = indexOld;

            if (index >= 0)
            {
                tb进样后溶剂A.Text = this.methodconfig.sample[index].sASSolventA;
                tb进样后溶剂B.Text = this.methodconfig.sample[index].sASSolventB;
                tb进样前溶剂A.Text = this.methodconfig.sample[index].sBSSolventA;
                tb进样前溶剂B.Text = this.methodconfig.sample[index].sBSSolventB;
                tb进样前样品.Text = this.methodconfig.sample[index].sFrontSample;
                tb进样器尺寸.Text = this.methodconfig.sample[index].fInjectorSize.ToString();
                tb进样量.Text = this.methodconfig.sample[index].fSampleQuantity.ToString();
                tb进样前针芯次数.Text = this.methodconfig.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 = this.methodconfig.sample[index].sASSolventA;
            tb进样后溶剂B.Text = this.methodconfig.sample[index].sASSolventB;
            tb进样前溶剂A.Text = this.methodconfig.sample[index].sBSSolventA;
            tb进样前溶剂B.Text = this.methodconfig.sample[index].sBSSolventB;
            tb进样前样品.Text = this.methodconfig.sample[index].sFrontSample;
            tb进样器尺寸.Text = this.methodconfig.sample[index].fInjectorSize.ToString();
            tb进样量.Text = this.methodconfig.sample[index].fSampleQuantity.ToString();
            tb进样前针芯次数.Text = this.methodconfig.sample[index].u16PushPullTimes.ToString();
        }

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

            if (index < 0)
                return;

            if (this.hwconfig.hwconfiginfo.u16SampleFront == 1 && index == 0)
            {

            }
            else if (this.hwconfig.hwconfiginfo.u16SampleBehind == 1 && index == 1)
            {
 
            }
            else
            {
                return;
            }

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