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.injectionport
{
    public partial class IPVAL : Form
    {
        HWConfig hwconfig;
        GCMethodConfig methodconfig;

        //private int indexOld = 0;

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

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

        public void reflashContent(int index)
        {
            this.methodconfig.GetValInjPortAllPara();

            lblCG1Actual.Text = this.methodconfig.val[0].valCG1Actual.ToString();
            lblCG2Actual.Text = this.methodconfig.val[0].valCG2Actual.ToString();
            lblCG3Actual.Text = this.methodconfig.val[0].valCG3Actual.ToString();
            //lblCGColumn1.Text = ;
            //lblCGColumn2.Text = ;
            //lblCGColumn3.Text = ;
            //lblControlMode.Text = ;
            //lblSamplePortType.Text = ;
            txtCG1BlowFlow.Text = this.methodconfig.val[0].valCG1BlowFlow.ToString();
            txtCG1UpFlowEndTime.Text = this.methodconfig.val[0].valCG1UpFlowEndTime.ToString();
            txtCG1UpFlowStartTime.Text = this.methodconfig.val[0].valCG1UpFlowStartTime.ToString();
            txtCG2BlowFlow.Text = this.methodconfig.val[0].valCG2BlowFlow.ToString();
            txtCG2UpFlowEndTime.Text = this.methodconfig.val[0].valCG2UpFlowEndTime.ToString();
            txtCG2UpFlowStartTime.Text = this.methodconfig.val[0].valCG2UpFlowStartTime.ToString();
            txtCG3BlowFlow.Text = this.methodconfig.val[0].valCG3BlowFlow.ToString();
            txtCG3UpFlowEndTime.Text = this.methodconfig.val[0].valCG3UpFlowEndTime.ToString();
            txtCG3UpFlowStartTime.Text = this.methodconfig.val[0].valCG3UpFlowStartTime.ToString();
            txtCGColumn1Bore.Text = this.methodconfig.val[0].valCGColumn1Bore.ToString();
            txtCGColumn1ColumnFlow.Text = this.methodconfig.val[0].valCGColumn1ColumnFlow.ToString();
            txtCGColumn1Length.Text = this.methodconfig.val[0].valCGColumn1Length.ToString();
            txtCGColumn1Theca.Text = this.methodconfig.val[0].valCGColumn1Theca.ToString();
            txtCGColumn2Bore.Text = this.methodconfig.val[0].valCGColumn2Bore.ToString();
            txtCGColumn2ColumnFlow.Text = this.methodconfig.val[0].valCGColumn2ColumnFlow.ToString();
            txtCGColumn2Length.Text = this.methodconfig.val[0].valCGColumn2Length.ToString();
            txtCGColumn2Theca.Text = this.methodconfig.val[0].valCGColumn2Theca.ToString();
            txtCGColumn3Bore.Text = this.methodconfig.val[0].valCGColumn3Bore.ToString();
            txtCGColumn3ColumnFlow.Text = this.methodconfig.val[0].valCGColumn3ColumnFlow.ToString();
            txtCGColumn3Length.Text = this.methodconfig.val[0].valCGColumn3Length.ToString();
            txtCGColumn3Theca.Text = this.methodconfig.val[0].valCGColumn3Theca.ToString();
            txtProtecttemp.Text = this.methodconfig.val[0].valProtecttemp.ToString();

            if (this.methodconfig.val[0].valCG1 == 1)
                cbCG1.CheckState = CheckState.Checked;
            else
                cbCG1.CheckState = CheckState.Unchecked;

            if (this.methodconfig.val[0].valCG2 == 1)
                cbCG2.CheckState = CheckState.Checked;
            else
                cbCG2.CheckState = CheckState.Unchecked;

            if (this.methodconfig.val[0].valCG3 == 1)
                cbCG3.CheckState = CheckState.Checked;
            else
                cbCG3.CheckState = CheckState.Unchecked;


            combCarrierGasType.SelectedIndex = this.methodconfig.val[0].valCarrierGasType;
            combControlMode.SelectedIndex = this.methodconfig.val[0].valControlMode;

        }

        float string2float(string s)
        {
            float ret;

            if (s == "" || s == null)
            {
                ret = 0;
            }
            else
            {
                ret = float.Parse(s);
            }

            return ret;
        }

        //private void InjPortBox_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //    recordCurData();

        //    int index;
        //    indexOld = this.InjPortBox.SelectedIndex;
        //    index = indexOld;

        //    if (index < 0)
        //        return;

        //    tb加热.Text = this.methodconfig.port[index].fHeaterSetTemp.ToString();
        //    tb压力设定.Text = this.methodconfig.port[index].fSetPre.ToString();
        //    tb总流量设定.Text = this.methodconfig.port[index].fSetSumFlow.ToString();
        //    tb柱流量.Text = this.methodconfig.port[index].fSetColumnFlow.ToString();
        //    tb吹扫流量.Text = this.methodconfig.port[index].fSetPurgeFlow.ToString();
        //    if (this.methodconfig.port[index].bHeater == true)
        //        cBox加热器.CheckState = CheckState.Checked;
        //    else
        //        cBox加热器.CheckState = CheckState.Unchecked;
        //    ShuntPer.Text = this.methodconfig.port[index].u16SplitRatio.ToString();
        //    ShuntFlow.Text = this.methodconfig.port[index].fSplitFlow.ToString();
        //    CarrierGas1.Text = this.methodconfig.port[index].fCarrierGas1.ToString();
        //    CarrierGas2.Text = this.methodconfig.port[index].fCarrierGas2.ToString();
        //    CarrierGas3.Text = this.methodconfig.port[index].fCarrierGas3.ToString();

        //    if (this.methodconfig.port[index].bCarrierGasSave == true)
        //        cBox省EPC.CheckState = CheckState.Checked;
        //    else
        //        cBox省EPC.CheckState = CheckState.Unchecked;

        //    cargasthrift.Text = this.methodconfig.port[index].u16CarrierGasSave.ToString();
        //    tb等待时间.Text = this.methodconfig.port[index].fSaveGasTime.ToString();
        //}

        public void recordCurData(int index)
        {
            this.methodconfig.val[0].valCG1BlowFlow = string2float(txtCG1BlowFlow.Text);
            this.methodconfig.val[0].valCG1Set = string2float(txtCG1Set.Text);
            this.methodconfig.val[0].valCG1UpFlowEndTime = string2float(txtCG1UpFlowEndTime.Text);
            this.methodconfig.val[0].valCG1UpFlowStartTime = string2float(txtCG1UpFlowStartTime.Text);

            this.methodconfig.val[0].valCG2BlowFlow = string2float(txtCG2BlowFlow.Text);
            this.methodconfig.val[0].valCG2Set = string2float(txtCG2Set.Text);
            this.methodconfig.val[0].valCG2UpFlowEndTime = string2float(txtCG2UpFlowEndTime.Text);
            this.methodconfig.val[0].valCG2UpFlowStartTime = string2float(txtCG2UpFlowStartTime.Text);

            this.methodconfig.val[0].valCG3BlowFlow = string2float(txtCG3BlowFlow.Text);
            this.methodconfig.val[0].valCG3Set = string2float(txtCG3Set.Text);
            this.methodconfig.val[0].valCG3UpFlowEndTime = string2float(txtCG3UpFlowEndTime.Text);
            this.methodconfig.val[0].valCG3UpFlowStartTime = string2float(txtCG3UpFlowStartTime.Text);

            this.methodconfig.val[0].valCGColumn1Bore = string2float(txtCGColumn1Bore.Text);
            this.methodconfig.val[0].valCGColumn1ColumnFlow = string2float(txtCGColumn1ColumnFlow.Text);
            this.methodconfig.val[0].valCGColumn1Length = string2float(txtCGColumn1Length.Text);
            this.methodconfig.val[0].valCGColumn1Theca = string2float(txtCGColumn1Theca.Text);

            this.methodconfig.val[0].valCGColumn2Bore = string2float(txtCGColumn2Bore.Text);
            this.methodconfig.val[0].valCGColumn2ColumnFlow = string2float(txtCGColumn2ColumnFlow.Text);
            this.methodconfig.val[0].valCGColumn2Length = string2float(txtCGColumn2Length.Text);
            this.methodconfig.val[0].valCGColumn2Theca = string2float(txtCGColumn2Theca.Text);

            this.methodconfig.val[0].valCGColumn3Bore = string2float(txtCGColumn3Bore.Text);
            this.methodconfig.val[0].valCGColumn3ColumnFlow = string2float(txtCGColumn3ColumnFlow.Text);
            this.methodconfig.val[0].valCGColumn3Length = string2float(txtCGColumn3Length.Text);
            this.methodconfig.val[0].valCGColumn3Theca = string2float(txtCGColumn3Theca.Text);

            this.methodconfig.val[0].valProtecttemp = string2float(txtProtecttemp.Text);

            this.methodconfig.val[0].valCarrierGasType = (ushort)combCarrierGasType.SelectedIndex;
            this.methodconfig.val[0].valControlMode = (ushort)combControlMode.SelectedIndex;

            if (cbCG1.CheckState == CheckState.Checked)
                this.methodconfig.val[0].valCG1 = 1;
            else
                this.methodconfig.val[0].valCG1 = 0;

            if (cbCG2.CheckState == CheckState.Checked)
                this.methodconfig.val[0].valCG2 = 1;
            else
                this.methodconfig.val[0].valCG2 = 0;

            if (cbCG3.CheckState == CheckState.Checked)
                this.methodconfig.val[0].valCG3 = 1;
            else
                this.methodconfig.val[0].valCG3 = 0;
        }

        private void combControlMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblControlMode.Text = combControlMode.Text;
        }

        private void combCarrierGasType_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbCG1.Text = "载气" + (1 + (3 * combCarrierGasType.SelectedIndex));
            cbCG2.Text = "载气" + (2 + (3 * combCarrierGasType.SelectedIndex));
            cbCG3.Text = "载气" + (3 + (3 * combCarrierGasType.SelectedIndex));

            lblCGColumn1.Text = "载气" + (1 + (3 * combCarrierGasType.SelectedIndex)) + "柱规则";
            lblCGColumn2.Text = "载气" + (2 + (3 * combCarrierGasType.SelectedIndex)) + "柱规则";
            lblCGColumn3.Text = "载气" + (3 + (3 * combCarrierGasType.SelectedIndex)) + "柱规则";
        }
        private void CheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (!cbCG1.Checked)
            {
                txtCGColumn1Bore.Text = txtCGColumn1ColumnFlow.Text =
                    txtCGColumn1Length.Text = txtCGColumn1Theca.Text = string.Empty;
            }

            if (!cbCG2.Checked)
            {
                txtCGColumn2Bore.Text = txtCGColumn2ColumnFlow.Text =
                    txtCGColumn2Length.Text = txtCGColumn2Theca.Text = string.Empty;
            }

            if (!cbCG3.Checked)
            {
                txtCGColumn3Bore.Text = txtCGColumn3ColumnFlow.Text =
                    txtCGColumn3Length.Text = txtCGColumn3Theca.Text = string.Empty;
            }

            txtCGColumn1Bore.Enabled = txtCGColumn1ColumnFlow.Enabled =
                txtCGColumn1Length.Enabled = txtCGColumn1Theca.Enabled = cbCG1.Checked;
            txtCGColumn2Bore.Enabled = txtCGColumn2ColumnFlow.Enabled =
                txtCGColumn2Length.Enabled = txtCGColumn2Theca.Enabled = cbCG2.Checked;
            txtCGColumn3Bore.Enabled = txtCGColumn3ColumnFlow.Enabled =
                txtCGColumn3Length.Enabled = txtCGColumn3Theca.Enabled = cbCG3.Checked;
        }
    }
}
