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

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

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

        private Define.E_MenuBottomEquipment CurrentMenu;

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

        #region Constructor
        public ControlCenterEquipHelp(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()
        {
            this.buttonManufacturerSetting.Font = new Font("새굴림", 15, FontStyle.Bold);

            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.buttonUpdate.Text = "Update";
                this.buttonInitialize.Text = "Initialization";
                this.buttonFunction.Text = "Feature settings";
                this.buttonUser.Text = "User settings";
                this.buttonEngineerSetting.Text = "Engineer settings";
                this.buttonManufacturerSetting.Text = "Manufacturer settings";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.buttonUpdate.Text = "更新";
                this.buttonInitialize.Text = "工厂初期化";
                this.buttonFunction.Text = "功能设定";
                this.buttonUser.Text = "用户设置";
                this.buttonEngineerSetting.Text = "工程师设置";
                this.buttonManufacturerSetting.Text = "制造商设置";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {

            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.buttonUpdate.Text = "Обнов";
                this.buttonInitialize.Text = "Инициализация";
                this.buttonFunction.Text = "Настр.функций";
                this.buttonUser.Text = "Настр.польз";
                this.buttonEngineerSetting.Text = "Настр.инженера";
                this.buttonManufacturerSetting.Text = "Настр.производителя";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.buttonUpdate.Text = "Aktualisierung";
                this.buttonInitialize.Text = "Werkseinstellung";
                this.buttonFunction.Text = "Funktionseinstellungen";
                this.buttonUser.Text = "Benutzereinstellungen";
                this.buttonEngineerSetting.Text = "Ingenieur-Einstellungen";
                this.buttonManufacturerSetting.Text = "Herstellereinstellungen";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {
                this.buttonUpdate.Text = "Actualizar";
                this.buttonInitialize.Text = "Inicializar";
                this.buttonFunction.Text = "Funciones";
                this.buttonUser.Text = "Usuario";
                this.buttonEngineerSetting.Text = "Ingeniería";
                this.buttonManufacturerSetting.Font = new Font("새굴림", 13, FontStyle.Bold);
                this.buttonManufacturerSetting.Text = "Configuración del fabricante";
            }
            else
            {
                this.buttonUpdate.Text = "업데이트";
                this.buttonInitialize.Text = "공장초기화";
                this.buttonFunction.Text = "기능설정";
                this.buttonUser.Text = "유저설정";
                this.buttonEngineerSetting.Text = "엔지니어설정";
                this.buttonManufacturerSetting.Text = "제조사설정";
            }
        }
        private void DefaultSetting()
        {
            this.CurrentMenu = Define.E_MenuBottomEquipment.Help;

            this.CollectionButtonHelp = new Collection<SmartButton>();
            this.CollectionButtonHelp.Clear();
            this.CollectionButtonHelp.Add(this.buttonUpdate);
            this.CollectionButtonHelp.Add(this.buttonInitialize);
            this.CollectionButtonHelp.Add(this.buttonFunction);

            this.CollectionPictureBoxHelpEnable = new Collection<PictureBox>();
            this.CollectionPictureBoxHelpEnable.Clear();
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxUpdateEnable);
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxInitializationEnable);
            this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxFunctionEnable);

            this.CollectionPictureBoxHelpDisable = new Collection<PictureBox>();
            this.CollectionPictureBoxHelpDisable.Clear();
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxUpdateDisable);
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxInitializationDisable);
            this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxFunctionDisable);

            if (this.ParentForm.ParentForm.SystemConfig1.IsLogin == true)
            {
                this.buttonUser.Visible = true;
                this.pictureBoxUserDisable.Visible = true;
                this.pictureBoxUserEnable.Visible = true;

                this.CollectionButtonHelp.Add(this.buttonUser);
                this.CollectionButtonHelp.Add(this.buttonEngineerSetting);
                this.CollectionButtonHelp.Add(this.buttonManufacturerSetting);

                this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxUserEnable);
                this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxEngineerEnable);
                this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxManufacturerEnable);

                this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxUserDisable);
                this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxEngineerDisable);
                this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxManufacturerDisable);

                this.ParentForm.HelpLocation(4, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
            }
            else
            {
                this.buttonUser.Visible = false;
                this.pictureBoxUserDisable.Visible = false;
                this.pictureBoxUserEnable.Visible = false;

                this.CollectionButtonHelp.Add(this.buttonEngineerSetting);
                this.CollectionButtonHelp.Add(this.buttonManufacturerSetting);

                this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxEngineerEnable);
                this.CollectionPictureBoxHelpEnable.Add(this.pictureBoxManufacturerEnable);

                this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxEngineerDisable);
                this.CollectionPictureBoxHelpDisable.Add(this.pictureBoxManufacturerDisable);

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

        public void DisplayHiddenEngineer(bool bValue)
        {
            if (bValue == true)
            {
                if (this.ParentForm.ParentForm.SystemConfig1.IsLogin == true)
                    this.ParentForm.HelpLocation(5, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
                else
                    this.ParentForm.HelpLocation(4, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
            }
            else
            {
                if (this.ParentForm.ParentForm.SystemConfig1.IsLogin == true)
                    this.ParentForm.HelpLocation(4, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
                else
                    this.ParentForm.HelpLocation(3, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
            }

            this.buttonEngineerSetting.Visible = bValue;
            this.pictureBoxEngineerDisable.Visible = bValue;
            this.pictureBoxEngineerEnable.Visible = bValue;
        }
        public void DisplayHiddenManufacturer(bool bValue)
        {
            if (bValue == true)
            {
                if (this.ParentForm.ParentForm.SystemConfig1.IsLogin == true)
                    this.ParentForm.HelpLocation(6, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);
                else
                    this.ParentForm.HelpLocation(5, this.CollectionButtonHelp, this.CollectionPictureBoxHelpDisable, this.CollectionPictureBoxHelpEnable);

                if (this.ParentForm.ParentForm.IsManufacturerVisible == true)
                {
                    this.buttonManufacturerSetting.Visible = true;
                    this.pictureBoxManufacturerDisable.Visible = true;
                    this.pictureBoxManufacturerEnable.Visible = true;
                }
            }
            else
            {
                this.buttonManufacturerSetting.Visible = false;
                this.pictureBoxManufacturerDisable.Visible = false;
                this.pictureBoxManufacturerEnable.Visible = false;
            }
        }

        public void DisplayHiddenMenu(bool bValue)
        {
            if (this.ParentForm.ParentForm.SystemConfig1.IsLogin == true)
                this.buttonEngineerSetting.Location = new Point(28, 240);
            else
                this.buttonEngineerSetting.Location = new Point(526, 17);

            this.buttonEngineerSetting.Visible = bValue;
        }
        private void UpdateDisplayUser(UserItem user)
        {
            if (user.Group == Define.E_UserGroup.Developer && this.ParentForm.ParentForm.SystemConfig1.IsLogin == true)
            {
                this.DisplayHiddenEngineer(true);
                this.ParentForm.ParentForm.IsManufacturerVisible = true;
                this.DisplayHiddenManufacturer(true);
            }
            else
            {
                this.DisplayHiddenEngineer(false);
                this.ParentForm.ParentForm.IsManufacturerVisible = false;
                this.DisplayHiddenManufacturer(false);
            }
        }
        public void UpdateMenuDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case Define.E_UserGroup.Level1:
                    this.buttonUpdate.Enabled = this.pictureBoxUpdateEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipUpdate;
                    this.buttonInitialize.Enabled = this.pictureBoxInitializationEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipInitialize;
                    this.buttonFunction.Enabled = this.pictureBoxFunctionEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipFunctionSetting;
                    this.buttonManufacturerSetting.Enabled = this.pictureBoxManufacturerEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipManufacturerSetting;
                    this.buttonUser.Enabled = true;
                    this.buttonEngineerSetting.Enabled = this.pictureBoxEngineerEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipEngineerSetting;
                    break;
                case Define.E_UserGroup.Level2:
                    this.buttonUpdate.Enabled = this.pictureBoxUpdateEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipUpdate;
                    this.buttonInitialize.Enabled = this.pictureBoxInitializationEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipInitialize;
                    this.buttonFunction.Enabled = this.pictureBoxFunctionEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipFunctionSetting;
                    this.buttonManufacturerSetting.Enabled = this.pictureBoxManufacturerEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipManufacturerSetting;
                    this.buttonUser.Enabled = true;
                    this.buttonEngineerSetting.Enabled = this.pictureBoxEngineerEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipEngineerSetting;
                    break;
                case Define.E_UserGroup.Level3:
                    this.buttonUpdate.Enabled = this.pictureBoxUpdateEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipUpdate;
                    this.buttonInitialize.Enabled = this.pictureBoxInitializationEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipInitialize;
                    this.buttonFunction.Enabled = this.pictureBoxFunctionEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipFunctionSetting;
                    this.buttonManufacturerSetting.Enabled = this.pictureBoxManufacturerEnable.Visible = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipManufacturerSetting;
                    this.buttonUser.Enabled = true;
                    this.buttonEngineerSetting.Enabled = true;
                    break;
                case Define.E_UserGroup.Admin:
                case Define.E_UserGroup.Developer:
                    this.buttonUpdate.Enabled = this.pictureBoxUpdateEnable.Visible = true;
                    this.buttonInitialize.Enabled = this.pictureBoxInitializationEnable.Visible = true;
                    this.buttonFunction.Enabled = this.pictureBoxFunctionEnable.Visible = true;
                    this.buttonManufacturerSetting.Enabled = this.pictureBoxManufacturerEnable.Visible = true;
                    this.buttonUser.Enabled = true;
                    this.buttonEngineerSetting.Enabled = this.pictureBoxEngineerEnable.Visible = true;
                    break;
                case Define.E_UserGroup.NotLogin:
                    //this.buttonUpdate.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipUpdate;
                    //this.buttonInitialize.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipInitialize;
                    //this.buttonFunction.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipFunctionSetting;
                    //this.buttonCompanySetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipCompanySetting;
                    //this.buttonUser.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsEquipUserSetting;
                    //this.buttonEngineerSetting.Enabled = true;
                    break;
                default:
                    break;
            }

            this.pictureBoxUpdateEnable.BringToFront();
            this.pictureBoxInitializationEnable.BringToFront();
            this.pictureBoxFunctionEnable.BringToFront();
            this.pictureBoxManufacturerEnable.BringToFront();
            this.pictureBoxUserEnable.BringToFront();
            this.pictureBoxEngineerEnable.BringToFront();
        }

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

            this.UpdateDisplayUser(status.CurrentUser);
        }
        #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 == "Update")
                this.CurrentMenu = Define.E_MenuBottomEquipment.Update;
            else if (control == "Initialize")
                this.CurrentMenu = Define.E_MenuBottomEquipment.Initialize;
            else if (control == "Function")
                this.CurrentMenu = Define.E_MenuBottomEquipment.FunctionSetting;
            else if (control == "Manufacturer")
                this.CurrentMenu = Define.E_MenuBottomEquipment.Manufacturer;
            else if (control == "User")
                this.CurrentMenu = Define.E_MenuBottomEquipment.User;
            else if (control == "Engineer")
                this.CurrentMenu = Define.E_MenuBottomEquipment.Engineer;
            else
                this.CurrentMenu = Define.E_MenuBottomEquipment.Help;

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