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;

namespace INT69DC_7C.DialogForms
{
    public partial class DialogFormPasswordKeyPad1 : Form
    {
        #region Field
        private string m_InputKey;
        private string m_PassKey;
        private string m_PasswordHiddenMenu;
        private int m_Digit;
        #endregion

        #region Constructor
        public DialogFormPasswordKeyPad1(DataStore.LanguageID language)
        {
            InitializeComponent();

            this.InitializeDesign(language);
        }
        public DialogFormPasswordKeyPad1(int digit, DataStore.LanguageID language)
        {
            InitializeComponent();

            this.Digit = digit;
            this.PasswordHiddenMenu = DateTime.Now.ToString("MMdd") + "0810";

            this.InitializeDesign(language);
        }
        #endregion

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

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

        private void InitializeDesign(DataStore.LanguageID language)
        {
            if (language == DataStore.LanguageID.Chinese)
            {
                this.labelSubject.Text = "密码";

                this.buttonCancel.Text = "取消";
                this.buttonEnter.Text = "确认";
            }
            else if (language == DataStore.LanguageID.Czech)
            {
                this.labelSubject.Text = "Klávesnice";

                this.buttonCancel.Text = "Zrušit";
                this.buttonEnter.Text = "Enter";
            }
            else if (language == DataStore.LanguageID.German)
            {
                this.labelSubject.Text = "Passwort";

                this.buttonCancel.Text = "X";
                this.buttonEnter.Text = "Enter";
            }
            else if (language == DataStore.LanguageID.Japanese)
            {
                this.labelSubject.Text = "キㅡパッド";

                this.buttonCancel.Text = "X";
                this.buttonEnter.Text = "入力";
            }
            else
            {

            }
        }
        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(251, 390);

            this.InputKey = "";
            this.labelScreen.Text = "";
        }
        #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.Digit == 8)
            {
                if (this.InputKey == this.PasswordHiddenMenu)
                    this.DialogResult = DialogResult.OK;
                else
                    this.DialogResult = DialogResult.Cancel;
            }
        }

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

            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");
        }

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