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

using SmartX;
using ITC81DB_2_ImageDll;
using ITC81DB_2.Datastore;

namespace ITC81DB_2.DialogForms
{
    public partial class DialogFormHexKeyPad : Form
    {
        #region Field
        private string m_InputKey;
        private int m_Digit;

        private string m_StringValue;
        #endregion

        #region Property
        public string InputKey
        {
            get { return this.m_InputKey; }
            set { this.m_InputKey = value; }
        }
        private int Digit
        {
            get { return this.m_Digit; }
            set { this.m_Digit = value; }
        }

        public string StringValue
        {
            get { return this.m_StringValue; }
            private set { this.m_StringValue = value; }
        }
        #endregion

        #region Constructor
        public DialogFormHexKeyPad(string value, int digit, Define.E_LanguageID language)
        {
            InitializeComponent();

            this.InitializeDesign(language);
            this.Digit = digit;
            this.labelScreen.Text = value;
        }
        #endregion

        #region Method
        private void InputNum(string key)
        {
            if (this.InputKey.Length >= this.Digit)
            {
                this.InputKey = key;
                this.labelScreen.Text = this.InputKey;
            }
            else
            {
                this.InputKey += key;
                this.labelScreen.Text = this.InputKey;
            }
        }

        private void InitializeDesign(Define.E_LanguageID language)
        {
            Class1 images = new Class1();

            if (language == Define.E_LanguageID.English)
            {
                this.buttonCancel.Text = "ESC";
                this.buttonEnter.Text = "Enter";
            }
            else if (language == Define.E_LanguageID.Chinese)
            {
                this.labelTitle.Text = "键盘";
                this.buttonCancel.Text = "取消";
                this.buttonEnter.Text = "确认";
            }
            else if (language == Define.E_LanguageID.Czech)
            {
            }
            else if (language == Define.E_LanguageID.Russian)
            {
                this.labelTitle.Text = "Клавиатура";

                this.buttonCancel.Text = "X";
                this.buttonEnter.Text = "Ввод";
            }
            else if (language == Define.E_LanguageID.German)
            {
                this.buttonCancel.Text = "X";
                this.buttonEnter.Text = "Enter";
            }
            else if (language == Define.E_LanguageID.Spanish)
            {
                this.buttonCancel.Text = "X";
                this.buttonEnter.Text = "Entrar";
            }
            else
            {
                this.buttonCancel.Text = "ESC";
                this.buttonEnter.Text = "Enter";
            }
        }
        private void InitializeControl()
        {
            int x = 0, y = 0;

            x = Screen.PrimaryScreen.Bounds.Width / 2 - this.Size.Width / 2;
            y = Screen.PrimaryScreen.Bounds.Height / 2 - this.Size.Height / 2;

            this.Location = new Point(x, y);
            this.Size = new Size(455, 360);

            this.InputKey = "";
        }
        #endregion

        #region Override Member
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.InitializeControl();
        }
        #endregion

        #region Event Handler
        private void buttonEnter_Click(object sender, EventArgs e)
        {
            if (this.labelScreen.Text.Length == this.Digit)
            {
                this.StringValue = this.labelScreen.Text;
                this.DialogResult = DialogResult.OK;
            }
        }

        private void buttonNumber_Click(object sender, EventArgs e)
        {
            SmartButton bt = sender as SmartButton;

            if (bt == null)
                return;

            if (bt == this.buttonNumber0)
                this.InputNum("0");
            else if (bt == this.buttonNumber1)
                this.InputNum("1");
            else if (bt == this.buttonNumber2)
                this.InputNum("2");
            else if (bt == this.buttonNumber3)
                this.InputNum("3");
            else if (bt == this.buttonNumber4)
                this.InputNum("4");
            else if (bt == this.buttonNumber5)
                this.InputNum("5");
            else if (bt == this.buttonNumber6)
                this.InputNum("6");
            else if (bt == this.buttonNumber7)
                this.InputNum("7");
            else if (bt == this.buttonNumber8)
                this.InputNum("8");
            else if (bt == this.buttonNumber9)
                this.InputNum("9");
            else if (bt == this.buttonCharA)
                this.InputNum("A");
            else if (bt == this.buttonCharB)
                this.InputNum("B");
            else if (bt == this.buttonCharC)
                this.InputNum("C");
            else if (bt == this.buttonCharD)
                this.InputNum("D");
            else if (bt == this.buttonCharE)
                this.InputNum("E");
            else if (bt == this.buttonCharF)
                this.InputNum("F");
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}