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 && type <= 5)
            {
                this.sampling_type = SamplingDevice.Sample;
            }
            else if (type >= 6 && type <= 11)
            {
                this.sampling_type = SamplingDevice.Valve;
            }
            else if (type >= 12 && type <= 13)
            {
                this.sampling_type = SamplingDevice.InjPortValve;
            }
            else if (type >= 14 && type <= 15)
            {
                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.InjValveVA1.Checked = this.hWConfig.hwconfiginfo.u16InjValveVA1 == 1 ? true : false; //VA1阀
                this.InjValveTemp_VA1.Text = this.hWConfig.hwconfiginfo.u16InjValveTemp_VA1.ToString(); //VA1阀保护温度

                this.InjValveVA2.Checked = this.hWConfig.hwconfiginfo.u16InjValveVA2 == 1 ? true : false; //VA1阀
                this.InjValveTemp_VA2.Text = this.hWConfig.hwconfiginfo.u16InjValveTemp_VA2.ToString(); //VA1阀保护温度
                //进样阀
                if (this.hWConfig.hwconfiginfo.u16StartType==0)
                {
                    this.InjValveLoadGas_VA1.Enabled = false; //VA1阀载气类型
                    this.InjValveLoadGas1.Enabled = false; //VA1阀载气1
                    this.InjValveLoadGas2.Enabled = false; //VA1阀载气2
                    this.InjValveLoadGas3.Enabled = false; //VA1阀载气3


                    this.InjValveLoadGas_VA2.Enabled = false; //VA1阀载气类型
                    this.InjValveLoadGas4.Enabled = false; //VA1阀载气1
                    this.InjValveLoadGas5.Enabled = false; //VA1阀载气2
                    this.InjValveLoadGas6.Enabled = false;     //VA1阀载气3
                }
                else
                {
                    
                    this.InjValveLoadGas_VA1.SelectedIndex = this.hWConfig.hwconfiginfo.u16InjValveLoadGas_VA1; //VA1阀载气类型
                    this.InjValveLoadGas1.Checked =
                        this.hWConfig.hwconfiginfo.u16InjValveLoadGas1 == 1 ? true : false; //VA1阀载气1
                    this.InjValveLoadGas2.Checked =
                        this.hWConfig.hwconfiginfo.u16InjValveLoadGas2 == 1 ? true : false; //VA1阀载气2
                    this.InjValveLoadGas3.Checked =
                        this.hWConfig.hwconfiginfo.u16InjValveLoadGas3 == 1 ? true : false; //VA1阀载气3

                    
                    this.InjValveLoadGas_VA2.SelectedIndex = this.hWConfig.hwconfiginfo.u16InjValveLoadGas_VA2; //VA1阀载气类型
                    this.InjValveLoadGas4.Checked =
                        this.hWConfig.hwconfiginfo.u16InjValveLoadGas4 == 1 ? true : false; //VA1阀载气1
                    this.InjValveLoadGas5.Checked =
                        this.hWConfig.hwconfiginfo.u16InjValveLoadGas5 == 1 ? true : false; //VA1阀载气2
                    this.InjValveLoadGas6.Checked = this.hWConfig.hwconfiginfo.u16InjValveLoadGas6 == 1 ? true : false;     //VA1阀载气3
                }
            }
        }
        #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.u16InjValveVA1 = this.InjValveVA1.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16InjValveTemp_VA1 = int.Parse(this.InjValveTemp_VA1.Text); //VA1阀保护温度
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas_VA1 = this.InjValveLoadGas_VA1.SelectedIndex; //VA1阀载气类型
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas1 = this.InjValveLoadGas1.Checked ? 1 : 0; //VA1阀载气1
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas2 = this.InjValveLoadGas2.Checked ? 1 : 0; //VA1阀载气2
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas3 = this.InjValveLoadGas3.Checked ? 1 : 0; //VA1阀载气3
                this.hWConfig.hwconfiginfo.u16InjValveVA2 = this.InjValveVA2.Checked ? 1 : 0; //VA1阀
                this.hWConfig.hwconfiginfo.u16InjValveTemp_VA2 = int.Parse(this.InjValveTemp_VA2.Text); //VA1阀保护温度
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas_VA2 = this.InjValveLoadGas_VA2.SelectedIndex; //VA1阀载气类型
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas4 = this.InjValveLoadGas4.Checked ? 1 : 0; //VA1阀载气1
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas5 = this.InjValveLoadGas5.Checked ? 1 : 0; //VA1阀载气2
                this.hWConfig.hwconfiginfo.u16InjValveLoadGas6 = this.InjValveLoadGas6.Checked ? 1 : 0; //VA1阀载气3
            }

            this.Close();
        }

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

        #endregion


    }
}
