using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace ModbusControl
{
    partial class EditDialog : Form
    {
        public EditDialog()
        {
            InitializeComponent();
        }
        private Boolean FBooleanValue = false;
        private UInt16 FUInt16Value = 0;
        private UInt16 FMode = 0;

        public Boolean BooleanValue
        {
            get
            {
                return FBooleanValue;
            }
        }
        public UInt16 UInt16Value
        {
            get
            {
                return FUInt16Value;
            }
        }
        public UInt16 Mode
        {
            get
            {
                return FMode;
            }
            set
            {
                FMode = value;
                if (value == 0)
                {
                    cbValue.Visible = true;
                    tbValue.Visible = false;
                }
                if (value == 1)
                {
                    cbValue.Visible = false;
                    tbValue.Visible = true;
                }
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbValue.Visible) FUInt16Value = Convert.ToUInt16(tbValue.Text);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Incorrect value. Please type value 0..65535.");
                return;
            }
            if ((cbValue.Visible) && (cbValue.Text == ""))
            {
                MessageBox.Show("Please select value.");
                return;
            }
            if (cbValue.Visible) FBooleanValue = Convert.ToBoolean(cbValue.Text);

            this.DialogResult = DialogResult.OK;
        }
    }
}
