using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;//.Tasks;
using System.Windows.Forms;
using GcDevicePc.DevParam;
using GcDevicePc.IniParam;

namespace GcDevicePc.ConfigDlg
{
    public partial class FIDDlg : Form
    {
        
        public FIDDlg()
        {
            InitializeComponent();
        }

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

            tb温度设定.Text = CProfileDevice.m_DevParam.fid[index].fHeaterTempSet.ToString();
            tb氢气压力设定.Text = CProfileDevice.m_DevParam.fid[index].fSetH2Flow.ToString();
            tb空气压力设定.Text = CProfileDevice.m_DevParam.fid[index].fAirFlowSet.ToString();
            tb尾吹气压力设定.Text = CProfileDevice.m_DevParam.fid[index].fSetTailGas.ToString();

            cb灵敏度.SelectedIndex = CProfileDevice.m_DevParam.fid[index].u16Sensitive;
            cb极性.SelectedIndex = CProfileDevice.m_DevParam.fid[index].u16Polarity;

            if (CProfileDevice.m_DevParam.fid[index].u16KeyFire == 1)
                cBox自动点火.CheckState = CheckState.Checked;
            else
                cBox自动点火.CheckState = CheckState.Unchecked;

            if (CProfileDevice.m_DevParam.fid[index].u16Zero == 1)
                cBox自动调零.CheckState = CheckState.Checked;
            else
                cBox自动调零.CheckState = CheckState.Unchecked;

            if (CProfileDevice.m_DevParam.fid[index].u16KeyHeater == 1)
                cBox加热器.CheckState = CheckState.Checked;
            else
                cBox加热器.CheckState = CheckState.Unchecked;

            if (CProfileDevice.m_DevParam.fid[index].u16KeyH2Flow == 1)
                cBox氢气.CheckState = CheckState.Checked;
            else
                cBox氢气.CheckState = CheckState.Unchecked;

            if (CProfileDevice.m_DevParam.fid[index].u16KeyAirFlow == 1)
                cBox空气.CheckState = CheckState.Checked;
            else
                cBox空气.CheckState = CheckState.Unchecked;

            if (CProfileDevice.m_DevParam.fid[index].u16KeyTailGas == 1)
                cBox尾吹气.CheckState = CheckState.Checked;
            else
                cBox尾吹气.CheckState = CheckState.Unchecked;

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

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

        float string2float(string s)
        {
            float ret;

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

            return ret;
        }

        public void recordCurData(int index)
        {
       
            CProfileDevice.m_DevParam.fid[index].fHeaterTempSet = string2float(tb温度设定.Text);
            CProfileDevice.m_DevParam.fid[index].fSetH2Flow = string2float(tb氢气压力设定.Text);
            CProfileDevice.m_DevParam.fid[index].fAirFlowSet = string2float(tb空气压力设定.Text);
            CProfileDevice.m_DevParam.fid[index].fSetTailGas = string2float(tb尾吹气压力设定.Text);

            CProfileDevice.m_DevParam.fid[index].u16Sensitive = (ushort)cb灵敏度.SelectedIndex;
            CProfileDevice.m_DevParam.fid[index].u16Polarity = (ushort)cb极性.SelectedIndex;

            if (cBox自动点火.CheckState == CheckState.Checked)
                CProfileDevice.m_DevParam.fid[index].u16KeyFire = 1;
            else
                CProfileDevice.m_DevParam.fid[index].u16KeyFire = 0;

            if (cBox自动调零.CheckState == CheckState.Checked)
                CProfileDevice.m_DevParam.fid[index].u16Zero = 1;
            else
                CProfileDevice.m_DevParam.fid[index].u16Zero = 0;

            if (cBox加热器.CheckState == CheckState.Checked)
                CProfileDevice.m_DevParam.fid[index].u16KeyHeater = 1;
            else
                CProfileDevice.m_DevParam.fid[index].u16KeyHeater = 0;

            if (cBox氢气.CheckState == CheckState.Checked)
                CProfileDevice.m_DevParam.fid[index].u16KeyH2Flow = 1;
            else
                CProfileDevice.m_DevParam.fid[index].u16KeyH2Flow = 0;

            if (cBox空气.CheckState == CheckState.Checked)
                CProfileDevice.m_DevParam.fid[index].u16KeyAirFlow = 1;
            else
                CProfileDevice.m_DevParam.fid[index].u16KeyAirFlow = 0;

            if (cBox尾吹气.CheckState == CheckState.Checked)
                CProfileDevice.m_DevParam.fid[index].u16KeyTailGas = 1;
            else
                CProfileDevice.m_DevParam.fid[index].u16KeyTailGas = 0;

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