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

using ITC81DB_2H.Forms;
using ITC81DB_2H_ImageDll;
using ITC81DB_2H.Datastore;
using ITC81DB_2H.DialogForms;
using ITC81DB_2H.Part11_UserManager;

namespace ITC81DB_2H.Controls
{
    public partial class ControlCenterEquipMyPage : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        private int m_FirstLineNumber;
        #endregion

        #region Constructor
        public ControlCenterEquipMyPage(FormMenu parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

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

        public int FirstLineNumber
        {
            get { return this.m_FirstLineNumber; }
            set { this.m_FirstLineNumber = value; }
        }
        #endregion

        #region Method
        public void InitializeDesign()
        {
            Class1 images = new Class1();

            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.labelTitle.Text = "User information";
                this.labelTitleID.Text = "ID";
                this.labelTitleNewPassword.Text = "New";
                this.labelTitleVerifyPassword.Text = "Verify";

                this.buttonChangePassword.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginChangeDisable));
                this.buttonChangePassword.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginChangeDown));
                this.buttonChangePassword.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginChangeUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitle.Text = "用户信息";
                this.labelTitleID.Text = "用户名";
                this.labelTitleNewPassword.Text = "新的";
                this.labelTitleVerifyPassword.Text = "核实";

                this.buttonChangePassword.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginChangeDisable));
                this.buttonChangePassword.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginChangeDown));
                this.buttonChangePassword.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginChangeUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.labelTitle.Text = "Информация о пользователе";
                this.labelTitleID.Text = "ID";
                this.labelTitleNewPassword.Text = "Новый";
                this.labelTitleVerifyPassword.Text = "Проверять";

                this.buttonChangePassword.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusMainLoginChangeDisable));
                this.buttonChangePassword.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusMainLoginChangeDown));
                this.buttonChangePassword.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusMainLoginChangeUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.labelTitle.Text = "Nutzerinformation";
                this.labelTitleID.Text = "ID";
                this.labelTitleNewPassword.Text = "Neu";
                this.labelTitleVerifyPassword.Text = "Verifizieren";

                this.buttonChangePassword.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainLoginChangeDisable));
                this.buttonChangePassword.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainLoginChangeDown));
                this.buttonChangePassword.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainLoginChangeUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {
                this.labelTitle.Text = "Informacion del usuario";
                this.labelTitleID.Text = "ID";
                this.labelTitleNewPassword.Text = "Nuevo";
                this.labelTitleVerifyPassword.Text = "Verificar";

                this.buttonChangePassword.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginChangeDisable));
                this.buttonChangePassword.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginChangeDown));
                this.buttonChangePassword.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainLoginChangeUp));
            }
            else
            {
                this.labelTitle.Text = "유저 정보";
                this.labelTitleID.Text = "ID";
                this.labelTitleNewPassword.Text = "새 비밀번호";
                this.labelTitleVerifyPassword.Text = "비밀번호 확인";

                this.buttonChangePassword.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginChangeDisable));
                this.buttonChangePassword.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginChangeDown));
                this.buttonChangePassword.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainLoginChangeUp));
            }
        }
        public void DefaultSetting()
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Show();
        }

        private void UpdateDisplayID()
        {
            this.labelID.Text = this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ID;
        }

        public void CallBackUserListModifyInfoDataEvent(UserManager.UserMgr_user_info_t user)
        {
            try
            {
                if (user.status == 0)
                {
                    string code = "", message1 = "", message2 = "";

                    switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                    {
                        case Define.E_LanguageID.Korean:
                            code = "비밀번호 변경";
                            message1 = "비밀번호가 변경되었습니다.";
                            message2 = "";
                            break;
                        case Define.E_LanguageID.English:
                            code = "Change Password";
                            message1 = "Password has been changed.";
                            message2 = "";
                            break;
                        case Define.E_LanguageID.Chinese:
                            code = "更改密码";
                            message1 = "您的密码已被更改。";
                            message2 = "";
                            break;
                        case Define.E_LanguageID.Russian:
                            code = "Изменить пароль";
                            message1 = "Ваш пароль был изменен.";
                            message2 = "";
                            break;
                        case Define.E_LanguageID.German:
                            code = "Kennwort ändern";
                            message1 = "Ihr Passwort wurde geändert.";
                            message2 = "";
                            break;
                        case Define.E_LanguageID.Spanish:
                            code = "Cambiar la contraseña";
                            message1 = "Tu contraseña ha sido cambiada.";
                            message2 = "";
                            break;
                        default:
                            break;
                    }

                    // 비밀번호가 변경되었습니다.
                    DialogFormMessage dlg = new DialogFormMessage(Define.E_MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    dlg.ShowDialog();
                }
                else
                {
                    DialogFormMessage myMsg = new DialogFormMessage(null, user.status, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                FormMain.Exception(ex);
            }
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.EquipMyPage;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.UpdateDisplayID();

            this.textBoxNewPassword.Text = "";
            this.textBoxVerifyPassword.Text = "";
        }
        #endregion

        #region Event Handler
        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {

        }

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

            this.textBoxNewPassword.Select(this.textBoxNewPassword.Text.Length, 0);
        }
        private void textBoxVerifyPassword_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxVerifyPassword;

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

        private void buttonChangePassword_Click(object sender, EventArgs e)
        {
            string detail = "";

            // Check Password
            if (this.textBoxNewPassword.Text.Length < 6 || this.textBoxVerifyPassword.Text.Length < 6)
            {
                // PASSWORD : 6~20자 입력하세요
                DialogFormMessage msg = new DialogFormMessage(null, 9, this.ParentForm.ParentForm.SystemConfig1.Language);
                msg.ShowDialog();

                return;
            }

            if (this.textBoxNewPassword.Text != this.textBoxVerifyPassword.Text)
            {
                // 비밀번호가 동일하지 않습니다
                DialogFormMessage myMsg = new DialogFormMessage(null, 17, this.ParentForm.ParentForm.SystemConfig1.Language);
                myMsg.ShowDialog();

                return;
            }
            else
            {
                UserManager.UserManager_UserModifyPW(this.labelID.Text, this.textBoxVerifyPassword.Text);

                // Part 11
                detail = string.Format("Modify Password : {0}", this.labelID.Text);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            }
        }
        #endregion
    }
}
