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 INT63DC_ImageDll;
using INT63DC_6CH.Controls;
using INT63DC_6CH.DialogForms;
using INT63DC_6CH.In_UserManager;

namespace INT63DC_6CH.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.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.E_LanguageID.Korean)
            {

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

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

                this.labelCaution.Text = "Notes when registering a user";
                this.labelCaution1.Text = "- When registering a new user, the password is set to the initial value [Password12!].";
                this.labelCaution2.Text = "- After registering as a new user, you can change the password when you first log in.";

                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.E_LanguageID.Chinese)
            {
                this.labelTitle.Text = "用户设置";

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

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnGroupEditorUp));
                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.E_LanguageID.Czech)
            {
                this.labelTitle.Text = "uživatelské nastavení";

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

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeGroupEditorUp));
                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.E_LanguageID.German)
            {
                this.labelTitle.Text = "Benutzereinstellungen";

                this.buttonResetPW.Text = "Zurücksetzen";

                this.labelTitleID.Text = "ID";
                this.labelTitlePassword.Text = "Passwort";
                this.labelTitleAccessRight.Text = this.groupBoxTitleAccessRight.Text = "Zugangsberechtigung";

                this.labelTitleExpiryDateOfAccount.Text = "Verfallsdatum(ID)";
                this.labelTitleExpiryDateOfPassword.Text = "Verfallsdatum(PW)";
                this.labelTitleNumberOfLoginFailures.Text = "Anzahl der Ausfälle";
                this.labelTitleAutomaticLogoutTime.Text = "Automatische Abmeldung";
                this.labelStatusExpiryAccount.Text = "Kontoablauf";
                this.labelStatusExpiryPassword.Text = "Kennwortablauf";
                this.labelTitleDayAccount.Text = this.labelTitleDayPassword.Text = "tage";

                this.labelStaticMainDisplayAccess.Text = "Hauptanzeige";
                this.labelStaticProductNo.Text = "Warenwechsel";
                this.labelStaticWeightSetting.Font = new Font("새굴림", 8, FontStyle.Regular);
                this.labelStaticWeightSetting.Text = "Gewichts-Einstellungen";
                this.labelStaticClear.Text = "Löschen";

                this.labelStaticMenu.Text = "Menü";
                this.labelStaticCommunication.Font = new Font("새굴림", 7, FontStyle.Regular);
                this.labelStaticCommunication.Text = "Kommunikationseinstellungen";
                this.labelStaticSubMenu.Text = "Untermenü";
                this.labelStaticTimeSetting.Text = "Zeiteinstellung";
                this.labelStaticInformation.Text = "Systeminformation";
                this.labelStaticDataBackup.Text = "Datensicherung";
                this.labelStaticCalibration.Text = "Kalibrierung";
                this.labelStaticConfiguration.Text = "Konfiguration";
                this.labelStaticUpdate.Text = "Aktualisierung";
                this.labelStaticSystemSetting.Text = "Systemeinstellung";
                this.labelStaticFactoryReset.Text = "Werkseinstellung";
                this.labelStaticMotorSetting.Text = "Motoreinstellung";
                this.labelStaticEquipmentSetting.Text = "Vorrichtungeinstellung";
                this.labelStaticIOTest.Text = "I/O Test";
                this.labelStaticStatistics.Text = "Statistik";

                this.labelTitleContents.Text = "* Elemente, die allen Benutzern gemeinsam sind";

                this.labelCaution.Text = "Hinweise zur Benutzerregistrierung";
                this.labelCaution1.Text = "- Bei der Registrierung eines neuen Benutzers wird das Passwort auf den Wert  [Password12!] gesetzt.";
                this.labelCaution2.Text = "- Nach der Registrierung als neuer Benutzer können Sie das Passwort bei der ersten Anmeldung ändern.";

                this.buttonGroupEditor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerGroupEditorDisable));
                this.buttonGroupEditor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerGroupEditorDown));
                this.buttonGroupEditor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerGroupEditorUp));
                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
            {

            }
        }
        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.IsPart11 == 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.labelTitleContents.Visible = false;

                this.labelTitleNumberOfLoginFailures.Location = new Point(13, 405);
                this.labelNumberOfLoginFailures.Location = new Point(199, 405);
                this.labelTitleContents.Location = new Point(310, 405);
                this.labelTitleContents.Size = new Size(295, 30);

                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.E_LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "신규 사용자 추가 하시겠습니까?";
                        message2 = "";
                        break;
                    case DataStore.E_LanguageID.English:
                        code = "User Editor";
                        message1 = "Do you want to add a new user?";
                        message2 = "";
                        break;
                    case DataStore.E_LanguageID.Chinese:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    case DataStore.E_LanguageID.Czech:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    case DataStore.E_LanguageID.German:
                        code = "Benutzer-Editor";
                        message1 = "Möchten Sie einen neuen Benutzer hinzufügen?";
                        message2 = "";
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (this.ParentForm.SystemConfig.Language)
                {
                    case DataStore.E_LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "선택된 사용자의 정보를 수정 하시겠습니까?";
                        message2 = "";
                        break;
                    case DataStore.E_LanguageID.English:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    case DataStore.E_LanguageID.Chinese:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    case DataStore.E_LanguageID.Czech:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    case DataStore.E_LanguageID.German:
                        code = "Benutzer-Editor";
                        message1 = "Möchten Sie die Informationen des";
                        message2 = "ausgewählten Benutzers bearbeiten?";
                        break;
                    default:
                        break;
                }
            }
            #endregion

            DialogFormYesNo dlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 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.IsPart11 == true)
                {
                    item.ExpireId = int.Parse(this.labelExpiryDateOfAccount.Text);
                    item.ExpirePassword = int.Parse(this.labelExpiryDateOfPassword.Text);
                }
                else
                {
                    item.ExpireId = 0;
                    item.ExpirePassword = 0;
                }

                //item.IsAdmin = this.cbAdministrator.Checked;
                if (isNewReg == true)
                    item.ActiveLevel = this.comboBoxAccessRight.SelectedIndex + 1;
                else
                {
                    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
            }
        }
        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.labelStaticProductNo.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo);
                    this.labelStaticClear.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear);
                    this.labelStaticSubMenu.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplaySubMenu);
                    this.labelStaticWeightSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayWeightSetting);

                    this.labelStaticInformation.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuInformation);
                    this.labelStaticConfiguration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuConfiguration);
                    this.labelStaticCommunication.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuCommunication);
                    this.labelStaticCalibration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuCalibration);
                    this.labelStaticSystemSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuSystem);
                    this.labelStaticMotorSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuMotor);
                    this.labelStaticIOTest.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuIOTest);
                    this.labelStaticUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuUpdate);
                    this.labelStaticFactoryReset.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuInitialization);
                    this.labelStaticTimeSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuTime);
                    this.labelStaticDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuDataBackup);
                    this.labelStaticEquipmentSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuEquipment);
                    this.labelStaticStatistics.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuStatistics);
                    this.labelStaticViewer.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level1.IsMenuViewer);
                    break;
                case DataStore.UserGroup.Level2:
                    this.labelStaticProductNo.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo);
                    this.labelStaticClear.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear);
                    this.labelStaticSubMenu.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplaySubMenu);
                    this.labelStaticWeightSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayWeightSetting);

                    this.labelStaticInformation.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuInformation);
                    this.labelStaticConfiguration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuConfiguration);
                    this.labelStaticCommunication.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuCommunication);
                    this.labelStaticCalibration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuCalibration);
                    this.labelStaticSystemSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuSystem);
                    this.labelStaticMotorSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuMotor);
                    this.labelStaticIOTest.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuIOTest);
                    this.labelStaticUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuUpdate);
                    this.labelStaticFactoryReset.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuInitialization);
                    this.labelStaticTimeSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuTime);
                    this.labelStaticDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuDataBackup);
                    this.labelStaticEquipmentSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuEquipment);
                    this.labelStaticStatistics.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuStatistics);
                    this.labelStaticViewer.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level2.IsMenuViewer);
                    break;
                case DataStore.UserGroup.Level3:
                    this.labelStaticProductNo.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo);
                    this.labelStaticClear.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear);
                    this.labelStaticSubMenu.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplaySubMenu);
                    this.labelStaticWeightSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayWeightSetting);

                    this.labelStaticInformation.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuInformation);
                    this.labelStaticConfiguration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuConfiguration);
                    this.labelStaticCommunication.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuCommunication);
                    this.labelStaticCalibration.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuCalibration);
                    this.labelStaticSystemSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuSystem);
                    this.labelStaticMotorSetting.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuMotor);
                    this.labelStaticIOTest.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuIOTest);
                    this.labelStaticUpdate.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuUpdate);
                    this.labelStaticFactoryReset.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuInitialization);
                    this.labelStaticTimeSetting.ForeColor = this.ReturnColor(true);
                    this.labelStaticDataBackup.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuDataBackup);
                    this.labelStaticEquipmentSetting.ForeColor = this.ReturnColor(true);
                    this.labelStaticStatistics.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuStatistics);
                    this.labelStaticViewer.ForeColor = this.ReturnColor(this.ParentForm.CurrentUserGroup.Level3.IsMenuViewer);
                    break;
                case DataStore.UserGroup.Developer:
                case DataStore.UserGroup.Admin:
                    this.labelStaticProductNo.ForeColor = Color.DarkGreen;
                    this.labelStaticClear.ForeColor = Color.DarkGreen;
                    this.labelStaticSubMenu.ForeColor = Color.DarkGreen;
                    this.labelStaticWeightSetting.ForeColor = Color.DarkGreen;

                    this.labelStaticInformation.ForeColor = Color.DarkGreen;
                    this.labelStaticConfiguration.ForeColor = Color.DarkGreen;
                    this.labelStaticCommunication.ForeColor = Color.DarkGreen;
                    this.labelStaticCalibration.ForeColor = Color.DarkGreen;
                    this.labelStaticSystemSetting.ForeColor = Color.DarkGreen;
                    this.labelStaticMotorSetting.ForeColor = Color.DarkGreen;
                    this.labelStaticIOTest.ForeColor = Color.DarkGreen;
                    this.labelStaticUpdate.ForeColor = Color.DarkGreen;
                    this.labelStaticFactoryReset.ForeColor = Color.DarkGreen;
                    this.labelStaticTimeSetting.ForeColor = Color.DarkGreen;
                    this.labelStaticDataBackup.ForeColor = Color.DarkGreen;
                    this.labelStaticEquipmentSetting.ForeColor = Color.DarkGreen;
                    this.labelStaticStatistics.ForeColor = Color.DarkGreen;
                    this.labelStaticViewer.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.AutoLogoutTime.ToString();
            this.labelNumberOfLoginFailures.Text = system.NumberOfLoginFailures.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.labelStaticProductNo.ForeColor = this.ReturnColor(item.IsMainDisplayProductNo);
            this.labelStaticWeightSetting.ForeColor = this.ReturnColor(item.IsMainDisplayWeightSetting);
            this.labelStaticClear.ForeColor = this.ReturnColor(item.IsMainDisplayClear);
            this.labelStaticSubMenu.ForeColor = this.ReturnColor(item.IsMainDisplaySubMenu);

            this.labelStaticInformation.ForeColor = this.ReturnColor(item.IsMenuInformation);
            this.labelStaticConfiguration.ForeColor = this.ReturnColor(item.IsMenuConfiguration);
            this.labelStaticCommunication.ForeColor = this.ReturnColor(item.IsMenuCommunication);
            this.labelStaticCalibration.ForeColor = this.ReturnColor(item.IsMenuCalibration);
            this.labelStaticSystemSetting.ForeColor = this.ReturnColor(item.IsMenuSystem);
            this.labelStaticMotorSetting.ForeColor = this.ReturnColor(item.IsMenuMotor);
            this.labelStaticIOTest.ForeColor = this.ReturnColor(item.IsMenuIOTest);
            this.labelStaticUpdate.ForeColor = this.ReturnColor(item.IsMenuUpdate);
            this.labelStaticFactoryReset.ForeColor = this.ReturnColor(item.IsMenuInitialization);
            this.labelStaticTimeSetting.ForeColor = this.ReturnColor(item.IsMenuTime);
            this.labelStaticDataBackup.ForeColor = this.ReturnColor(item.IsMenuDataBackup);
            this.labelStaticStatistics.ForeColor = this.ReturnColor(item.IsMenuStatistics);
            this.labelStaticEquipmentSetting.ForeColor = this.ReturnColor(item.IsMenuEquipment);
            this.labelStaticViewer.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.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 추가 완료!";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.English:
                    code = "user settings";
                    message1 = "User addition complete!";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Chinese:
                    code = "用户设置";
                    message1 = "用户添加完成!";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Czech:
                    code = "uživatelské nastavení";
                    message1 = "Přidání uživatele dokončeno!";
                    message2 = "";
                    break;
                case DataStore.E_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.E_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.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 정보 수정 완료!";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.English:
                    code = "user settings";
                    message1 = "User information modified!";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Chinese:
                    code = "用户设置";
                    message1 = "用户信息修改!";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Czech:
                    code = "uživatelské nastavení";
                    message1 = "Informace o uživateli upraveny!";
                    message2 = "";
                    break;
                case DataStore.E_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.E_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.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = string.Format("{0} 사용자 삭제 완료!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.English:
                    code = "user settings";
                    message1 = string.Format("{0} User deletion complete!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Chinese:
                    code = "用户设置";
                    message1 = string.Format("{0} 用户删除完成!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Czech:
                    code = "uživatelské nastavení";
                    message1 = string.Format("{0} Smazání uživatele dokončeno!", user.user_id);
                    message2 = "";
                    break;
                case DataStore.E_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.E_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);

                if (this.ParentForm.SystemConfig.IsDataStatistics == false)
                    this.labelStaticStatistics.Visible = false;
                if (this.ParentForm.SystemConfig.IsPart11 == false)
                    this.labelStaticViewer.Visible = false;

                this.labelCaution.Visible = true;
                this.labelCaution1.Visible = true;
                this.labelCaution2.Visible = true;
            }
            else
            {
                this.buttonGroupEditor.Visible = false;
                this.ChildControlUserSet.Visible = true;
                this.ChildControlUserSet.BringToFront();
                this.ChildControlUserSet.DisplayRefresh();

                this.labelCaution.Visible = false;
                this.labelCaution1.Visible = false;
                this.labelCaution2.Visible = false;
            }
        }
        #endregion

        #region Override Member
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.InitializeDesign();
        }
        #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);

                this.buttonDelete.Visible = false;
            }
        }
        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 = "";
            DialogFormKeyboard keyboard = new DialogFormKeyboard(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 = "";
            DialogFormKeyboard keyboard = new DialogFormKeyboard(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 labelNumberOfLoginFailures_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = this.labelNumberOfLoginFailures.Text;

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

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

                    // Part11
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.NumberOfLoginFailure, "", before, after);
                }
            }
        }
        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.AutoLogoutTime = myKeyPad.IntValue;
                    this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
                    after = this.labelAutomaticLogoutTime.Text;

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

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

                    // Part11
                    if (this.ParentForm.SystemConfig.IsPart11 == 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.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.English:
                    code = "User Settings";
                    message1 = "Do you want to unlock the user?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Chinese:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Czech:
                    code = "유저설정";
                    message1 = "사용자 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = "Möchten Sie den Benutzer entsperren?";
                    message2 = "";
                    break;
                default:
                    break;
            }

            DialogFormYesNo dlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 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.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.English:
                    code = "User Settings";
                    message1 = "Do you want to unlock the password?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Chinese:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.Czech:
                    code = "유저설정";
                    message1 = "비밀번호 잠금 해제 하시겠습니까?";
                    message2 = "";
                    break;
                case DataStore.E_LanguageID.German:
                    code = "Benutzereinstellungen";
                    message1 = "Möchten Sie das Passwort entsperren?";
                    message2 = "";
                    break;
                default:
                    break;
            }

            DialogFormYesNo dlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 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
    }
}