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

using INT69DB_2A_ImageDll;
using INT69DB_2A.Controls;
using INT69DB_2A.Part11_UserManager;
using INT69DB_2A.DialogForms;

namespace INT69DB_2A.Forms
{
    public partial class FormUserEditor : Form
    {
        #region Field
        private FormMain m_ParentForm;

        private UserItem SelectedUserItem;
        private ControlUserSetting ChildControlUserSet;

        private bool IsNew;
        private bool PasswordChar;

        private string BeforeID;
        private string BeforePassword;
        #endregion

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

            this.ParentForm = parent;

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

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

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

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    this.labelTitle.Text = "유저설정";
                    this.labelStatusExpireAccount.Text = "만료";
                    this.labelStatusExpirePassword.Text = "만료";
                    break;
                case DataStore.LanguageID.English:
                    this.labelTitle.Text = "User";
                    this.labelStatusExpireAccount.Text = "Expiration";
                    this.labelStatusExpirePassword.Text = "Expiration";
                    break;
                case DataStore.LanguageID.Chinese:
                    this.labelTitle.Text = "用户设置";
                    this.labelStatusExpireAccount.Text = "过期";
                    this.labelStatusExpirePassword.Text = "过期";
                    break;
                case DataStore.LanguageID.Czech:
                    this.labelTitle.Text = "Uživatelské nastavení";
                    this.labelStatusExpireAccount.Text = "Vypršení";
                    this.labelStatusExpirePassword.Text = "Vypršení";
                    break;
                case DataStore.LanguageID.Russian:
                    this.labelTitle.Text = "Пользователь";
                    this.labelStatusExpireAccount.Text = "Истечение срока";
                    this.labelStatusExpirePassword.Text = "Истечение срока";
                    break;
                case DataStore.LanguageID.German:
                    this.labelTitle.Text = "Benutzereinstellungen";
                    this.labelStatusExpireAccount.Text = "Ablauf";
                    this.labelStatusExpirePassword.Text = "Ablauf";
                    break;
                default:
                    break;
            }
        }
        private void DefaultSetting()
        {
            this.IsNew = false;
            this.PasswordChar = false;
            this.BeforeID = "";
            this.BeforePassword = "";
            this.DisplayOnlyPart11Item(this.ParentForm.SystemConfig.IsPart11);

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

            this.ChildControlUserSet = new ControlUserSetting(this);
            this.Controls.Add(this.ChildControlUserSet);
            this.ChildControlUserSet.Location = new Point(0, 69);
            this.ChildControlUserSet.Visible = false;
        }

        private void SetEnableID(bool value)
        {
            if (value == true)
                this.labelID.BackColor = Color.White;
            else
                this.labelID.BackColor = Color.Silver;
        }
        private void SetEnablePassword(bool value)
        {
            if (value == true)
                this.labelPassword.BackColor = Color.White;
            else
                this.labelPassword.BackColor = Color.Silver;
        }
        private void SetEnableOnlyPart11Value(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.SetEnableOnlyPart11Value(value);
        }

        private void SaveUserDll()
        {
            string code = "", message1 = "", message2 = "";
            string detail = "";

            #region listbox 미선택 시 신규 유저 등록, 선택 시 기존 유저 정보 수정
            if (this.IsNew == true)
            {
                switch (this.ParentForm.SystemConfig.Language)
                {
                    case DataStore.LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "신규 사용자 추가 하시겠습니까?";
                        message2 = "";
                        break;
                    case DataStore.LanguageID.English:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    case DataStore.LanguageID.Chinese:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    case DataStore.LanguageID.Czech:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    case DataStore.LanguageID.German:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (this.ParentForm.SystemConfig.Language)
                {
                    case DataStore.LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "선택된 사용자의 정보를 수정 하시겠습니까?";
                        message2 = "";
                        break;
                    case DataStore.LanguageID.English:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    case DataStore.LanguageID.Chinese:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    case DataStore.LanguageID.Czech:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    case DataStore.LanguageID.German:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    default:
                        break;
                }
            }
            #endregion

            DialogFormYesNo dlg = new DialogFormYesNo(DataStore.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 검사
                // Chck ID
                if (this.IsNew == true)
                {
                    if (this.labelID.Text.Length < 6)
                    {
                        // ID : 6~20자 입력하세요
                        DialogFormMessage msg = new DialogFormMessage(null, 3, this.ParentForm.SystemConfig.Language);
                        msg.ShowDialog();

                        return;
                    }
                }

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

                if (this.labelExpiryDateOfAccount.Text == "000")
                {
                    DialogFormMessage msg = new DialogFormMessage(null, 16, this.ParentForm.SystemConfig.Language);
                    msg.ShowDialog();

                    return;
                }

                if (this.labelExpiryDateOfPassword.Text == "00")
                {
                    DialogFormMessage msg = new DialogFormMessage(null, 16, this.ParentForm.SystemConfig.Language);
                    msg.ShowDialog();

                    return;
                }
                #endregion

                item.ID = this.labelID.Text;
                item.SetPassword(this.labelPassword.Text);
                item.ExpireAccount = int.Parse(this.labelExpiryDateOfAccount.Text);
                item.ExpirePassword = int.Parse(this.labelExpiryDateOfPassword.Text);

                //item.IsAdmin = this.cbAdministrator.Checked;

                if (this.SelectedUserItem.Group == DataStore.UserGroup.Admin)
                {
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        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 신규 등록
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                    {
                        if (item.ActiveLevel == 1 || item.ActiveLevel == 2 || item.ActiveLevel == 3)
                            UserManager.UserManager_UserNew(item.ID, item.Password, 0, item.ExpirePassword, item.ExpireAccount, item.ActiveLevel, menuId);
                        else
                            UserManager.UserManager_UserNew(item.ID, item.Password, 1, item.ExpirePassword, item.ExpireAccount, item.ActiveLevel, menuId);
                    }
                    else // Part11 미사용, Login 사용 시, 항상 관리자로 지정
                        UserManager.UserManager_UserNew(item.ID, item.Password, 1, item.ExpirePassword, item.ExpireAccount, item.ActiveLevel, menuId);

                    // Part 11
                    detail = string.Format("Add : {0}", item.ID);
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.UserEditor, detail);
                    #endregion
                }
                else
                {
                    #region 유저 수정
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                    {
                        if (item.ActiveLevel == 1 || item.ActiveLevel == 2 || item.ActiveLevel == 3)
                            UserManager.UserManager_UserModify(item.ID, item.Password, 0, item.ExpirePassword, item.ExpireAccount, item.ActiveLevel, menuId);
                        else
                            UserManager.UserManager_UserModify(item.ID, item.Password, 1, item.ExpirePassword, item.ExpireAccount, item.ActiveLevel, menuId);
                    }
                    else // Part11 미사용, Login 사용 시, 항상 관리자로 지정
                        UserManager.UserManager_UserModify(item.ID, item.Password, 1, item.ExpirePassword, item.ExpireAccount, item.ActiveLevel, menuId);

                    // Part 11
                    detail = string.Format("Modify : {0}", item.ID);
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.UserEditor, detail);
                    #endregion
                }

                #region 자동 로그아웃 타임
                //this.ParentForm.ParentForm.SystemConfig.AUTOMATIC_LOGOUT = int.Parse(this.labelAutomaticLogoutTime.Text);

                //if (this.ParentForm.ParentForm.SystemConfig.AUTOMATIC_LOGOUT == 1)
                //    this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime = 30;
                //else
                //    this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime = 60;

                //UserManager.UserManager_AutoLogoutSetTimeout(this.ParentForm.ParentForm.SystemConfig.AUTOMATIC_LOGOUT, this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime);
                #endregion
            }
        }
        private void ChangeUserControlEnable(bool enable)
        {
            this.listBoxUserList.Enabled = enable;
            this.smartGroupBox1.Enabled = enable;
            this.buttonGroupEditor.Enabled = enable;
            this.buttonBack.Enabled = enable;
        }
        private void UserNew()
        {
            this.UpdateInitializeUserDisplay(this.ParentForm.SystemConfig);
        }
        private Color ReturnColor(bool bValue)
        {
            if (bValue == true)
                return Color.Black;
            else
                return Color.DarkGray;
        }
        private void CheckBoxCheckedAsLevel(DataStore.UserGroup level)
        {
            switch (level)
            {
                case DataStore.UserGroup.Level1:
                    this.labelProductNo.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo);
                    this.labelClear.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear);
                    this.labelSubMenu.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplaySubMenu);
                    this.labelWeightSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayWeightSetting);

                    this.labelInformation.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuInformation);
                    this.labelConfiguration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuConfiguration);
                    this.labelCommunication.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuCommunication);
                    this.labelCalibration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuCalibration);
                    this.labelSystem.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuSystem);
                    this.labelMotor.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuMotor);
                    this.labelIOTest.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuIOTest);
                    this.labelEquipment.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuEquipment);
                    this.labelUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuUpdate);
                    this.labelInitialization.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuInitialization);
                    this.labelTime.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuTime);
                    this.labelUser.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuUser);
                    this.labelDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuDataBackup);
                    this.labelStatistics.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuStatistics);
                    this.labelViewer.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuViewer);
                    break;
                case DataStore.UserGroup.Level2:
                    this.labelProductNo.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo);
                    this.labelClear.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear);
                    this.labelSubMenu.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplaySubMenu);
                    this.labelWeightSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayWeightSetting);

                    this.labelInformation.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuInformation);
                    this.labelConfiguration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuConfiguration);
                    this.labelCommunication.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuCommunication);
                    this.labelCalibration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuCalibration);
                    this.labelSystem.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuSystem);
                    this.labelMotor.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuMotor);
                    this.labelIOTest.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuIOTest);
                    this.labelEquipment.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuEquipment);
                    this.labelUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuUpdate);
                    this.labelInitialization.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuInitialization);
                    this.labelTime.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuTime);
                    this.labelUser.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuUser);
                    this.labelDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuDataBackup);
                    this.labelStatistics.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuStatistics);
                    this.labelViewer.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuViewer);
                    break;
                case DataStore.UserGroup.Level3:
                    this.labelProductNo.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo);
                    this.labelClear.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear);
                    this.labelSubMenu.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplaySubMenu);
                    this.labelWeightSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayWeightSetting);

                    this.labelInformation.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuInformation);
                    this.labelConfiguration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuConfiguration);
                    this.labelCommunication.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuCommunication);
                    this.labelCalibration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuCalibration);
                    this.labelSystem.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuSystem);
                    this.labelMotor.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuMotor);
                    this.labelIOTest.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuIOTest);
                    this.labelEquipment.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuEquipment);
                    this.labelUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuUpdate);
                    this.labelInitialization.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuInitialization);
                    this.labelTime.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuTime);
                    this.labelUser.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuUser);
                    this.labelDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuDataBackup);
                    this.labelStatistics.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuStatistics);
                    this.labelViewer.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuViewer);
                    break;
                case DataStore.UserGroup.Developer:
                case DataStore.UserGroup.Admin:
                    this.labelProductNo.ForeColor = Color.Black;
                    this.labelClear.ForeColor = Color.Black;
                    this.labelSubMenu.ForeColor = Color.Black;
                    this.labelWeightSetting.ForeColor = Color.Black;

                    this.labelInformation.ForeColor = Color.Black;
                    this.labelConfiguration.ForeColor = Color.Black;
                    this.labelCommunication.ForeColor = Color.Black;
                    this.labelCalibration.ForeColor = Color.Black;
                    this.labelSystem.ForeColor = Color.Black;
                    this.labelMotor.ForeColor = Color.Black;
                    this.labelIOTest.ForeColor = Color.Black;
                    this.labelEquipment.ForeColor = Color.Black;
                    this.labelUpdate.ForeColor = Color.Black;
                    this.labelInitialization.ForeColor = Color.Black;
                    this.labelTime.ForeColor = Color.Black;
                    this.labelUser.ForeColor = Color.Black;
                    this.labelDataBackup.ForeColor = Color.Black;
                    this.labelStatistics.ForeColor = Color.Black;
                    this.labelViewer.ForeColor = Color.Black;
                    break;
                default:
                    break;
            }
        }

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

            this.IsNew = true;

            this.labelID.Text = "";
            this.labelPassword.Text = "";
            this.labelExpiryDateOfAccount.Text = "180";
            this.labelExpiryDateOfPassword.Text = "90";
            this.labelExpiryDateOfAccount2.Text = "yyyy.mm.DD";
            this.labelExpiryDateOfPassword2.Text = "yyyy.mm.DD";

            this.comboBoxAccessRight.Visible = true;
            this.comboBoxAccessRight.BringToFront();
            this.UpdateAccessRightComboBox();
            this.comboBoxAccessRight.SelectedIndexChanged -= new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            this.comboBoxAccessRight.SelectedIndex = 0;
            this.comboBoxAccessRight.SelectedIndexChanged += new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            this.UpdateDefaultSetAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level1);

            this.SetEnableID(true);

            this.buttonDelete.Visible = false;
            this.buttonSave.Visible = false;

            this.labelAutomaticLogoutTime.Text = system.AutomaticLogout.ToString();

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

            this.SelectedUserItem.ExpireAccount = item.expire_period_account;
            this.SelectedUserItem.ExpirePassword = item.expire_period_pw;

            DateTime time = DateTime.ParseExact(item.register_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateRegister = time;
            time = DateTime.ParseExact(item.login_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateLogin = time;
            time = DateTime.ParseExact(item.expire_account_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateExpireRegister = time;
            time = DateTime.ParseExact(item.expire_register_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateExpireLogin = time;

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

            this.SelectedUserItem.IsAdmin = item.fadmin == 0 ? false : true;
            this.SelectedUserItem.ActiveLevel = item.active_level;

            if (this.SelectedUserItem.ActiveLevel == 1)
                this.SelectedUserItem.Group = DataStore.UserGroup.Level1;
            else if (this.SelectedUserItem.ActiveLevel == 2)
                this.SelectedUserItem.Group = DataStore.UserGroup.Level2;
            else if (this.SelectedUserItem.ActiveLevel == 3)
                this.SelectedUserItem.Group = DataStore.UserGroup.Level3;
            else if (this.SelectedUserItem.ActiveLevel == 9)
                this.SelectedUserItem.Group = DataStore.UserGroup.Admin;
            else if (this.SelectedUserItem.ActiveLevel == 10)
                this.SelectedUserItem.Group = DataStore.UserGroup.Developer;
            else
                this.SelectedUserItem.Group = DataStore.UserGroup.None;
        }
        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.ExpireAccount = item.expire_period_account;
            this.SelectedUserItem.ExpirePassword = item.expire_period_pw;

            DateTime time = DateTime.ParseExact(item.register_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateRegister = time;
            time = DateTime.ParseExact(item.login_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateLogin = time;
            time = DateTime.ParseExact(item.expire_account_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateExpireRegister = time;
            time = DateTime.ParseExact(item.expire_register_date.GetDateTime(), "yyyyMMddHHmmss", null);
            this.SelectedUserItem.DateExpireLogin = time;

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

            this.SelectedUserItem.IsAdmin = item.fadmin == 0 ? false : true;
            this.SelectedUserItem.ActiveLevel = item.active_level;

            if (item.active_level == 1)
                this.SelectedUserItem.Group = DataStore.UserGroup.Level1;
            else if (item.active_level == 2)
                this.SelectedUserItem.Group = DataStore.UserGroup.Level2;
            else if (item.active_level == 3)
                this.SelectedUserItem.Group = DataStore.UserGroup.Level3;
            else if (item.active_level == 9)
                this.SelectedUserItem.Group = DataStore.UserGroup.Admin;
            else if (item.active_level == 10)
                this.SelectedUserItem.Group = DataStore.UserGroup.Developer;
        }
        private void UpdateSelectUserDisplay(UserItem item)
        {
            this.SetEnableID(false);
            this.SetEnablePassword(true);
            this.SetEnableControl(true);

            // 화면 Enable 처리 추가할것
            this.ChangeUserControlEnable(true);

            this.labelID.Text = item.ID;
            this.labelPassword.Text = item.Password;

            if (this.listBoxUserList.SelectItemIndex == 0)
            {
                this.labelExpiryDateOfAccount.Text = "0";
                this.labelExpiryDateOfPassword.Text = "0";
                this.labelExpiryDateOfAccount2.Text = "-";
                this.labelExpiryDateOfPassword2.Text = "-";

                this.buttonDelete.Visible = false;
                this.comboBoxAccessRight.Visible = false;
                this.SetEnableOnlyPart11Value(false);

                if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Admin
                    || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer)
                    this.SetEnablePassword(true);
                else
                    this.SetEnablePassword(false);
            }
            else
            {
                this.labelExpiryDateOfAccount.Text = item.ExpireAccount.ToString();
                this.labelExpiryDateOfPassword.Text = item.ExpirePassword.ToString();
                this.labelExpiryDateOfAccount2.Text = string.Format("{0:yyyy/MM/dd} ~ {1:yyyy/MM/dd}", item.DateRegister, item.DateExpireRegister);
                this.labelExpiryDateOfPassword2.Text = string.Format("{0:yyyy/MM/dd} ~ {1:yyyy/MM/dd}", item.DateLogin, item.DateExpireLogin);

                this.labelStatusExpireAccount.Visible = item.IsLockAccount;
                this.labelStatusExpirePassword.Visible = item.IsLockPassword;

                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.ParentForm.SystemConfig.CurrentUser.ActiveLevel < item.ActiveLevel)
                {
                    this.SetEnablePassword(false);
                    this.buttonDelete.Visible = false;

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

            //this.CheckBoxCheckedAsLevel(item.Group);

            //this.cbAdministrator.Visible = true;
            //this.cbAdministrator.Checked = item.IsAdmin;
        }
        private void UpdateUserListBoxDisplay(List<string> items)
        {
            this.listBoxUserList.ClearAll();
            for (int i = 1; i < items.Count; i++)
                this.listBoxUserList.AddItem(items[i]);
        }
        private void UpdateDefaultSetAccessRightDisplay(UserGroupItem item)
        {
            this.labelProductNo.ForeColor = this.ReturnColor(item.IsMainDisplayProductNo);
            this.labelWeightSetting.ForeColor = this.ReturnColor(item.IsMainDisplayWeightSetting);
            this.labelClear.ForeColor = this.ReturnColor(item.IsMainDisplayClear);
            this.labelSubMenu.ForeColor = this.ReturnColor(item.IsMainDisplaySubMenu);

            this.labelInformation.ForeColor = this.ReturnColor(item.IsMenuInformation);
            this.labelConfiguration.ForeColor = this.ReturnColor(item.IsMenuConfiguration);
            this.labelCommunication.ForeColor = this.ReturnColor(item.IsMenuCommunication);
            this.labelCalibration.ForeColor = this.ReturnColor(item.IsMenuCalibration);
            this.labelSystem.ForeColor = this.ReturnColor(item.IsMenuSystem);
            this.labelMotor.ForeColor = this.ReturnColor(item.IsMenuMotor);
            this.labelIOTest.ForeColor = this.ReturnColor(item.IsMenuIOTest);
            this.labelEquipment.ForeColor = this.ReturnColor(item.IsMenuEquipment);
            this.labelUpdate.ForeColor = this.ReturnColor(item.IsMenuUpdate);
            this.labelInitialization.ForeColor = this.ReturnColor(item.IsMenuInitialization);
            this.labelTime.ForeColor = this.ReturnColor(item.IsMenuTime);
            this.labelUser.ForeColor = this.ReturnColor(item.IsMenuUser);
            this.labelDataBackup.ForeColor = this.ReturnColor(item.IsMenuDataBackup);
            this.labelStatistics.ForeColor = this.ReturnColor(item.IsMenuStatistics);
            this.labelViewer.ForeColor = this.ReturnColor(item.IsMenuViewer);
        }

        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 = "", detail = "";

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 추가 완료!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.English:
                    code = "user settings";
                    message1 = "User addition complete!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "用户设置";
                    message1 = "用户添加完成!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "uživatelské nastavení";
                    message1 = "Přidání uživatele dokončeno!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = "Benutzer hinzufügen abgeschlossen!";
                    message2 = "";
                    break;
                default:
                    break;
            }

            if (user.status == (int)UserManager.E_user_mgr_status.USER_MGR_STATUS_OK)
            {
                this.UI_Invoke(delegate
                {
                    // Part 11
                    detail = string.Format("Add : {0}", user.user_id);
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.UserEditor, detail);

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

                    this.ParentForm.ListDllUserName.Add(user.user_id);
                    this.UpdateUserListBoxDisplay(this.ParentForm.ListDllUserName);
                    this.listBoxUserList.SelectItemIndex = this.listBoxUserList.ItemCount - 1;

                    this.buttonDelete.Enabled = true;
                    this.labelID.Enabled = false;
                    this.labelID.BackColor = Color.LightGray;

                    DialogFormMessage dlg = new DialogFormMessage(DataStore.MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    dlg.ShowDialog();
                });
            }
            else
            {
                DialogFormMessage msg = new DialogFormMessage(null, user.status, this.ParentForm.SystemConfig.Language);
                msg.ShowDialog();
            }
        }
        public void CallBackUserModifyUserData(UserManager.UserMgr_user_modify_t user)
        {
            string code = "", message1 = "", message2 = "", detail = "";

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 정보 수정 완료!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.English:
                    code = "user settings";
                    message1 = "User information modified!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "用户设置";
                    message1 = "用户信息修改!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "uživatelské nastavení";
                    message1 = "Informace o uživateli upraveny!";
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = "Benutzerinformationen geändert!";
                    message2 = "";
                    break;
                default:
                    break;
            }

            if (user.status == (int)UserManager.E_user_mgr_status.USER_MGR_STATUS_OK)
            {
                this.UI_Invoke(delegate
                {
                    // Part 11
                    detail = string.Format("Modify : {0}", user.user_id);
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.UserEditor, detail);

                    // 메시지 박스 교체
                    UserManager.UserManager_GetUserListID(this.listBoxUserList.Items[this.listBoxUserList.SelectItemIndex]);

                    DialogFormMessage dlg = new DialogFormMessage(DataStore.MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    dlg.ShowDialog();
                });
            }
            else
            {
                DialogFormMessage msg = new DialogFormMessage(null, user.status, this.ParentForm.SystemConfig.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.listBoxUserList.Items[this.listBoxUserList.SelectItemIndex]);
            }
        }
        public void CallBackUserListDeleteDataEvent(UserManager.UserMgr_user_del_t user)
        {
            string code = "", message1 = "", message2 = "", detail = "";

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    code = "유저설정";
                    message1 = string.Format("{0} 사용자 삭제 완료!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.LanguageID.English:
                    code = "user settings";
                    message1 = string.Format("{0} User deletion complete!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "用户设置";
                    message1 = string.Format("{0} 用户删除完成!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "uživatelské nastavení";
                    message1 = string.Format("{0} Smazání uživatele dokončeno!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = string.Format("{0} Benutzerlöschung abgeschlossen!", user.user_id);
                    message2 = "";
                    break;
                default:
                    break;
            }


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

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

                    this.UserNew();

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

                // Part 11
                if (this.ParentForm.SystemConfig.IsPart11 == true)
                {
                    detail = string.Format("Delete : {0}", user.user_id);
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.UserEditor, detail);
                }
            }
            else
            {
                DialogFormMessage msg = new DialogFormMessage(null, user.status, this.ParentForm.SystemConfig.Language);
                msg.ShowDialog();
            }
        }
        public void CallBackUserListModifyInfoDataEvent(UserManager.UserMgr_user_info_t user)
        {
            //if (this.ChildControlUserSet.Visible == true)
            //{
            this.ChildControlUserSet.CallBackUserListModifyInfoDataEvent(user);
            //}
        }

        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 DisplayOnlyPart11Item(bool bValue)
        {
            if (bValue == true)
            {
                this.labelTitleExpiryDateOfAccount.Visible = true;
                this.labelExpiryDateOfAccount.Visible = true;
                this.labelExpiryDateOfAccount2.Visible = true;
                this.labelTitleDayAccount.Visible = true;

                this.labelTitleExpiryDateOfPassword.Visible = true;
                this.labelExpiryDateOfPassword.Visible = true;
                this.labelExpiryDateOfPassword2.Visible = true;
                this.labelTitleDayPassword.Visible = true;

                this.labelTitleAutomaticLogoutTime.Visible = true;
                this.labelAutomaticLogoutTime.Visible = true;
                this.labelTitleMin.Visible = true;
                this.labelAutoLogoutWarning.Visible = true;

                this.smartSeparatorLine1.Visible = true;
                this.smartSeparatorLine2.Visible = true;
            }
            else
            {
                this.labelTitleExpiryDateOfAccount.Visible = false;
                this.labelExpiryDateOfAccount.Visible = false;
                this.labelExpiryDateOfAccount2.Visible = false;
                this.labelTitleDayAccount.Visible = false;

                this.labelTitleExpiryDateOfPassword.Visible = false;
                this.labelExpiryDateOfPassword.Visible = false;
                this.labelExpiryDateOfPassword2.Visible = false;
                this.labelTitleDayPassword.Visible = false;

                this.labelTitleAutomaticLogoutTime.Visible = false;
                this.labelAutomaticLogoutTime.Visible = false;
                this.labelTitleMin.Visible = false;
                this.labelAutoLogoutWarning.Visible = false;

                this.smartSeparatorLine1.Visible = false;
                this.smartSeparatorLine2.Visible = false;
            }
        }
        public void UpdateAccessRightComboBox()
        {
            this.comboBoxAccessRight.Items.Clear();
            this.comboBoxAccessRight.Items.Add(this.ParentForm.SystemConfig.User_Level1_Name);
            this.comboBoxAccessRight.Items.Add(this.ParentForm.SystemConfig.User_Level2_Name);
            this.comboBoxAccessRight.Items.Add(this.ParentForm.SystemConfig.User_Level3_Name);
        }

        public void DisplayRefresh()
        {
            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormUserEditor;

            if (this.ParentForm.SystemConfig.CurrentUser.IsAdmin == true || this.ParentForm.SystemConfig.CurrentUser.ActiveLevel == 3)
            {
                this.buttonGroupEditor.Visible = true;
                this.ChildControlUserSet.Visible = false;
                this.buttonNew.Visible = true;
            }
            else
            {
                this.buttonGroupEditor.Visible = false;
                this.buttonNew.Visible = false;
                this.buttonDelete.Visible = false;

                this.ChildControlUserSet.Visible = true;
                this.ChildControlUserSet.BringToFront();
                this.ChildControlUserSet.DisplayRefresh();
            }

            this.UpdateInitializeUserDisplay(this.ParentForm.SystemConfig);
            this.UpdateUserListBoxDisplay(this.ParentForm.ListDllUserName);
            this.listBoxUserList.SelectedIndexChanged -= new EventHandler(this.listBoxUserList_SelectedIndexChanged);
            this.listBoxUserList.SelectItemIndex = -1;
            this.listBoxUserList.SelectedIndexChanged += new EventHandler(this.listBoxUserList_SelectedIndexChanged);

            this.buttonNew.Visible = true;
            this.listBoxUserList.Enabled = true;
            this.SetEnablePassword(true);
            this.SetEnableID(true);
        }
        #endregion

        #region Event Handler
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
        }
        private void buttonExpireAccount_Click(object sender, EventArgs e)
        {

        }
        private void buttonExpirePassword_Click(object sender, EventArgs e)
        {

        }
        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)
        {
            // 메시지 추가
            // 사용자를 삭제 하시겠습니까?
            DialogFormYesNo dlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 16);
            if (dlg.ShowDialog() == DialogResult.Yes)
            {
                if (this.listBoxUserList.Items.Count <= 1)
                    return;

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

                string id = this.listBoxUserList.Items[this.listBoxUserList.SelectItemIndex];

                UserManager.UserManager_UserDel(id);
            }
        }

        private void buttonGroupEditor_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormUserGroupEditor.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormUserGroupEditor);

            //this.DisplayRefresh();
        }

        private void labelID_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormUserEditorKeyboard keyboard = new DialogFormUserEditorKeyboard(this.labelID.Text, this.labelTitleID.Text);

            if (keyboard.ShowDialog() == DialogResult.OK)
            {
                value = keyboard.RetStringValue;

                this.labelID.Text = value;

                if (this.buttonSave.Visible == false)
                    this.buttonSave.Visible = true;
            }
        }
        private void labelPassword_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormUserEditorKeyboard keyboard = new DialogFormUserEditorKeyboard(this.labelPassword.Text, this.labelTitlePassword.Text);

            if (keyboard.ShowDialog() == DialogResult.OK)
            {
                value = keyboard.RetStringValue;

                this.labelPassword.Text = value;

                if (this.buttonSave.Visible == false)
                    this.buttonSave.Visible = true;
            }

            if (this.IsNew == true)
                this.SetEnableID(true);
        }
        private void labelExpireAccount_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelExpiryDateOfAccount.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue <= 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.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 labelExpirePassword_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelExpiryDateOfPassword.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue <= 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.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 labelAutomaticLogout_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelAutomaticLogoutTime.Text, 2, 0, false, this.ParentForm.SystemConfig.Language);

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

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

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

                this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

                UserManager.UserManager_AutoLogoutSetTimeout(this.ParentForm.SystemConfig.UserAutomaticLogout, this.ParentForm.FlagAutomaticLogoutWarningTime);
            }
        }
        private void labelStatusExpireAccount_Click(object sender, EventArgs e)
        {
            string code = "", message1 = "", message2 = "";

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.English:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                default:
                    break;
            }

            DialogFormYesNo dlg = new DialogFormYesNo(DataStore.MessageBoxIcon.Question, code, message1, message2);
            if (dlg.ShowDialog() == DialogResult.Yes)
                UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, true, false);
        }
        private void labelStatusExpirePassword_Click(object sender, EventArgs e)
        {
            string code = "", message1 = "", message2 = "";

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.English:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                default:
                    break;
            }

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

        private void comboBoxAccessRight_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (this.comboBoxAccessRight.SelectedIndex)
            {
                case 0:
                    this.UpdateDefaultSetAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level1);
                    break;
                case 1:
                    this.UpdateDefaultSetAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level2);
                    break;
                case 2:
                    this.UpdateDefaultSetAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level3);
                    break;
                default:
                    this.UpdateDefaultSetAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level1);
                    break;
            }

            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }

        private void listBoxUserList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = this.listBoxUserList.SelectItemIndex;
            this.IsNew = false;

            this.SetEnablePassword(true);
            this.labelAutomaticLogoutTime.Enabled = true;

            if (index == 0)
            {
                UserManager.UserManager_GetUserListID(this.listBoxUserList.Items[index]);
            }
            else if (index < 0)
            {
                this.UpdateInitializeUserDisplay(this.ParentForm.SystemConfig);
            }
            else if (index > 0)
            {
                if (this.ParentForm.SystemConfig.CurrentUser.ID == this.listBoxUserList.Items[index])
                    this.buttonDelete.Visible = false;
                else
                    this.buttonDelete.Visible = true;

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

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