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.Forms;

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

        private DataStore.MenuBottomBasic CurrentMenu;
        private Collection<SmartButton> CollectionButtonMenu;
        #endregion

        #region Constructor
        public ControlBottomBasic(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 = DataStore.MenuBottomBasic.Help;

            this.CollectionButtonMenu = new Collection<SmartButton>();
            this.CollectionButtonMenu.Clear();
            this.CollectionButtonMenu.Add(this.buttonHelp);
            this.CollectionButtonMenu.Add(this.buttonTime);
            this.CollectionButtonMenu.Add(this.buttonProduct);
            this.CollectionButtonMenu.Add(this.buttonDataBackup);
            this.CollectionButtonMenu.Add(this.buttonDataStatistics);
        }

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

        public void UpdateMenuDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case DataStore.UserGroup.Level1Operator:
                    this.buttonTime.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicTime;
                    this.buttonProduct.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicProduct;
                    this.buttonDataBackup.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicDataBackup;
                    this.buttonDataStatistics.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicDataStatistics;
                    break;
                case DataStore.UserGroup.Level2Engineer:
                    this.buttonTime.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicTime;
                    this.buttonProduct.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicProduct;
                    this.buttonDataBackup.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicDataBackup;
                    this.buttonDataStatistics.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicDataStatistics;
                    break;
                case DataStore.UserGroup.Level3Manager:
                    this.buttonTime.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicTime;
                    this.buttonProduct.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicProduct;
                    this.buttonDataBackup.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicDataBackup;
                    this.buttonDataStatistics.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicDataStatistics;
                    break;
                case DataStore.UserGroup.Level4Developer:
                    this.buttonTime.Enabled = true;
                    this.buttonProduct.Enabled = true;
                    this.buttonDataBackup.Enabled = true;
                    this.buttonDataStatistics.Enabled = true;
                    break;
                case DataStore.UserGroup.NotLogin:
                    this.buttonTime.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicTime;
                    this.buttonProduct.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicProduct;
                    this.buttonDataBackup.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicDataBackup;
                    this.buttonDataStatistics.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsBasicDataStatistics;
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayMenuButton(DataStore.MenuBottomBasic menu)
        {
            switch (menu)
            {
                case DataStore.MenuBottomBasic.DataBackup:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonTime.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonTime.ButtonUp();
                    if (this.buttonProduct.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonProduct.ButtonUp();
                    if (this.buttonDataBackup.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonDataBackup.ButtonDown();
                    if (this.buttonDataStatistics.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataStatistics.ButtonUp();
                    break;
                case DataStore.MenuBottomBasic.DataStatistics:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonTime.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonTime.ButtonUp();
                    if (this.buttonProduct.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonProduct.ButtonUp();
                    if (this.buttonDataBackup.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataBackup.ButtonUp();
                    if (this.buttonDataStatistics.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonDataStatistics.ButtonDown();
                    break;
                case DataStore.MenuBottomBasic.Help:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonHelp.ButtonDown();
                    if (this.buttonTime.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonTime.ButtonUp();
                    if (this.buttonProduct.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonProduct.ButtonUp();
                    if (this.buttonDataBackup.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataBackup.ButtonUp();
                    if (this.buttonDataStatistics.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataStatistics.ButtonUp();
                    break;
                case DataStore.MenuBottomBasic.Product:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonTime.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonTime.ButtonUp();
                    if (this.buttonProduct.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonProduct.ButtonDown();
                    if (this.buttonDataBackup.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataBackup.ButtonUp();
                    if (this.buttonDataStatistics.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataStatistics.ButtonUp();
                    break;
                case DataStore.MenuBottomBasic.Time:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonTime.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonTime.ButtonDown();
                    if (this.buttonProduct.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonProduct.ButtonUp();
                    if (this.buttonDataBackup.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataBackup.ButtonUp();
                    if (this.buttonDataStatistics.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonDataStatistics.ButtonUp();
                    break;
                default:
                    break;
            }
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.buttonHelp.ButtonDown();
            this.buttonDataBackup.ButtonUp();
            this.buttonDataStatistics.ButtonUp();
            this.buttonProduct.ButtonUp();
            this.buttonTime.ButtonUp();

            this.CurrentMenu = DataStore.MenuBottomBasic.Help;
            this.ParentForm.DisplayBottomBasic(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 = DataStore.MenuBottomBasic.Help;
            else if (button == this.buttonTime)
                this.CurrentMenu = DataStore.MenuBottomBasic.Time;
            else if (button == this.buttonProduct)
                this.CurrentMenu = DataStore.MenuBottomBasic.Product;
            else if (button == this.buttonDataBackup)
                this.CurrentMenu = DataStore.MenuBottomBasic.DataBackup;
            else if (button == this.buttonDataStatistics)
                this.CurrentMenu = DataStore.MenuBottomBasic.DataStatistics;
            else
                this.CurrentMenu = DataStore.MenuBottomBasic.Help;

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