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;
using System.Collections.ObjectModel;

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

        private Define.E_MenuBottomConfiguration CurrentMenu;

        private Collection<SmartButton> CollectionButtonHelp;
        private Collection<PictureBox> CollectionPictureBoxHelpEnable;
        private Collection<PictureBox> CollectionPictureBoxHelpDisable;
        #endregion

        #region Constructor
        public ControlCenterConfiHelp(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()
        {
            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.buttonEthernet.Text = "Ethernet";
                this.buttonOptionBoard.Text = "Option board";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.buttonEthernet.Text = "以太网";
                this.buttonOptionBoard.Text = "选项板";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {

            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.buttonEthernet.Text = "Ethernet";
                this.buttonOptionBoard.Text = "Опции";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.buttonEthernet.Text = "Ethernet";
                this.buttonOptionBoard.Text = "Optionsplatine";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {
                this.buttonEthernet.Text = "Ethernet";
                this.buttonOptionBoard.Text = "Tablero opcional";
            }
            else
            {
                this.buttonEthernet.Text = "이더넷설정";
                this.buttonOptionBoard.Text = "옵션보드설정";
            }
        }
        private void DefaultSetting()
        {
            this.CurrentMenu = Define.E_MenuBottomConfiguration.Help;
            this.OptionBoardVisible();

            this.CollectionButtonHelp = new Collection<SmartButton>();
            this.CollectionButtonHelp.Clear();
            this.CollectionButtonHelp.Add(this.buttonSerialCOM1);
            this.CollectionButtonHelp.Add(this.buttonSerialCOM3);
            this.CollectionButtonHelp.Add(this.buttonSerialCOM4);
            this.CollectionButtonHelp.Add(this.buttonEthernet);

            this.CollectionPictureBoxHelpEnable = new Collection<PictureBox>();
            this.CollectionPictureBoxHelpEnable.Clear();
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxCOM1Enable);
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxCOM3Enable);
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxCOM4Enable);
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxEthernetEnable);

            this.CollectionPictureBoxHelpDisable = new Collection<PictureBox>();
            this.CollectionPictureBoxHelpDisable.Clear();
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxCOM1Disable);
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxCOM3Disable);
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxCOM4Disable);
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxEthernetDisable);

            if (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.OptionBoard) == 0)
            {
                this.buttonOptionBoard.Visible = false;
                this.pictureBoxOptionBoardDisable.Visible = false;
                this.pictureBoxOptionBoardEnable.Visible = false;

                this.ParentForm.HelpLocation(4, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
            }
            else
            {
                this.buttonOptionBoard.Visible = true;
                this.pictureBoxOptionBoardDisable.Visible = true;
                this.pictureBoxOptionBoardEnable.Visible = true;

                this.ParentForm.HelpLocation(5, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
            }
        }

        public void OptionBoardVisible()
        {
            int value;

            value = int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.OptionBoard);
            if (value == 0)
                this.buttonOptionBoard.Visible = false;
            else
                this.buttonOptionBoard.Visible = true;
        }
        public void UpdateMenuDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case Define.E_UserGroup.Level1:
                    this.buttonSerialCOM1.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiSerial;
                    this.buttonSerialCOM3.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiSerial;
                    this.buttonSerialCOM4.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiSerial;
                    this.buttonEthernet.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiEthernet;
                    break;
                case Define.E_UserGroup.Level2:
                    this.buttonSerialCOM1.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiSerial;
                    this.buttonSerialCOM3.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiSerial;
                    this.buttonSerialCOM4.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiSerial;
                    this.buttonEthernet.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiEthernet;
                    break;
                case Define.E_UserGroup.Level3:
                    this.buttonSerialCOM1.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiSerial;
                    this.buttonSerialCOM3.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiSerial;
                    this.buttonSerialCOM4.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiSerial;
                    this.buttonEthernet.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiEthernet;
                    break;
                case Define.E_UserGroup.Admin:
                case Define.E_UserGroup.Developer:
                    this.buttonSerialCOM1.Enabled = true;
                    this.buttonSerialCOM3.Enabled = true;
                    this.buttonSerialCOM4.Enabled = true;
                    this.buttonEthernet.Enabled = true;
                    break;
                case Define.E_UserGroup.NotLogin:
                    //this.buttonSerialCOM1.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsConfiSerial;
                    //this.buttonSerialCOM3.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsConfiSerial;
                    //this.buttonSerialCOM4.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsConfiSerial;
                    //this.buttonEthernet.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsConfiEthernet;
                    break;
                default:
                    break;
            }
        }

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

        #region Event Handler
        private void buttonMenu_Click(object sender, EventArgs e)
        {
            string control = (sender as Control).Tag.ToString();

            if (control == null || control == "")
                return;

            if (control == "COM1")
                this.CurrentMenu = Define.E_MenuBottomConfiguration.SerialCOM1;
            else if (control == "COM3")
                this.CurrentMenu = Define.E_MenuBottomConfiguration.SerialCOM3;
            else if (control == "COM4")
                this.CurrentMenu = Define.E_MenuBottomConfiguration.SerialCOM4;
            else if (control == "Ethernet")
                this.CurrentMenu = Define.E_MenuBottomConfiguration.Ethernet;
            else if (control == "OptionBoard")
                this.CurrentMenu = Define.E_MenuBottomConfiguration.OptionBoard;
            else
                this.CurrentMenu = Define.E_MenuBottomConfiguration.Help;

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