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

using INT_LKD_2.Forms;
using INT_LKD_2.DialogForms;
using INT_LKD_2.Part11_UserManager;
using INT_LKD_2.DataStore;

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

        private UserItem SelectedUserItem;

        private bool IsNew;
        private bool PasswordChar;

        private string BeforeID;
        private string BeforePassword;
        #endregion

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

            this.ParentForm = parent;
            this.Initialize();
            this.DefaultSetting();
        }
        #endregion

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

        #region Method
        private void Initialize()
        {
            this.smartGroupBox1.Text = "User > UserEditor";
        }
        private void DefaultSetting()
        {
            this.IsNew = false;
            this.PasswordChar = false;
            this.BeforeID = "";
            this.BeforePassword = "";

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

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

                return true;

            }
            catch (Exception e)
            {
                return false;
            }
        }
        
        private void KeyboardClose()
        {
            this.smartKeyboard.Hide();

            this.SetEnableControl(true);
        }

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

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

            if (value == true)
            {
                this.textBoxPassword.BackColor = Color.White;
                this.labelPasswordBackGround.BackGroundColor = Color.White;
            }
            else
            {
                this.textBoxPassword.BackColor = Color.Silver;
                this.labelPasswordBackGround.BackGroundColor = Color.Silver;
            }
        }
        private void SetEnableLevelButton(bool value)
        {
            this.buttonLevel1.Enabled = value;
            this.buttonLevel2.Enabled = value;
            this.buttonLevel3.Enabled = value;
        }
        private void SetEnableExpireDate(bool value)
        {
            this.labelExpiryDateOfAccount.Enabled = value;
            this.labelExpiryDateOfPassword.Enabled = value;

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

            this.buttonRegister.Enabled = value;
            this.buttonDelete.Enabled = value;
            this.buttonSave.Enabled = value;
        }
        private void SetTextBoxPasswordChar(bool bValue)
        {
            if (bValue == false)
            {
                if (this.textBoxPassword.Text == this.SelectedUserItem.ResetPW)
                    this.textBoxPassword.PasswordChar = default(char);
                else
                    this.textBoxPassword.PasswordChar = '*';
            }
            else
                this.textBoxPassword.PasswordChar = default(char);
        }
        
        private void UserNew()
        {
            this.listBoxUserList.SelectedIndexChanged -= new EventHandler(this.listBoxUserList_SelectedIndexChanged);
            this.listBoxUserList.SelectItemIndex = -1;
            this.listBoxUserList.SelectedIndexChanged += new EventHandler(this.listBoxUserList_SelectedIndexChanged);

            this.UpdateInitializeUserDisplay(this.ParentForm.ParentForm.SystemConfig);

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

            this.labelExpiryDateOfAccount.Enabled = true;
            this.labelExpiryDateOfPassword.Enabled = true;
        }
        private void SaveUserDll()
        {
            string detail = "";
            string code = "", message1 = "", message2 = "";
            bool isNewReg = false;

            #region listbox 미선택 시 신규 유저 등록, 선택 시 기존 유저 정보 수정
            if (this.listBoxUserList.SelectItemIndex == -1)
                isNewReg = true;
            else
                isNewReg = false;

            if (isNewReg == true)
            {
                switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "신규 사용자 추가 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User Editor";
                        message1 = "Would you like to register as a user?";
                        message2 = "";
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저 설정";
                        message1 = "선택된 사용자의 정보를 수정 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User Editor";
                        message1 = "Are you sure you want to edit the";
                        message2 = "selected user's information?";
                        break;
                    default:
                        break;
                }
            }
            #endregion
                                   
            DialogFormYesNo dlg = new DialogFormYesNo(Define.E_MessageBoxIcon.Question, code, message1, message2);
            if (dlg.ShowDialog() == DialogResult.Yes)
            {
                UserItem item = new UserItem();
                DateTime time = DateTime.Now;
                UserManager.MenuID_t menuId = new UserManager.MenuID_t();

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

                        return;
                    }
                }

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

                    return;
                }

                if (this.labelAccessRight.Text == "")
                {
                    DialogFormMessage msg = new DialogFormMessage(null, 16, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    msg.ShowDialog();

                    return;
                }

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

                    return;
                }

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

                    return;
                }
                #endregion

                item.ID = this.textBoxID.Text;
                item.Password = this.textBoxPassword.Text;
                item.ExpireId = int.Parse(this.labelExpiryDateOfAccount.Text);
                item.ExpirePassword = int.Parse(this.labelExpiryDateOfPassword.Text);

                if (this.buttonLevel1.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                    item.ActiveLevel = 1;
                if (this.buttonLevel2.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                    item.ActiveLevel = 2;
                if (this.buttonLevel3.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                    item.ActiveLevel = 3;

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

                    // Part 11
                    detail = string.Format("Add : {0}", item.ID);
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
                    #endregion
                }
                else
                {
                    #region 유저 수정
                    UserManager.UserManager_UserModify(item.ID, item.Password, item.IsAdmin == false ? 0 : 1, item.ExpirePassword, item.ExpireId, item.ActiveLevel, menuId);

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

                this.buttonSave.Visible = false;
            }
        }
        private void CheckBoxCheckedAsLevel(Define.E_UserGroup level)
        {
            switch (level)
            {
                case Define.E_UserGroup.Level1:
                    this.buttonLevel2.ButtonUp();
                    this.buttonLevel3.ButtonUp();
                    this.buttonLevel1.ButtonDown();
                    this.SetEnableLevelButton(true);

                    this.labelAccessRight.Text = this.ParentForm.ParentForm.SystemConfig.LEVEL1_NAME;

                    this.checkBoxMainProductChange.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductChange;
                    this.checkBoxMainClear.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear;
                    this.checkBoxMainSubMenu.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplaySubMenu;

                    this.checkBoxMenuRecipe.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuRecipe;
                    this.checkBoxMenuUserEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuUserSetting;
                    this.checkBoxMenuUserGroupEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuUserGroupEditor;
                    this.checkBoxMenuIOTest.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuIOTest;
                    this.checkBoxMenuHistoryLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuHistoryLog;
                    this.checkBoxMenuCheckLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuInspectionLog;
                    this.checkBoxMenuAlarmList.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuAlarmLog;
                    this.checkBoxMenuInformation.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuInformation;
                    this.checkBoxMenuEquipment.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuEquipment;
                    this.checkBoxMenuEthernet.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuEthernet;
                    break;
                case Define.E_UserGroup.Level2:
                    this.buttonLevel1.ButtonUp();
                    this.buttonLevel3.ButtonUp();
                    this.buttonLevel2.ButtonDown();
                    this.SetEnableLevelButton(true);

                    this.labelAccessRight.Text = this.ParentForm.ParentForm.SystemConfig.LEVEL2_NAME;

                    this.checkBoxMainProductChange.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductChange;
                    this.checkBoxMainClear.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear;
                    this.checkBoxMainSubMenu.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplaySubMenu;

                    this.checkBoxMenuRecipe.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuRecipe;
                    this.checkBoxMenuUserEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuUserSetting;
                    this.checkBoxMenuUserGroupEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuUserGroupEditor;
                    this.checkBoxMenuIOTest.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuIOTest;
                    this.checkBoxMenuHistoryLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuHistoryLog;
                    this.checkBoxMenuCheckLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuInspectionLog;
                    this.checkBoxMenuAlarmList.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuAlarmLog;
                    this.checkBoxMenuInformation.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuInformation;
                    this.checkBoxMenuEquipment.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuEquipment;
                    this.checkBoxMenuEthernet.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuEthernet;
                    break;
                case Define.E_UserGroup.Level3:
                    this.buttonLevel1.ButtonUp();
                    this.buttonLevel2.ButtonUp();
                    this.buttonLevel3.ButtonDown();
                    this.SetEnableLevelButton(true);

                    this.labelAccessRight.Text = this.ParentForm.ParentForm.SystemConfig.LEVEL3_NAME;

                    this.checkBoxMainProductChange.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductChange;
                    this.checkBoxMainClear.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear;
                    this.checkBoxMainSubMenu.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplaySubMenu;

                    this.checkBoxMenuRecipe.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuRecipe;
                    this.checkBoxMenuUserEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuUserSetting;
                    this.checkBoxMenuUserGroupEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuUserGroupEditor;
                    this.checkBoxMenuIOTest.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuIOTest;
                    this.checkBoxMenuHistoryLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuHistoryLog;
                    this.checkBoxMenuCheckLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuInspectionLog;
                    this.checkBoxMenuAlarmList.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuAlarmLog;
                    this.checkBoxMenuInformation.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuInformation;
                    this.checkBoxMenuEquipment.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuEquipment;
                    this.checkBoxMenuEthernet.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuEthernet;
                    break;
                case Define.E_UserGroup.Admin:
                    this.buttonLevel1.ButtonUp();
                    this.buttonLevel2.ButtonUp();
                    this.buttonLevel3.ButtonUp();
                    this.SetEnableLevelButton(false);

                    this.labelAccessRight.Text = "Admin";

                    //this.checkBoxMainProductChange.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMainDisplayProductChange;
                    //this.checkBoxMainClear.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMainDisplayClear;
                    //this.checkBoxMainSubMenu.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMainDisplaySubMenu;

                    //this.checkBoxMenuRecipe.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuRecipe;
                    //this.checkBoxMenuUserEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuUserSetting;
                    //this.checkBoxMenuUserGroupEditor.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuUserGroupEditor;
                    //this.checkBoxMenuIOTest.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuIOTest;
                    //this.checkBoxMenuHistoryLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuHistoryLog;
                    //this.checkBoxMenuCheckLog.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuInspectionLog;
                    //this.checkBoxMenuAlarmList.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuAlarmLog;
                    //this.checkBoxMenuInformation.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuInformation;
                    //this.checkBoxMenuEquipment.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuEquipment;
                    //this.checkBoxMenuEthernet.Checked = this.ParentForm.ParentForm.CurrentUserGroup.Admin.IsMenuEthernet;

                    this.checkBoxMainProductChange.Checked = true;
                    this.checkBoxMainClear.Checked = true;
                    this.checkBoxMainSubMenu.Checked = true;

                    this.checkBoxMenuRecipe.Checked = true;
                    this.checkBoxMenuUserEditor.Checked = true;
                    this.checkBoxMenuUserGroupEditor.Checked = true;
                    this.checkBoxMenuIOTest.Checked = true;
                    this.checkBoxMenuHistoryLog.Checked = true;
                    this.checkBoxMenuCheckLog.Checked = true;
                    this.checkBoxMenuAlarmList.Checked = true;
                    this.checkBoxMenuInformation.Checked = true;
                    this.checkBoxMenuEquipment.Checked = true;
                    this.checkBoxMenuEthernet.Checked = true;
                    break;
                default:
                    this.buttonLevel1.ButtonUp();
                    this.buttonLevel2.ButtonUp();
                    this.buttonLevel3.ButtonUp();
                    this.SetEnableLevelButton(true);

                    this.labelAccessRight.Text = "";

                    this.checkBoxMainProductChange.Checked = false;
                    this.checkBoxMainClear.Checked = false;
                    this.checkBoxMainSubMenu.Checked = false;

                    this.checkBoxMenuRecipe.Checked = false;
                    this.checkBoxMenuUserEditor.Checked = false;
                    this.checkBoxMenuUserGroupEditor.Checked = false;
                    this.checkBoxMenuIOTest.Checked = false;
                    this.checkBoxMenuHistoryLog.Checked = false;
                    this.checkBoxMenuCheckLog.Checked = false;
                    this.checkBoxMenuAlarmList.Checked = false;
                    this.checkBoxMenuInformation.Checked = false;
                    this.checkBoxMenuEquipment.Checked = false;
                    this.checkBoxMenuEthernet.Checked = false;
                    break;
            }
        }

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

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

            this.labelAccessRight.Text = "";

            this.buttonLevel1.ButtonText = system.LEVEL1_NAME;
            this.buttonLevel2.ButtonText = system.LEVEL2_NAME;
            this.buttonLevel3.ButtonText = system.LEVEL3_NAME;

            this.checkBoxMainProductChange.Checked = false;
            this.checkBoxMainClear.Checked = false;
            this.checkBoxMainSubMenu.Checked = false;

            this.checkBoxMenuRecipe.Checked = false;
            this.checkBoxMenuUserEditor.Checked = false;
            this.checkBoxMenuUserGroupEditor.Checked = false;
            this.checkBoxMenuIOTest.Checked = false;
            this.checkBoxMenuHistoryLog.Checked = false;
            this.checkBoxMenuCheckLog.Checked = false;
            this.checkBoxMenuAlarmList.Checked = false;
            this.checkBoxMenuInformation.Checked = false;
            this.checkBoxMenuEquipment.Checked = false;
            this.checkBoxMenuEthernet.Checked = false;

            this.buttonLevel1.ButtonUp();
            this.buttonLevel2.ButtonUp();
            this.buttonLevel3.ButtonUp();

            this.KeyboardClose();
            this.SetEnableID(true);
            this.SetEnablePasswordTextBox(false);
            this.SetEnableLevelButton(true);

            this.buttonDelete.Visible = false;
            this.buttonSave.Visible = false;
            if (this.buttonPasswordReset.ButtonText != "Reset")
                this.buttonPasswordReset.ButtonText = "Reset";

            this.listBoxUserList.SelectedIndexChanged -= new EventHandler(this.listBoxUserList_SelectedIndexChanged);
            this.listBoxUserList.SelectItemIndex = -1;
            this.listBoxUserList.SelectedIndexChanged += new EventHandler(this.listBoxUserList_SelectedIndexChanged);
        }
        public void UpdateLevelNameDisplay(SystemConfiguration system)
        {
            this.buttonLevel1.ButtonText = system.LEVEL1_NAME;
            this.buttonLevel2.ButtonText = system.LEVEL2_NAME;
            this.buttonLevel3.ButtonText = system.LEVEL3_NAME;
        }
        private void UpdateCurrentUserItem(UserManager.UserMgr_user_list_t item)
        {
            try
            {
                // CurrentUserItem SET
                this.SelectedUserItem.ID = item.user_id;
                this.SelectedUserItem.Password = item.user_pw;

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

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

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

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

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

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

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

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

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

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

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

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

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

                this.SetEnableLevelButton(false);
                this.buttonDelete.Visible = false;

                if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.Admin
                    || this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.Developer)
                {
                    this.SetEnablePasswordTextBox(true);
                    this.buttonPasswordReset.Enabled = true;
                }
                else
                {
                    this.SetEnablePasswordTextBox(false);
                    this.buttonPasswordReset.Enabled = false;
                }
            }
            else
            {
                #region 만료일
                this.labelExpiryDateOfAccount.Text = item.ExpireId.ToString();
                this.labelExpiryDateOfPassword.Text = item.ExpirePassword.ToString();

                if (item.IsLockAccount == true)
                {
                    this.labelExpiryDateOfAccount2.TextColor = Color.Red;
                    switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                    {
                        case Define.E_LanguageID.Korean:
                            this.labelExpiryDateOfAccount2.Text = "계정 만료";
                            break;
                        case Define.E_LanguageID.English:
                            this.labelExpiryDateOfAccount2.Text = "Account expiration";
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    this.labelExpiryDateOfAccount2.TextColor = Color.White;
                    this.labelExpiryDateOfAccount2.Text = string.Format("{0:yy/MM/dd} ~ {1:yy/MM/dd}", item.DateIdLogin, item.DateIdExpire);
                }

                if (item.IsLockPassword == true)
                {
                    this.labelExpiryDateOfPassword2.TextColor = Color.Red;
                    switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                    {
                        case Define.E_LanguageID.Korean:
                            this.labelExpiryDateOfPassword2.Text = "비밀번호 만료";
                            break;
                        case Define.E_LanguageID.English:
                            this.labelExpiryDateOfPassword2.Text = "Password expiration";
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    this.labelExpiryDateOfPassword2.TextColor = Color.White;
                    this.labelExpiryDateOfPassword2.Text = string.Format("{0:yy/MM/dd} ~ {1:yy/MM/dd}", item.DatePasswordRegister, item.DatePasswordExpire);
                }
                #endregion

                this.CheckBoxCheckedAsLevel(item.Group);

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

                    this.SetEnablePasswordTextBox(false);
                    this.buttonPasswordReset.Enabled = false;
                }
                else
                {
                    this.SetEnableLevelButton(true);
                    this.SetEnableExpireDate(true);
                    this.buttonPasswordReset.Enabled = true;
                }
            }

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

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

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

            this.UI_Invoke(delegate
            {
                this.UpdateSelectUserDisplay(this.SelectedUserItem);
            });
        }
        public void CallBackUserListNewData(UserManager.UserMgr_user_info_t user)
        {
            string code = "", message1 = "", message2 = "";

            switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
            {
                case Define.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 추가 완료!";
                    message2 = "";
                    break;
                case Define.E_LanguageID.English:
                    code = "user settings";
                    message1 = "User addition complete!";
                    message2 = "";
                    break;
                default:
                    break;
            }

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

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

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

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

                    this.SetEnableID(false);
                    this.labelExpiryDateOfAccount.Enabled = false;
                    this.labelExpiryDateOfAccount.BackColor = Color.Silver;
                    this.labelExpiryDateOfPassword.Enabled = false;
                    this.labelExpiryDateOfPassword.BackColor = Color.Silver;
                    this.buttonDelete.Enabled = true;
                    this.SetEnableLevelButton(false);

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

            switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
            {
                case Define.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = "사용자 정보 수정 완료!";
                    message2 = "";
                    break;
                case Define.E_LanguageID.English:
                    code = "user settings";
                    message1 = "User information modified!";
                    message2 = "";
                    break;
                default:
                    break;
            }

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

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

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

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

                UserManager.UserManager_GetUserListID(this.listBoxUserList.Items[this.listBoxUserList.SelectItemIndex]);
            }
        }
        public void CallBackUserListDeleteDataEvent(UserManager.UserMgr_user_del_t user)
        {
            string code = "", message1 = "", message2 = "", detail = "";

            switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
            {
                case Define.E_LanguageID.Korean:
                    code = "유저설정";
                    message1 = string.Format("{0} 사용자 삭제 완료!", user.user_id);
                    message2 = "";
                    break;
                case Define.E_LanguageID.English:
                    code = "user settings";
                    message1 = string.Format("{0} User deletion complete!", user.user_id);
                    message2 = "";
                    break;
                default:
                    break;
            }

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

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

                    this.UserNew();

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

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

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

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

                    switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                    {
                        case Define.E_LanguageID.Korean:
                            code = "비밀번호 변경";
                            message1 = "비밀번호가 변경되었습니다.";
                            message2 = "";
                            break;
                        case Define.E_LanguageID.English:
                            code = "Change Password";
                            message1 = "Password has been changed.";
                            message2 = "";
                            break;
                        default:
                            break;
                    }

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

        public void DisplayRefresh()
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplayMode = Define.E_DisplayModeStore.UserEditor;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_EquipmentMode.Menu);

            this.PasswordChar = false;
            this.labelAutomaticLogoutTime.Text = this.ParentForm.ParentForm.SystemConfig.AUTOMATIC_LOGOUT.ToString();
            this.labelNumberOfLoginFailures.Text = this.ParentForm.ParentForm.SystemConfig.NUMBER_OF_LOGIN_FAILURE.ToString();

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

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

            this.SetEnablePasswordTextBox(false);
            this.buttonPasswordReset.Enabled = false;
            //this.labelAutomaticLogoutTime.Enabled = true;
            this.buttonSave.Visible = false;
            if (this.buttonPasswordReset.ButtonText != "Reset")
                this.buttonPasswordReset.ButtonText = "Reset";

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

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

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

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

            this.textBoxID.Select(this.textBoxID.Text.Length, 0);
        }
        private void textBoxPassword_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxPassword;

            this.textBoxPassword.Select(this.textBoxPassword.Text.Length, 0);
        }
        private void textBoxID_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                e.Handled = true;

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

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

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

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

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

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

                if (this.PasswordChar == false)
                    this.SetTextBoxPasswordChar(this.PasswordChar);
                if (this.IsNew == true)
                    this.SetEnableID(true);
                this.textBoxPassword.Text = this.BeforePassword;
                this.KeyboardClose();
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }
        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            if (this.smartKeyboard.TargetInputObject == this.textBoxPassword)
            {
                this.textBoxPassword.Text = this.BeforePassword;
                if (this.PasswordChar == false)
                    this.SetTextBoxPasswordChar(this.PasswordChar);
                this.textBoxPassword.Select(this.textBoxPassword.Text.Length, 0);
            }
            else if (this.smartKeyboard.TargetInputObject == this.textBoxID)
            {
                this.textBoxID.Text = this.BeforeID;
                this.textBoxID.Select(this.textBoxID.Text.Length, 0);
            }

            this.KeyboardClose();

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

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

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

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

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

                UserManager.UserManager_UserDel(id);

                this.buttonDelete.Visible = false;
            }
        }

        private void buttonLevel_Click(object sender, EventArgs e)
        {
            SmartX.SmartButton button = sender as SmartX.SmartButton;

            if (button == this.buttonLevel1)
            {
                this.CheckBoxCheckedAsLevel(Define.E_UserGroup.Level1);
            }
            else if (button == this.buttonLevel2)
            {
                this.CheckBoxCheckedAsLevel(Define.E_UserGroup.Level2);
            }
            else if (button == this.buttonLevel3)
            {
                this.CheckBoxCheckedAsLevel(Define.E_UserGroup.Level3);
            }

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

        private void buttonIDEdit_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(5, 125);
            this.smartKeyboard.Size = new Size(897, 352);
            this.smartKeyboard.Hide();

            this.BeforeID = this.textBoxID.Text;

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

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

            this.listBoxUserList.Enabled = false;
            this.SetEnableControl(false);
        }
        private void buttonPasswordReset_Click(object sender, EventArgs e)
        {
            if (this.buttonPasswordReset.ButtonText == "Edit")
            {
                if (this.listBoxUserList.SelectItemIndex == 0
                    && this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.ActiveLevel < 9)
                    return;

                this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
                this.smartKeyboard.Location = new Point(5, 125);
                this.smartKeyboard.Size = new Size(897, 352);
                this.smartKeyboard.Hide();

                this.BeforePassword = this.textBoxPassword.Text;

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

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

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

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

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

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

                    ret = UserManager.UserManager_UserResetPWDirect(id, pw);

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

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

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

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

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

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

                    if (this.buttonSave.Visible == false)
                        this.buttonSave.Visible = true;
                }
            }
        }
        private void labelAutomaticLogoutTime_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelAutomaticLogoutTime.Text, 2, 0, false);

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

                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;

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

                UserManager.UserManager_AutoLogoutSetTimeout(this.ParentForm.ParentForm.SystemConfig.AUTOMATIC_LOGOUT, this.ParentForm.ParentForm.FlagAutomaticLogoutWarningTime);
            }
        }
        private void labelNumberOfLoginFailures_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelNumberOfLoginFailures.Text, 2, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue <= 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelNumberOfLoginFailures.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.SystemConfig.NUMBER_OF_LOGIN_FAILURE = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);
                }
            }
        }
        private void labelExpiryDateOfAccount2_Click(object sender, EventArgs e)
        {
            string code = "", message1 = "", message2 = "";
            string detail = "";

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

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

                // Part 11
                detail = string.Format("Extend EXP date(ID) : {0}", this.SelectedUserItem.ID);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            }
            else
            {
                switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저설정";
                        message1 = "사용자 잠금 해제 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User settings";
                        message1 = "Do you want to unlock user?";
                        message2 = "";
                        break;
                    default:
                        break;
                }

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

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

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

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

                // Part 11
                detail = string.Format("Extend EXP date(PW) : {0}", this.SelectedUserItem.ID);
                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
            }
            else
            {
                switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE)
                {
                    case Define.E_LanguageID.Korean:
                        code = "유저설정";
                        message1 = "비밀번호 잠금 해제 하시겠습니까?";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "User settings";
                        message1 = "Do you want to unlock password?";
                        message2 = "";
                        break;
                    default:
                        break;
                }

                DialogFormYesNo dlg = new DialogFormYesNo(Define.E_MessageBoxIcon.Question, code, message1, message2);
                if (dlg.ShowDialog() == DialogResult.Yes)
                {
                    UserManager.UserManager_UserLockRelease(this.SelectedUserItem.ID, false, true);
                    
                    // Part 11
                    detail = string.Format("Release PW: {0}", this.SelectedUserItem.ID);
                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.UserEditor, detail);
                }
            }
        }
        #endregion
    }
}
