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_2C.DialogForms;
using INT63DC_2C.Part11_UserManager;

namespace INT63DC_2C.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.labelTitleSorter4Location.Text = "Sorter4 Location";
                this.labelInfo4.Text = "※ Leak detector selection (fixed to position 1)";

                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 = "选项设定";

                this.groupBoxOption.Text = "选项";

                this.labelTitleDataStatistics.Text = "数据统计";
                this.labelTitleSorter4Location.Text = "分类机4 地点";
                this.labelTitleSorterCheckEnable.Text = "分拣机运动检测";
                
                this.labelInfo4.Text = "※ 泄漏检测器选择 (固定为位置1)";
                this.labelInfo5.Text = "※ 激活 : [登錄], [数据备份], [数据统计]";

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

                this.buttonDataStatistics.DownImage = this.buttonSorter4Location.DownImage = this.buttonSorterCheckEnable.DownImage =
                    this.buttonPart11.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnOn_84X25));
                this.buttonDataStatistics.UpImage = this.buttonSorter4Location.UpImage = this.buttonSorterCheckEnable.UpImage =
                    this.buttonPart11.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.labelTitleSorter4Location.Text = "Vyřazovač4 umístění";
                this.labelInfo4.Text = "※ Výběr detektoru netěsností (pevně na pozici 1)";

                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.labelTitleSorter4Location.Text = "Sortierer4 Standort";
                this.labelInfo4.Text = "※ Auswahl des Lecksuchers (fest auf Position 1 eingestellt)";


                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.labelTitleSorter4Location.Text = "ソㅡタㅡ 4 の場所";
                this.labelInfo4.Text = "※リークディテクタ選択（位置1に固定)";

                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.IsOptDataStatistics == true)
                this.buttonDataStatistics.ButtonDown();
            else
                this.buttonDataStatistics.ButtonUp();

            // 선별기4 위치
            if (this.ParentForm.SystemConfig.Sorter4Location == 0)
                this.buttonSorter4Location.ButtonUp();
            else
                this.buttonSorter4Location.ButtonDown();

            // 선별부 동작 감지 사용 여부
            if (this.ParentForm.SystemConfig.IsSorterCheckEnable == true)
                this.buttonSorterCheckEnable.ButtonDown();
            else
                this.buttonSorterCheckEnable.ButtonUp();

            // Part11
            if (this.ParentForm.SystemConfig.IsPart11 == true)
                this.buttonPart11.ButtonDown();
            else
                this.buttonPart11.ButtonUp();
        }

        public void DisplayRefresh()
        {
            this.buttonSave.Visible = false;

            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.buttonDataStatistics.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsOptDataStatistics = true;
            else
                this.ParentForm.SystemConfig.IsOptDataStatistics = false;

            // 선별기4 위치
            if (this.buttonSorter4Location.ButtonStatus == SmartButton.BUTSTATUS.UP)
                this.ParentForm.SystemConfig.Sorter4Location = 0;
            else
                this.ParentForm.SystemConfig.Sorter4Location = 1;

            // 선별부 동작 감지 사용 여부
            if (this.buttonSorterCheckEnable.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsSorterCheckEnable = true;
            else
                this.ParentForm.SystemConfig.IsSorterCheckEnable = false;

            // Part11
            if (this.buttonPart11.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.SystemConfig.IsPart11 = true;
                this.ParentForm.SystemConfig.IsOptDataStatistics = true;
                this.ParentForm.SystemConfig.IsLogin = true;
                this.ParentForm.SystemConfig.IsDataBackup = true;
            }
            else
            {
                this.ParentForm.SystemConfig.IsPart11 = false;
                this.ParentForm.SystemConfig.IsOptDataStatistics = false;
                this.ParentForm.SystemConfig.IsLogin = false;
                this.ParentForm.SystemConfig.IsDataBackup = false;

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

            this.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.SystemConfig);
            this.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.SystemConfig);

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

            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }
        private void buttonSorter4Location_Click(object sender, EventArgs e)
        {
            this.buttonSave.Visible = true;
        }
        private void buttonSorterCheckEnable_Click(object sender, EventArgs e)
        {
            this.buttonSave.Visible = true;
        }
        private void buttonPart11_Click(object sender, EventArgs e)
        {
            if (this.buttonPart11.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.CurrentUserPasswordType.SetDefinedPassword(OptionPassword.Part11);
                DialogFormPasswordKeyPad pass = new DialogFormPasswordKeyPad(this.ParentForm.SystemConfig.Language, this.ParentForm.CurrentUserPasswordType, 8);
                if (pass.ShowDialog() == DialogResult.OK)
                    this.buttonDataStatistics.ButtonDown();
                else
                    this.buttonDataStatistics.ButtonUp();
            }

            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }
        #endregion
    }
}