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;

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

        private Define.E_MenuBottomSystem CurrentMenu;
        #endregion

        #region Constructor
        public ControlCenterSystemHelp(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.buttonCalibration.Text = "Calibration";
                this.buttonJudgmentSetting.Text = "Judgment";
                this.buttonSorter.Text = "Sorter settings";
                this.buttonAutoZero.Text = "Auto zero";
                this.buttonIOTest.Text = "I/O test";
                this.buttonExternalOutput.Text = "External output";
                this.buttonExternalInput.Text = "External input";
                this.buttonBLDCMotorSetting.Text = "BLDC Settings";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.buttonCalibration.Text = "校准";
                this.buttonJudgmentSetting.Text = "判断设置";
                this.buttonSorter.Text = "筛选设定";
                this.buttonAutoZero.Text = "自动零点跟踪";
                this.buttonIOTest.Text = "I/O测试";
                this.buttonExternalOutput.Text = "外部输出";
                this.buttonExternalInput.Text = "外部输入";
                this.buttonBLDCMotorSetting.Text = "BLDC设置";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {

            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.buttonCalibration.Text = "Калибровка";
                this.buttonJudgmentSetting.Text = "Отбрак";
                this.buttonSorter.Text = "Настр.сорт";
                this.buttonAutoZero.Text = "Авто.нуль";
                this.buttonIOTest.Text = "Тест I/O";
                this.buttonExternalOutput.Text = "Внешний выход";
                this.buttonExternalInput.Text = "Внешний вход";
                this.buttonBLDCMotorSetting.Text = "Настройки BLDC";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.buttonCalibration.Text = "Kalibrierung";
                this.buttonJudgmentSetting.Text = "Tascheneinstellung";
                this.buttonSorter.Text = "Sortierereinstellung";
                this.buttonAutoZero.Text = "Automatische Nullung";
                this.buttonIOTest.Text = "I/O Test";
                this.buttonExternalOutput.Text = "Externer Ausgang";
                this.buttonExternalInput.Text = "Externer Eingang";
                this.buttonBLDCMotorSetting.Text = "BLDC-Einstellung";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {
                this.buttonCalibration.Text = "Calibración";
                this.buttonJudgmentSetting.Text = "Dictar sentencia";
                this.buttonSorter.Text = "Clasificador";
                this.buttonAutoZero.Text = "Seguimiento de cero";
                this.buttonIOTest.Text = "Test I/O";
                this.buttonExternalOutput.Text = "Salida externa";
                this.buttonExternalInput.Text = "Salida internet";
                this.buttonBLDCMotorSetting.Text = "BLDC Ajustes";
            }
            else
            {
                this.buttonCalibration.Text = "중량조정";
                this.buttonJudgmentSetting.Text = "판정설정";
                this.buttonSorter.Text = "선별기설정";
                this.buttonAutoZero.Text = "자동영점";
                this.buttonIOTest.Text = "I/O테스트";
                this.buttonExternalOutput.Text = "외부출력";
                this.buttonExternalInput.Text = "외부입력";
                this.buttonBLDCMotorSetting.Text = "BLDC 설정";
            }
        }
        private void DefaultSetting()
        {
            this.CurrentMenu = Define.E_MenuBottomSystem.Help;
            this.ButtonBLDCVisible(this.ParentForm.ParentForm.SystemConfig1.IsBLDCON);
        }

        public void ButtonBLDCVisible(bool bValue)
        {
            this.buttonBLDCMotorSetting.Visible = bValue;
            this.pictureBoxBLDCSettingDisable.Visible = bValue;
            this.pictureBoxBLDCSettingEnable.Visible = bValue;
        }
        public void UpdateMenuDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case Define.E_UserGroup.Level1:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemExternalOutput;
                    break;
                case Define.E_UserGroup.Level2:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemExternalOutput;
                    break;
                case Define.E_UserGroup.Level3:
                    this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemCalibration;
                    this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemJudgmentSetting;
                    this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemSorterSetting;
                    this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemAutoZero;
                    this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemIOTest;
                    this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemExternalOutput;
                    break;
                case Define.E_UserGroup.Admin:
                case Define.E_UserGroup.Developer:
                    this.buttonCalibration.Enabled = true;
                    this.buttonJudgmentSetting.Enabled = true;
                    this.buttonSorter.Enabled = true;
                    this.buttonAutoZero.Enabled = true;
                    this.buttonIOTest.Enabled = true;
                    this.buttonExternalOutput.Enabled = true;
                    break;
                case Define.E_UserGroup.NotLogin:
                    //this.buttonCalibration.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemCalibration;
                    //this.buttonJudgmentSetting.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemJudgmentSetting;
                    //this.buttonSorter.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemSorterSetting;
                    //this.buttonAutoZero.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemAutoZero;
                    //this.buttonIOTest.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemIOTest;
                    //this.buttonExternalOutput.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.NotLogin.IsSystemExternalOutput;
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayMenuButton(Define.E_MenuBottomSystem menu)
        {
            switch (menu)
            {
                case Define.E_MenuBottomSystem.Calibration:
                    break;
                case Define.E_MenuBottomSystem.Help:
                    break;
                case Define.E_MenuBottomSystem.IOTest:
                    break;
                case Define.E_MenuBottomSystem.JudgmentSetting:
                    break;
                case Define.E_MenuBottomSystem.SorterSetting:
                    break;
                default:
                    break;
            }
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.SystemHelp;
            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 == "Calibration")
                this.CurrentMenu = Define.E_MenuBottomSystem.Calibration;
            else if (control == "Judgment")
                this.CurrentMenu = Define.E_MenuBottomSystem.JudgmentSetting;
            else if (control == "Sorter")
                this.CurrentMenu = Define.E_MenuBottomSystem.SorterSetting;
            else if (control == "AutoZero")
                this.CurrentMenu = Define.E_MenuBottomSystem.AutoZero;
            else if (control == "ExternalOutput")
                this.CurrentMenu = Define.E_MenuBottomSystem.ExternalOutput;
            else if (control == "IOTest")
                this.CurrentMenu = Define.E_MenuBottomSystem.IOTest;
            else if (control == "BLDC")
                this.CurrentMenu = Define.E_MenuBottomSystem.BLDCMotorSetting;
            else
                this.CurrentMenu = Define.E_MenuBottomSystem.Help;

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