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.DeviceConfigUI
{
    public partial class Sampling : Form
    {
        enum SamplingDevice
        {
            Sample,
            Valve,
            InjPortValve,
        };

        #region 私有变量
        private HWConfig hWConfig;
        private SamplingDevice sampling_type;
        #endregion

        #region 构造函数
        public Sampling()
        {
            InitializeComponent();
        }

        public Sampling(ref HWConfig hwconfig, int type)
        {
            InitializeComponent();
            this.hWConfig = hwconfig;
            if (type == 4)
            {
                this.sampling_type = SamplingDevice.Sample;
            }
            else if (type == 5)
            {
                this.sampling_type = SamplingDevice.Valve;
            }
            else if (type == 6)
            {
                this.sampling_type = SamplingDevice.InjPortValve;
            }
            else
            {
                this.sampling_type = SamplingDevice.Sample;
            }
        }
        #endregion

        #region 窗口事件
        private void Sampling_Load(object sender, EventArgs e)
        {
            this.Maintab.SelectedIndex = (int) this.sampling_type;

            if (hWConfig != null)
            {
                //进样器
                this.SampleFront.Checked = this.hWConfig.hwconfiginfo.u16SampleFront == 1 ? true : false;
                this.SampleFrontType.SelectedIndex = this.hWConfig.hwconfiginfo.u16SampleFrontType;
                this.SampleBehind.Checked = this.hWConfig.hwconfiginfo.u16SampleBehind == 1 ? true : false;
                this.SampleBehindType.SelectedIndex = this.hWConfig.hwconfiginfo.u16SampleBehindType;

                //阀
                this.ValveBox.SelectedIndex = this.hWConfig.hwconfiginfo.u16ValveBox;
                this.ValveOne.Checked = this.hWConfig.hwconfiginfo.u16ValveOne == 1 ? true : false;
                this.ValveTwo.Checked = this.hWConfig.hwconfiginfo.u16ValveTwo == 1 ? true : false;
                this.ValveThree.Checked = this.hWConfig.hwconfiginfo.u16ValveThree == 1 ? true : false;
                this.ValveFour.Checked = this.hWConfig.hwconfiginfo.u16ValveFour == 1 ? true : false;
                this.ValveFive.Checked = this.hWConfig.hwconfiginfo.u16ValveFive == 1 ? true : false;
                this.ValveSix.Checked = this.hWConfig.hwconfiginfo.u16ValveSix == 1 ? true : false;

                //进样口
                this.InjPortFront.Checked = this.hWConfig.hwconfiginfo.u16InjPortFront == 1 ? true : false;
                this.InjPortFPTemp.Text = this.hWConfig.hwconfiginfo.u16InjPortFPTemp.ToString();
                this.InjPortType_Front.SelectedIndex = this.hWConfig.hwconfiginfo.u16InjPortType_Front;
                this.InjPortLoadGas_Front.SelectedIndex = this.hWConfig.hwconfiginfo.u16InjPortLoadGas_Front;

                this.InjPortBehind.Checked = this.hWConfig.hwconfiginfo.u16InjPortBehind == 1 ? true : false;
                this.InjPortBPTemp.Text = this.hWConfig.hwconfiginfo.u16InjPortBPTemp.ToString();
                this.InjPortType_Behind.SelectedIndex = this.hWConfig.hwconfiginfo.u16InjPortType_Behind;
                this.InjPortLoadGas_Behind.SelectedIndex = this.hWConfig.hwconfiginfo.u16InjPortLoadGas_Behind;

                //色谱柱
                this.ChromFront.Checked = this.hWConfig.hwconfiginfo.u16ChromFront == 1 ? true : false;
                this.ChromFrontType.SelectedIndex = this.hWConfig.hwconfiginfo.u16ChromFrontType;
                this.ChromFront_Length.Text = this.hWConfig.hwconfiginfo.u16ChromFront_Length.ToString();
                this.ChromFront_Caliber.Text = this.hWConfig.hwconfiginfo.u16ChromFront_Caliber.ToString();
                this.ChromFront_Thickness.Text = this.hWConfig.hwconfiginfo.u16ChromFront_Thickness.ToString();

                this.ChromBehind.Checked = this.hWConfig.hwconfiginfo.u16ChromBehind == 1 ? true : false;
                this.ChromBehindType.SelectedIndex = this.hWConfig.hwconfiginfo.u16ChromBehindType;
                this.ChromBehind_Length.Text = this.hWConfig.hwconfiginfo.u16ChromBehind_Length.ToString();
                this.ChromBehind_Caliber.Text = this.hWConfig.hwconfiginfo.u16ChromBehind_Caliber.ToString();
                this.ChromBehind_Thickness.Text = this.hWConfig.hwconfiginfo.u16ChromBehind_Thickness.ToString();
            }
        }
        #endregion

        #region 控件事件
        private void okbtn_Click(object sender, EventArgs e)
        {
            if (hWConfig != null)
            {
                //进样器
                this.hWConfig.hwconfiginfo.u16SampleFront = this.SampleFront.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16SampleFrontType = this.SampleFrontType.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16SampleBehind  = this.SampleBehind.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16SampleBehindType = this.SampleBehindType.SelectedIndex;

                //阀
                this.hWConfig.hwconfiginfo.u16ValveBox = (this.ValveOne.Checked ? 1 : 0) + (this.ValveTwo.Checked ? 1 : 0) + (this.ValveThree.Checked ? 1 : 0) + (this.ValveFour.Checked ? 1 : 0) + (this.ValveFive.Checked ? 1 : 0) + (this.ValveSix.Checked ? 1 : 0);
                this.hWConfig.hwconfiginfo.u16ValveOne = this.ValveOne.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ValveTwo = this.ValveTwo.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ValveThree = this.ValveThree.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ValveFour = this.ValveFour.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ValveFive = this.ValveFive.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ValveSix = this.ValveSix.Checked ? 1 : 0;

                //进样口
                int num = 0;
                if (InjPortFront.Checked)
                {
                    num++;
                }
                if (InjPortBehind.Checked)
                {
                    num++;
                }
                this.hWConfig.hwconfiginfo.u16InjPortNum = num;
                this.hWConfig.hwconfiginfo.u16InjPortFront = this.InjPortFront.Checked? 1: 0;
                this.hWConfig.hwconfiginfo.u16InjPortFPTemp = int.Parse(this.InjPortFPTemp.Text);
                this.hWConfig.hwconfiginfo.u16InjPortType_Front = this.InjPortType_Front.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16InjPortLoadGas_Front = this.InjPortLoadGas_Front.SelectedIndex;

                this.hWConfig.hwconfiginfo.u16InjPortBehind = this.InjPortBehind.Checked? 1 : 0;
                this.hWConfig.hwconfiginfo.u16InjPortBPTemp = int.Parse(this.InjPortBPTemp.Text);
                this.hWConfig.hwconfiginfo.u16InjPortType_Behind = this.InjPortType_Behind.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16InjPortLoadGas_Behind = this.InjPortLoadGas_Behind.SelectedIndex;

                //色谱柱
                this.hWConfig.hwconfiginfo.u16ChromNum = (this.ChromFront.Checked ? 1 : 0) + (this.ChromBehind.Checked ? 1 : 0);

                this.hWConfig.hwconfiginfo.u16ChromFront = this.ChromFront.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ChromFrontType = this.ChromFrontType.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16ChromFront_Length = int.Parse(this.ChromFront_Length.Text);
                this.hWConfig.hwconfiginfo.u16ChromFront_Caliber = int.Parse(this.ChromFront_Caliber.Text);
                this.hWConfig.hwconfiginfo.u16ChromFront_Thickness = int.Parse(this.ChromFront_Thickness.Text);

                this.hWConfig.hwconfiginfo.u16ChromBehind = this.ChromBehind.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ChromBehindType = this.ChromBehindType.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16ChromBehind_Length = int.Parse(this.ChromBehind_Length.Text);
                this.hWConfig.hwconfiginfo.u16ChromBehind_Caliber = int.Parse(this.ChromBehind_Caliber.Text);
                this.hWConfig.hwconfiginfo.u16ChromBehind_Thickness = int.Parse(this.ChromBehind_Thickness.Text);

            }

            this.Close();
        }

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

        #endregion


    }
}
