using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using SmartX;
using INT63DC_ImageDll;
using INT63DC_6CH.DialogForms;
using INT63DC_6CH.In_UserManager;

namespace INT63DC_6CH.Forms
{
    public partial class FormOptionSetting : Form
    {
        #region Field
        private FormMain m_ParentForm;
        #endregion

        #region Constructor
        public FormOptionSetting(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.DefaultSetting();
        } 
        #endregion

        #region Property
        public FormMain ParentForm
        {
            get { return this.m_ParentForm; }
            private set { this.m_ParentForm = value; }
        }
        #endregion

        #region Method
        private void InitializeDesign()
        {
            ImageDll images = new ImageDll();

            if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Korean)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.English)
            {
                #region English
                this.labelTitle.Text = "Option Setting";

                this.labelBuadrateWarning.Text = "※ After changing setting, Turn the power off and back on";
                this.labelBuadrateWarning2.Text = "※ Do not change the value except engineer";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp)); 
                #endregion
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
            {
                #region Chinese
                this.labelTitle.Text = "Option Setting";

                this.labelBuadrateWarning.Text = "※ 电源重启后，设置会自动更新";
                this.labelBuadrateWarning2.Text = "※ 除了工程师之外，不要改变这个值";

                this.buttonDataStatistics.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnOn_84X25));
                this.buttonDataStatistics.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnOff_84X25));

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp)); 
                #endregion
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
            {
                #region Czech
                this.labelTitle.Text = "Option Setting";

                this.labelBuadrateWarning.Text = "※ Po změně nastavení vypněte a znovu zapněte napájení";
                this.labelBuadrateWarning2.Text = "※ Nezměňujte hodnotu kromě inženýra";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp)); 
                #endregion
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.German)
            {
                #region German
                this.labelTitle.Text = "Option Setting";

                this.labelBuadrateWarning.Text = "※ Stellen Sie nach dem Einstellen des Servoantriebs sicher, Mit dem Hauptschalter aus- und einschalten";
                this.labelBuadrateWarning2.Text = "※ Werte dürfen nur vom Servicetechniker des Herstellers geändert werden";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp)); 
                #endregion
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Japanese)
            {
                #region Japanese
                this.labelTitle.Text = "オプション設定";

                this.labelBuadrateWarning.Text = "※ 設定変更後は電源を入れ直してください";
                this.labelBuadrateWarning2.Text = "※ エンジニア以外は値を変更しないこと";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackUp)); 
                #endregion
            }
            else
            {

            }
        }
        private void DefaultSetting()
        {

        }
        private void InitializeControl()
        {
            // 피드백 보드 사용 유무
            if (this.ParentForm.SystemConfig.IsFeedback == true)
                this.buttonFeedback.ButtonDown();
            else
                this.buttonFeedback.ButtonUp();

            // 데이터 통계 기능 사용 유무
            if (this.ParentForm.SystemConfig.IsDataStatistics == true)
                this.buttonDataStatistics.ButtonDown();
            else
                this.buttonDataStatistics.ButtonUp();

            // Part 11 사용 유무
            if (this.ParentForm.SystemConfig.IsPart11 == true)
                this.buttonPart11.ButtonDown();
            else
                this.buttonPart11.ButtonUp();

            this.buttonSave.Visible = false;
        }

        public void DisplayRefresh()
        {
            this.InitializeControl();
        }
        #endregion

        #region Event Handler
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            // 피드백 보드 사용 유무
            if (this.buttonFeedback.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsFeedback = true;
            else
                this.ParentForm.SystemConfig.IsFeedback = false;

            // 데이터 통계 기능 사용 유무
            if (this.buttonDataStatistics.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsDataStatistics = true;
            else
                this.ParentForm.SystemConfig.IsDataStatistics = false;

            // Part11 기능 사용 유무
            if (this.buttonPart11.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.SystemConfig.IsPart11 = true;
                this.ParentForm.SystemConfig.IsLogin = true;
                this.ParentForm.SystemConfig.IsDataBackup = true;
                this.ParentForm.SystemConfig.IsDataStatistics = true;
            }
            else
            {
                this.ParentForm.SystemConfig.IsPart11 = false;
                this.ParentForm.SystemConfig.IsLogin = false;
                this.ParentForm.SystemConfig.IsDataBackup = false;
                this.ParentForm.SystemConfig.IsDataStatistics = false;

                // Delete user list
                UserManager.UserManager_UserAllDel();
            }

            this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

            this.smartGroupBox1.Enabled = false;
            this.buttonBack.Visible = false;
        }
        private void buttonDataStatistics_Click(object sender, EventArgs e)
        {
            //if (this.buttonDataStatistics.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            //{
            //    DialogFormPasswordKeyPad pass = new DialogFormPasswordKeyPad(8, this.ParentForm.SystemConfig.Language);
            //    if (pass.ShowDialog() == DialogResult.OK)
            //        this.buttonDataStatistics.ButtonDown();
            //    else
            //        this.buttonDataStatistics.ButtonUp();
            //}

            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }
        private void buttonPart11_Click(object sender, EventArgs e)
        {
            if (this.buttonPart11.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.buttonPart11.ButtonDown();
                this.buttonDataStatistics.ButtonDown();

                //DialogFormPasswordKeyPad pass = new DialogFormPasswordKeyPad(8, this.ParentForm.SystemConfig.Language);
                //if (pass.ShowDialog() == DialogResult.OK)
                //{
                //    this.buttonPart11.ButtonDown();
                //    this.buttonDataStatistics.ButtonDown();
                //}
                //else
                //{
                //    this.buttonPart11.ButtonUp();
                //    this.buttonDataStatistics.ButtonUp();
                //}
            }
            else
            {
                this.buttonPart11.ButtonUp();
            }

            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }
        private void buttonFeedback_Click(object sender, EventArgs e)
        {
            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }
        #endregion
    }
}