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 ITC81DB_2.Forms;
using ITC81DB_2_ImageDll;

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

        #region Constructor
        public DialogFormLogOn(FormMain parent, Define.E_LanguageID language)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

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

        #region Method
        public void InitializeDesign(Define.E_LanguageID language)
        {
            Class1 images = new Class1();

            if (language == Define.E_LanguageID.English)
            {
                this.labelTitleLogin.Text = "Login";
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "Password";

                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));
                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));
            }
            else if (language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleLogin.Text = "登錄";
                this.labelTitleID.Text = "用户名";
                this.labelTitlePassword.Text = "密码";

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainLoginCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainLoginCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainLoginCancelUp));
                this.buttonLogon.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginLoginDisable));
                this.buttonLogon.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginLoginDown));
                this.buttonLogon.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginLoginUp));
            }
            else if (language == Define.E_LanguageID.Czech)
            {
            }
            else if (language == Define.E_LanguageID.Spanish)
            {
                this.labelTitleLogin.Text = "Acceso";
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "Clave";

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainLoginCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainLoginCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainLoginCancelUp));
                this.buttonLogon.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainLoginDisable));
                this.buttonLogon.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainLoginDown));
                this.buttonLogon.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainLoginUp));
            }
            else
            {
                this.labelTitleLogin.Text = "로그인";
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "비밀번호";

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginCancelUp));
                this.buttonLogon.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginDisable));
                this.buttonLogon.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginDown));
                this.buttonLogon.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginUp));
            }
        }
        private void DefaultSetting()
        {
            this.textBoxID.Text = "";
            this.textBoxPassword.Text = "";

            this.Location = new Point(0, 65);

            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Show();
        }
        #endregion
       
        #region Event Handler
        private void buttonLogon_Click(object sender, EventArgs e)
        {
            UserItem user = null;

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

            if (user != null)
            {
                if (user.Password == this.textBoxPassword.Text)
                {
                    this.ParentForm.CurrentSystemStatus.CurrentUser.ID = user.ID;
                    this.ParentForm.CurrentSystemStatus.CurrentUser.Password = user.Password;
                    this.ParentForm.CurrentSystemStatus.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
    }
}