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 INT89DB_26.DialogForms;
using INT89DB_26_ImageDll;

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

        #region Costructor
        public FormMenu(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;
        }
        #endregion

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

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

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

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

                this.buttonBack.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBackUp));

                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuCalibrationUp));
                this.buttonConfiguration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuConfigurationDisable));
                this.buttonConfiguration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuConfigurationDown));
                this.buttonConfiguration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuConfigurationUp));
                this.buttonDataBackup.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuDataBackupDisable));
                this.buttonDataBackup.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuDataBackupDown));
                this.buttonDataBackup.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuDataBackupUp));
                this.buttonFactoryInitialize.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuInitializationDisable));
                this.buttonFactoryInitialize.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuInitializationDown));
                this.buttonFactoryInitialize.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuInitializationUp));
                this.buttonInformation.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuInformationDisable));
                this.buttonInformation.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuInformationDown));
                this.buttonInformation.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuInformationUp));
                this.buttonSysConfig.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuSystemDisable));
                this.buttonSysConfig.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuSystemDown));
                this.buttonSysConfig.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuSystemUp));
                this.buttonTimeSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuTimeDisable));
                this.buttonTimeSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuTimeDown));
                this.buttonTimeSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuTimeUp));
                this.buttonUpdate.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuUpdateDisable));
                this.buttonUpdate.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuUpdateDown));
                this.buttonUpdate.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuUpdateUp));
                this.buttonEquipmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuEquipmentDisable));
                this.buttonEquipmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuEquipmentDown));
                this.buttonEquipmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuEquipmentUp));
                this.buttonEquipmentTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuTestDisable));
                this.buttonEquipmentTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuTestDown));
                this.buttonEquipmentTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuTestUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuIOTestUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuUserDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuUserDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuUserUp));
                this.buttonCommunication.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuCommunicationDisable));
                this.buttonCommunication.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuCommunicationDown));
                this.buttonCommunication.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuCommunicationUp));
                this.buttonOptionSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuOptionDisable));
                this.buttonOptionSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuOptionDown));
                this.buttonOptionSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMenuOptionUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
            {
                this.labelTitle.Text = "菜单";

                this.buttonBack.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackUp));

                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuCalibrationUp));
                this.buttonConfiguration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuConfigurationDisable));
                this.buttonConfiguration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuConfigurationDown));
                this.buttonConfiguration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuConfigurationUp));
                this.buttonDataBackup.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuDataBackupDisable));
                this.buttonDataBackup.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuDataBackupDown));
                this.buttonDataBackup.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuDataBackupUp));
                this.buttonFactoryInitialize.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuInitializationDisable));
                this.buttonFactoryInitialize.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuInitializationDown));
                this.buttonFactoryInitialize.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuInitializationUp));
                this.buttonInformation.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuInformationDisable));
                this.buttonInformation.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuInformationDown));
                this.buttonInformation.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuInformationUp));
                this.buttonSysConfig.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuSystemDisable));
                this.buttonSysConfig.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuSystemDown));
                this.buttonSysConfig.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuSystemUp));
                this.buttonTimeSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuTimeDisable));
                this.buttonTimeSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuTimeDown));
                this.buttonTimeSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuTimeUp));
                this.buttonUpdate.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuUpdateDisable));
                this.buttonUpdate.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuUpdateDown));
                this.buttonUpdate.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuUpdateUp));
                this.buttonEquipmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuEquipmentDisable));
                this.buttonEquipmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuEquipmentDown));
                this.buttonEquipmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuEquipmentUp));
                this.buttonEquipmentTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuTestDisable));
                this.buttonEquipmentTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuTestDown));
                this.buttonEquipmentTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuTestUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuIOTestUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuUserDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuUserDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuUserUp));
                this.buttonCommunication.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuCommunicationDisable));
                this.buttonCommunication.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuCommunicationDown));
                this.buttonCommunication.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuCommunicationUp));
                this.buttonOptionSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuOptionDisable));
                this.buttonOptionSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuOptionDown));
                this.buttonOptionSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMenuOptionUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
            {

            }
            else
            {

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

        private void UpdateDisplayUser(User user)
        {
            string id = "", group = "";

            switch (user.Group)
            {
                case DataStore.UserGroup.Level1Operator:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别1";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň1`";
                    else
                        group = "Level1";

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

                    this.buttonConfiguration.Visible = false;
                    this.buttonCommunication.Visible = false;
                    this.buttonSysConfig.Visible = false;
                    this.buttonIOTest.Visible = false;

                    this.buttonUpdate.Visible = false;
                    this.buttonFactoryInitialize.Visible = false;
                    this.buttonEquipmentSetting.Visible = false;
                    this.buttonUser.Visible = false;

                    this.buttonEquipmentTest.Visible = false;
                    this.buttonOptionSetting.Visible = false;

                    break;
                case DataStore.UserGroup.Level2Engineer:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别2";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň2`";
                    else
                        group = "Level2";

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

                    this.buttonConfiguration.Visible = true;
                    this.buttonCommunication.Visible = true;
                    this.buttonSysConfig.Visible = true;
                    this.buttonIOTest.Visible = true;

                    this.buttonUpdate.Visible = false;
                    this.buttonFactoryInitialize.Visible = false;
                    this.buttonEquipmentSetting.Visible = false;
                    this.buttonUser.Visible = false;

                    this.buttonEquipmentTest.Visible = false;
                    this.buttonOptionSetting.Visible = false;
                    break;
                case DataStore.UserGroup.Level3Manager:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别3";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň3`";
                    else
                        group = "Level3";

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

                    this.buttonConfiguration.Visible = true;
                    this.buttonCommunication.Visible = true;
                    this.buttonSysConfig.Visible = true;
                    this.buttonIOTest.Visible = true;

                    this.buttonUpdate.Visible = true;
                    this.buttonFactoryInitialize.Visible = true;
                    this.buttonEquipmentSetting.Visible = true;
                    this.buttonUser.Visible = true;

                    this.buttonEquipmentTest.Visible = false;
                    this.buttonOptionSetting.Visible = false;
                    break;
                case DataStore.UserGroup.Level4Developer:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别4";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň4`";
                    else
                        group = "Level4";

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

                    this.buttonConfiguration.Visible = true;
                    this.buttonCommunication.Visible = true;
                    this.buttonSysConfig.Visible = true;
                    this.buttonIOTest.Visible = true;

                    this.buttonUpdate.Visible = true;
                    this.buttonFactoryInitialize.Visible = true;
                    this.buttonEquipmentSetting.Visible = true;
                    this.buttonUser.Visible = true;

                    this.buttonEquipmentTest.Visible = true;
                    this.buttonOptionSetting.Visible = true;
                    break;
                case DataStore.UserGroup.LogOff:
                    break;
                default:
                    break;
            }

            if (this.labelUserID.Text != id)
                this.labelUserID.Text = id;
            if (this.labelUserLevel.Text != group)
                this.labelUserLevel.Text = group;

        }

        public void DisplayRefresh()
        {
            if (this.ParentForm.SystemConfig.IsLogin == true)
                this.UpdateDisplayUser(this.ParentForm.SystemConfig.CurrentUser);
            else
            {
                this.ParentForm.SystemConfig.CurrentUser.Group = DataStore.UserGroup.Level3Manager;
                this.buttonEquipmentTest.Visible = false;
                this.buttonOptionSetting.Visible = false;
            }

            this.ParentForm.TransferData(CommunicationCommand.ModeMenu, CommunicationID.MainBoard);
            this.ParentForm.SystemConfig.CurrentForm = DataStore.E_FormStore.FormMenu;
        }
        #endregion

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

            this.InitializeDesign();
            this.DefaultSetting();
        }
        #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.buttonTimeSetting)
            {
                #region 시간설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormTimeSetting);
                this.ParentForm.ChildFormTimeSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonInformation)
            {
                #region 시스템정보
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormInformation);
                this.ParentForm.ChildFormInformation.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonDataBackup)
            {
                #region 데이터백업
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormDataBackup);
                this.ParentForm.ChildFormDataBackup.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonSysConfig)
            {
                #region 시스템설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormSystemSetting);
                this.ParentForm.ChildFormSystemSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonCalibration)
            {
                #region 중량조정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormCalibration);
                this.ParentForm.ChildFormCalibration.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonConfiguration)
            {
                #region 환경설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormConfiguration);
                this.ParentForm.ChildFormConfiguration.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonFactoryInitialize)
            {
                #region 공장초기화
                DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 5);
                DialogResult dr = myDlg.ShowDialog();
                if (dr == DialogResult.Yes)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_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)
                    this.ParentForm.ChildFormProgramUpdate.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonEquipmentSetting)
            {
                #region 장비설정
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormEquipmentSetting);
                this.ParentForm.ChildFormEquipmentSetting.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonIOTest)
            {
                #region IO테스트
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormIOTest);
                this.ParentForm.ChildFormIOTest.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonEquipmentTest)
            {
                #region 장비테스트
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormEquipmentTest);
                this.ParentForm.ChildFormEquipmentTest.DisplayRefresh();
                #endregion
            }
            else if (button == this.buttonUser)
            {
                #region 유저설정
                this.ParentForm.ChildFormUserSetting.DisplayRefresh();
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormUserSetting);
                #endregion
            }
            else if (button == this.buttonCommunication)
            {
                #region 통신설정
                this.ParentForm.ChildFormCommunication.DisplayRefresh();
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormCommunication);
                #endregion
            }
            else if (button == this.buttonOptionSetting)
            {
                #region 옵션설정
                this.ParentForm.ChildFormOptionSetting.DisplayRefresh();
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormOptionSetting);
                #endregion
            }
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormMainDisplay);
            this.ParentForm.ChildFormMainDisplay.DisplayRefresh();
        }
        private void buttonFunction_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.IsLogin == false)
            {
                DialogFormPasswordKeyPad pass = new DialogFormPasswordKeyPad(8, this.ParentForm.SystemConfig.Language);

                if (pass.ShowDialog() == DialogResult.OK)
                {
                    this.ParentForm.SystemConfig.CurrentUser.Group = DataStore.UserGroup.Level4Developer;

                    if (this.buttonEquipmentTest.Visible != true)
                        this.buttonEquipmentTest.Visible = true;
                    if (this.buttonOptionSetting.Visible == false)
                        this.buttonOptionSetting.Visible = true;
                }
            }
        }
        #endregion
    }
}