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

using SmartX;
using ITC81DB_2.Forms;

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

        private Define.E_MenuBottomSystem CurrentMenu;
        private Collection<SmartButton> CollectionButtonMenu;
        #endregion

        #region Constructor
        public ControlBottomSystem(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()
        {
        }
        private void DefaultSetting()
        {
            this.CurrentMenu = Define.E_MenuBottomSystem.Help;

            this.CollectionButtonMenu = new Collection<SmartButton>();
            this.CollectionButtonMenu.Clear();
            this.CollectionButtonMenu.Add(this.buttonHelp);
            this.CollectionButtonMenu.Add(this.buttonCalibration);
            this.CollectionButtonMenu.Add(this.buttonJudgmentSetting);
            this.CollectionButtonMenu.Add(this.buttonSorter);
            this.CollectionButtonMenu.Add(this.buttonAutoZero);
            this.CollectionButtonMenu.Add(this.buttonIOTest);
        }

        public void CurrentControlEnable(bool enable)
        {
            foreach (SmartButton button in this.CollectionButtonMenu)
                button.Enabled = enable;
        }

        public void UpdateDisplayMenuButton(Define.E_MenuBottomSystem menu)
        {
            switch (menu)
            {
                case Define.E_MenuBottomSystem.AutoZero:
                    if (this.buttonAutoZero.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonAutoZero.ButtonDown();
                    if (this.buttonCalibration.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonCalibration.ButtonUp();
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonIOTest.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonIOTest.ButtonUp();
                    if (this.buttonJudgmentSetting.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonJudgmentSetting.ButtonUp();
                    if (this.buttonSorter.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonSorter.ButtonUp();
                    break;
                case Define.E_MenuBottomSystem.Calibration:
                    if (this.buttonAutoZero.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonAutoZero.ButtonUp();
                    if (this.buttonCalibration.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonCalibration.ButtonDown();
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonIOTest.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonIOTest.ButtonUp();
                    if (this.buttonJudgmentSetting.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonJudgmentSetting.ButtonUp();
                    if (this.buttonSorter.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonSorter.ButtonUp();
                    break;
                case Define.E_MenuBottomSystem.Help:
                    if (this.buttonAutoZero.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonAutoZero.ButtonUp();
                    if (this.buttonCalibration.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonCalibration.ButtonUp();
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonHelp.ButtonDown();
                    if (this.buttonIOTest.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonIOTest.ButtonUp();
                    if (this.buttonJudgmentSetting.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonJudgmentSetting.ButtonUp();
                    if (this.buttonSorter.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonSorter.ButtonUp();
                    break;
                case Define.E_MenuBottomSystem.IOTest:
                    if (this.buttonAutoZero.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonAutoZero.ButtonUp();
                    if (this.buttonCalibration.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonCalibration.ButtonUp();
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonIOTest.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonIOTest.ButtonDown();
                    if (this.buttonJudgmentSetting.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonJudgmentSetting.ButtonUp();
                    if (this.buttonSorter.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonSorter.ButtonUp();
                    break;
                case Define.E_MenuBottomSystem.JudgmentSetting:
                    if (this.buttonAutoZero.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonAutoZero.ButtonUp();
                    if (this.buttonCalibration.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonCalibration.ButtonUp();
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonIOTest.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonIOTest.ButtonUp();
                    if (this.buttonJudgmentSetting.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonJudgmentSetting.ButtonDown();
                    if (this.buttonSorter.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonSorter.ButtonUp();
                    break;
                case Define.E_MenuBottomSystem.SorterSetting:
                    if (this.buttonAutoZero.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonAutoZero.ButtonUp();
                    if (this.buttonCalibration.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonCalibration.ButtonUp();
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonIOTest.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonIOTest.ButtonUp();
                    if (this.buttonJudgmentSetting.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonJudgmentSetting.ButtonUp();
                    if (this.buttonSorter.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonSorter.ButtonDown();
                    break;
                default:
                    break;
            }
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.buttonHelp.ButtonDown();
            this.buttonCalibration.ButtonUp();
            this.buttonJudgmentSetting.ButtonUp();
            this.buttonAutoZero.ButtonUp();
            this.buttonIOTest.ButtonUp();

            this.CurrentMenu = Define.E_MenuBottomSystem.Help;
            this.ParentForm.DisplayBottomSystem(this.CurrentMenu);
        }
        #endregion

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

            if (button == null)
                return;

            if (button == this.buttonHelp)
                this.CurrentMenu = Define.E_MenuBottomSystem.Help;
            else 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.buttonIOTest)
                this.CurrentMenu = Define.E_MenuBottomSystem.IOTest;
            else
                this.CurrentMenu = Define.E_MenuBottomSystem.Help;

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