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

namespace GcDevicePc.ConfigDlg
{
    public partial class TCDDlg : Form
    {
       

        public TCDDlg()
        {
            InitializeComponent();
        }

        float string2float(string s)
        {
            float ret;

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

            return ret;
        }

        public void reflashContent(int index)
        {
            globaldata.m_profileMethod.GetDevState();
            globaldata.m_profileMethod.GetTcdAllPara();

            tb桥电流.Text = CProfileDevice.m_DevParam.tcd[index].u16Electric.ToString();
            tb设定加热器温压.Text = CProfileDevice.m_DevParam.tcd[index].fHeaterTempSet.ToString();
            tb设定尾吹气温压.Text = CProfileDevice.m_DevParam.tcd[index].fTaiGasSet.ToString();

            if(CProfileDevice.m_DevParam.tcd[index].u16Polarity == 0)
            {
                cb极性.SelectedIndex = 0;
            }
            else
            {
                cb极性.SelectedIndex = 1;
            }

            if(CProfileDevice.m_DevParam.tcd[index].u16AutoZeroSet == 1)
            {
                cBox调零.CheckState = CheckState.Checked;
            }
            else
            {
                cBox调零.CheckState = CheckState.Unchecked;
            }

            if (CProfileDevice.m_DevParam.tcd[index].u16HeaterSel == 1)
            {
                cBox加热器.CheckState = CheckState.Checked;
            }
            else
            {
                cBox加热器.CheckState = CheckState.Unchecked;
            }

            if (CProfileDevice.m_DevParam.tcd[index].u16TaiGasSel == 1)
            {
                cBox尾吹气.CheckState = CheckState.Checked;
            }
            else
            {
                cBox尾吹气.CheckState = CheckState.Unchecked;
            }

            if (CProfileDevice.m_DevParam.tcd[index].u16AutoZeroSet == 1)
            {
                cBox调零.CheckState = CheckState.Checked;
            }
            else
            {
                cBox调零.CheckState = CheckState.Unchecked;
            }

            if (CProfileDevice.m_DevParam.tcd[index].u16SigDeduct < 3 && CProfileDevice.m_DevParam.tcd[index].u16SigDeduct >= 0)
                cListBoxSign.SetItemChecked(CProfileDevice.m_DevParam.tcd[index].u16SigDeduct, true);
            
        }

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

        public void recordCurData(int index)
        {
            
            if (tb桥电流.Text == "")
                CProfileDevice.m_DevParam.tcd[index].u16Electric = 0;
            else
                CProfileDevice.m_DevParam.tcd[index].u16Electric = System.UInt16.Parse(tb桥电流.Text);

            CProfileDevice.m_DevParam.tcd[index].fHeaterTempSet = string2float(tb设定加热器温压.Text);
            CProfileDevice.m_DevParam.tcd[index].fTaiGasSet = string2float(tb设定尾吹气温压.Text);

            if (cb极性.SelectedIndex == 0)
            {
                CProfileDevice.m_DevParam.tcd[index].u16Polarity = 0;
            }
            else
            {
                CProfileDevice.m_DevParam.tcd[index].u16Polarity = 1;
            }

            if ( cBox调零.CheckState == CheckState.Checked)
            {
                CProfileDevice.m_DevParam.tcd[index].u16AutoZeroSet = 1;
            }
            else
            {
                CProfileDevice.m_DevParam.tcd[index].u16AutoZeroSet = 0;
            }

            if (cBox加热器.CheckState == CheckState.Checked)
            {
                CProfileDevice.m_DevParam.tcd[index].u16HeaterSel = 1;
            }
            else
            {
                CProfileDevice.m_DevParam.tcd[index].u16HeaterSel = 0;
            }

            if (cBox尾吹气.CheckState == CheckState.Checked)
            {
                CProfileDevice.m_DevParam.tcd[index].u16TaiGasSel = 1;
            }
            else
            {
                CProfileDevice.m_DevParam.tcd[index].u16TaiGasSel = 0;
            }

            if ( cBox调零.CheckState == CheckState.Checked)
            {
                CProfileDevice.m_DevParam.tcd[index].u16AutoZeroSet = 1;
            }
            else
            {
                CProfileDevice.m_DevParam.tcd[index].u16AutoZeroSet = 0;
            }

            if (cListBoxSign.GetItemChecked(0) == true)
                CProfileDevice.m_DevParam.tcd[index].u16SigDeduct = 1;
            else if(cListBoxSign.GetItemChecked(1) == true)
                CProfileDevice.m_DevParam.tcd[index].u16SigDeduct = 2;
            else if(cListBoxSign.GetItemChecked(2) == true)
                CProfileDevice.m_DevParam.tcd[index].u16SigDeduct = 3;
        }
    }
}
