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

using SmartX;
using INT69DC_ImageDll;
using INT69DC_7C.Controls;
using INT69DC_7C.DialogForms;
using INT69DC_7C.Part11_UserManager;

namespace INT69DC_7C.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;
        private string CurrentUserPassword;
        #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();

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

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
                this.labelTitle.Text = "User settings";

                this.labelStatusExpiryAccount.Text = "Account Expiration";
                this.labelStatusExpiryPassword.Text = "Password Expiration";
                this.labelAutoLogoutWarning.Text = "* Applies to all users";

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorUp));
                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.labelTitle.Text = "用户设置";

                this.labelStatusExpiryAccount.Text = "帐户到期";
                this.labelStatusExpiryPassword.Text = "密码过期";
                this.labelAutoLogoutWarning.Text = "* 适用于所有用户";

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorUp));
                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
                this.labelTitle.Text = "uživatelské nastavení";

                this.labelStatusExpiryAccount.Text = "Vypršení platnosti účtu";
                this.labelStatusExpiryPassword.Text = "Vypršení platnosti hesla";
                this.labelAutoLogoutWarning.Text = "* Platí pro všechny uživatele";

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorUp));
                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
            {
                this.labelTitle.Text = "Benutzereinstellungen";

                this.labelStatusExpiryAccount.Text = "Account Expiration";
                this.labelStatusExpiryPassword.Text = "Password Expiration";
                this.labelAutoLogoutWarning.Text = "* Applies to all users";

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engGroupEditorUp));
                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.labelTitle.Text = "ユㅡザㅡ設定";

                this.labelTitlePassword.Text = "パスワㅡド";
                this.labelTitleAccessRight.Text = "アクセス権";

                this.labelStatusExpiryAccount.Text = "満了";
                this.labelStatusExpiryPassword.Text = "満了";
                this.labelAutoLogoutWarning.Text = "* すべてのユㅡザㅡに適用されます";

                this.groupBoxAccessRight.Text = "アクセス権";
                this.labelMain.Text = "メイン";
                this.labelMenu.Text = "メニュㅡ";
                this.buttonResetPW.Text = "リセット";

                this.labelProductNo.Text = "アイテム変更";
                this.labelWeightSetting.Text = "重量値設定";
                this.labelClear.Text = "クリア";
                this.labelSubMenu.Text = "サブメニュㅡ";
                this.labelInformation.Text = "インフォメㅡション";
                this.labelConfiguration.Text = "構成";
                this.labelCommunication.Text = "通信設定";
                this.labelCalibration.Text = "キャリブレㅡション";
                this.labelSystem.Text = "システム設定";
                this.labelMotor.Text = "モㅡタㅡ設定";
                this.labelIOTest.Text = "I/Oテスト";
                this.labelUpdate.Text = "更新";
                this.labelInitialization.Text = "初期化";
                this.labelTime.Text = "時間設定";
                this.labelDataBackup.Text = "デㅡタバックアップ";
                this.labelEquipment.Text = "装置設定";
                this.labelStatistics.Text = "デㅡタ統計";
                this.labelViewer.Text = "デㅡタビュㅡア";

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnGroupEditorUp));
                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackUp));
            }
            else
            {

            }
        }
        private void DefaultSetting()
        {
            this.IsNew = false;
            this.PasswordChar = false;
            this.BeforeID = "";
            this.BeforePassword = "";
            this.CurrentUserPassword = "Password12!";

            this.UpdateAccessRightComboBoxDisplay();
            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, 73);
            this.ChildControlUserSet.Visible = false;

            if (this.ParentForm.SystemConfig.IsOptPart11 == false)
            {
                // Expiry date(Account)
                this.labelTitleExpiryDateOfAccount.Visible = false;
                this.labelTitleDayAccount.Visible = false;
                this.labelExpiryDateOfAccount.Visible = false;
                this.labelExpiryDateOfAccount2.Visible = false;
                this.labelStatusExpiryAccount.Visible = false;
                // Expiry date(Password)
                this.labelTitleExpiryDateOfPassword.Visible = false;
                this.labelTitleDayPassword.Visible = false;
                this.labelExpiryDateOfPassword.Visible = false;
                this.labelExpiryDateOfPassword2.Visible = false;
                this.labelStatusExpiryPassword.Visible = false;
                // Auto logout time
                this.labelTitleAutomaticLogoutTime.Visible = false;
                this.labelAutomaticLogoutTime.Visible = false;
                this.labelTitleMin.Visible = false;
                this.labelAutoLogoutWarning.Visible = false;

                this.smartSeparatorLine1.Visible = false;
                this.smartSeparatorLine2.Visible = false;
            }
        }

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

            if (value == true)
                this.labelID.BackColor = Color.White;
            else
                this.labelID.BackColor = Color.Silver;
        }
        private void SetEnablePassword(bool value)
        {
            //value = false;

            this.labelPassword.Enabled = value;

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

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

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

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

            if (this.listBoxUserList.SelectedIndex == -1)
                isNewReg = true;
            else
                isNewReg = false;

            #region listbox 미선택 시 신규 유저 등록, 선택 시 기존 유저 정보 수정
            if (isNewReg == 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;
                    case DataStore.LanguageID.Japanese:
                        code = "ユㅡザㅡ設定";
                        message1 = "新規ユㅡザㅡを追加しますか？";
                        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;
                    case DataStore.LanguageID.Japanese:
                        code = "ユㅡザㅡ設定";
                        message1 = "選択したユㅡザㅡの情報を編集しますか？";
                        message2 = "";
                        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 (isNewReg == 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 < 5)
                {
                    // PASSWORD : 6~20자 입력하세요
                    DialogFormMessage msg = new DialogFormMessage(null, 9, this.ParentForm.SystemConfig.Language);
                    msg.ShowDialog();
                    return;
                }
                #endregion

                item.ID = this.labelID.Text;
                if (isNewReg == true)
                    item.Password = this.SelectedUserItem.ResetPW;
                else
                    item.Password = this.CurrentUserPassword;
                if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                {
                    item.ExpireId = int.Parse(this.labelExpiryDateOfAccount.Text);
                    item.ExpirePassword = int.Parse(this.labelExpiryDateOfPassword.Text);
                }
                else
                {
                    item.ExpireId = -1;
                    item.ExpirePassword = -1;
                }

                //item.IsAdmin = this.cbAdministrator.Checked;
                if (this.SelectedUserItem.Group == DataStore.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 (isNewReg == 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);
                    #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

                this.buttonSave.Visible = false;
            }
        }
        private void UserNew()
        {
            this.listBoxUserList.SelectedIndexChanged -= new EventHandler(this.listBoxUserList_SelectedIndexChanged);
            this.listBoxUserList.SelectedIndex = -1;
            this.listBoxUserList.SelectedIndexChanged += new EventHandler(this.listBoxUserList_SelectedIndexChanged);

            this.UpdateInitializeUserDisplay(this.ParentForm.SystemConfig);

            this.buttonDelete.Visible = false;
            this.buttonSave.Visible = false;
            this.comboBoxAccessRight.Enabled = true;
            this.SetEnableID(true);
        }
        private Color ReturnColor(bool bValue)
        {
            if (bValue == true)
                return Color.DarkGreen;
            else
                return Color.Silver;
        }
        private string PasswordToAsterisk(string sValue)
        {
            string temp = "";

            for (int i = 0; i < sValue.Length; i++)
                temp += "*";

            return temp;
        }
        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.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.labelDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuDataBackup);
                    this.labelEquipment.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuEquipment);
                    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.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.labelDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuDataBackup);
                    this.labelEquipment.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuEquipment);
                    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.labelUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuUpdate);
                    this.labelInitialization.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuInitialization);
                    this.labelTime.ForeColor = this.ReturnColor(true);
                    this.labelDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuDataBackup);
                    this.labelEquipment.ForeColor = this.ReturnColor(true);
                    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.DarkGreen;
                    this.labelClear.ForeColor = Color.DarkGreen;
                    this.labelSubMenu.ForeColor = Color.DarkGreen;
                    this.labelWeightSetting.ForeColor = Color.DarkGreen;

                    this.labelInformation.ForeColor = Color.DarkGreen;
                    this.labelConfiguration.ForeColor = Color.DarkGreen;
                    this.labelCommunication.ForeColor = Color.DarkGreen;
                    this.labelCalibration.ForeColor = Color.DarkGreen;
                    this.labelSystem.ForeColor = Color.DarkGreen;
                    this.labelMotor.ForeColor = Color.DarkGreen;
                    this.labelIOTest.ForeColor = Color.DarkGreen;
                    this.labelUpdate.ForeColor = Color.DarkGreen;
                    this.labelInitialization.ForeColor = Color.DarkGreen;
                    this.labelTime.ForeColor = Color.DarkGreen;
                    this.labelDataBackup.ForeColor = Color.DarkGreen;
                    this.labelEquipment.ForeColor = Color.DarkGreen;
                    this.labelStatistics.ForeColor = Color.DarkGreen;
                    this.labelViewer.ForeColor = Color.DarkGreen;
                    break;
                default:
                    break;
            }
        }
        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;
            }
        }
        private void UpdateAccessRightComboBoxDisplay()
        {
            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);
        }

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

            this.labelID.Text = "";
            this.labelPassword.Text = this.SelectedUserItem.ResetPW;
            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.Enabled = true;
            this.comboBoxAccessRight.BringToFront();
            this.UpdateAccessRightComboBoxDisplay();
            this.comboBoxAccessRight.SelectedIndexChanged -= new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            this.comboBoxAccessRight.SelectedIndex = 0;
            this.comboBoxAccessRight.SelectedIndexChanged += new EventHandler(this.comboBoxAccessRight_SelectedIndexChanged);
            this.UpdateAccessRightDisplay(this.comboBoxAccessRight.SelectedIndex + 1);

            this.buttonDelete.Visible = false;
            this.buttonSave.Visible = false;
            this.labelStatusExpiryAccount.Visible = false;
            this.labelStatusExpiryPassword.Visible = false;
            this.SetEnablePassword(false);
            this.SetEnableID(true);
            this.SetEnableExpireAccount(true);
            this.SetEnableExpirePassword(true);

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

            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)
        {
            // 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;

            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;

            //Console.WriteLine(item.password_register_date.GetDateTime());
            //Console.WriteLine(item.id_login_date.GetDateTime());
            //Console.WriteLine(item.id_expire_date.GetDateTime());
            //Console.WriteLine(item.password_expire_date.GetDateTime());

            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.IsAdmin = item.fadmin == 0 ? false : true;

            this.SelectedUserItem.IsFirstPassword = item.fFirstPW;
        }
        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;

            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;

            //Console.WriteLine(item.password_register_date.GetDateTime());
            //Console.WriteLine(item.id_login_date.GetDateTime());
            //Console.WriteLine(item.id_expire_date.GetDateTime());
            //Console.WriteLine(item.password_expire_date.GetDateTime());

            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;

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

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

            // ID
            this.labelID.Text = item.ID;
            // Password
            if (item.Password == this.SelectedUserItem.ResetPW)
                this.labelPassword.Text = item.Password;
            else
                this.labelPassword.Text = this.PasswordToAsterisk(item.Password);
            this.CurrentUserPassword = item.Password;
            
            this.UpdateAccessRightDisplay(item.ActiveLevel);
            this.buttonSave.Visible = false;

            if (item.Group == DataStore.UserGroup.Admin)
            {
                this.labelExpiryDateOfAccount.Text = "0";
                this.labelExpiryDateOfPassword.Text = "0";
                this.labelExpiryDateOfAccount2.Text = "-";
                this.labelExpiryDateOfPassword2.Text = "-";

                this.buttonDelete.Visible = false;
                this.comboBoxAccessRight.Visible = false;
                this.labelStatusExpiryAccount.Visible = false;
                this.labelStatusExpiryPassword.Visible = false;
                this.SetEnableExpireAccount(false);
                this.SetEnableExpirePassword(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.ExpireId.ToString();
                this.labelExpiryDateOfPassword.Text = item.ExpirePassword.ToString();

                if (item.ExpireId != 0)
                    this.labelExpiryDateOfAccount2.Text = string.Format("{0:yyyy/MM/dd} ~ {1:yyyy/MM/dd}", item.DateIdLogin, item.DateIdExpire);
                else
                    this.labelExpiryDateOfAccount2.Text = "-";

                if (item.ExpirePassword != 0)
                    this.labelExpiryDateOfPassword2.Text = string.Format("{0:yyyy/MM/dd} ~ {1:yyyy/MM/dd}", item.DatePasswordRegister, item.DatePasswordExpire);
                else
                    this.labelExpiryDateOfPassword2.Text = "-";

                this.labelStatusExpiryAccount.Visible = item.IsLockAccount;
                this.labelStatusExpiryPassword.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);

                this.SetEnableExpireAccount(true);
                this.SetEnableExpirePassword(true);

                if (this.ParentForm.SystemConfig.CurrentUser.ActiveLevel < item.ActiveLevel)
                {
                    this.buttonDelete.Visible = false;
                    this.SetEnablePassword(false);
                    this.comboBoxAccessRight.Enabled = false;
                }
                else if (this.ParentForm.SystemConfig.CurrentUser.ActiveLevel == item.ActiveLevel)
                {
                    this.buttonDelete.Visible = false;
                    this.comboBoxAccessRight.Enabled = false;
                }
                else
                {
                    this.buttonDelete.Visible = true;
                    this.comboBoxAccessRight.Enabled = true;
                }
            }
        }
        private void UpdateUserListBoxDisplay(List<string> items)
        {
            this.listBoxUserList.Items.Clear();
            for (int i = 1; i < items.Count; i++)
                this.listBoxUserList.Items.Add(items[i]);
        }
        private void UpdateAccessRightDisplay(int level)
        {
            UserGroupItem item;
            switch (level)
            {
                case 1:
                    item = this.ParentForm.CurrentUserGroup.Level1;
                    break;
                case 2:
                    item = this.ParentForm.CurrentUserGroup.Level2;
                    break;
                case 3:
                case 9:
                    item = this.ParentForm.CurrentUserGroup.Level3;
                    break;
                default:
                    item = this.ParentForm.CurrentUserGroup.Level1;
                    break;
            }

            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.labelUpdate.ForeColor = this.ReturnColor(item.IsMenuUpdate);
            this.labelInitialization.ForeColor = this.ReturnColor(item.IsMenuInitialization);
            this.labelTime.ForeColor = this.ReturnColor(item.IsMenuTime);
            this.labelDataBackup.ForeColor = this.ReturnColor(item.IsMenuDataBackup);
            this.labelStatistics.ForeColor = this.ReturnColor(item.IsMenuStatistics);
            this.labelEquipment.ForeColor = this.ReturnColor(item.IsMenuEquipment);
            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;
                case DataStore.LanguageID.Japanese:
                    code = "ユㅡザㅡ設定";
                    message1 = "ユㅡザㅡ追加完了！";
                    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.SelectedIndex = this.listBoxUserList.Items.Count - 1;

                    this.buttonDelete.Visible = true;
                    this.buttonSave.Visible = false;
                    this.SetEnableID(false);

                    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;
                case DataStore.LanguageID.Japanese:
                    code = "ユㅡザㅡ設定";
                    message1 = "ユㅡザㅡ情報修正完了！";
                    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.SelectedItem.ToString());

                    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.SelectedUserItem.ID);
            }
        }
        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;
                case DataStore.LanguageID.Japanese:
                    code = "ユㅡザㅡ設定";
                    message1 = string.Format("{0} ユㅡザㅡ削除完了！", 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.IsOptPart11 == 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);
            //}
        }
        
        public void DisplayRefresh()
        {
            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormUserEditor;

            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Level3 
                || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Admin
                || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer)
            {
                this.buttonGroupEditor.Visible = true;
                this.ChildControlUserSet.Visible = false;

                this.UpdateInitializeUserDisplay(this.ParentForm.SystemConfig);
                this.UpdateUserListBoxDisplay(this.ParentForm.ListDllUserName);
            }
            else
            {
                this.buttonGroupEditor.Visible = false;
                this.ChildControlUserSet.Visible = true;
                this.ChildControlUserSet.BringToFront();
                this.ChildControlUserSet.DisplayRefresh();
            }
        }
        #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 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, 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);
            }
        }
        private void buttonResetPW_Click(object sender, EventArgs e)
        {
            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.SystemConfig.Language, 17);
            if (dlg.ShowDialog() == DialogResult.Yes)
            {
                id = this.SelectedUserItem.ID;
                pw = this.SelectedUserItem.ResetPW;

                ret = UserManager.UserManager_UserResetPWDirect(id, pw);

                if (ret == 0)
                    this.labelPassword.Text = pw;
            }
        }

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

        private void labelID_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormUserEditorKeyboard keyboard = new DialogFormUserEditorKeyboard(this.labelID.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.SelectedUserItem.Password);
            if (keyboard.ShowDialog() == DialogResult.OK)
            {
                value = keyboard.RetStringValue;

                this.labelPassword.Text = value;

                if (this.labelPassword.Text != "")
                {
                    if (this.buttonSave.Visible == false)
                        this.buttonSave.Visible = 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.doubleValue < 0 || myKeyPad.doubleValue > 180)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelExpiryDateOfAccount.Text = myKeyPad.StringValue;

                    if (this.buttonSave.Visible != true)
                        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.doubleValue < 0 || myKeyPad.doubleValue > 90)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelExpiryDateOfPassword.Text = myKeyPad.StringValue;

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

            before = this.labelAutomaticLogoutTime.Text;

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

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

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

                    UserManager.UserManager_AutoLogoutSetTimeout(this.ParentForm.SystemConfig.AutomaticLogout, this.ParentForm.FlagAutomaticLogoutWarningTime);

                    // Part11
                    if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                        this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.AutoLogout, "", before, after);
                }
            }
        }
        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 = "User settings";
                    message1 = "Do you want to unlock the user?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "用户设置";
                    message1 = "是否要解锁用户？";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "Uživatelské nastavení";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = "Möchten Sie den Benutzer entsperren?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Japanese:
                    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 = "User settings";
                    message1 = "Do you want to unlock the password?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Chinese:
                    code = "用户设置";
                    message1 = "是否要解锁密码？";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Czech:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = "Möchten Sie das Passwort entsperren?";
                    message2 = "";
                    break;
                case DataStore.LanguageID.Japanese:
                    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.UpdateAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level1);
            //        break;
            //    case 1:
            //        this.UpdateAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level2);
            //        break;
            //    case 2:
            //        this.UpdateAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level3);
            //        break;
            //    default:
            //        this.UpdateAccessRightDisplay(this.ParentForm.CurrentUserGroup.Level1);
            //        break;
            //}
            this.UpdateAccessRightDisplay(this.comboBoxAccessRight.SelectedIndex + 1);

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

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

            if (index == 0)
            {
                UserManager.UserManager_GetUserListID(this.listBoxUserList.SelectedItem.ToString());
            }
            else if (index > 0)
            {

                if (this.ParentForm.SystemConfig.CurrentUser.ID == this.listBoxUserList.Items[index].ToString())
                {
                    this.SetEnablePassword(true);
                    this.buttonResetPW.Visible = false;
                }
                else
                {
                    this.SetEnablePassword(false);
                    this.buttonResetPW.Visible = true;
                }

                UserManager.UserManager_GetUserListID(this.listBoxUserList.SelectedItem.ToString());
            }
        }
        #endregion
    }
}