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 ITC81DB_2H.Forms;
using ITC81DB_2H.DialogForms;
using ITC81DB_2H_ImageDll;
using ITC81DB_2H.Datastore;
using SmartX;
using ITC81DB_2H.Part11_UserManager;

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

        private string BeforeTextBox1;
        private string BeforeTextBox2;
        private string BeforeTextBox3;
        #endregion

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

            this.ParentForm = parent;

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

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

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

            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                #region 영어
                this.labelTitleMainScreen.Text = "Main screen";
                this.labelTitleProductNo.Text = "Product change";
                this.labelTitleWeightSetting.Text = "Weight settings";
                this.labelTitleClear.Text = "Clear";
                this.labelTitleSubMenu.Text = "Sub menu";

                this.labelTitleBasic.Text = "Basic";
                this.labelTitleTime.Text = "Time setting";
                this.labelTitleProduct.Text = "Product settings";
                this.labelTitleDataStat.Text = "Data stats";

                this.labelTitleConfiguration.Text = "Configuration";
                this.labelTitleSerial.Text = "Serial";
                this.labelTitleEthernet.Text = "Ethernet";

                this.labelTitleSystem.Text = "System";
                this.labelTitleCalibration.Text = "Calibration";
                this.labelTitleJudgment.Text = "Judgment";
                this.labelTitleSorter.Text = "Sorter settings";
                this.labelTitleAutoZero.Text = "Auto zero";
                this.labelTitleIOTest.Text = "I/O test";
                this.labelTitleExternalOutput.Text = "External output";

                this.labelTitleEquipment.Text = "Equipment";
                this.labelTitleUpdate.Text = "Update";
                this.labelTitleInitialization.Text = "Initialization";
                this.labelTitleFunction.Text = "Feature settings";
                this.labelTitleUser.Text = "User settings";
                this.labelTitleEngineer.Text = "Engineer settings";

                this.labelTitleLog.Text = "Log";
                this.labelTitleChangeName.TextHAlign = SmartLabel.TextHorAlign.Left;
                this.labelTitleChangeName.TextVAlign = SmartLabel.TextVerAlign.Top;
                this.labelTitleChangeName.Text = "Change Lv Name";
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                #region 중국어
                this.labelTitleMainScreen.Text = "主屏幕";
                this.labelTitleProductNo.Text = "产品变化";
                this.labelTitleWeightSetting.Text = "体重设定";
                this.labelTitleClear.Text = "消除";
                this.labelTitleSubMenu.Text = "子菜单";

                this.labelTitleBasic.Text = "基本";
                this.labelTitleTime.Text = "时间设定";
                this.labelTitleProduct.Text = "产品设置";
                this.labelTitleDataStat.Text = "数据统计";

                this.labelTitleConfiguration.Text = "选项";
                this.labelTitleSerial.Text = "串行端口";
                this.labelTitleEthernet.Text = "以太网";

                this.labelTitleSystem.Text = "系统设定";
                this.labelTitleCalibration.Text = "校准";
                this.labelTitleJudgment.Text = "判断设置";
                this.labelTitleSorter.Text = "筛选设定";
                this.labelTitleAutoZero.Text = "自动零点跟踪";
                this.labelTitleIOTest.Text = "I/O测试";
                this.labelTitleExternalOutput.Text = "外部输出";

                this.labelTitleEquipment.Text = "设备设置";
                this.labelTitleUpdate.Text = "更新";
                this.labelTitleInitialization.Text = "工厂初期化";
                this.labelTitleFunction.Text = "功能设定";
                this.labelTitleUser.Text = "用户设置";
                this.labelTitleEngineer.Text = "工程师设置";

                this.labelTitleLog.Text = "日志";
                this.labelTitleChangeName.TextHAlign = SmartLabel.TextHorAlign.Middle;
                this.labelTitleChangeName.TextVAlign = SmartLabel.TextVerAlign.Middle;
                this.labelTitleChangeName.Text = "更改级别名称";
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                #region 러시아어
                this.labelTitleMainScreen.Text = "Зернистый";
                this.labelTitleProductNo.Text = "Изменять товар";
                this.labelTitleWeightSetting.Text = "Настройки вектора";
                this.labelTitleClear.Text = "Сброс";
                this.labelTitleSubMenu.Text = "Подменю";

                this.labelTitleBasic.Text = "Основной";
                this.labelTitleTime.Text = "Настройки времени";
                this.labelTitleProduct.Text = "Настройки продукта";
                this.labelTitleDataStat.Text = "Статистика данных";

                this.labelTitleConfiguration.Text = "Конфигурация";
                this.labelTitleSerial.Text = "Послед. порт";
                this.labelTitleEthernet.Text = "Локальная сеть";

                this.labelTitleSystem.Text = "Системные настройки";
                this.labelTitleCalibration.Text = "Калибровка";
                this.labelTitleJudgment.Text = "Настройка отбраковки";
                this.labelTitleSorter.Text = "Настройка сортировки";
                this.labelTitleAutoZero.Text = "Автоотслеживание нуля";
                this.labelTitleIOTest.Text = "Тест ввода/вывода";
                this.labelTitleExternalOutput.Text = "Внешний выход";

                this.labelTitleEquipment.Text = "Настройка оборудования";
                this.labelTitleUpdate.Text = "Обновить";
                this.labelTitleInitialization.Text = "Инициализация";
                this.labelTitleFunction.Text = "Функциональные настройки";
                this.labelTitleUser.Text = "Настройки пользователя";
                this.labelTitleEngineer.Text = "Инженерные настройки";

                this.labelTitleLog.Text = "Системный журнал";
                this.labelTitleChangeName.TextHAlign = SmartLabel.TextHorAlign.Left;
                this.labelTitleChangeName.TextVAlign = SmartLabel.TextVerAlign.Top;
                this.labelTitleChangeName.Text = "Изменить имя уровня";
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                #region 독일어
                this.labelTitleMainScreen.Text = "Hauptbildschirm";
                this.labelTitleProductNo.Text = "Warenwechsel";
                this.labelTitleWeightSetting.Text = "Gewichts-Einstellungen";
                this.labelTitleClear.Text = "Löschen";
                this.labelTitleSubMenu.Text = "Untermenü";

                this.labelTitleBasic.Text = "Basic";
                this.labelTitleTime.Text = "Zeiteinstellung";
                this.labelTitleProduct.Text = "Produkteinstellung";
                this.labelTitleDataStat.Text = "Statistik";

                this.labelTitleConfiguration.Text = "Konfiguration";
                this.labelTitleSerial.Text = "Kommunikationseinstellung";
                this.labelTitleEthernet.Text = "Ethernet";

                this.labelTitleSystem.Text = "Systemeinstellung";
                this.labelTitleCalibration.Text = "Kalibrierung";
                this.labelTitleJudgment.Text = "Tascheneinstellung";
                this.labelTitleSorter.Text = "Sortierereinstellung";
                this.labelTitleAutoZero.Text = "Automatische Nullung";
                this.labelTitleIOTest.Text = "I/O Test";
                this.labelTitleExternalOutput.Text = "Externer Ausgang";

                this.labelTitleEquipment.Text = "Vorrichtungeinstellung";
                this.labelTitleUpdate.Text = "Aktualisierung";
                this.labelTitleInitialization.Text = "Werkseinstellung";
                this.labelTitleFunction.Text = "Funktionseinstellungen";
                this.labelTitleUser.Text = "Benutzereinstellungen";
                this.labelTitleEngineer.Text = "Ingenieur-Einstellungen";

                this.labelTitleLog.Text = "Systemprotokoll";
                this.labelTitleChangeName.TextHAlign = SmartLabel.TextHorAlign.Left;
                this.labelTitleChangeName.TextVAlign = SmartLabel.TextVerAlign.Top;
                this.labelTitleChangeName.Text = "Ebenennamen ändern";
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {

            }
            else
            {
                #region 한국어
                this.labelTitleMainScreen.Text = "메인화면 접근";
                this.labelTitleProductNo.Text = "품번변경";
                this.labelTitleWeightSetting.Text = "중량설정";
                this.labelTitleClear.Text = "소거";
                this.labelTitleSubMenu.Text = "서브메뉴";

                this.labelTitleBasic.Text = "기본";
                this.labelTitleTime.Text = "시간설정";
                this.labelTitleProduct.Text = "품목설정";
                this.labelTitleDataStat.Text = "데이터집계";

                this.labelTitleConfiguration.Text = "환경";
                this.labelTitleSerial.Text = "시리얼통신";
                this.labelTitleEthernet.Text = "이더넷통신";

                this.labelTitleSystem.Text = "시스템";
                this.labelTitleCalibration.Text = "중량조정";
                this.labelTitleJudgment.Text = "판정설정";
                this.labelTitleSorter.Text = "선별기설정";
                this.labelTitleAutoZero.Text = "자동영점";
                this.labelTitleIOTest.Text = "I/O테스트";
                this.labelTitleExternalOutput.Text = "외부출력";

                this.labelTitleEquipment.Text = "장비";
                this.labelTitleUpdate.Text = "업데이트";
                this.labelTitleInitialization.Text = "공장초기화";
                this.labelTitleFunction.Text = "기능설정";
                this.labelTitleUser.Text = "유저설정";
                this.labelTitleEngineer.Text = "엔지니어설정";

                this.labelTitleLog.Text = "로그";
                this.labelTitleChangeName.TextHAlign = SmartLabel.TextHorAlign.Middle;
                this.labelTitleChangeName.TextVAlign = SmartLabel.TextVerAlign.Middle;
                this.labelTitleChangeName.Text = "레벨명변경";
                #endregion
            }
        }
        private void DefaultSetting()
        {
            this.BeforeTextBox1 = "";
            this.BeforeTextBox2 = "";
            this.BeforeTextBox3 = "";
        }

        private void UpdateDisplay(UserGroup group)
        {
            #region Level1
            this.checkBoxL1MainClear.Checked = group.Level1.IsMainDisplayClear;
            this.checkBoxL1MainProductNo.Checked = group.Level1.IsMainDisplayProductNo;
            this.checkBoxL1MainSubMenu.Checked = group.Level1.IsMainDisplaySubMenu;
            this.checkBoxL1MainWeightSetting.Checked = group.Level1.IsMainDisplayWeightSetting;

            this.checkBoxL1BasicDataStat.Checked = group.Level1.IsBasicDataStatistics;
            this.checkBoxL1BasicProduct.Checked = group.Level1.IsBasicProduct;
            this.checkBoxL1BasicTime.Checked = group.Level1.IsBasicTime;

            this.checkBoxL1ConfigEthernet.Checked = group.Level1.IsConfiEthernet;
            this.checkBoxL1ConfigSerial.Checked = group.Level1.IsConfiSerial;

            this.checkBoxL1SystemAutoZero.Checked = group.Level1.IsSystemAutoZero;
            this.checkBoxL1SystemCalibration.Checked = group.Level1.IsSystemCalibration;
            this.checkBoxL1SystemExternalOutput.Checked = group.Level1.IsSystemExternalOutput;
            this.checkBoxL1SystemIOTest.Checked = group.Level1.IsSystemIOTest;
            this.checkBoxL1SystemJudgment.Checked = group.Level1.IsSystemJudgmentSetting;
            this.checkBoxL1SystemSorter.Checked = group.Level1.IsSystemSorterSetting;

            this.checkBoxL1EquipmentEngineer.Checked = group.Level1.IsEquipEngineerSetting;
            this.checkBoxL1EquipmentFunction.Checked = group.Level1.IsEquipFunctionSetting;
            this.checkBoxL1EquipmentInitialization.Checked = group.Level1.IsEquipInitialize;
            this.checkBoxL1EquipmentUpdate.Checked = group.Level1.IsEquipUpdate;
            this.checkBoxL1EquipmentUser.Checked = group.Level1.IsEquipUserSetting;

            this.checkBoxL1Log.Checked = group.Level1.IsLogEnable;
            #endregion

            #region Level2
            this.checkBoxL2MainClear.Checked = group.Level2.IsMainDisplayClear;
            this.checkBoxL2MainProductNo.Checked = group.Level2.IsMainDisplayProductNo;
            this.checkBoxL2MainSubMenu.Checked = group.Level2.IsMainDisplaySubMenu;
            this.checkBoxL2MainWeightSetting.Checked = group.Level2.IsMainDisplayWeightSetting;

            this.checkBoxL2BasicDataStat.Checked = group.Level2.IsBasicDataStatistics;
            this.checkBoxL2BasicProduct.Checked = group.Level2.IsBasicProduct;
            this.checkBoxL2BasicTime.Checked = group.Level2.IsBasicTime;

            this.checkBoxL2ConfigEthernet.Checked = group.Level2.IsConfiEthernet;
            this.checkBoxL2ConfigSerial.Checked = group.Level2.IsConfiSerial;

            this.checkBoxL2SystemAutoZero.Checked = group.Level2.IsSystemAutoZero;
            this.checkBoxL2SystemCalibration.Checked = group.Level2.IsSystemCalibration;
            this.checkBoxL2SystemExternalOutput.Checked = group.Level2.IsSystemExternalOutput;
            this.checkBoxL2SystemIOTest.Checked = group.Level2.IsSystemIOTest;
            this.checkBoxL2SystemJudgment.Checked = group.Level2.IsSystemJudgmentSetting;
            this.checkBoxL2SystemSorter.Checked = group.Level2.IsSystemSorterSetting;

            this.checkBoxL2EquipmentEngineer.Checked = group.Level2.IsEquipEngineerSetting;
            this.checkBoxL2EquipmentFunction.Checked = group.Level2.IsEquipFunctionSetting;
            this.checkBoxL2EquipmentInitialization.Checked = group.Level2.IsEquipInitialize;
            this.checkBoxL2EquipmentUpdate.Checked = group.Level2.IsEquipUpdate;
            this.checkBoxL2EquipmentUser.Checked = group.Level2.IsEquipUserSetting;

            this.checkBoxL2Log.Checked = group.Level2.IsLogEnable;
            #endregion

            #region Level3
            this.checkBoxL3MainClear.Checked = group.Level3.IsMainDisplayClear;
            this.checkBoxL3MainProductNo.Checked = group.Level3.IsMainDisplayProductNo;
            this.checkBoxL3MainSubMenu.Checked = group.Level3.IsMainDisplaySubMenu;
            this.checkBoxL3MainWeightSetting.Checked = group.Level3.IsMainDisplayWeightSetting;

            this.checkBoxL3BasicDataStat.Checked = group.Level3.IsBasicDataStatistics;
            this.checkBoxL3BasicProduct.Checked = group.Level3.IsBasicProduct;
            this.checkBoxL3BasicTime.Checked = group.Level3.IsBasicTime;

            this.checkBoxL3ConfigEthernet.Checked = group.Level3.IsConfiEthernet;
            this.checkBoxL3ConfigSerial.Checked = group.Level3.IsConfiSerial;

            this.checkBoxL3SystemAutoZero.Checked = group.Level3.IsSystemAutoZero;
            this.checkBoxL3SystemCalibration.Checked = group.Level3.IsSystemCalibration;
            this.checkBoxL3SystemExternalOutput.Checked = group.Level3.IsSystemExternalOutput;
            this.checkBoxL3SystemIOTest.Checked = group.Level3.IsSystemIOTest;
            this.checkBoxL3SystemJudgment.Checked = group.Level3.IsSystemJudgmentSetting;
            this.checkBoxL3SystemSorter.Checked = group.Level3.IsSystemSorterSetting;

            this.checkBoxL3EquipmentEngineer.Checked = group.Level3.IsEquipEngineerSetting;
            this.checkBoxL3EquipmentFunction.Checked = true;
            this.checkBoxL3EquipmentInitialization.Checked = group.Level3.IsEquipInitialize;
            this.checkBoxL3EquipmentUpdate.Checked = group.Level3.IsEquipUpdate;
            this.checkBoxL3EquipmentUser.Checked = true;

            this.checkBoxL3Log.Checked = group.Level3.IsLogEnable;
            #endregion

            #region Not Login
            this.checkBoxNotLoginMainClear.Checked = group.NotLogin.IsMainDisplayClear;
            this.checkBoxNotLoginMainProductNo.Checked = group.NotLogin.IsMainDisplayProductNo;
            this.checkBoxNotLoginMainSubMenu.Checked = group.NotLogin.IsMainDisplaySubMenu;
            this.checkBoxNotLoginMainWeightSetting.Checked = group.NotLogin.IsMainDisplayWeightSetting;

            this.checkBoxNotLoginBasicDataStat.Checked = group.NotLogin.IsBasicDataStatistics;
            this.checkBoxNotLoginBasicProduct.Checked = group.NotLogin.IsBasicProduct;
            this.checkBoxNotLoginBasicTime.Checked = group.NotLogin.IsBasicTime;

            this.checkBoxNotLoginConfigEthernet.Checked = group.NotLogin.IsConfiEthernet;
            this.checkBoxNotLoginConfigSerial.Checked = group.NotLogin.IsConfiSerial;

            this.checkBoxNotLoginSystemAutoZero.Checked = group.NotLogin.IsSystemAutoZero;
            this.checkBoxNotLoginSystemCalibration.Checked = group.NotLogin.IsSystemCalibration;
            this.checkBoxNotLoginSystemExternalOutput.Checked = group.NotLogin.IsSystemExternalOutput;
            this.checkBoxNotLoginSystemIOTest.Checked = group.NotLogin.IsSystemIOTest;
            this.checkBoxNotLoginSystemJudgment.Checked = group.NotLogin.IsSystemJudgmentSetting;
            this.checkBoxNotLoginSystemSorter.Checked = group.NotLogin.IsSystemSorterSetting;

            this.checkBoxNotLoginEquipmentEngineer.Checked = group.NotLogin.IsEquipEngineerSetting;
            this.checkBoxNotLoginEquipmentFunction.Checked = group.NotLogin.IsEquipFunctionSetting;
            this.checkBoxNotLoginEquipmentInitialization.Checked = group.NotLogin.IsEquipInitialize;
            this.checkBoxNotLoginEquipmentUpdate.Checked = group.NotLogin.IsEquipUpdate;
            this.checkBoxNotLoginEquipmentUser.Checked = false;

            this.checkBoxNotLoginLog.Checked = group.NotLogin.IsLogEnable;
            #endregion

            if (this.buttonSave.Visible == true)
                this.buttonSave.Visible = false;
        }
        public void UpdateNotLoginVisible(bool bValue)
        {
            this.labelTitleNotLogin1.Visible = bValue;
            this.labelTitleNotLogin2.Visible = bValue;

            this.checkBoxNotLoginMainClear.Visible = bValue;
            this.checkBoxNotLoginMainProductNo.Visible = bValue;
            this.checkBoxNotLoginMainSubMenu.Visible = bValue;
            this.checkBoxNotLoginMainWeightSetting.Visible = bValue;

            this.checkBoxNotLoginBasicDataStat.Visible = bValue;
            this.checkBoxNotLoginBasicProduct.Visible = bValue;
            this.checkBoxNotLoginBasicTime.Visible = bValue;

            this.checkBoxNotLoginConfigEthernet.Visible = bValue;
            this.checkBoxNotLoginConfigSerial.Visible = bValue;

            this.checkBoxNotLoginSystemAutoZero.Visible = bValue;
            this.checkBoxNotLoginSystemCalibration.Visible = bValue;
            //this.checkBoxNotLoginSystemExternalOutput.Visible = bValue;
            this.checkBoxNotLoginSystemIOTest.Visible = bValue;
            this.checkBoxNotLoginSystemJudgment.Visible = bValue;
            this.checkBoxNotLoginSystemSorter.Visible = bValue;

            //this.checkBoxNotLoginEquipmentEngineer.Visible = bValue;
            this.checkBoxNotLoginEquipmentFunction.Visible = bValue;
            this.checkBoxNotLoginEquipmentInitialization.Visible = bValue;
            this.checkBoxNotLoginEquipmentUpdate.Visible = bValue;
            this.checkBoxNotLoginEquipmentUser.Visible = bValue;

            this.checkBoxNotLoginLog.Visible = bValue;
        }
        public void UpdateAllMenu(SystemStatus status)
        {         
            this.ParentForm.ParentForm.ChildFormMainDisplay.UpdateMainDisplay(status);

            this.ParentForm.UpdateMenuDisplay(status);

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

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

        public void UpdateLevelNameDisplay(SystemConfigurationItem2 system)
        {
            this.textBoxLevel1.Text = system.UserGroupLevel1Name;
            this.textBoxLevel2.Text = system.UserGroupLevel2Name;
            this.textBoxLevel3.Text = system.UserGroupLevel3Name;
        }

        public void DisplayRefresh(SystemStatus status)
        {
            if(this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.Developer)
                this.UpdateNotLoginVisible(true);
            else
                this.UpdateNotLoginVisible(false);
            this.UpdateDisplay(this.ParentForm.ParentForm.CurrentUserGroup);
            this.UpdateLevelNameDisplay(this.ParentForm.ParentForm.SystemConfig2);
        }
        #endregion

        #region Event Handler
        private void checkBox_Click(object sender, EventArgs e)
        {
            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }

        private void textBoxLevel1_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxLevel1;
            this.textBoxLevel1.Select(this.textBoxLevel1.Text.Length, 0);
        }
        private void textBoxLevel2_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxLevel2;
            this.textBoxLevel2.Select(this.textBoxLevel2.Text.Length, 0);
        }
        private void textBoxLevel3_GotFocus(object sender, EventArgs e)
        {
            this.smartKeyboard.TargetInputObject = this.textBoxLevel3;
            this.textBoxLevel3.Select(this.textBoxLevel3.Text.Length, 0);
        }

        private void buttonEdit_Click(object sender, EventArgs e)
        {
            SmartButton button = sender as SmartButton;

            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(8, 0);
            this.smartKeyboard.Size = new Size(695, 377);
            this.smartKeyboard.KeyFillColor = Color.Black;
            this.smartKeyboard.BackColor = Color.FromArgb(30, 30, 30);

            if (button == this.buttonEditLevel1)
            {
                this.textBoxLevel2.Enabled = false;
                this.textBoxLevel3.Enabled = false;

                this.BeforeTextBox1 = this.textBoxLevel1.Text;
                this.smartKeyboard.TargetInputObject = this.textBoxLevel1;
                this.textBoxLevel1.Select(this.textBoxLevel1.Text.Length, 0);
            }
            else if (button == this.buttonEditLevel2)
            {
                this.textBoxLevel1.Enabled = false;
                this.textBoxLevel3.Enabled = false;

                this.BeforeTextBox2 = this.textBoxLevel2.Text;
                this.smartKeyboard.TargetInputObject = this.textBoxLevel2;
                this.textBoxLevel2.Select(this.textBoxLevel2.Text.Length, 0);
            }
            else if (button == this.buttonEditLevel3)
            {
                this.textBoxLevel1.Enabled = false;
                this.textBoxLevel2.Enabled = false;

                this.BeforeTextBox3 = this.textBoxLevel3.Text;
                this.smartKeyboard.TargetInputObject = this.textBoxLevel3;
                this.textBoxLevel3.Select(this.textBoxLevel3.Text.Length, 0);
            }

            this.smartKeyboard.Show();
        }

        private void textBoxLevel1_KeyPress(object sender, KeyPressEventArgs e)
        {
            string before = "", after = "";

            if (e.KeyChar == '\r')
            {
                e.Handled = true;
                this.smartKeyboard.Hide();

                if (this.textBoxLevel1.Text == ""
                    || this.textBoxLevel1.Text == this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel2Name
                    || this.textBoxLevel1.Text == this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel3Name)
                {
                    this.UpdateLevelNameDisplay(this.ParentForm.ParentForm.SystemConfig2);
                }
                else
                {
                    before = this.BeforeTextBox1;
                    after = this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel1Name = this.textBoxLevel1.Text;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);

                    this.ParentForm.ParentForm.ChildFormMenu.CenterEquipUser.UpdateAccessRightComboBox();
                    this.ParentForm.ParentForm.ChildFormMainDisplay.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus);
                    this.ParentForm.ParentForm.ChildFormMenu.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.ChangeL1Name, "", before, after);
                }

                this.textBoxLevel1.Enabled = true;
                this.textBoxLevel2.Enabled = true;
                this.textBoxLevel3.Enabled = true;
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;

                this.textBoxLevel1.Text = this.BeforeTextBox1;
                this.smartKeyboard.Hide();

                this.textBoxLevel1.Enabled = true;
                this.textBoxLevel2.Enabled = true;
                this.textBoxLevel3.Enabled = true;
            }
            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 textBoxLevel2_KeyPress(object sender, KeyPressEventArgs e)
        {
            string before = "", after = "";

            if (e.KeyChar == '\r')
            {
                e.Handled = true;
                this.smartKeyboard.Hide();

                if (this.textBoxLevel2.Text == ""
                    || this.textBoxLevel2.Text == this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel1Name
                    || this.textBoxLevel2.Text == this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel3Name)
                {
                    this.UpdateLevelNameDisplay(this.ParentForm.ParentForm.SystemConfig2);
                }
                else
                {
                    before = this.BeforeTextBox2;
                    after = this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel2Name = this.textBoxLevel2.Text;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);

                    this.ParentForm.ParentForm.ChildFormMenu.CenterEquipUser.UpdateAccessRightComboBox();
                    this.ParentForm.ParentForm.ChildFormMainDisplay.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus);
                    this.ParentForm.ParentForm.ChildFormMenu.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.ChangeL2Name, "", before, after);
                }
                this.textBoxLevel1.Enabled = true;
                this.textBoxLevel2.Enabled = true;
                this.textBoxLevel3.Enabled = true;
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;

                this.textBoxLevel2.Text = this.BeforeTextBox2;
                this.smartKeyboard.Hide();

                this.textBoxLevel1.Enabled = true;
                this.textBoxLevel2.Enabled = true;
                this.textBoxLevel3.Enabled = true;
            }
            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 textBoxLevel3_KeyPress(object sender, KeyPressEventArgs e)
        {
            string before = "", after = "";

            if (e.KeyChar == '\r')
            {
                e.Handled = true;
                this.smartKeyboard.Hide();

                if (this.textBoxLevel3.Text == ""
                    || this.textBoxLevel3.Text == this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel1Name
                    || this.textBoxLevel3.Text == this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel2Name)
                {
                    this.UpdateLevelNameDisplay(this.ParentForm.ParentForm.SystemConfig2);
                }
                else
                {
                    before = this.BeforeTextBox3;
                    after = this.ParentForm.ParentForm.SystemConfig2.UserGroupLevel3Name = this.textBoxLevel3.Text;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);

                    this.ParentForm.ParentForm.ChildFormMenu.CenterEquipUser.UpdateAccessRightComboBox();
                    this.ParentForm.ParentForm.ChildFormMainDisplay.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus);
                    this.ParentForm.ParentForm.ChildFormMenu.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.ChangeL3Name, "", before, after);
                }

                this.textBoxLevel1.Enabled = true;
                this.textBoxLevel2.Enabled = true;
                this.textBoxLevel3.Enabled = true;
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;

                this.textBoxLevel3.Text = this.BeforeTextBox3;
                this.smartKeyboard.Hide();

                this.textBoxLevel1.Enabled = true;
                this.textBoxLevel2.Enabled = true;
                this.textBoxLevel3.Enabled = true;
            }
            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.textBoxLevel1)
            {
                this.textBoxLevel1.Text = this.BeforeTextBox1;
            }
            else if (this.smartKeyboard.TargetInputObject == this.textBoxLevel2)
            {
                this.textBoxLevel2.Text = this.BeforeTextBox2;
            }
            else if (this.smartKeyboard.TargetInputObject == this.textBoxLevel3)
            {
                this.textBoxLevel3.Text = this.BeforeTextBox3;
            }

            this.smartKeyboard.Hide();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            string detail;

            #region Level1
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear = this.checkBoxL1MainClear.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo = this.checkBoxL1MainProductNo.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplaySubMenu = this.checkBoxL1MainSubMenu.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMainDisplayWeightSetting = this.checkBoxL1MainWeightSetting.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicDataStatistics = this.checkBoxL1BasicDataStat.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicProduct = this.checkBoxL1BasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicTime = this.checkBoxL1BasicTime.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiEthernet = this.checkBoxL1ConfigEthernet.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiSerial = this.checkBoxL1ConfigSerial.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemAutoZero = this.checkBoxL1SystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemCalibration = this.checkBoxL1SystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemExternalOutput = this.checkBoxL1SystemExternalOutput.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemIOTest = this.checkBoxL1SystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemJudgmentSetting = this.checkBoxL1SystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemSorterSetting = this.checkBoxL1SystemSorter.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipEngineerSetting = this.checkBoxL1EquipmentEngineer.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipFunctionSetting = this.checkBoxL1EquipmentFunction.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipInitialize = this.checkBoxL1EquipmentInitialization.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipUpdate = this.checkBoxL1EquipmentUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipUserSetting = this.checkBoxL1EquipmentUser.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsLogJudge = this.checkBoxL1Log.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsLogHistory = this.checkBoxL1Log.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsLogOthers = this.checkBoxL1Log.Checked;
            #endregion

            #region Level2
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear = this.checkBoxL2MainClear.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo = this.checkBoxL2MainProductNo.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplaySubMenu = this.checkBoxL2MainSubMenu.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMainDisplayWeightSetting = this.checkBoxL2MainWeightSetting.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicDataStatistics = this.checkBoxL2BasicDataStat.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicProduct = this.checkBoxL2BasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicTime = this.checkBoxL2BasicTime.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiEthernet = this.checkBoxL2ConfigEthernet.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiSerial = this.checkBoxL2ConfigSerial.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemAutoZero = this.checkBoxL2SystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemCalibration = this.checkBoxL2SystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemExternalOutput = this.checkBoxL2SystemExternalOutput.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemIOTest = this.checkBoxL2SystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemJudgmentSetting = this.checkBoxL2SystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemSorterSetting = this.checkBoxL2SystemSorter.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipEngineerSetting = this.checkBoxL2EquipmentEngineer.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipFunctionSetting = this.checkBoxL2EquipmentFunction.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipInitialize = this.checkBoxL2EquipmentInitialization.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipUpdate = this.checkBoxL2EquipmentUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipUserSetting = this.checkBoxL2EquipmentUser.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsLogJudge = this.checkBoxL2Log.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsLogHistory = this.checkBoxL2Log.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsLogOthers = this.checkBoxL2Log.Checked;
            #endregion

            #region Level3
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear = this.checkBoxL3MainProductNo.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo = this.checkBoxL3MainProductNo.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplaySubMenu = this.checkBoxL3MainSubMenu.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMainDisplayWeightSetting = this.checkBoxL3MainWeightSetting.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicDataStatistics = this.checkBoxL3BasicDataStat.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicProduct = this.checkBoxL3BasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicTime = true;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiEthernet = this.checkBoxL3ConfigEthernet.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiSerial = this.checkBoxL3ConfigSerial.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemAutoZero = this.checkBoxL3SystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemCalibration = this.checkBoxL3SystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemExternalOutput = this.checkBoxL3SystemExternalOutput.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemIOTest = this.checkBoxL3SystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemJudgmentSetting = this.checkBoxL3SystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemSorterSetting = this.checkBoxL3SystemSorter.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipEngineerSetting = true;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipFunctionSetting = true;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipInitialize = this.checkBoxL3EquipmentInitialization.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipUpdate = this.checkBoxL3EquipmentUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipUserSetting = true;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsLogJudge = this.checkBoxL3Log.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsLogHistory = this.checkBoxL3Log.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsLogOthers = this.checkBoxL3Log.Checked;
            #endregion

            #region Not Login
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayClear = this.checkBoxNotLoginMainClear.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayProductNo = this.checkBoxNotLoginMainProductNo.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplaySubMenu = this.checkBoxNotLoginMainSubMenu.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayWeightSetting = this.checkBoxNotLoginMainWeightSetting.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicDataStatistics = this.checkBoxNotLoginBasicDataStat.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicProduct = this.checkBoxNotLoginBasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicTime = this.checkBoxNotLoginBasicTime.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsConfiEthernet = this.checkBoxNotLoginConfigEthernet.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsConfiSerial = this.checkBoxNotLoginConfigSerial.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemAutoZero = this.checkBoxNotLoginSystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemCalibration = this.checkBoxNotLoginSystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemExternalOutput = this.checkBoxNotLoginSystemExternalOutput.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemIOTest = this.checkBoxNotLoginSystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemJudgmentSetting = this.checkBoxNotLoginSystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemSorterSetting = this.checkBoxNotLoginSystemSorter.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipEngineerSetting = true;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipFunctionSetting = this.checkBoxNotLoginEquipmentFunction.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipInitialize = this.checkBoxNotLoginEquipmentInitialization.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipUpdate = this.checkBoxNotLoginEquipmentUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipUserSetting = false;

            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsLogJudge = this.checkBoxNotLoginLog.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsLogHistory = this.checkBoxNotLoginLog.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsLogOthers = this.checkBoxNotLoginLog.Checked;
            #endregion

            this.ParentForm.ParentForm.SaveUserGroupFile(this.ParentForm.ParentForm.CurrentUserGroup);
            this.UpdateAllMenu(this.ParentForm.ParentForm.CurrentSystemStatus);

            // Part 11
            detail = "Change access right";
            this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.GroupEditor, detail);

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

            this.ParentForm.CenterEquipUser.DisplayRefresh(this.ParentForm.ParentForm.CurrentSystemStatus);
            this.ParentForm.CenterEquipUser.BringToFront();
        }
        #endregion
    }
}
