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 INT63DC_ImageDll;
using INT63DC_2C.Forms;

namespace INT63DC_2C.DialogForms
{
    public partial class DialogFormLogOn : Form
    {
        #region Field
        private FormMain m_ParentForm;
        #endregion

        #region Constructor
        public DialogFormLogOn(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.InitializeControl();
            this.DefaultSetting();
        }
        #endregion

        #region Property
        public FormMain ParentForm
        {
            get { return this.m_ParentForm; }
            private set { this.m_ParentForm = value; }
        }
        #endregion

        #region Method
        private void InitializeDesign()
        {
            ImageDll images = new ImageDll();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    break;
                case DataStore.LanguageID.English:
                    #region English
                    this.labelTitle1.Text = "User Login";
                    this.labelTitle2.Text = "ID";
                    this.labelTitle3.Text = "Password";

                    this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginDisable));
                    this.buttonLogOn.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginDown));
                    this.buttonLogOn.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginUp));
                    this.buttonCancel.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainCancelDisable));
                    this.buttonCancel.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainCancelDown));
                    this.buttonCancel.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainCancelUp)); 
                    #endregion
                    break;
                case DataStore.LanguageID.Chinese:
                    #region Chinese
                    this.labelTitle1.Visible = false;
                    this.labelTitle2.Visible = false;
                    this.labelTitle3.Visible = false;
                    this.pictureBoxImage.Visible = false;

                    this.smartForm1.Image = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackgroundUserLogin));

                    this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnMainLoginDisable));
                    this.buttonLogOn.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnMainLoginDown));
                    this.buttonLogOn.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnMainLoginUp));
                    this.buttonCancel.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnMainCancelDisable));
                    this.buttonCancel.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnMainCancelDown));
                    this.buttonCancel.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnMainCancelUp)); 
                    #endregion
                    break;
                case DataStore.LanguageID.Czech:
                    #region Czech
                    this.labelTitle1.Text = "User Login";
                    this.labelTitle2.Text = "ID";
                    this.labelTitle3.Text = "Password";

                    this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginDisable));
                    this.buttonLogOn.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginDown));
                    this.buttonLogOn.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginUp));
                    this.buttonCancel.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeMainCancelDisable));
                    this.buttonCancel.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeMainCancelDown));
                    this.buttonCancel.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeMainCancelUp)); 
                    #endregion
                    break;
                case DataStore.LanguageID.German:
                    #region German
                    this.labelTitle1.Text = "Einloggen";
                    this.labelTitle2.Text = "ID";
                    this.labelTitle3.Text = "Passwort";

                    this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginDisable));
                    this.buttonLogOn.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginDown));
                    this.buttonLogOn.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engMainLoginUp));
                    this.buttonCancel.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerMainCancelDisable));
                    this.buttonCancel.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerMainCancelDown));
                    this.buttonCancel.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerMainCancelUp)); 
                    #endregion
                    break;
                case DataStore.LanguageID.Japanese:
                    #region Japanese
                    this.labelTitle1.Text = "ログイン";
                    this.labelTitle2.Text = "ID";
                    this.labelTitle3.Text = "パスワㅡド";

                    this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnMainLoginLoginDisable));
                    this.buttonLogOn.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnMainLoginLoginDown));
                    this.buttonLogOn.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnMainLoginLoginUp));
                    this.buttonCancel.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnMainLoginCancelDisable));
                    this.buttonCancel.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnMainLoginCancelDown));
                    this.buttonCancel.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnMainLoginCancelUp));
                    #endregion
                    break;
                default:
                    break;
            }
        }
        private void InitializeControl()
        {
            this.textBoxID.Text = "";
            this.textBoxPassword.Text = "";

            this.Location = new Point(157, 150);

            //this.smartKeyboard.HanYoungKeyToggle();
            this.smartKeyboard.HanYoungKeyDisable = true;
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Show();
        }
        private void DefaultSetting()
        {

        }
        #endregion

        #region Event Handler
        private void buttonLogOn_Click(object sender, EventArgs e)
        {
            User user = null;

            user = this.ParentForm.CurrentCollectionUser.FindUser(this.textBoxID.Text);

            if (user != null)
            {
                if (user.Password == this.textBoxPassword.Text)
                {
                    this.ParentForm.SystemConfig.CurrentUser.ID = user.ID;
                    this.ParentForm.SystemConfig.CurrentUser.Password = user.Password;
                    this.ParentForm.SystemConfig.CurrentUser.Group = user.Group;

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    DialogFormMessage myMsg = new DialogFormMessage(33, this.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
            }
            else
            {
                DialogFormMessage myMsg = new DialogFormMessage(32, this.ParentForm.SystemConfig.Language);
                myMsg.ShowDialog();
            }
        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void textBoxID_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxID;

            this.textBoxID.Select(this.textBoxID.Text.Length, 0);
        }
        private void textBoxPassword_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxPassword;

            this.textBoxPassword.Select(this.textBoxPassword.Text.Length, 0);
        }

        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            this.smartKeyboard.Show();
        }
        #endregion
    }
}