using System;
using System.Windows.Forms;
using CRVM.Entity;

namespace CRVM
{
    public partial class SetSenserForm : Form
    {
        public SetSenserForm()
        {
            InitializeComponent();
        }

        private void Sensor_Load(object sender, EventArgs e)
        {
            InitalSetting();
        }

        private void InitalSetting()
        {
            for (int i = 0; i < 8; i++)
            {
                TextBox tb1 = (TextBox)this.panel1.Controls["textBox" + (i + 1)];
                if (tb1 != null)
                {
                    tb1.Text = SysParam.Instance.channel[i].vibSens.ToString();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 8; i++)
            {
                TextBox tb1 = (TextBox)this.panel1.Controls["textBox" + (i + 1)];
                Label lab = (Label)this.panel1.Controls["label" + (i + 1)];
                if (tb1 != null)
                {
                    float value = 0f;
                    if (float.TryParse(tb1.Text.Trim(), out value))
                    {
                        SysParam.Instance.channel[i].vibSens = value;
                    }
                    else
                    {
                        tb1.Text = SysParam.Instance.channel[i].vibSens.ToString();
                        MessageBox.Show(lab.Text + "传感器参数格式不对（用户需输入内容需是数字类型）");
                        return;
                    }
                }
            }

            ConfigHelper.GetInstance("").SaveConfig(Application.StartupPath + "\\AppSetting.config");
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

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