using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TheDarkWraith.WM16MEV
{
    public partial class InputBox : Form
    {
        #region Constants
        public enum inputtype { intvalue, strvalue, floatvalue };
        #endregion

        #region Variables
        private inputtype it;
        private float fvalue;
        private int ivalue;
        #endregion

        #region Properties
        public String StrValue
        {
            get
            {
                return tbValue.Text;
            }
        }

        public int IValue
        {
            get
            {
                return ivalue;
            }
        }

        public float FValue
        {
            get
            {
                return fvalue;
            }
        }
        #endregion

        #region Constructor
        public InputBox(inputtype itpassed, String text)
        {
            InitializeComponent();

            if (itpassed == inputtype.floatvalue)
            {
                text += " (float)";
            }
            else if (itpassed == inputtype.intvalue)
            {
                text += " (integer)";
            }
            else if (itpassed == inputtype.strvalue)
            {
                text += " (string)";
            }

            lblValue.Text = text;

            it = itpassed;
        }
        #endregion

        #region Accept click
        private void btnAccept_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbValue.Text == null || tbValue.Text == "")
                {
                    if (it != inputtype.strvalue)
                    {
                        throw new NullReferenceException();
                    }
                }

                if (it == inputtype.floatvalue)
                {
                    fvalue = Convert.ToSingle(tbValue.Text);
                }
                else if (it == inputtype.intvalue)
                {
                    ivalue = Convert.ToInt32(tbValue.Text);
                }
            }
            catch
            {
                MessageBox.Show("Invalid value entered. Please try again", "Error", MessageBoxButtons.OK);
                tbValue.Focus();
                return;
            }

            this.DialogResult = DialogResult.OK;
        }
        #endregion

        #region Cancel click
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
        #endregion


    }
}
