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_2H.Forms;
using ITC81DB_2H.Datastore;

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

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

        #region Constructor
        public ControlBottomLog(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_MenuBottomLog.Help;

            this.CollectionButtonMenu = new Collection<SmartButton>();
            this.CollectionButtonMenu.Clear();
            this.CollectionButtonMenu.Add(this.buttonHelp);
            this.CollectionButtonMenu.Add(this.buttonLogInspection);
            this.CollectionButtonMenu.Add(this.buttonLogHistory);
            this.CollectionButtonMenu.Add(this.buttonLogOthers);
        }

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

        public void UpdateMenuDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case Define.E_UserGroup.Level1:
                    this.buttonLogInspection.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsLogEnable;
                    this.buttonLogHistory.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsLogEnable;
                    this.buttonLogOthers.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsLogEnable;
                    break;
                case Define.E_UserGroup.Level2:
                    this.buttonLogInspection.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsLogEnable;
                    this.buttonLogHistory.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsLogEnable;
                    this.buttonLogOthers.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsLogEnable;
                    break;
                case Define.E_UserGroup.Level3:
                    this.buttonLogInspection.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsLogEnable;
                    this.buttonLogHistory.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsLogEnable;
                    this.buttonLogOthers.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsLogEnable;
                    break;
                case Define.E_UserGroup.Admin:
                case Define.E_UserGroup.Developer:
                    this.buttonLogInspection.Enabled = true;
                    this.buttonLogHistory.Enabled = true;
                    this.buttonLogOthers.Enabled = true;
                    break;
                case Define.E_UserGroup.NotLogin:
                    //this.buttonLogInspection.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsLogEnable;
                    //this.buttonLogHistory.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsLogEnable;
                    //this.buttonLogOthers.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsLogEnable;
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayMenuButton(Define.E_MenuBottomLog menu)
        {
            switch (menu)
            {
                case Define.E_MenuBottomLog.Help:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonHelp.ButtonDown();
                    if (this.buttonLogInspection.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogInspection.ButtonUp();
                    if (this.buttonLogHistory.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogHistory.ButtonUp();
                    if (this.buttonLogOthers.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogOthers.ButtonUp();
                    break;
                case Define.E_MenuBottomLog.LogInspection:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonLogInspection.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonLogInspection.ButtonDown();
                    if (this.buttonLogHistory.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogHistory.ButtonUp();
                    if (this.buttonLogOthers.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogOthers.ButtonUp();
                    break;
                case Define.E_MenuBottomLog.LogHistory:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonLogInspection.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogInspection.ButtonUp();
                    if (this.buttonLogHistory.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonLogHistory.ButtonDown();
                    if (this.buttonLogOthers.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogOthers.ButtonUp();
                    break;
                case Define.E_MenuBottomLog.LogOthers:
                    if (this.buttonHelp.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonHelp.ButtonUp();
                    if (this.buttonLogInspection.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogInspection.ButtonUp();
                    if (this.buttonLogHistory.ButtonStatus != SmartButton.BUTSTATUS.UP)
                        this.buttonLogHistory.ButtonUp();
                    if (this.buttonLogOthers.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonLogOthers.ButtonDown();
                    break;
                default:
                    break;
            }
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.buttonHelp.ButtonDown();
            this.buttonLogInspection.ButtonUp();
            this.buttonLogHistory.ButtonUp();
            this.buttonLogOthers.ButtonUp();

            this.CurrentMenu = Define.E_MenuBottomLog.Help;
            this.ParentForm.DisplayBottomLog(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_MenuBottomLog.Help;
            else if (button == this.buttonLogInspection)
                this.CurrentMenu = Define.E_MenuBottomLog.LogInspection;
            else if (button == this.buttonLogHistory)
                this.CurrentMenu = Define.E_MenuBottomLog.LogHistory;
            else if (button == this.buttonLogOthers)
                this.CurrentMenu = Define.E_MenuBottomLog.LogOthers;
            else
                this.CurrentMenu = Define.E_MenuBottomLog.Help;

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