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 INT89DB_26_ImageDll;
using INT89DB_26.Forms;

namespace INT89DB_26.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()
        {
            Class1 images = new Class1();

            if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Korean)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.English)
            {
                this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginDisable));
                this.buttonLogOn.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginDown));
                this.buttonLogOn.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginUp));
                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginCancelUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
            {
                this.smartForm1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundUserLogin));

                this.buttonLogOn.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginDisable));
                this.buttonLogOn.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginDown));
                this.buttonLogOn.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginUp));
                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainCancelUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
            {
              
            }
            else
            {

            }
        }
        private void InitializeControl()
        {
            this.textBoxID.Text = "";
            this.textBoxPassword.Text = "";

            this.Location = new Point(45, 66);

            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
    }
}