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

using SmartX;
using ITC81DB_2H.Forms;
using ITC81DB_2H_ImageDll;
using ITC81DB_2H.Datastore;

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

        private Define.E_MenuBottomSystem CurrentMenu;
        #endregion

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

            this.ParentForm = parent;

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

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

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

            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpCalibrationUp));
                this.buttonJudgmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpJudgmentDisable));
                this.buttonJudgmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpJudgmentDown));
                this.buttonJudgmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpJudgmentUp));
                this.buttonSorter.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpSorterDisable));
                this.buttonSorter.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpSorterDown));
                this.buttonSorter.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpSorterUp));
                this.buttonAutoZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpAutoZeroDisable));
                this.buttonAutoZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpAutoZeroDown));
                this.buttonAutoZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpAutoZeroUp));
                this.buttonExternalOutput.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpExternalOutputDisable));
                this.buttonExternalOutput.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpExternalOutputDown));
                this.buttonExternalOutput.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpExternalOutputUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpIOTestUp));
                this.buttonBLDCMotorSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpBLDCDisable));
                this.buttonBLDCMotorSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpBLDCDown));
                this.buttonBLDCMotorSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engHelpBLDCUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpCalibrationUp));
                this.buttonJudgmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpJudgmentDisable));
                this.buttonJudgmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpJudgmentDown));
                this.buttonJudgmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpJudgmentUp));
                this.buttonSorter.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpSorterDisable));
                this.buttonSorter.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpSorterDown));
                this.buttonSorter.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpSorterUp));
                this.buttonAutoZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpAutoZeroDisable));
                this.buttonAutoZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpAutoZeroDown));
                this.buttonAutoZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpAutoZeroUp));
                this.buttonExternalOutput.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpExternalOutputDisable));
                this.buttonExternalOutput.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpExternalOutputDown));
                this.buttonExternalOutput.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpExternalOutputUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnHelpIOTestUp));
                this.buttonBLDCMotorSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDisable));
                this.buttonBLDCMotorSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDown));
                this.buttonBLDCMotorSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpCalibrationUp));
                this.buttonJudgmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpJudgmentDisable));
                this.buttonJudgmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpJudgmentDown));
                this.buttonJudgmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpJudgmentUp));
                this.buttonSorter.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpSorterDisable));
                this.buttonSorter.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpSorterDown));
                this.buttonSorter.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpSorterUp));
                this.buttonAutoZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpAutoZeroDisable));
                this.buttonAutoZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpAutoZeroDown));
                this.buttonAutoZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpAutoZeroUp));
                this.buttonExternalOutput.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpExternalOutputDisable));
                this.buttonExternalOutput.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpExternalOutputDown));
                this.buttonExternalOutput.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpExternalOutputUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusHelpIOTestUp));
                this.buttonBLDCMotorSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDisable));
                this.buttonBLDCMotorSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDown));
                this.buttonBLDCMotorSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpCalibrationUp));
                this.buttonJudgmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpJudgmentDisable));
                this.buttonJudgmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpJudgmentDown));
                this.buttonJudgmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpJudgmentUp));
                this.buttonSorter.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpSorterDisable));
                this.buttonSorter.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpSorterDown));
                this.buttonSorter.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpSorterUp));
                this.buttonAutoZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpAutoZeroDisable));
                this.buttonAutoZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpAutoZeroDown));
                this.buttonAutoZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpAutoZeroUp));
                this.buttonExternalOutput.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpExternalOutputDisable));
                this.buttonExternalOutput.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpExternalOutputDown));
                this.buttonExternalOutput.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpExternalOutputUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerHelpIOTestUp));
                this.buttonBLDCMotorSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDisable));
                this.buttonBLDCMotorSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDown));
                this.buttonBLDCMotorSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCUp));
            }
            else
            {
                this.buttonCalibration.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpCalibrationDisable));
                this.buttonCalibration.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpCalibrationDown));
                this.buttonCalibration.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpCalibrationUp));
                this.buttonJudgmentSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpJudgmentDisable));
                this.buttonJudgmentSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpJudgmentDown));
                this.buttonJudgmentSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpJudgmentUp));
                this.buttonSorter.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpSorterDisable));
                this.buttonSorter.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpSorterDown));
                this.buttonSorter.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpSorterUp));
                this.buttonAutoZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpAutoZeroDisable));
                this.buttonAutoZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpAutoZeroDown));
                this.buttonAutoZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpAutoZeroUp));
                this.buttonExternalOutput.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpExternalOutputDisable));
                this.buttonExternalOutput.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpExternalOutputDown));
                this.buttonExternalOutput.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpExternalOutputUp));
                this.buttonIOTest.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpIOTestDisable));
                this.buttonIOTest.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpIOTestDown));
                this.buttonIOTest.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpIOTestUp));
                this.buttonBLDCMotorSetting.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDisable));
                this.buttonBLDCMotorSetting.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCDown));
                this.buttonBLDCMotorSetting.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korHelpBLDCUp));
            }
        }
        private void DefaultSetting()
        {
            this.CurrentMenu = Define.E_MenuBottomSystem.Help;
        }

        public void UpdateMenuDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case Define.E_UserGroup.Level1:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemExternalOutput;
                    break;
                case Define.E_UserGroup.Level2:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemExternalOutput;
                    break;
                case Define.E_UserGroup.Level3:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemExternalOutput;
                    break;
                case Define.E_UserGroup.Admin:
                case Define.E_UserGroup.Developer:
                    this.buttonCalibration.Enabled = true;
                    this.buttonJudgmentSetting.Enabled = true;
                    this.buttonSorter.Enabled = true;
                    this.buttonAutoZero.Enabled = true;
                    this.buttonIOTest.Enabled = true;
                    this.buttonExternalOutput.Enabled = true;
                    break;
                case Define.E_UserGroup.NotLogin:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemExternalOutput;
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayMenuButton(Define.E_MenuBottomSystem menu)
        {
            switch (menu)
            {
                case Define.E_MenuBottomSystem.Calibration:
                    break;
                case Define.E_MenuBottomSystem.Help:
                    break;
                case Define.E_MenuBottomSystem.IOTest:
                    break;
                case Define.E_MenuBottomSystem.JudgmentSetting:
                    break;
                case Define.E_MenuBottomSystem.SorterSetting:
                    break;
                default:
                    break;
            }
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.SystemHelp;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.buttonBLDCMotorSetting.Visible = this.ParentForm.ParentForm.SystemConfig1.IsBLDCON;
        }
        #endregion

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

            if (button == null)
                return;

            if (button == this.buttonCalibration)
                this.CurrentMenu = Define.E_MenuBottomSystem.Calibration;
            else if (button == this.buttonJudgmentSetting)
                this.CurrentMenu = Define.E_MenuBottomSystem.JudgmentSetting;
            else if (button == this.buttonSorter)
                this.CurrentMenu = Define.E_MenuBottomSystem.SorterSetting;
            else if (button == this.buttonAutoZero)
                this.CurrentMenu = Define.E_MenuBottomSystem.AutoZero;
            else if (button == this.buttonExternalOutput)
                this.CurrentMenu = Define.E_MenuBottomSystem.ExternalOutput;
            else if (button == this.buttonIOTest)
                this.CurrentMenu = Define.E_MenuBottomSystem.IOTest;
            else if (button == this.buttonBLDCMotorSetting)
                this.CurrentMenu = Define.E_MenuBottomSystem.BLDCMotorSetting;
            else
                this.CurrentMenu = Define.E_MenuBottomSystem.Help;

            this.ParentForm.DisplayBottomSystem(this.CurrentMenu);
        }
        #endregion
    }
}
