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

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

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

        private Collection<Point> CollectionLevel1Location;
        private Collection<Point> CollectionLevel2Location;
        private Collection<Point> CollectionLevel3Location;

        private Collection<Control> CollectionLevel1Control;
        private Collection<Control> CollectionLevel2Control;
        private Collection<Control> CollectionLevel3Control;
        private Collection<Control> CollectionLevel4Control;

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

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

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

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

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

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    this.labelTitle.Text = "그룹 에디터";
                    break;
                case DataStore.LanguageID.English:
                    this.labelTitle.Text = "Group Editor";

                    this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveDisable));
                    this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveDown));
                    this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveUp));
                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp));
                    break;
                case DataStore.LanguageID.Chinese:
                    this.labelTitle.Text = "组编辑";

                    this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveDisable));
                    this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveDown));
                    this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveUp));
                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp));
                    break;
                case DataStore.LanguageID.Czech:
                    this.labelTitle.Text = "Group Editor";

                    this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveDisable));
                    this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveDown));
                    this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveUp));
                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp));
                    break;
                case DataStore.LanguageID.German:
                    this.labelTitle.Text = "Group Editor";

                    this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveDisable));
                    this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveDown));
                    this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveUp));
                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp));
                    break;
                case DataStore.LanguageID.Japanese:
                    this.labelTitle.Text = "グルㅡプエディタㅡ";

                    this.labelMain.Text = "メイン";
                    this.labelMenu.Text = "メニュㅡ";

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

                    this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveDisable));
                    this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveDown));
                    this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveUp));
                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackUp));
                    break;
                default:
                    break;
            }
        }
        private void DefaultSetting()
        {
            this.BeforeTextBox1 = "";
            this.BeforeTextBox2 = "";
            this.BeforeTextBox3 = "";

            this.CollectionLevel1Location = new Collection<Point>();
            this.CollectionLevel1Location.Add(this.labelTitle1.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MainProductNo.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MainWeightSet.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MainClear.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MainSubMenu.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuTime.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuInformation.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuDataBackup.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuCommunication.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuConfiguration.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuCalibration.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuSystem.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuMotor.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuIOTest.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuUpdate.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuInitialization.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuEquipment.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuStatistics.Location);
            this.CollectionLevel1Location.Add(this.checkBoxL1MenuViewer.Location);

            this.CollectionLevel2Location = new Collection<Point>();
            this.CollectionLevel2Location.Add(this.labelTitle2.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MainProductNo.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MainWeightSet.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MainClear.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MainSubMenu.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuTime.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuInformation.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuDataBackup.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuCommunication.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuConfiguration.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuCalibration.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuSystem.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuMotor.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuIOTest.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuUpdate.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuInitialization.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuEquipment.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuStatistics.Location);
            this.CollectionLevel2Location.Add(this.checkBoxL2MenuViewer.Location);

            this.CollectionLevel3Location = new Collection<Point>();
            this.CollectionLevel3Location.Add(this.labelTitle3.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MainProductNo.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MainWeightSet.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MainClear.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MainSubMenu.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuTime.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuInformation.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuDataBackup.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuConfiguration.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuCommunication.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuCalibration.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuSystem.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuMotor.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuIOTest.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuUpdate.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuInitialization.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuEquipment.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuStatistics.Location);
            this.CollectionLevel3Location.Add(this.checkBoxL3MenuViewer.Location);

            this.CollectionLevel1Control = new Collection<Control>();
            this.CollectionLevel1Control.Add(this.labelTitle1);
            this.CollectionLevel1Control.Add(this.checkBoxL1MainProductNo);
            this.CollectionLevel1Control.Add(this.checkBoxL1MainWeightSet);
            this.CollectionLevel1Control.Add(this.checkBoxL1MainClear);
            this.CollectionLevel1Control.Add(this.checkBoxL1MainSubMenu);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuTime);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuInformation);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuDataBackup);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuConfiguration);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuCommunication);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuCalibration);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuSystem);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuMotor);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuIOTest);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuUpdate);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuInitialization);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuEquipment);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuStatistics);
            this.CollectionLevel1Control.Add(this.checkBoxL1MenuViewer);

            this.CollectionLevel2Control = new Collection<Control>();
            this.CollectionLevel2Control.Add(this.labelTitle2);
            this.CollectionLevel2Control.Add(this.checkBoxL2MainProductNo);
            this.CollectionLevel2Control.Add(this.checkBoxL2MainWeightSet);
            this.CollectionLevel2Control.Add(this.checkBoxL2MainClear);
            this.CollectionLevel2Control.Add(this.checkBoxL2MainSubMenu);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuTime);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuInformation);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuDataBackup);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuConfiguration);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuCommunication);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuCalibration);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuSystem);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuMotor);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuIOTest);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuUpdate);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuInitialization);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuEquipment);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuStatistics);
            this.CollectionLevel2Control.Add(this.checkBoxL2MenuViewer);

            this.CollectionLevel3Control = new Collection<Control>();
            this.CollectionLevel3Control.Add(this.labelTitle3);
            this.CollectionLevel3Control.Add(this.checkBoxL3MainProductNo);
            this.CollectionLevel3Control.Add(this.checkBoxL3MainWeightSet);
            this.CollectionLevel3Control.Add(this.checkBoxL3MainClear);
            this.CollectionLevel3Control.Add(this.checkBoxL3MainSubMenu);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuTime);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuInformation);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuDataBackup);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuConfiguration);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuCommunication);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuCalibration);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuSystem);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuMotor);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuIOTest);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuUpdate);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuInitialization);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuEquipment);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuStatistics);
            this.CollectionLevel3Control.Add(this.checkBoxL3MenuViewer);

            this.CollectionLevel4Control = new Collection<Control>();
            this.CollectionLevel4Control.Add(this.labelTitleNotLogin1);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMainProductNo);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMainWeightSet);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMainClear);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMainSubMenu);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuTime);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuInformation);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuDataBackup);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuConfiguration);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuCommunication);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuCalibration);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuSystem);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuMotor);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuIOTest);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuUpdate);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuInitialization);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuEquipment);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuStatistics);
            this.CollectionLevel4Control.Add(this.checkBoxNotLoginMenuViewer);

            this.UpdateDisplay(this.ParentForm.CurrentUserGroup, this.ParentForm.SystemConfig);
        }

        private void UpdateDisplay(UserGroup group, SystemConfigurationItem system)
        {
            this.labelLevel1Name.Text = system.User_Level1_Name;
            this.labelLevel2Name.Text = system.User_Level2_Name;
            this.labelLevel3Name.Text = system.User_Level3_Name;

            #region Level1
            this.checkBoxL1MainProductNo.Checked = group.Level1.IsMainDisplayProductNo;
            this.checkBoxL1MainWeightSet.Checked = group.Level1.IsMainDisplayWeightSetting;
            this.checkBoxL1MainClear.Checked = group.Level1.IsMainDisplayClear;
            this.checkBoxL1MainSubMenu.Checked = group.Level1.IsMainDisplaySubMenu;

            this.checkBoxL1MenuInformation.Checked = group.Level1.IsMenuInformation;
            this.checkBoxL1MenuConfiguration.Checked = group.Level1.IsMenuConfiguration;
            this.checkBoxL1MenuCommunication.Checked = group.Level1.IsMenuCommunication;
            this.checkBoxL1MenuCalibration.Checked = group.Level1.IsMenuCalibration;
            this.checkBoxL1MenuSystem.Checked = group.Level1.IsMenuSystem;
            this.checkBoxL1MenuMotor.Checked = group.Level1.IsMenuMotor;
            this.checkBoxL1MenuIOTest.Checked = group.Level1.IsMenuIOTest;
            this.checkBoxL1MenuEquipment.Checked = group.Level1.IsMenuEquipment;
            this.checkBoxL1MenuUpdate.Checked = group.Level1.IsMenuUpdate;
            this.checkBoxL1MenuInitialization.Checked = group.Level1.IsMenuInitialization;
            this.checkBoxL1MenuTime.Checked = group.Level1.IsMenuTime;
            this.checkBoxL1MenuDataBackup.Checked = group.Level1.IsMenuDataBackup;
            this.checkBoxL1MenuStatistics.Checked = group.Level1.IsMenuStatistics;
            this.checkBoxL1MenuViewer.Checked = group.Level1.IsMenuViewer;
            #endregion

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

            this.checkBoxL2MenuInformation.Checked = group.Level2.IsMenuInformation;
            this.checkBoxL2MenuConfiguration.Checked = group.Level2.IsMenuConfiguration;
            this.checkBoxL2MenuCommunication.Checked = group.Level2.IsMenuCommunication;
            this.checkBoxL2MenuCalibration.Checked = group.Level2.IsMenuCalibration;
            this.checkBoxL2MenuSystem.Checked = group.Level2.IsMenuSystem;
            this.checkBoxL2MenuMotor.Checked = group.Level2.IsMenuMotor;
            this.checkBoxL2MenuIOTest.Checked = group.Level2.IsMenuIOTest;
            this.checkBoxL2MenuEquipment.Checked = group.Level2.IsMenuEquipment;
            this.checkBoxL2MenuUpdate.Checked = group.Level2.IsMenuUpdate;
            this.checkBoxL2MenuInitialization.Checked = group.Level2.IsMenuInitialization;
            this.checkBoxL2MenuTime.Checked = group.Level2.IsMenuTime;
            this.checkBoxL2MenuDataBackup.Checked = group.Level2.IsMenuDataBackup;
            this.checkBoxL2MenuStatistics.Checked = group.Level2.IsMenuStatistics;
            this.checkBoxL2MenuViewer.Checked = group.Level2.IsMenuViewer;
            #endregion

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

            this.checkBoxL3MenuInformation.Checked = group.Level3.IsMenuInformation;
            this.checkBoxL3MenuConfiguration.Checked = group.Level3.IsMenuConfiguration;
            this.checkBoxL3MenuCommunication.Checked = group.Level3.IsMenuCommunication;
            this.checkBoxL3MenuCalibration.Checked = group.Level3.IsMenuCalibration;
            this.checkBoxL3MenuSystem.Checked = group.Level3.IsMenuSystem;
            this.checkBoxL3MenuMotor.Checked = group.Level3.IsMenuMotor;
            this.checkBoxL3MenuIOTest.Checked = group.Level3.IsMenuIOTest;
            this.checkBoxL3MenuEquipment.Checked = true;
            this.checkBoxL3MenuUpdate.Checked = group.Level3.IsMenuUpdate;
            this.checkBoxL3MenuInitialization.Checked = group.Level3.IsMenuInitialization;
            this.checkBoxL3MenuTime.Checked = true;
            this.checkBoxL3MenuDataBackup.Checked = group.Level3.IsMenuDataBackup;
            this.checkBoxL3MenuStatistics.Checked = group.Level3.IsMenuStatistics;
            this.checkBoxL3MenuViewer.Checked = group.Level3.IsMenuViewer;
            #endregion

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

            this.checkBoxNotLoginMenuInformation.Checked = group.NotLogin.IsMenuInformation;
            this.checkBoxNotLoginMenuConfiguration.Checked = group.NotLogin.IsMenuConfiguration;
            this.checkBoxNotLoginMenuCommunication.Checked = group.NotLogin.IsMenuCommunication;
            this.checkBoxNotLoginMenuCalibration.Checked = group.NotLogin.IsMenuCalibration;
            this.checkBoxNotLoginMenuSystem.Checked = group.NotLogin.IsMenuSystem;
            this.checkBoxNotLoginMenuMotor.Checked = group.NotLogin.IsMenuMotor;
            this.checkBoxNotLoginMenuIOTest.Checked = group.NotLogin.IsMenuIOTest;
            this.checkBoxNotLoginMenuEquipment.Checked = group.NotLogin.IsMenuEquipment;
            this.checkBoxNotLoginMenuUpdate.Checked = group.NotLogin.IsMenuUpdate;
            this.checkBoxNotLoginMenuInitialization.Checked = group.NotLogin.IsMenuInitialization;
            this.checkBoxNotLoginMenuTime.Checked = group.NotLogin.IsMenuTime;
            this.checkBoxNotLoginMenuDataBackup.Checked = group.NotLogin.IsMenuDataBackup;
            this.checkBoxNotLoginMenuStatistics.Checked = group.NotLogin.IsMenuStatistics;
            this.checkBoxNotLoginMenuViewer.Checked = group.NotLogin.IsMenuViewer;
            #endregion
        }
        private void UpdatePart11Visible()
        {
            if (this.ParentForm.SystemConfig.IsOptPart11 == false)
            {
                this.labelStatistics.Visible = false;
                this.checkBoxL1MenuStatistics.Visible = false;
                this.checkBoxL2MenuStatistics.Visible = false;
                this.checkBoxL3MenuStatistics.Visible = false;
                this.checkBoxNotLoginMenuStatistics.Visible = false;

                this.labelViewer.Visible = false;
                this.checkBoxL1MenuViewer.Visible = false;
                this.checkBoxL2MenuViewer.Visible = false;
                this.checkBoxL3MenuViewer.Visible = false;
                this.checkBoxNotLoginMenuViewer.Visible = false;
            }
            else
            {
                this.labelStatistics.Visible = true;
                this.checkBoxL1MenuStatistics.Visible = true;
                this.checkBoxL2MenuStatistics.Visible = true;
                this.checkBoxL3MenuStatistics.Visible = true;
                this.checkBoxNotLoginMenuStatistics.Visible = true;

                this.labelViewer.Visible = true;
                this.checkBoxL1MenuViewer.Visible = true;
                this.checkBoxL2MenuViewer.Visible = true;
                this.checkBoxL3MenuViewer.Visible = true;
                this.checkBoxNotLoginMenuViewer.Visible = true;
            }
        }

        public void DisplayRefresh()
        {
            this.UpdateDisplay(this.ParentForm.CurrentUserGroup, this.ParentForm.SystemConfig);
            this.UpdatePart11Visible();
            this.buttonSave.Visible = false;

            if (this.ParentForm.SystemConfig.CurrentUser.Group != DataStore.UserGroup.Developer)
            {
                this.labelTitleNotLogin1.Visible = false;
                this.labelTitleNotLogin2.Visible = false;

                for (int i = 0; i < this.CollectionLevel1Control.Count; i++)
                {

                    //this.CollectionLevel1Control[i].Location = new Point(this.CollectionLevel2Location[i].X, this.CollectionLevel2Location[i].Y);
                    //this.CollectionLevel2Control[i].Location = new Point(this.CollectionLevel3Location[i].X, this.CollectionLevel3Location[i].Y);

                    //this.CollectionLevel3Control[i].Visible = false;
                    this.CollectionLevel4Control[i].Visible = false;
                }
            }
            else
            {
                this.labelTitleNotLogin1.Visible = true;
                this.labelTitleNotLogin2.Visible = true;

                for (int i = 0; i < this.CollectionLevel1Control.Count; i++)
                {
                    //this.CollectionLevel1Control[i].Location = new Point(this.CollectionLevel1Location[i].X, this.CollectionLevel1Location[i].Y);
                    //this.CollectionLevel2Control[i].Location = new Point(this.CollectionLevel2Location[i].X, this.CollectionLevel2Location[i].Y);

                    //this.CollectionLevel3Control[i].Visible = true;
                    this.CollectionLevel4Control[i].Visible = true;
                }
            }
        }
        #endregion

        #region Event Handler
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormUserEditor.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormUserEditor);
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string detail;

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

            this.ParentForm.CurrentUserGroup.Level1.IsMenuInformation = this.checkBoxL1MenuInformation.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuConfiguration = this.checkBoxL1MenuConfiguration.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuCommunication = this.checkBoxL1MenuCommunication.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuCalibration = this.checkBoxL1MenuCalibration.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuSystem = this.checkBoxL1MenuSystem.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuMotor = this.checkBoxL1MenuMotor.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuIOTest = this.checkBoxL1MenuIOTest.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuUpdate = this.checkBoxL1MenuUpdate.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuInitialization = this.checkBoxL1MenuInitialization.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuTime = this.checkBoxL1MenuTime.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuDataBackup = this.checkBoxL1MenuDataBackup.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuEquipment = this.checkBoxL1MenuEquipment.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuStatistics = this.checkBoxL1MenuStatistics.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuViewer = this.checkBoxL1MenuViewer.Checked;
            this.ParentForm.CurrentUserGroup.Level1.IsMenuUser = true;

            #endregion

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

            this.ParentForm.CurrentUserGroup.Level2.IsMenuInformation = this.checkBoxL2MenuInformation.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuConfiguration = this.checkBoxL2MenuConfiguration.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuCommunication = this.checkBoxL2MenuCommunication.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuCalibration = this.checkBoxL2MenuCalibration.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuSystem = this.checkBoxL2MenuSystem.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuMotor = this.checkBoxL2MenuMotor.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuIOTest = this.checkBoxL2MenuIOTest.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuUpdate = this.checkBoxL2MenuUpdate.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuInitialization = this.checkBoxL2MenuInitialization.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuTime = this.checkBoxL2MenuTime.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuDataBackup = this.checkBoxL2MenuDataBackup.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuEquipment = this.checkBoxL2MenuEquipment.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuStatistics = this.checkBoxL2MenuStatistics.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuViewer = this.checkBoxL2MenuViewer.Checked;
            this.ParentForm.CurrentUserGroup.Level2.IsMenuUser = true;
            #endregion

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

            this.ParentForm.CurrentUserGroup.Level3.IsMenuInformation = this.checkBoxL3MenuInformation.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuConfiguration = this.checkBoxL3MenuConfiguration.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuCommunication = this.checkBoxL3MenuCommunication.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuCalibration = this.checkBoxL3MenuCalibration.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuSystem = this.checkBoxL3MenuSystem.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuMotor = this.checkBoxL3MenuMotor.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuIOTest = this.checkBoxL3MenuIOTest.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuUpdate = this.checkBoxL3MenuUpdate.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuInitialization = this.checkBoxL3MenuInitialization.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuTime = true;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuDataBackup = this.checkBoxL3MenuDataBackup.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuEquipment = true;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuStatistics = this.checkBoxL3MenuStatistics.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuViewer = this.checkBoxL3MenuViewer.Checked;
            this.ParentForm.CurrentUserGroup.Level3.IsMenuUser = true;
            #endregion

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

            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuInformation = this.checkBoxNotLoginMenuInformation.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuConfiguration = this.checkBoxNotLoginMenuConfiguration.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuCommunication = this.checkBoxNotLoginMenuCommunication.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuCalibration = this.checkBoxNotLoginMenuCalibration.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuSystem = this.checkBoxNotLoginMenuSystem.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuMotor = this.checkBoxNotLoginMenuMotor.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuIOTest = this.checkBoxNotLoginMenuIOTest.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuEquipment = this.checkBoxNotLoginMenuEquipment.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuUpdate = this.checkBoxNotLoginMenuUpdate.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuInitialization = this.checkBoxNotLoginMenuInitialization.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuTime = this.checkBoxNotLoginMenuTime.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuDataBackup = this.checkBoxNotLoginMenuDataBackup.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuStatistics = this.checkBoxNotLoginMenuStatistics.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuViewer = this.checkBoxNotLoginMenuViewer.Checked;
            this.ParentForm.CurrentUserGroup.NotLogin.IsMenuUser = false;
            #endregion

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

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

            this.buttonSave.Visible = false;
        }

        private void labelTitle1_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer
                || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Admin)
            {
                this.checkBoxL1MainProductNo.Checked = true;
                this.checkBoxL1MainWeightSet.Checked = true;
                this.checkBoxL1MainClear.Checked = true;
                this.checkBoxL1MainSubMenu.Checked = true;

                this.checkBoxL1MenuInformation.Checked = true;
                this.checkBoxL1MenuConfiguration.Checked = true;
                this.checkBoxL1MenuCommunication.Checked = true;
                this.checkBoxL1MenuCalibration.Checked = true;
                this.checkBoxL1MenuSystem.Checked = true;
                this.checkBoxL1MenuMotor.Checked = true;
                this.checkBoxL1MenuIOTest.Checked = true;
                this.checkBoxL1MenuUpdate.Checked = true;
                this.checkBoxL1MenuInitialization.Checked = true;
                this.checkBoxL1MenuTime.Checked = true;
                this.checkBoxL1MenuDataBackup.Checked = true;
                this.checkBoxL1MenuStatistics.Checked = true;
                this.checkBoxL1MenuViewer.Checked = true;
                this.checkBoxL1MenuEquipment.Checked = true;

                this.buttonSave.Visible = true;
            }
        }
        private void labelTitle2_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer
                || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Admin)
            {
                this.checkBoxL2MainProductNo.Checked = true;
                this.checkBoxL2MainWeightSet.Checked = true;
                this.checkBoxL2MainClear.Checked = true;
                this.checkBoxL2MainSubMenu.Checked = true;

                this.checkBoxL2MenuInformation.Checked = true;
                this.checkBoxL2MenuConfiguration.Checked = true;
                this.checkBoxL2MenuCommunication.Checked = true;
                this.checkBoxL2MenuCalibration.Checked = true;
                this.checkBoxL2MenuSystem.Checked = true;
                this.checkBoxL2MenuMotor.Checked = true;
                this.checkBoxL2MenuIOTest.Checked = true;
                this.checkBoxL2MenuUpdate.Checked = true;
                this.checkBoxL2MenuInitialization.Checked = true;
                this.checkBoxL2MenuTime.Checked = true;
                this.checkBoxL2MenuDataBackup.Checked = true;
                this.checkBoxL2MenuStatistics.Checked = true;
                this.checkBoxL2MenuViewer.Checked = true;
                this.checkBoxL2MenuEquipment.Checked = true;

                this.buttonSave.Visible = true;
            }
        }
        private void labelTitle3_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer
                || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Admin)
            {
                this.checkBoxL3MainProductNo.Checked = true;
                this.checkBoxL3MainWeightSet.Checked = true;
                this.checkBoxL3MainClear.Checked = true;
                this.checkBoxL3MainSubMenu.Checked = true;

                this.checkBoxL3MenuInformation.Checked = true;
                this.checkBoxL3MenuConfiguration.Checked = true;
                this.checkBoxL3MenuCommunication.Checked = true;
                this.checkBoxL3MenuCalibration.Checked = true;
                this.checkBoxL3MenuSystem.Checked = true;
                this.checkBoxL3MenuMotor.Checked = true;
                this.checkBoxL3MenuIOTest.Checked = true;
                this.checkBoxL3MenuUpdate.Checked = true;
                this.checkBoxL3MenuInitialization.Checked = true;
                this.checkBoxL3MenuTime.Checked = true;
                this.checkBoxL3MenuDataBackup.Checked = true;
                this.checkBoxL3MenuStatistics.Checked = true;
                this.checkBoxL3MenuViewer.Checked = true;
                this.checkBoxL3MenuEquipment.Checked = true;

                this.buttonSave.Visible = true;
            }
        }
        private void labelTitle4_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer
                || this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Admin)
            {
                this.checkBoxNotLoginMainProductNo.Checked = true;
                this.checkBoxNotLoginMainWeightSet.Checked = true;
                this.checkBoxNotLoginMainClear.Checked = true;
                this.checkBoxNotLoginMainSubMenu.Checked = true;

                this.checkBoxNotLoginMenuInformation.Checked = true;
                this.checkBoxNotLoginMenuCommunication.Checked = true;
                this.checkBoxNotLoginMenuConfiguration.Checked = true;
                this.checkBoxNotLoginMenuCalibration.Checked = true;
                this.checkBoxNotLoginMenuSystem.Checked = true;
                this.checkBoxNotLoginMenuMotor.Checked = true;
                this.checkBoxNotLoginMenuIOTest.Checked = true;
                this.checkBoxNotLoginMenuUpdate.Checked = true;
                this.checkBoxNotLoginMenuInitialization.Checked = true;
                this.checkBoxNotLoginMenuTime.Checked = true;
                this.checkBoxNotLoginMenuStatistics.Checked = true;
                this.checkBoxNotLoginMenuViewer.Checked = true;
                this.checkBoxNotLoginMenuDataBackup.Checked = true;
                this.checkBoxNotLoginMenuEquipment.Checked = true;

                this.buttonSave.Visible = true;
            }
        }

        private void labelLevel1Name_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = this.labelLevel1Name.Text;

            DialogFormUserEditorKeyboard keyboard = new DialogFormUserEditorKeyboard(this.labelLevel1Name.Text);

            if (keyboard.ShowDialog() == DialogResult.OK)
            {
                this.labelLevel1Name.Text = keyboard.RetStringValue;
                after = this.labelLevel1Name.Text;

                this.ParentForm.SystemConfig.User_Level1_Name = this.labelLevel1Name.Text;
                this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

                // Part11
                if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.Level1Name, "", before, after);
            }
        }
        private void labelLevel2Name_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = this.labelLevel2Name.Text;

            DialogFormUserEditorKeyboard keyboard = new DialogFormUserEditorKeyboard(this.labelLevel2Name.Text);

            if (keyboard.ShowDialog() == DialogResult.OK)
            {
                this.labelLevel2Name.Text = keyboard.RetStringValue;
                after = this.labelLevel2Name.Text;

                this.ParentForm.SystemConfig.User_Level2_Name = this.labelLevel2Name.Text;
                this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

                // Part11
                if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.Level2Name, "", before, after);
            }
        }
        private void labelLevel3Name_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = this.labelLevel3Name.Text;

            DialogFormUserEditorKeyboard keyboard = new DialogFormUserEditorKeyboard(this.labelLevel3Name.Text);

            if (keyboard.ShowDialog() == DialogResult.OK)
            {
                this.labelLevel3Name.Text = keyboard.RetStringValue;
                after = this.labelLevel3Name.Text;

                this.ParentForm.SystemConfig.User_Level3_Name = this.labelLevel3Name.Text;
                this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

                // Part11
                if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                    this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.Level3Name, "", before, after);
            }
        }

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