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.Threading;

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

namespace ITC81DB_2H.Controls
{
    public partial class ControlCenterEquipUser : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;

        private bool IsNew;
        private object LockObject = new object();
        private bool PasswordChar;
        
        private UserItem m_SelectedUserItem;

        private string BeforeID;
        private string BeforePassword;
        #endregion

        #region Constructor
        public ControlCenterEquipUser(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 UserItem SelectedUserItem
        {
            get { return this.m_SelectedUserItem; }
            private set { this.m_SelectedUserItem = value; }
        } 
        #endregion

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

            this.labelTitleNumberOfLoginFailures.TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
            this.labelTitleNumberOfLoginFailures.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
            this.labelTitleExpiryDateOfPassword.TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
            this.labelTitleExpiryDateOfPassword.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
            this.labelTitleAutomaticLogoutTime.TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
            this.labelTitleAutomaticLogoutTime.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;

            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English
                || this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "Password";
                this.labelTitleAccessRight.Text = "Access right";

                this.buttonIDEdit.Text = "Edit";
                this.labelAccessRightAdmin.Text = "Administrator";

                this.labelTitleContents.Text = "<Items common to all users>";
                this.labelTitleNumberOfLoginFailures.Text = "Number of failures";

                this.labelTitleExpiryDateOfAccount.Text = "Expiry date(ID)";
                this.labelTitleExpiryDateOfPassword.Text = "Expiry date(PW)";

                this.labelTitleAutomaticLogoutTime.Text = "Auto Logout";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleID.Text = "用户名";
                this.labelTitlePassword.Text = "密码";
                this.labelTitleAccessRight.Text = "访问权";

                this.buttonIDEdit.Text = "编辑";
                this.labelAccessRightAdmin.Text = "行政人员";

                this.labelTitleContents.Text = "<所有用户共有的项目>";
                this.labelTitleNumberOfLoginFailures.Text = "失败次数";

                this.labelTitleExpiryDateOfAccount.Text = "到期日(用户名)";
                this.labelTitleExpiryDateOfPassword.Text = "到期日(密码)";

                this.labelTitleAutomaticLogoutTime.Text = "自动注销";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "Пароль";
                this.labelTitleAccessRight.Text = "Право доступа";

                this.buttonIDEdit.Text = "Ред";
                this.labelAccessRightAdmin.Text = "Админ";

                this.labelTitleContents.Text = "<Элементы, общие для всех пользователей>";
                this.labelTitleNumberOfLoginFailures.TextHAlign = SmartX.SmartLabel.TextHorAlign.Left;
                this.labelTitleNumberOfLoginFailures.TextVAlign = SmartX.SmartLabel.TextVerAlign.Top;
                this.labelTitleNumberOfLoginFailures.Text = "Количество отказов";

                this.labelTitleExpiryDateOfAccount.Text = "Истечения(ID)";
                this.labelTitleExpiryDateOfPassword.Text = "Истечения(Пароль)";

                this.labelTitleAutomaticLogoutTime.Text = "Автоматический выход";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "Passwort";
                this.labelTitleAccessRight.Text = "Zugangsberechtigung";

                this.buttonIDEdit.Text = "Bearbeiten";
                this.labelAccessRightAdmin.Text = "Administrator";

                this.labelTitleContents.Text = "<Elemente, die allen Benutzern gemeinsam sind>";
                this.labelTitleNumberOfLoginFailures.Text = "Anzahl der Ausfälle";

                this.labelTitleExpiryDateOfAccount.Text = "Verfallsdatum(ID)";
                this.labelTitleExpiryDateOfPassword.Text = "Verfallsdatum(PW)";

                this.labelTitleAutomaticLogoutTime.Text = "Automatische Abmeldung";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {

            }
            else
            {
                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "비밀번호";
                this.labelTitleAccessRight.Text = "접근 권한";

                this.buttonIDEdit.Text = "수정";
                this.labelAccessRightAdmin.Text = "관리자";

                this.labelTitleContents.Text = "<전체 사용자 공통 적용 항목>";
                this.labelTitleNumberOfLoginFailures.Text = "로그인 실패 횟수";

                this.labelTitleExpiryDateOfAccount.Text = "만료일(ID)";
                this.labelTitleExpiryDateOfPassword.Text = "만료일(PW)";

                this.labelTitleAutomaticLogoutTime.Text = "자동 로그아웃";
            }
        }
        private void DefaultSetting()
        {
            this.IsNew = false;
            this.PasswordChar = false;
            this.BeforeID = "";
            this.BeforePassword = "";
            this.DisplayOnlyPart11Item(this.ParentForm.ParentForm.SystemConfig3.IsPart11);

            this.UpdateAccessRightComboBox();
            this.comboBoxAccessRight.SelectedIndexChanged -= new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            this.comboBoxAccessRight.SelectedIndex = 0;
            this.comboBoxAccessRight.SelectedIndexChanged += new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);

            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Show();
        }
        private bool UI_Invoke(ThreadStart invoker)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    if (this.IsDisposed)
                        return true;

                    this.Invoke(invoker);
                }
                else
                {
                    invoker();
                }

                return true;

            }
            catch (Exception e)
            {
                return false;
            }
        }

        public void VisibleAccountLockLabel(bool bValue)
        {
            this.labelAccountLock.Visible = bValue;
        }
        public void DisplayOnlyPart11Item(bool bValue)
        {
            if (bValue == true)
            {
                //this.labelTitleExpiryDateOfAccount.Visible = true;
                //this.labelExpiryDateOfAccount.Visible = true;
                //this.labelExpiryDateOfAccount2.Visible = true;
                //this.labelTitleExpiryDateOfPassword.Visible = true;
                //this.labelExpiryDateOfPassword.Visible = true;
                //this.labelExpiryDateOfPassword2.Visible = true;
                //this.labelTitleDayAccount.Visible = true;
                //this.labelTitleDayPassword.Visible = true;

                this.smartGroupBox2.Visible = true;
                this.smartGroupBox2.Location = new Point(263, 105);

                this.smartSeparatorLine1.Location = new Point(263, 183);
                this.labelTitleContents.Location = new Point(263, 195);
                this.labelTitleNumberOfLoginFailures.Location = new Point(263, 227);
                this.labelNumberOfLoginFailures.Location = new Point(390, 227);

                this.labelTitleAutomaticLogoutTime.Visible = true;
                this.labelAutomaticLogoutTime.Visible = true;
                this.smartLabel11.Visible = true;

                this.smartSeparatorLine1.Visible = true;
            }
            else
            {
                //this.labelTitleExpiryDateOfAccount.Visible = false;
                //this.labelExpiryDateOfAccount.Visible = false;
                //this.labelExpiryDateOfAccount2.Visible = false;
                //this.labelTitleExpiryDateOfPassword.Visible = false;
                //this.labelExpiryDateOfPassword.Visible = false;
                //this.labelExpiryDateOfPassword2.Visible = false;
                //this.labelTitleDayAccount.Visible = false;
                //this.labelTitleDayPassword.Visible = false;

                this.smartGroupBox2.Visible = false;
                this.smartGroupBox2.Location = new Point(263, 307);

                this.smartSeparatorLine1.Location = new Point(263, 115);
                this.labelTitleContents.Location = new Point(263, 127);
                this.labelTitleNumberOfLoginFailures.Location = new Point(263, 159);
                this.labelNumberOfLoginFailures.Location = new Point(390, 159);
                this.labelAccountLock.Location = new Point(458, 159);

                this.labelTitleAutomaticLogoutTime.Visible = false;
                this.labelAutomaticLogoutTime.Visible = false;
                this.smartLabel11.Visible = false;

                this.smartSeparatorLine1.Visible = false;
            }
        }
        public void UpdateAccessRightComboBox()
        {
            this.comboBoxAccessRight.Items.Clear();
            this.comboBoxAccessRight.Items.Add(this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel1Name);
            this.comboBoxAccessRight.Items.Add(this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel2Name);
            this.comboBoxAccessRight.Items.Add(this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel3Name);
        }

        private void SetTextBoxPasswordChar(bool bValue)
        {
            if (bValue == false)
            {
                if(this.textBoxPassword.Text == this.SelectedUserItem.ResetPW)
                    this.textBoxPassword.PasswordChar = default(char);
                else
                    this.textBoxPassword.PasswordChar = '*';
            }
            else
                this.textBoxPassword.PasswordChar = default(char);
        }
        public void DisplayHiddenMenu(bool bValue)
        {
            this.PasswordChar = bValue;
            this.SetTextBoxPasswordChar(this.PasswordChar);
        }

        private void SetEnableID(bool value)
        {
            this.textBoxID.Enabled = value;
            this.buttonIDEdit.Enabled = value;

            if (value == true)
                this.textBoxID.BackColor = Color.White;
            else
                this.textBoxID.BackColor = Color.Silver;
        }
        private void SetEnablePassword(bool value)
        {
            this.textBoxPassword.Enabled = value;

            if (value == true)
                this.textBoxPassword.BackColor = Color.White;
            else
                this.textBoxPassword.BackColor = Color.Silver;
        }

        private void SetEnableExpireDate(bool value)
        {
            this.labelExpiryDateOfAccount.Enabled = value;
            this.labelExpiryDateOfPassword.Enabled = value;

            if (value == true)
            {
                this.labelExpiryDateOfAccount.BackColor = Color.White;
                this.labelExpiryDateOfPassword.BackColor = Color.White;
            }
            else
            {
                this.labelExpiryDateOfAccount.BackColor = Color.Silver;
                this.labelExpiryDateOfPassword.BackColor = Color.Silver;
            }
        }
        private void SetEnableControl(bool value)
        {
            this.listBoxUserList.Enabled = value;

            this.buttonNew.Enabled = value;
            this.buttonDelete.Enabled = value;
            this.buttonSave.Enabled = value;

            this.buttonGroupEditor.Enabled = value;

            this.SetEnableExpireDate(value);
        }
        private void KeyboardClose()
        {
            this.smartKeyboard.Hide();

            this.SetEnableControl(true);
        }

        public void UpdateAllMenu(SystemStatus status)
        {
            this.ParentForm.ParentForm.ChildFormMainDisplay.UpdateMainDisplay(status);

            this.ParentForm.UpdateMenuDisplay(status);

            this.ParentForm.CenterBasicHelp.UpdateMenuDisplay(status);
            this.ParentForm.CenterConfiHelp.UpdateMenuDisplay(status);
            this.ParentForm.CenterEquipHelp.UpdateMenuDisplay(status);
            this.ParentForm.CenterInforHelp.UpdateMenuDisplay(status);
            this.ParentForm.CenterSystemHelp.UpdateMenuDisplay(status);
            this.ParentForm.CenterLogHelp.UpdateMenuDisplay(status);

            this.ParentForm.BottomBasic.UpdateMenuDisplay(status);
            this.ParentForm.BottomConfiguration.UpdateMenuDisplay(status);
            this.ParentForm.BottomEquipment.UpdateMenuDisplay(status);
            this.ParentForm.BottomInformation.UpdateMenuDisplay(status);
            this.ParentForm.BottomSystem.UpdateMenuDisplay(status);
            this.ParentForm.BottomLog.UpdateMenuDisplay(status);
        }

        private void UserNew()
        {
            this.UpdateInitializeUserDisplay(this.ParentForm.ParentForm.SystemConfig2);
        }
        private void SaveUserDll()
        {
            string detail = "";
            string code = "", message1 = "", message2 = "";

            #region listbox 미선택 시 신규 유저 등록, 선택 시 기존 유저 정보 수정
            if (this.IsNew == true)
            {
                switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "신규 사용자 추가 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        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 = "Benutzereinstellungen";
                        message1 = "Sie möchten sich als Benutzer registrieren?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.Spanish:
                        code = "Ajustes de usuario";
                        message1 = "¿Quieres registrarte como usuario?";
                        message2 = "";
                        break;
                     default:
                        break;
                }
            }
            else
            {
                switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "선택된 사용자의 정보를 수정 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        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 = "Benutzereinstellungen";
                        message1 = "Möchten Sie die Informationen des";
                        message2 = "ausgewählten Benutzers wirklich bearbeiten?";
                        break;
                    case Define.E_LanguageID.Spanish:
                        code = "Ajustes de usuario";
                        message1 = "¿Está seguro de que desea editar";
                        message2 = "la información del usuario seleccionado?";
                        break;
                    default:
                        break;
                }
            }
            #endregion

            DialogFormYesNo dlg = new DialogFormYesNo(Define.E_MessageBoxIcon.Question, code, message1, message2);
            if (dlg.ShowDialog() == DialogResult.Yes)
            {
                UserItem item = new UserItem();
                DateTime time = DateTime.Now;
                UserManager.MenuID_t menuId = new UserManager.MenuID_t();

                #region ID, Password 검사
                // Check ID
                if (this.IsNew == true)
                {
                    if (this.textBoxID.Text.Length < 6)
                    {
                        // ID : 6~20자 입력하세요
                        DialogFormMessage msg = new DialogFormMessage(null, 3, this.ParentForm.ParentForm.SystemConfig1.Language);
                        msg.ShowDialog();

                        return;
                    }
                }

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

                    return;
                }
                #endregion

                item.ID = this.textBoxID.Text;
                item.Password = this.textBoxPassword.Text;
                if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                {
                    item.ExpireId = int.Parse(this.labelExpiryDateOfAccount.Text);
                    item.ExpirePassword = int.Parse(this.labelExpiryDateOfPassword.Text);
                }
                else
                {
                    item.ExpireId = -1;
                    item.ExpirePassword = -1;
                }

                if (this.SelectedUserItem.Group == Define.E_UserGroup.Admin)
                    item.ActiveLevel = 9;
                else
                    item.ActiveLevel = this.comboBoxAccessRight.SelectedIndex + 1;

                menuId.fMenu = new bool[UserManager.USER_MENU_ID_MAX];
                for (int i = 0; i < UserManager.USER_MENU_ID_MAX; i++)
                    menuId.fMenu[i] = false;

                if (this.IsNew == true)
                {
                    #region 신규 등록
                    UserManager.UserManager_UserNew(item.ID, item.Password, item.IsAdmin == false ? 0 : 1, item.ExpirePassword, item.ExpireId, item.ActiveLevel, menuId);
                    #endregion
                }
                else
                {
                    #region 유저 수정
                    UserManager.UserManager_UserModify(item.ID, item.Password, item.IsAdmin == false ? 0 : 1, item.ExpirePassword, item.ExpireId, item.ActiveLevel, menuId);
                    //if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                    //{
                    //    if (item.ActiveLevel == 1 || item.ActiveLevel == 2 || item.ActiveLevel == 3)
                    //        UserManager.UserManager_UserModify(item.ID, item.Password, 0, item.ExpirePassword, item.ExpireId, item.ActiveLevel, menuId);
                    //    else
                    //        UserManager.UserManager_UserModify(item.ID, item.Password, 1, item.ExpirePassword, item.ExpireId, item.ActiveLevel, menuId);
                    //}
                    //else // Part11 미사용, Login 사용 시, 항상 관리자로 지정
                    //    UserManager.UserManager_UserModify(item.ID, item.Password, 1, item.ExpirePassword, item.ExpireId, item.ActiveLevel, menuId);
                    #endregion
                }

                this.buttonSave.Visible = false;
            }
        }

        private void UpdateInitializeUserDisplay(SystemConfigurationItem2 system)
        {
            this.SelectedUserItem = new UserItem();

            this.IsNew = true;

            this.textBoxID.Text = "";
            this.textBoxPassword.Text = this.SelectedUserItem.ResetPW;
            this.SetTextBoxPasswordChar(true);
            this.labelExpiryDateOfAccount.Text = "180";
            this.labelExpiryDateOfPassword.Text = "90";
            this.labelExpiryDateOfAccount2.Text = "-";
            this.labelExpiryDateOfPassword2.Text = "-";
            this.labelExpiryDateOfAccount2.ForeColor = Color.White;
            this.labelExpiryDateOfPassword2.ForeColor = Color.White;

            this.comboBoxAccessRight.Visible = true;
            this.comboBoxAccessRight.SelectedIndexChanged -= new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            this.comboBoxAccessRight.SelectedIndex = 0;
            this.comboBoxAccessRight.SelectedIndexChanged += new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);

            this.KeyboardClose();
            this.SetEnableID(true);
            this.SetEnablePassword(false);

            this.buttonDelete.Visible = false;
            this.buttonSave.Visible = false;
            this.VisibleAccountLockLabel(false);

            switch (this.ParentForm.ParentForm.SystemConfig1.Language)
            {
                case Define.E_LanguageID.Korean:
                    if (this.buttonResetPW.Text != "재설정")
                        this.buttonResetPW.Text = "재설정";
                    break;
                case Define.E_LanguageID.English:
                    if (this.buttonResetPW.Text != "Reset")
                        this.buttonResetPW.Text = "Reset";
                    break;
                case Define.E_LanguageID.Chinese:
                    if (this.buttonResetPW.Text != "重置")
                        this.buttonResetPW.Text = "重置";
                    break;
                case Define.E_LanguageID.Russian:
                    if (this.buttonResetPW.Text != "Сброс")
                        this.buttonResetPW.Text = "Сброс";
                    break;
                case Define.E_LanguageID.German:
                    if (this.buttonResetPW.Text != "zurücksetzen")
                        this.buttonResetPW.Text = "zurücksetzen";
                    break;
                case Define.E_LanguageID.Spanish:
                    if (this.buttonResetPW.Text != "reiniciar")
                        this.buttonResetPW.Text = "reiniciar";
                    break;
                default:
                    if (this.buttonResetPW.Text != "Reset")
                        this.buttonResetPW.Text = "Reset";
                    break;
            }

            this.listBoxUserList.SelectedIndexChanged -= new EventHandler(this.listBoxUserList_SelectedIndexChanged);
            this.listBoxUserList.SelectedIndex = -1;
            this.listBoxUserList.SelectedIndexChanged += new EventHandler(this.listBoxUserList_SelectedIndexChanged);
        }
        private void UpdateCurrentUserItem(UserManager.UserMgr_user_list_t item)
        {
            try
            {
                // CurrentUserItem SET
                this.SelectedUserItem.ID = item.user_id;
                this.SelectedUserItem.Password = item.user_pw;

                this.SelectedUserItem.ExpireId = item.id_expire_period;
                this.SelectedUserItem.ExpirePassword = item.password_expire_period;
                
                //if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                    this.SelectedUserItem.IsAdmin = item.fadmin == 0 ? false : true;
                //else
                //    this.SelectedUserItem.IsAdmin = true;

                this.SelectedUserItem.ActiveLevel = item.active_level;
                if (this.SelectedUserItem.ActiveLevel == 1)
                    this.SelectedUserItem.Group = Define.E_UserGroup.Level1;
                else if (this.SelectedUserItem.ActiveLevel == 2)
                    this.SelectedUserItem.Group = Define.E_UserGroup.Level2;
                else if (this.SelectedUserItem.ActiveLevel == 3)
                    this.SelectedUserItem.Group = Define.E_UserGroup.Level3;
                else if (this.SelectedUserItem.ActiveLevel == 9)
                    this.SelectedUserItem.Group = Define.E_UserGroup.Admin;
                else if (this.SelectedUserItem.ActiveLevel == 10)
                    this.SelectedUserItem.Group = Define.E_UserGroup.Developer;
                else
                    this.SelectedUserItem.Group = Define.E_UserGroup.None;

                if (this.SelectedUserItem.Group == Define.E_UserGroup.Admin
                    || this.SelectedUserItem.Group == Define.E_UserGroup.Developer)
                {
                    this.SelectedUserItem.DatePasswordRegister = DateTime.Now;
                    this.SelectedUserItem.DateIdLogin = DateTime.Now;
                    this.SelectedUserItem.DatePasswordExpire = DateTime.Now;
                    this.SelectedUserItem.DateIdExpire = DateTime.Now;
                }
                else
                {
                    DateTime time = DateTime.ParseExact(item.password_register_date.GetDateTime(), "yyyyMMddHHmmss", null);
                    this.SelectedUserItem.DatePasswordRegister = time;
                    time = DateTime.ParseExact(item.id_login_date.GetDateTime(), "yyyyMMddHHmmss", null);
                    this.SelectedUserItem.DateIdLogin = time;
                    time = DateTime.ParseExact(item.id_expire_date.GetDateTime(), "yyyyMMddHHmmss", null);
                    this.SelectedUserItem.DateIdExpire = time;
                    time = DateTime.ParseExact(item.password_expire_date.GetDateTime(), "yyyyMMddHHmmss", null);
                    this.SelectedUserItem.DatePasswordExpire = time;                    
                }

                this.SelectedUserItem.IsLockAccount = item.id_flock_status == 0 ? false : true;
                this.SelectedUserItem.IsLockPassword = item.flock_status_password == 0 ? false : true;

                this.SelectedUserItem.IsFirstPassword = item.fFirstPW;
            }
            catch (Exception ex)
            {
                FormMain.Exception(ex);
            }
        }
        private void UpdateCurrentUserItem(UserManager.UserMgr_user_info_t item)
        {
            // CurrentUserItem SET
            this.SelectedUserItem.ID = item.user_id;
            this.SelectedUserItem.Password = item.user_pw;

            this.SelectedUserItem.ExpireId = item.id_expire_period;
            this.SelectedUserItem.ExpirePassword = item.password_expire_period;

            if (this.SelectedUserItem.Group == Define.E_UserGroup.Admin
                    || this.SelectedUserItem.Group == Define.E_UserGroup.Developer)
            {
                this.SelectedUserItem.DatePasswordRegister = DateTime.Now;
                this.SelectedUserItem.DateIdLogin = DateTime.Now;
                this.SelectedUserItem.DatePasswordExpire = DateTime.Now;
                this.SelectedUserItem.DateIdExpire = DateTime.Now;
            }
            else
            {
                DateTime time = DateTime.ParseExact(item.password_register_date.GetDateTime(), "yyyyMMddHHmmss", null);
                this.SelectedUserItem.DatePasswordRegister = time;
                time = DateTime.ParseExact(item.id_login_date.GetDateTime(), "yyyyMMddHHmmss", null);
                this.SelectedUserItem.DateIdLogin = time;
                time = DateTime.ParseExact(item.id_expire_date.GetDateTime(), "yyyyMMddHHmmss", null);
                this.SelectedUserItem.DateIdExpire = time;
                time = DateTime.ParseExact(item.password_expire_date.GetDateTime(), "yyyyMMddHHmmss", null);
                this.SelectedUserItem.DatePasswordExpire = time;
            }

            this.SelectedUserItem.IsLockAccount = item.id_flock_status == 0 ? false : true;
            this.SelectedUserItem.IsLockPassword = item.password_flock_status == 0 ? false : true;

            //if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.SelectedUserItem.IsAdmin = item.fadmin == 0 ? false : true;
            //else
            //    this.SelectedUserItem.IsAdmin = true;

            this.SelectedUserItem.ActiveLevel = item.active_level;
            if (item.active_level == 1)
                this.SelectedUserItem.Group = Define.E_UserGroup.Level1;
            else if (item.active_level == 2)
                this.SelectedUserItem.Group = Define.E_UserGroup.Level2;
            else if (item.active_level == 3)
                this.SelectedUserItem.Group = Define.E_UserGroup.Level3;
            else if (item.active_level == 9)
                this.SelectedUserItem.Group = Define.E_UserGroup.Admin;
            else if (item.active_level == 10)
                this.SelectedUserItem.Group = Define.E_UserGroup.Developer;

            this.SelectedUserItem.IsFirstPassword = item.fFirstPW;
        }
        private void UpdateSelectUserDisplay(UserItem item)
        {
            this.SetEnableID(false);
            this.SetEnableControl(true);

            this.textBoxID.Text = item.ID;
            this.textBoxPassword.Text = item.Password;
            if (this.listBoxUserList.SelectedIndex == 0)
            {
                this.labelExpiryDateOfAccount.Text = "0";
                this.labelExpiryDateOfPassword.Text = "0";
                this.labelExpiryDateOfAccount2.Text = "-";
                this.labelExpiryDateOfPassword2.Text = "-";
                this.labelExpiryDateOfAccount2.ForeColor = Color.White;
                this.labelExpiryDateOfPassword2.ForeColor = Color.White;

                this.buttonDelete.Visible = false;
                this.comboBoxAccessRight.Visible = false;
                this.SetEnableExpireDate(false);
                this.VisibleAccountLockLabel(false);

                if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.Admin
                    || this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.Developer)
                    this.SetEnablePassword(true);
                else
                    this.SetEnablePassword(false);
            }
            else
            {

                if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                {
                    #region 만료일
                    this.labelExpiryDateOfAccount.Text = item.ExpireId.ToString();
                    this.labelExpiryDateOfPassword.Text = item.ExpirePassword.ToString();

                    if (item.IsLockAccount == true)
                    {
                        this.labelExpiryDateOfAccount2.ForeColor = Color.Red;
                        switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                        {
                            case Define.E_LanguageID.Korean:
                                this.labelExpiryDateOfAccount2.Text = "계정 만료";
                                break;
                            case Define.E_LanguageID.English:
                                this.labelExpiryDateOfAccount2.Text = "Account expiration";
                                break;
                            case Define.E_LanguageID.Chinese:
                                this.labelExpiryDateOfAccount2.Text = "账户过期";
                                break;
                            case Define.E_LanguageID.Russian:
                                this.labelExpiryDateOfAccount2.Text = "Срок действия учетной записи";
                                break;
                            case Define.E_LanguageID.German:
                                this.labelExpiryDateOfAccount2.Text = "Kontoablauf";
                                break;
                            case Define.E_LanguageID.Spanish:
                                this.labelExpiryDateOfAccount2.Text = "Caducidad de la cuenta";
                                break;
                            default:
                                break;
                        }

                        this.buttonLockRelease.Visible = true;
                    }
                    else
                    {
                        this.labelExpiryDateOfAccount2.ForeColor = Color.White;
                        this.labelExpiryDateOfAccount2.Text = string.Format("{0:yy/MM/dd} ~ {1:yy/MM/dd}", item.DateIdLogin, item.DateIdExpire);

                        this.buttonLockRelease.Visible = false;
                    }

                    if (item.IsLockPassword == true)
                    {
                        this.labelExpiryDateOfPassword2.ForeColor = Color.Red;
                        switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                        {
                            case Define.E_LanguageID.Korean:
                                this.labelExpiryDateOfPassword2.Text = "비밀번호 만료";
                                break;
                            case Define.E_LanguageID.English:
                                this.labelExpiryDateOfPassword2.Text = "Password expiration";
                                break;
                            case Define.E_LanguageID.Chinese:
                                this.labelExpiryDateOfPassword2.Text = "密码过期";
                                break;
                            case Define.E_LanguageID.Russian:
                                this.labelExpiryDateOfPassword2.Text = "Срок действия пароля";
                                break;
                            case Define.E_LanguageID.German:
                                this.labelExpiryDateOfPassword2.Text = "Kennwortablauf";
                                break;
                            case Define.E_LanguageID.Spanish:
                                this.labelExpiryDateOfPassword2.Text = "Caducidad de la contraseña";
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        this.labelExpiryDateOfPassword2.ForeColor = Color.White;
                        this.labelExpiryDateOfPassword2.Text = string.Format("{0:yy/MM/dd} ~ {1:yy/MM/dd}", item.DatePasswordRegister, item.DatePasswordExpire);
                    }
                    #endregion

                    if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ActiveLevel < item.ActiveLevel)
                    {
                        this.buttonDelete.Visible = false;
                        this.comboBoxAccessRight.Enabled = false;
                        this.SetEnableExpireDate(false);

                        this.SetEnablePassword(false);
                    }
                    else
                    {
                        this.SetEnableExpireDate(true);
                        this.comboBoxAccessRight.Enabled = true;
                    }
                }
                else
                {
                    if (item.IsLockAccount == true)
                    {
                        switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                        {
                            case Define.E_LanguageID.Korean:
                                this.labelAccountLock.Text = "잠김";
                                break;
                            case Define.E_LanguageID.English:
                                this.labelAccountLock.Text = "Lock";
                                break;
                            case Define.E_LanguageID.Chinese:
                                this.labelAccountLock.Text = "锁住";
                                break;
                            case Define.E_LanguageID.Russian:
                                this.labelAccountLock.Text = "Блок";
                                break;
                            case Define.E_LanguageID.German:
                                this.labelAccountLock.Text = "Sperren";
                                break;
                            case Define.E_LanguageID.Spanish:
                                this.labelAccountLock.Text = "Cerrar con llave";
                                break;
  
                            default:
                                break;
                        }

                        this.VisibleAccountLockLabel(true);
                    }
                    else
                    {
                        this.VisibleAccountLockLabel(false);
                    }

                    if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ActiveLevel < item.ActiveLevel)
                    {
                        this.buttonDelete.Visible = false;
                        this.comboBoxAccessRight.Enabled = false;

                        this.SetEnablePassword(false);
                    }
                    else
                    {
                        this.comboBoxAccessRight.Enabled = true;
                    }
                }

                this.comboBoxAccessRight.Visible = true;
                this.comboBoxAccessRight.BringToFront();
                this.comboBoxAccessRight.SelectedIndexChanged -= new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
                this.comboBoxAccessRight.SelectedIndex = item.ActiveLevel - 1;
                this.comboBoxAccessRight.SelectedIndexChanged += new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            }

            if (this.textBoxPassword.Text == this.SelectedUserItem.ResetPW)
                this.SetTextBoxPasswordChar(true);
            else
                this.SetTextBoxPasswordChar(false);

            //this.cbAdministrator.Visible = true;
            //this.cbAdministrator.Checked = item.IsAdmin;
        }
        private void UpdateUserListBoxDisplay(List<string> items)
        {
            this.listBoxUserList.Items.Clear();
            for (int i = 1; i < items.Count; i++)
                this.listBoxUserList.Items.Add(items[i]);
        }

        public void CallBackGetUserData(UserManager.UserMgr_user_list_t user)
        {
            this.UpdateCurrentUserItem(user);

            this.UI_Invoke(delegate
            {
                this.UpdateSelectUserDisplay(this.SelectedUserItem);
            });
        }
        public void CallBackUserListNewData(UserManager.UserMgr_user_info_t user)
        {
            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 = "User settings";
                    message1 = "User addition complete!";
                    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 = "Benutzereinstellungen";
                    message1 = "Benutzerhinzufügung abgeschlossen!";
                    message2 = "";
                    break;
                case Define.E_LanguageID.Spanish:
                    code = "Ajustes de usuario";
                    message1 = "Adición de usuario completa!";
                    message2 = "";
                    break;
                default:
                    break;
            }

            if (user.status == (int)UserManager.E_user_mgr_status.USER_MGR_STATUS_OK)
            {
                this.UI_Invoke(delegate
                {
                    string detail = "";

                    detail = string.Format("Add : {0}", user.user_id);
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);

                    this.UpdateCurrentUserItem(user);
                    this.UpdateSelectUserDisplay(this.SelectedUserItem);

                    this.ParentForm.ParentForm.ListDllUserName.Add(user.user_id);
                    this.UpdateUserListBoxDisplay(this.ParentForm.ParentForm.ListDllUserName);
                    this.listBoxUserList.SelectedIndex = this.listBoxUserList.Items.Count - 1;

                    this.SetEnableID(false);
                    this.SetEnableExpireDate(false);
                    //this.labelAutomaticLogoutTime.Enabled = false;

                    DialogFormMessage dlg = new DialogFormMessage(Define.E_MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    dlg.ShowDialog();
                });
            }
            else
            {
                DialogFormMessage msg = new DialogFormMessage(null, user.status, this.ParentForm.ParentForm.SystemConfig1.Language);
                msg.ShowDialog();
            }
        }
        public void CallBackUserModifyUserData(UserManager.UserMgr_user_modify_t user)
        {
            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 = "User settings";
                    message1 = "User information modified!";
                    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 = "Benutzereinstellungen";
                    message1 = "Benutzerinformationen geändert!";
                    message2 = "";
                    break;
                case Define.E_LanguageID.Spanish:
                    code = "Ajustes de usuario";
                    message1 = "¡Información de usuario modificada!";
                    message2 = "";
                    break;
                default:
                    break;
            }

            if (user.status == (int)UserManager.E_user_mgr_status.USER_MGR_STATUS_OK)
            {
                this.UI_Invoke(delegate
                {
                    string detail = "";

                    detail = string.Format("Modify : {0}", user.user_id);
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);

                    // 메시지 박스 교체
                    UserManager.UserManager_GetUserListID(this.listBoxUserList.SelectedItem.ToString());

                    DialogFormMessage dlg = new DialogFormMessage(Define.E_MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    dlg.ShowDialog();
                });
            }
            else
            {
                DialogFormMessage msg = new DialogFormMessage(null, user.status, this.ParentForm.ParentForm.SystemConfig1.Language);
                msg.ShowDialog();
            }
        }
        public void CallBackUserListLockDataEvent(UserManager.UserMgr_user_lock_t user)
        {
            if (user.user_id == this.SelectedUserItem.ID)
            {
                this.SelectedUserItem.IsLockAccount = user.flock_status_account == 0 ? false : true;
                this.SelectedUserItem.IsLockPassword = user.flock_status_password == 0 ? false : true;

                UserManager.UserManager_GetUserListID(this.SelectedUserItem.ID);
            }
        }
        public void CallBackUserListDeleteDataEvent(UserManager.UserMgr_user_del_t user)
        {
            string code = "", message1 = "", message2 = "", detail = "";

            switch (this.ParentForm.ParentForm.SystemConfig1.Language)
            {
                case Define.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = string.Format("{0} 사용자 삭제 완료!", user.user_id);
                    message2 = "";
                    break;
                case Define.E_LanguageID.English:
                    code = "User settings";
                    message1 = string.Format("{0} User deletion complete!", user.user_id);
                    message2 = "";
                    break;
                case Define.E_LanguageID.Chinese:
                    code = "用户设置";
                    message1 = string.Format("{0} 用户添加完成！", user.user_id);
                    message2 = "";
                    break;
                case Define.E_LanguageID.Russian:
                    code = "Пользовательские настройки";
                    message1 = string.Format("{0} Добавление пользователя завершено!", user.user_id);
                    message2 = "";
                    break;
                case Define.E_LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = string.Format("{0} Benutzerhinzufügung abgeschlossen!", user.user_id);
                    message2 = "";
                    break;
                case Define.E_LanguageID.Spanish:
                    code = "Ajustes de usuario";
                    message1 = string.Format("{0} Adición de usuario completa!", user.user_id);
                    message2 = "";
                    break;
                default:
                    break;
            }

            if (user.status == 0)
            {
                for (int i = 0; i < this.ParentForm.ParentForm.ListDllUserName.Count; i++)
                {
                    if (this.ParentForm.ParentForm.ListDllUserName[i] == user.user_id)
                    {
                        this.ParentForm.ParentForm.ListDllUserName.RemoveAt(i);
                        break;
                    }
                }

                this.UI_Invoke(delegate
                {
                    this.UpdateUserListBoxDisplay(this.ParentForm.ParentForm.ListDllUserName);

                    this.UserNew();

                    DialogFormMessage dlg = new DialogFormMessage(Define.E_MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    dlg.ShowDialog();
                });

                //// Part 11
                //if (this.ParentForm.ParentForm.SystemConfig.IsPart11 == true)
                //{
                detail = string.Format("Delete : {0}", user.user_id);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
                //}
            }
            else
            {
                DialogFormMessage msg = new DialogFormMessage(null, user.status, this.ParentForm.ParentForm.SystemConfig1.Language);
                msg.ShowDialog();
            }
        }
        public void CallBackUserListModifyInfoDataEvent(UserManager.UserMgr_user_info_t user)
        {
            try
            {
                if (user.status == 0)
                {
                    string detail = "", code = "", message1 = "", message2 = "";

                    this.textBoxPassword.Text = user.user_pw;
                    this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Password = user.user_pw;

                    detail = string.Format("Modify Password : {0}", user.user_id);
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);

                    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.EquipUser;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.PasswordChar = false;
            this.labelAutomaticLogoutTime.Text = this.ParentForm.ParentForm.SystemConfig2.UserAutomaticLogout.ToString();
            //this.labelAutomaticLogoutTime.Enabled = true;
            this.labelNumberOfLoginFailures.Text = this.ParentForm.ParentForm.SystemConfig3.NumberOfLoginFailures.ToString();

            this.buttonLockRelease.Visible = false;

            this.UpdateUserListBoxDisplay(this.ParentForm.ParentForm.ListDllUserName);
            this.UpdateInitializeUserDisplay(this.ParentForm.ParentForm.SystemConfig2);
        }
        #endregion

        #region Event Handler
        private void listBoxUserList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = this.listBoxUserList.SelectedIndex;
            this.IsNew = false;

            this.SetEnablePassword(false);
            //this.labelAutomaticLogoutTime.Enabled = true;
            this.buttonSave.Visible = false;
            switch (this.ParentForm.ParentForm.SystemConfig1.Language)
            {
                case Define.E_LanguageID.Korean:
                    if (this.buttonResetPW.Text != "재설정")
                        this.buttonResetPW.Text = "재설정";
                    break;
                case Define.E_LanguageID.English:
                    if (this.buttonResetPW.Text != "Reset")
                        this.buttonResetPW.Text = "Reset";
                    break;
                case Define.E_LanguageID.Chinese:
                    if (this.buttonResetPW.Text != "重置")
                        this.buttonResetPW.Text = "重置";
                    break;
                case Define.E_LanguageID.Russian:
                    if (this.buttonResetPW.Text != "Сброс")
                        this.buttonResetPW.Text = "Сброс";
                    break;
                case Define.E_LanguageID.German:
                    if (this.buttonResetPW.Text != "zurücksetzen")
                        this.buttonResetPW.Text = "zurücksetzen";
                    break;
                case Define.E_LanguageID.Spanish:
                    if (this.buttonResetPW.Text != "reiniciar")
                        this.buttonResetPW.Text = "reiniciar";
                    break;
                default:
                    if (this.buttonResetPW.Text != "Reset")
                        this.buttonResetPW.Text = "Reset";
                    break;
            }

            if (index == 0)
            {
                UserManager.UserManager_GetUserListID(this.listBoxUserList.Items[index].ToString());
                this.SetEnablePassword(true);
                switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                {
                    case Define.E_LanguageID.Korean:
                        if (this.buttonResetPW.Text != "수정")
                            this.buttonResetPW.Text = "수정";
                        break;
                    case Define.E_LanguageID.English:
                        if (this.buttonResetPW.Text != "Edit")
                            this.buttonResetPW.Text = "Edit";
                        break;
                    case Define.E_LanguageID.Chinese:
                        if (this.buttonResetPW.Text != "编辑")
                            this.buttonResetPW.Text = "编辑";
                        break;
                    case Define.E_LanguageID.Russian:
                        if (this.buttonResetPW.Text != "Ред")
                            this.buttonResetPW.Text = "Ред";
                        break;
                    case Define.E_LanguageID.German:
                        if (this.buttonResetPW.Text != "Bearbeiten")
                            this.buttonResetPW.Text = "Bearbeiten";
                        break;
                    case Define.E_LanguageID.Spanish:
                        if (this.buttonResetPW.Text != "Editar")
                            this.buttonResetPW.Text = "Editar";
                        break;
        default:
                        if (this.buttonResetPW.Text != "Edit")
                            this.buttonResetPW.Text = "Edit";
                        break;
                }
            }
            else if (index < 0)
            {
                this.UpdateInitializeUserDisplay(this.ParentForm.ParentForm.SystemConfig2);
            }
            else if (index > 0)
            {
                if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ID == this.listBoxUserList.Items[index].ToString())
                    this.buttonDelete.Visible = false;
                else
                    this.buttonDelete.Visible = true;

                this.SetEnableID(false);
                this.SetEnableControl(true);

                UserManager.UserManager_GetUserListID(this.listBoxUserList.Items[index].ToString());
            }
        }

        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 textBoxID_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                e.Handled = true;

                this.ParentForm.Enabled = true;
                this.KeyboardClose();

                if (this.buttonSave.Visible == false)
                    this.buttonSave.Visible = true;
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;

                this.ParentForm.Enabled = true;
                this.textBoxID.Text = this.BeforeID;
                this.KeyboardClose();
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }
        private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                e.Handled = true;

                if (this.PasswordChar == false)
                    this.SetTextBoxPasswordChar(this.PasswordChar);
                this.KeyboardClose();

                if (this.IsNew == true)
                    this.SetEnableID(true);

                if (this.buttonSave.Visible == false)
                    this.buttonSave.Visible = true;
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;

                if (this.PasswordChar == false)
                    this.SetTextBoxPasswordChar(this.PasswordChar);
                if (this.IsNew == true)
                    this.SetEnableID(true);
                this.textBoxPassword.Text = this.BeforePassword;
                this.KeyboardClose();
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }

        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            if (this.smartKeyboard.TargetInputObject == this.textBoxPassword)
            {
                this.textBoxPassword.Text = this.BeforePassword;
                if (this.PasswordChar == false)
                    this.SetTextBoxPasswordChar(this.PasswordChar);
                this.textBoxPassword.Select(this.textBoxPassword.Text.Length, 0);
            }
            else if (this.smartKeyboard.TargetInputObject == this.textBoxID)
            {
                this.textBoxID.Text = this.BeforeID;
                this.textBoxID.Select(this.textBoxID.Text.Length, 0);
            }

            this.KeyboardClose();

            if (this.IsNew == true)
                this.SetEnableID(true);
        }

        private void buttonNew_Click(object sender, EventArgs e)
        {
            this.UserNew();
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            this.SaveUserDll();
        }
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (this.listBoxUserList.SelectedIndex == -1)
                return;

            // 사용자를 삭제 하시겠습니까?
            DialogFormYesNo dlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 14);
            if (dlg.ShowDialog() == DialogResult.Yes)
            {
                if (this.listBoxUserList.Items.Count <= 1)
                    return;

                if (this.listBoxUserList.SelectedIndex <= 0)
                    return;

                string id = this.listBoxUserList.Items[this.listBoxUserList.SelectedIndex].ToString();

                UserManager.UserManager_UserDel(id);

                this.buttonDelete.Visible = false;
            }
        }

        private void comboBoxAccessRight_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }

        private void buttonIDEdit_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(3, 43);
            this.smartKeyboard.Size = new Size(704, 276);
            this.smartKeyboard.Hide();

            this.BeforeID = this.textBoxID.Text;

            this.smartKeyboard.TargetInputObject = this.textBoxID;
            this.smartKeyboard.Show();

            this.textBoxID.Select(this.textBoxID.Text.Length, 0);

            this.listBoxUserList.Enabled = false;
            this.SetEnableControl(false);
        }
        private void buttonResetPW_Click(object sender, EventArgs e)
        {
            if (this.listBoxUserList.SelectedIndex == 0)
            {
                if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ActiveLevel < 9)
                    return;

                this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
                this.smartKeyboard.Location = new Point(3, 74);
                this.smartKeyboard.Size = new Size(704, 276);
                this.smartKeyboard.Hide();

                this.BeforePassword = this.textBoxPassword.Text;

                this.smartKeyboard.TargetInputObject = this.textBoxPassword;
                this.smartKeyboard.Show();

                this.SetTextBoxPasswordChar(true);
                this.textBoxPassword.Select(this.textBoxPassword.Text.Length, 0);

                this.listBoxUserList.Enabled = false;
                this.SetEnableControl(false);
                this.SetEnableID(false);
            }
            else
            {
                int ret = 0;
                string id = "", pw = "";

                if (this.listBoxUserList.Items.Count <= 1)
                    return;

                if (this.listBoxUserList.SelectedIndex <= 0)
                    return;

                // 메시지
                // 비밀번호를 초기화 하시겠습니까?
                DialogFormYesNo dlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 29);
                if (dlg.ShowDialog() == DialogResult.Yes)
                {
                    id = this.SelectedUserItem.ID;
                    pw = this.SelectedUserItem.ResetPW;

                    ret = UserManager.UserManager_UserResetPWDirect(id, pw);

                    if (ret == 0)
                    {
                        this.SetTextBoxPasswordChar(true);
                        this.textBoxPassword.Text = pw;
                    }
                }
            }
        }
        private void labelExpiryDateOfAccount_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelExpiryDateOfAccount.Text, 3, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue <= 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else if (myKeyPad.IntValue > 180)
                {
                    this.labelExpiryDateOfAccount.Text = "180";

                    if (this.buttonSave.Visible == false)
                        this.buttonSave.Visible = true;
                }
                else
                {
                    this.labelExpiryDateOfAccount.Text = myKeyPad.StringValue;

                    if (this.buttonSave.Visible == false)
                        this.buttonSave.Visible = true;
                }
            }
        }
        private void labelExpiryDateOfPassword_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelExpiryDateOfPassword.Text, 3, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue <= 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else if (myKeyPad.IntValue > 90)
                {
                    this.labelExpiryDateOfPassword.Text = "90";

                    if (this.buttonSave.Visible == false)
                        this.buttonSave.Visible = true;
                }
                else
                {
                    this.labelExpiryDateOfPassword.Text = myKeyPad.StringValue;

                    if (this.buttonSave.Visible == false)
                        this.buttonSave.Visible = true;
                }
            }
        }
        private void labelAutomaticLogoutTime_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = this.labelAutomaticLogoutTime.Text;
             DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelAutomaticLogoutTime.Text, 2, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

             if (myKeyPad.ShowDialog() == DialogResult.OK)
             {
                 if (myKeyPad.IntValue < 0)
                 {
                     // 입력범위를 확인하세요
                     DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                     myMsg.ShowDialog();
                 }
                 else if (myKeyPad.IntValue > 90)
                 {
                     this.labelAutomaticLogoutTime.Text = "90";
                 }
                 else
                 {
                     this.labelAutomaticLogoutTime.Text = myKeyPad.StringValue;
                 }

                 this.ParentForm.ParentForm.SystemConfig2.UserAutomaticLogout = myKeyPad.IntValue;

                 if (this.ParentForm.ParentForm.SystemConfig2.UserAutomaticLogout == 1)
                     this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime = 30;
                 else
                     this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime = 60;

                 after = this.labelAutomaticLogoutTime.Text;
                 this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);

                 UserManager.UserManager_AutoLogoutSetTimeout(this.ParentForm.ParentForm.SystemConfig2.UserAutomaticLogout, this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime);

                 this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.AutoLogout, "", before, after);
             }
        }
        private void labelNumberOfLoginFailures_Click(object sender, EventArgs e)
        {
            string before = "", after = "";
            before = this.labelNumberOfLoginFailures.Text;
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelNumberOfLoginFailures.Text, 2, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue <= 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelNumberOfLoginFailures.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.SystemConfig3.NumberOfLoginFailures = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile3(this.ParentForm.ParentForm.SystemConfig3);

                    after = this.labelNumberOfLoginFailures.Text;
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.NumberOfLoginFailure, "", before, after);
                }
            }
        }
        private void buttonLockRelease_Click(object sender, EventArgs e)
        {
            string code = "", message1 = "", message2 = "";
            string detail = "";

            switch (this.ParentForm.ParentForm.SystemConfig1.Language)
            {
                case Define.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case Define.E_LanguageID.English:
                    code = "User settings";
                    message1 = "Do you want to unlock user?";
                    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 = "Benutzereinstellungen";
                    message1 = "Möchten Sie Benutzer entsperren?";
                    message2 = "";
                    break;
                case Define.E_LanguageID.Spanish:
                    code = "Ajustes de usuario";
                    message1 = "¿Quieres desbloquear usuario?";
                    message2 = "";
                    break;
                default:
                    break;
            }

            DialogFormYesNo dlg = new DialogFormYesNo(Define.E_MessageBoxIcon.Question, code, message1, message2);
            if (dlg.ShowDialog() == DialogResult.Yes)
            {
                UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, true, false);

                // Part 11
                detail = string.Format("Release ID : {0}", this.SelectedUserItem.ID);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            }
        }

        private void labelExpiryDateOfAccount2_Click(object sender, EventArgs e)
        {
            string code = "", message1 = "", message2 = "";
            string detail = "";

            if (this.labelExpiryDateOfAccount2.ForeColor == Color.White)
            {
                if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ActiveLevel < (int)Define.E_UserGroup.Level3)
                    return;

                UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, true, false);

                // Part 11
                detail = string.Format("Extend EXP date(ID) : {0}", this.SelectedUserItem.ID);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            }
            //else
            //{
            //    switch (this.ParentForm.ParentForm.SystemConfig1.Language)
            //    {
            //        case Define.E_LanguageID.Korean:
            //            code = "유저설정";
            //            message1 = "사용자 잠금 해제 하시겠습니까?";
            //            message2 = "";
            //            break;
            //        case Define.E_LanguageID.English:
            //            code = "User settings";
            //            message1 = "Do you want to unlock user?";
            //            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 = "Benutzereinstellungen";
            //            message1 = "Möchten Sie Benutzer entsperren?";
            //            message2 = "";
            //            break;
            //        case Define.E_LanguageID.Spanish:
            //            code = "Ajustes de usuario";
            //            message1 = "¿Quieres desbloquear usuario?";
            //            message2 = "";
            //            break;
            //        default:
            //            break;
            //    }

            //    DialogFormYesNo dlg = new DialogFormYesNo(Define.E_MessageBoxIcon.Question, code, message1, message2);
            //    if (dlg.ShowDialog() == DialogResult.Yes)
            //    {
            //        UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, true, false);

            //        // Part 11
            //        detail = string.Format("Release ID : {0}", this.SelectedUserItem.ID);
            //        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            //    }
            //}
        }
        private void labelExpiryDateOfPassword2_Click(object sender, EventArgs e)
        {
            string code = "", message1 = "", message2 = "";
            string detail = "";

            if (this.labelExpiryDateOfPassword2.ForeColor == Color.White)
            {
                if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ActiveLevel < (int)Define.E_UserGroup.Level3)
                    return;

                UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, false, true);

                // Part 11
                detail = string.Format("Extend EXP date(PW) : {0}", this.SelectedUserItem.ID);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            }
            else
            {
                switch (this.ParentForm.ParentForm.SystemConfig1.Language)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저설정";
                        message1 = "비밀번호 잠금 해제 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User settings";
                        message1 = "Do you want to unlock password?";
                        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 = "Benutzereinstellungen";
                        message1 = "Möchten Sie das Passwort entsperren?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.Spanish:
                        code = "Ajustes de usuario";
                        message1 = "¿Quieres desbloquear la contraseña?";
                        message2 = "";
                        break;
                    default:
                        break;
                }

                DialogFormYesNo dlg = new DialogFormYesNo(Define.E_MessageBoxIcon.Question, code, message1, message2);
                if (dlg.ShowDialog() == DialogResult.Yes)
                {
                    UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, false, true);

                    // Part 11
                    detail = string.Format("Release PW: {0}", this.SelectedUserItem.ID);
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
                }
            }
        }

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

            // 잠금이 해제되었습니다
            DialogFormMessage msg = new DialogFormMessage(null, 18, this.ParentForm.ParentForm.SystemConfig1.Language);
            msg.ShowDialog();

            UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, true, true);

            detail = string.Format("Release ID: {0}", this.SelectedUserItem.ID);
            this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
        }

        private void buttonGroupEditor_Click(object sender, EventArgs e)
        {
            this.ParentForm.CenterEquipUserGroupEditor.Visible = true;
            this.ParentForm.CenterEquipUserGroupEditor.BringToFront();
            this.ParentForm.CenterEquipUserGroupEditor.DisplayRefresh(this.ParentForm.ParentForm.CurrentSystemStatus);
        }
        #endregion
    }
}
