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

using INT69DB_2A_ImageDll;
using INT69DB_2A.DialogForms;
using INT69DB_2A.Part11_UserManager;

namespace INT69DB_2A.Forms
{
    public partial class FormMenu : Form
    {
        #region Field
        private FormMain m_ParentForm;
        #endregion

        #region Costructor
        public FormMenu(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
        private void InitializeDesign()
        {
            ImageDll images = new ImageDll();

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

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

                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuCalibrationUp));
                this.buttonCommunication.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuCommunicationDisable));
                this.buttonCommunication.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuCommunicationDown));
                this.buttonCommunication.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuCommunicationUp));
                this.buttonConfiguration.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuConfigurationDisable));
                this.buttonConfiguration.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuConfigurationDown));
                this.buttonConfiguration.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuConfigurationUp));
                this.buttonDataBackup.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuDataBackupDisable));
                this.buttonDataBackup.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuDataBackupDown));
                this.buttonDataBackup.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuDataBackupUp));
                this.buttonEquipment.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuEquipmentDisable));
                this.buttonEquipment.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuEquipmentDown));
                this.buttonEquipment.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuEquipmentUp));
                this.buttonInformation.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuInformationDisable));
                this.buttonInformation.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuInformationDown));
                this.buttonInformation.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuInformationUp));
                this.buttonInitialization.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuInitializationDisable));
                this.buttonInitialization.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuInitializationDown));
                this.buttonInitialization.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuInitializationUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuIOTestUp));
                this.buttonMotor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuMotorDisable));
                this.buttonMotor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuMotorDown));
                this.buttonMotor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuMotorUp));
                this.buttonSystem.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuSystemDisable));
                this.buttonSystem.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuSystemDown));
                this.buttonSystem.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuSystemUp));
                this.buttonTest.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuTestDisable));
                this.buttonTest.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuTestDown));
                this.buttonTest.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuTestUp));
                this.buttonTime.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuTimeDisable));
                this.buttonTime.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuTimeDown));
                this.buttonTime.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuTimeUp));
                this.buttonUpdate.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuUpdateDisable));
                this.buttonUpdate.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuUpdateDown));
                this.buttonUpdate.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuUpdateUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuUserDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuUserDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuUserUp));
                this.buttonDataStatistics.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuStatisticsDisable));
                this.buttonDataStatistics.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuStatisticsDown));
                this.buttonDataStatistics.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuStatisticsUp));
                this.buttonDataViewer.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuDataViewerDisable));
                this.buttonDataViewer.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuDataViewerDown));
                this.buttonDataViewer.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuDataViewerUp));
                this.buttonOption.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuOptionDisable));
                this.buttonOption.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuOptionDown));
                this.buttonOption.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engFormMenuOptionUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.labelTitle.Text = "菜单";

                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuCalibrationUp));
                this.buttonCommunication.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuCommunicationDisable));
                this.buttonCommunication.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuCommunicationDown));
                this.buttonCommunication.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuCommunicationUp));
                this.buttonConfiguration.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuConfigurationDisable));
                this.buttonConfiguration.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuConfigurationDown));
                this.buttonConfiguration.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuConfigurationUp));
                this.buttonDataBackup.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuDataBackupDisable));
                this.buttonDataBackup.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuDataBackupDown));
                this.buttonDataBackup.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuDataBackupUp));
                this.buttonEquipment.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuEquipmentDisable));
                this.buttonEquipment.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuEquipmentDown));
                this.buttonEquipment.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuEquipmentUp));
                this.buttonInformation.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuInformationDisable));
                this.buttonInformation.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuInformationDown));
                this.buttonInformation.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuInformationUp));
                this.buttonInitialization.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuInitializationDisable));
                this.buttonInitialization.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuInitializationDown));
                this.buttonInitialization.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuInitializationUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuIOTestUp));
                this.buttonMotor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuMotorDisable));
                this.buttonMotor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuMotorDown));
                this.buttonMotor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuMotorUp));
                this.buttonSystem.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuSystemDisable));
                this.buttonSystem.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuSystemDown));
                this.buttonSystem.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuSystemUp));
                this.buttonTest.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuTestDisable));
                this.buttonTest.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuTestDown));
                this.buttonTest.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuTestUp));
                this.buttonTime.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuTimeDisable));
                this.buttonTime.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuTimeDown));
                this.buttonTime.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuTimeUp));
                this.buttonUpdate.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuUpdateDisable));
                this.buttonUpdate.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuUpdateDown));
                this.buttonUpdate.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuUpdateUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuUserDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuUserDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuUserUp));
                this.buttonDataStatistics.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuStatisticsDisable));
                this.buttonDataStatistics.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuStatisticsDown));
                this.buttonDataStatistics.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuStatisticsUp));
                this.buttonDataViewer.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuDataViewerDisable));
                this.buttonDataViewer.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuDataViewerDown));
                this.buttonDataViewer.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuDataViewerUp));
                this.buttonOption.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuOptionDisable));
                this.buttonOption.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuOptionDown));
                this.buttonOption.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormMenuOptionUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.labelTitle.Text = "メニュㅡ";

                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuCalibrationUp));
                this.buttonCommunication.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuCommunicationDisable));
                this.buttonCommunication.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuCommunicationDown));
                this.buttonCommunication.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuCommunicationUp));
                this.buttonConfiguration.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuConfigurationDisable));
                this.buttonConfiguration.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuConfigurationDown));
                this.buttonConfiguration.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuConfigurationUp));
                this.buttonDataBackup.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuDataBackupDisable));
                this.buttonDataBackup.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuDataBackupDown));
                this.buttonDataBackup.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuDataBackupUp));
                this.buttonEquipment.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuEquipmentDisable));
                this.buttonEquipment.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuEquipmentDown));
                this.buttonEquipment.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuEquipmentUp));
                this.buttonInformation.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuInformationDisable));
                this.buttonInformation.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuInformationDown));
                this.buttonInformation.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuInformationUp));
                this.buttonInitialization.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuInitializationDisable));
                this.buttonInitialization.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuInitializationDown));
                this.buttonInitialization.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuInitializationUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuIOTestUp));
                this.buttonMotor.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuMotorDisable));
                this.buttonMotor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuMotorDown));
                this.buttonMotor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuMotorUp));
                this.buttonSystem.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuSystemDisable));
                this.buttonSystem.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuSystemDown));
                this.buttonSystem.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuSystemUp));
                this.buttonTest.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuTestDisable));
                this.buttonTest.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuTestDown));
                this.buttonTest.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuTestUp));
                this.buttonTime.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuTimeDisable));
                this.buttonTime.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuTimeDown));
                this.buttonTime.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuTimeUp));
                this.buttonUpdate.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuUpdateDisable));
                this.buttonUpdate.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuUpdateDown));
                this.buttonUpdate.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuUpdateUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuUserDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuUserDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuUserUp));
                this.buttonDataStatistics.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuStatisticsDisable));
                this.buttonDataStatistics.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuStatisticsDown));
                this.buttonDataStatistics.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuStatisticsUp));
                this.buttonDataViewer.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuDataViewerDisable));
                this.buttonDataViewer.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuDataViewerDown));
                this.buttonDataViewer.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuDataViewerUp));
                this.buttonOption.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuOptionDisable));
                this.buttonOption.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuOptionDown));
                this.buttonOption.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnFormMenuOptionUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {

            }
            else
            {

            }
        }
        private void DefaultSetting()
        {
            if (this.ParentForm.SystemConfig.IsLogin == false)
            {
                this.labelUserID.Visible = false;
                this.labelUserLevel.Visible = false;
                this.labelExpireOfPassword.Visible = false;

                this.buttonUser.Visible = false;
                this.buttonTest.Visible = false;
                this.buttonOption.Visible = false;

                if (this.ParentForm.SystemConfig.IsPart11 == false)
                {
                    this.buttonDataStatistics.Visible = false;
                    this.buttonDataViewer.Visible = false;
                }
            }
            else
            {
            }
        }

        public void UpdateDisplayMenuAccess(UserItem user)
        {
            string id = "", group = "", expirePW = "";
            int expireDate = 0;
            Color colorExpirePW = this.ParentForm.ColorLogOff;

            if (this.ParentForm.SystemConfig.IsPart11 == true)
            {
                this.buttonDataStatistics.Visible = true;
                this.buttonDataViewer.Visible = true;
                this.buttonUser.Visible = true;
            }
            else
            {
                this.buttonDataStatistics.Visible = false;
                this.buttonDataViewer.Visible = false;

                if (this.ParentForm.SystemConfig.IsLogin == true)
                {
                    this.buttonUser.Location = new Point(this.buttonDataStatistics.Location.X, this.buttonDataStatistics.Location.Y);
                    this.buttonUser.Visible = true;
                }
                else
                {
                    this.buttonUser.Visible = false;
                }
            }

            switch (user.Group)
            {
                case DataStore.UserGroup.None:
                    break;
                case DataStore.UserGroup.Level1:
                    id = user.ID;
                    group = this.ParentForm.SystemConfig.User_Level1_Name;

                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                    {
                        this.labelExpireOfPassword.Visible = true;
                        this.buttonDataStatistics.Visible = true;
                        this.buttonDataViewer.Visible = true;
                    }

                    if (this.labelUserLevel.ForeColor != this.ParentForm.ColorLogOn)
                        this.labelUserLevel.ForeColor = this.labelUserID.ForeColor = this.ParentForm.ColorLogOn;

                    this.buttonInformation.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuInformation;
                    this.buttonDataBackup.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuDataBackup;
                    this.buttonConfiguration.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuConfiguration;
                    this.buttonCommunication.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuCommunication;
                    this.buttonCalibration.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuCalibration;

                    this.buttonSystem.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuSystem;
                    this.buttonMotor.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuMotor;
                    this.buttonUpdate.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuUpdate;
                    this.buttonInitialization.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuInitialization;
                    this.buttonIOTest.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuIOTest;

                    this.buttonEquipment.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuEquipment;
                    this.buttonTime.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuTime;
                    this.buttonUser.Enabled = true;
                    this.buttonDataStatistics.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuStatistics;
                    this.buttonDataViewer.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMenuViewer;

                    this.buttonTest.Visible = false;
                    this.buttonOption.Visible = false;
                    break;
                case DataStore.UserGroup.Level2:
                    id = user.ID;
                    group = this.ParentForm.SystemConfig.User_Level2_Name;

                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                    {
                        this.labelExpireOfPassword.Visible = true;
                        this.buttonDataStatistics.Visible = true;
                        this.buttonDataViewer.Visible = true;
                    }

                    if (this.labelUserLevel.ForeColor != this.ParentForm.ColorLogOn)
                        this.labelUserLevel.ForeColor = this.labelUserID.ForeColor = this.ParentForm.ColorLogOn;

                    this.buttonInformation.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuInformation;
                    this.buttonDataBackup.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuDataBackup;
                    this.buttonConfiguration.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuConfiguration;
                    this.buttonCommunication.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuCommunication;
                    this.buttonCalibration.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuCalibration;

                    this.buttonSystem.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuSystem;
                    this.buttonMotor.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuMotor;
                    this.buttonUpdate.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuUpdate;
                    this.buttonInitialization.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuInitialization;
                    this.buttonIOTest.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuIOTest;

                    this.buttonEquipment.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuEquipment;
                    this.buttonTime.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuTime;
                    this.buttonUser.Enabled = true;
                    this.buttonDataStatistics.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuStatistics;
                    this.buttonDataViewer.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMenuViewer;

                    this.buttonTest.Visible = false;
                    this.buttonOption.Visible = false;
                    break;
                case DataStore.UserGroup.Level3:
                    id = user.ID;
                    group = this.ParentForm.SystemConfig.User_Level3_Name;

                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                    {
                        this.labelExpireOfPassword.Visible = true;
                        this.buttonDataStatistics.Visible = true;
                        this.buttonDataViewer.Visible = true;
                    }

                    if (this.labelUserLevel.ForeColor != this.ParentForm.ColorLogOn)
                        this.labelUserLevel.ForeColor = this.labelUserID.ForeColor = this.ParentForm.ColorLogOn;

                    this.buttonInformation.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuInformation;
                    this.buttonDataBackup.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuDataBackup;
                    this.buttonConfiguration.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuConfiguration;
                    this.buttonCommunication.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuCommunication;
                    this.buttonCalibration.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuCalibration;

                    this.buttonSystem.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuSystem;
                    this.buttonMotor.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuMotor;
                    this.buttonUpdate.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuUpdate;
                    this.buttonInitialization.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuInitialization;
                    this.buttonIOTest.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuIOTest;

                    this.buttonEquipment.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuEquipment;
                    this.buttonTime.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuTime;
                    this.buttonUser.Enabled = true;
                    this.buttonDataStatistics.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuStatistics;
                    this.buttonDataViewer.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMenuViewer;

                    this.buttonTest.Visible = false;
                    this.buttonOption.Visible = false;
                    break;
                case DataStore.UserGroup.Admin:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
                        group = "Administrator";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
                        group = "行政";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
                        group = "管理者";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Russian)
                        group = "Администратор";
                    else
                        group = "Administrator";

                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                    {
                        this.labelExpireOfPassword.Visible = true;
                        this.buttonDataStatistics.Visible = true;
                        this.buttonDataViewer.Visible = true;
                    }

                    if (this.labelUserLevel.ForeColor != this.ParentForm.ColorLogOn)
                        this.labelUserLevel.ForeColor = this.labelUserID.ForeColor = this.ParentForm.ColorLogOn;

                    this.buttonInformation.Enabled = true;
                    this.buttonDataBackup.Enabled = true;
                    this.buttonConfiguration.Enabled = true;
                    this.buttonCommunication.Enabled = true;
                    this.buttonCalibration.Enabled = true;

                    this.buttonSystem.Enabled = true;
                    this.buttonMotor.Enabled = true;
                    this.buttonUpdate.Enabled = true;
                    this.buttonInitialization.Enabled = true;
                    this.buttonIOTest.Enabled = true;

                    this.buttonEquipment.Enabled = true;
                    this.buttonTime.Enabled = true;
                    this.buttonUser.Enabled = true;
                    this.buttonDataStatistics.Enabled = true;
                    this.buttonDataViewer.Enabled = true;

                    this.buttonTest.Visible = false;
                    this.buttonOption.Visible = false;
                    break;
                case DataStore.UserGroup.Developer:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
                        group = "Entwickler";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
                        group = "开发商";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
                        group = "開発者";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Russian)
                        group = "Разработчик";
                    else
                        group = "Developer";

                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        this.labelExpireOfPassword.Visible = true;

                    if (this.labelUserLevel.ForeColor != this.ParentForm.ColorLogOn)
                        this.labelUserLevel.ForeColor = this.labelUserID.ForeColor = this.ParentForm.ColorLogOn;

                    this.buttonInformation.Enabled = true;
                    this.buttonDataBackup.Enabled = true;
                    this.buttonConfiguration.Enabled = true;
                    this.buttonCommunication.Enabled = true;
                    this.buttonCalibration.Enabled = true;

                    this.buttonSystem.Enabled = true;
                    this.buttonMotor.Enabled = true;
                    this.buttonUpdate.Enabled = true;
                    this.buttonInitialization.Enabled = true;
                    this.buttonIOTest.Enabled = true;

                    this.buttonEquipment.Enabled = true;
                    this.buttonTime.Enabled = true;
                    this.buttonDataStatistics.Enabled = true;
                    this.buttonDataViewer.Enabled = true;
                    this.buttonUser.Enabled = true;

                    this.buttonTest.Visible = true;
                    this.buttonOption.Visible = true;
                    break;
                case DataStore.UserGroup.NotLogin:
                    this.buttonInformation.Enabled = true;
                    this.buttonDataBackup.Enabled = true;
                    this.buttonConfiguration.Enabled = true;
                    this.buttonCommunication.Enabled = true;
                    this.buttonCalibration.Enabled = true;

                    this.buttonSystem.Enabled = true;
                    this.buttonMotor.Enabled = true;
                    this.buttonUpdate.Enabled = true;
                    this.buttonInitialization.Enabled = true;
                    this.buttonIOTest.Enabled = true;

                    this.buttonEquipment.Enabled = true;
                    this.buttonTime.Enabled = true;

                    this.buttonDataViewer.Visible = false;
                    this.buttonDataStatistics.Visible = false;

                    this.buttonTest.Visible = false;
                    this.buttonUser.Visible = false;
                    this.buttonOption.Visible = false;
                    break;
                case DataStore.UserGroup.LogOut:
                    if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
                        group = "Ausloggen";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
                        group = "登出";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
                        group = "ログアウト";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Russian)
                        group = "Выйти.";
                    else
                        group = "Log out";

                    this.labelExpireOfPassword.Visible = false;
                    break;
                default:
                    break;
            }

            if (this.ParentForm.SystemConfig.IsPart11 == true)
            {
                if (user.ExpirePassword != 0)
                {
                    expireDate = user.GetPasswordExpiryDday();
                    colorExpirePW = this.ParentForm.ColorLogOn;
                    expirePW = "-";

                    if (expireDate < 9999)
                    {
                        if (expireDate >= -10)
                        {
                            colorExpirePW = this.ParentForm.ColorLogOff;
                            if (expireDate > 0)
                                expirePW = string.Format("D+{0}", expireDate);
                            else
                                expirePW = string.Format("D{0}", expireDate);
                        }
                        else
                        {
                            colorExpirePW = this.ParentForm.ColorLogOn;
                            expirePW = string.Format("D{0}", expireDate);
                        }
                    }
                }
            }

            if (this.labelUserID.Text != id)
                this.labelUserID.Text = id;
            if (this.labelUserLevel.Text != group)
                this.labelUserLevel.Text = group;
            if (this.labelExpireOfPassword.ForeColor != colorExpirePW)
                this.labelExpireOfPassword.ForeColor = colorExpirePW;
            if (this.labelExpireOfPassword.Text != expirePW)
                this.labelExpireOfPassword.Text = expirePW;
        }

        public void DisplayRefresh()
        {
            if (this.ParentForm.SystemConfig.IsLogin == false)
                this.ParentForm.SystemConfig.CurrentUser.Group = DataStore.UserGroup.NotLogin;

            this.UpdateDisplayMenuAccess(this.ParentForm.SystemConfig.CurrentUser);
            this.ParentForm.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard);
            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormMenu;
        }
        #endregion

        #region Event Handler
        private void buttonMenu_Click(object sender, EventArgs e)
        {
            SmartX.SmartButton button = sender as SmartX.SmartButton;

            if (button == null)
                return;

            if (button == this.buttonTime)
            {
                #region 시간설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormTimeSetting);
                this.ParentForm.ChildFormTimeSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonInformation)
            {
                #region 시스템정보
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormInformation);
                this.ParentForm.ChildFormInformation.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonDataBackup)
            {
                #region 데이터백업
                if (this.ParentForm.SystemConfig.IsPart11 == false)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormDataBackup);
                    this.ParentForm.ChildFormDataBackup.DisplayRefresh();
                }
                else
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormDataBackup);
                    this.ParentForm.ChildFormDataBackup_Part11.DisplayRefresh();
                }
                #endregion
            }
            else if (button == this.buttonSystem)
            {
                #region 시스템설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormSystemSetting);
                this.ParentForm.ChildFormSystemSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonCalibration)
            {
                #region 중량조정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormCalibration);
                this.ParentForm.ChildFormCalibration.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonConfiguration)
            {
                #region 환경설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormConfiguration);
                this.ParentForm.ChildFormConfiguration.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonCommunication)
            {
                #region 통신설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormCommunication);
                this.ParentForm.ChildFormCommunication.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonMotor)
            {
                #region 모터설정
                this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._1104_ImpellerMotorIndividualDirection, "");
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMotorSetting);
                this.ParentForm.ChildFormMotorSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonInitialization)
            {
                #region 공장초기화
                DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 5);
                DialogResult dr = myDlg.ShowDialog();
                if (dr == DialogResult.Yes)
                {
                    // Part 11
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.Initialization, "");

                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormFactory);
                    this.ParentForm.ChildFormFactoryInitialize.timer1.Enabled = true;
                }
                #endregion
            }
            else if (button == this.buttonUpdate)
            {
                #region 업데이트
                DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 3);
                DialogResult dr = myDlg.ShowDialog();
                if (dr == DialogResult.Yes)
                {
                    // Part 11
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.Update, "");

                    this.ParentForm.ChildFormProgramUpdate.DisplayRefresh();
                }
                #endregion
            }
            else if (button == this.buttonEquipment)
            {
                #region 장비설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormEquipmentSetting);
                this.ParentForm.ChildFormEquipmentSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonIOTest)
            {
                #region IO테스트
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormIOTest);
                this.ParentForm.ChildFormIOTest.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonTest)
            {
                #region 장비테스트
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormEquipmentTest);
                this.ParentForm.ChildFormEquipmentTest.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonUser)
            {
                #region 유저설정
                if (this.ParentForm.ChildFormUserEditor != null)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormUserEditor);
                    this.ParentForm.ChildFormUserEditor.DisplayRefresh();
                }
                #endregion
            }
            else if (button == this.buttonDataStatistics)
            {
                #region 데이터 집계
                if (this.ParentForm.ChildFormDataStatistics != null)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormDataStatistics);
                    this.ParentForm.ChildFormDataStatistics.DisplayRefresh();
                }
                #endregion
            }
            else if (button == this.buttonDataViewer)
            {
                #region 데이터 뷰어
                if (this.ParentForm.ChildFormDataViewer != null)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormDataViewer);
                    this.ParentForm.ChildFormDataViewer.DisplayRefresh();
                }
                #endregion
            }
            else if (button == this.buttonOption)
            {
                #region 옵션설정
                if (this.ParentForm.SystemConfig.IsPart11 == true && this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormOption);
                    this.ParentForm.ChildFormOption.DisplayRefresh();
                }
                else
                {
                    DialogFormPasswordKeyPad password = new DialogFormPasswordKeyPad(8, this.ParentForm.SystemConfig.Language);
                    DialogResult dialogResult = password.ShowDialog();
                    if (dialogResult == DialogResult.OK)
                    {
                        if (this.ParentForm.ChildFormOption != null)
                        {
                            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormOption);
                            this.ParentForm.ChildFormOption.DisplayRefresh();
                        }
                    }
                }
                #endregion
            }
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMainDisplay.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMainDisplay);
        }
        private void buttonHidden_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.IsLogin == false)
            {
                this.ParentForm.SystemConfig.CurrentUser.Group = DataStore.UserGroup.Developer;
                this.UpdateDisplayMenuAccess(this.ParentForm.SystemConfig.CurrentUser);
            }
            else
            {
                if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer)
                {
                    if (this.buttonEquipment.Visible != true)
                        this.buttonEquipment.Visible = true;
                    if (this.buttonOption.Visible != true)
                        this.buttonOption.Visible = true;
                    if (this.buttonTest.Visible != true)
                        this.buttonTest.Visible = true;
                }
            }
        }
        #endregion
    }
}