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 INT89DB_26_ImageDll;

namespace INT89DB_26.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()
        {
            Class1 images = new Class1();

            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 OFF the power and then turn ON the power";
                this.labelBuadrateWarning2.Text = "※ Do not change the value except engineer";

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

                //this.buttonBack.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(Class1.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.buttonSave.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnSaveUp));

                //this.buttonBack.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackUp));
                #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.IsFeedbackBoard == true)
                this.buttonFeedbackBoard.ButtonDown();
            else
                this.buttonFeedbackBoard.ButtonUp();

            this.buttonSave.Visible = false;
        }

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

        #region Event Handler
        private void buttonFeedback_Click(object sender, EventArgs e)
        {
            if (this.buttonFeedback.ButtonStatus == SmartButton.BUTSTATUS.UP)
                this.buttonFeedbackBoard.ButtonUp();

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

            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;
        }
        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.buttonFeedbackBoard.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.SystemConfig.IsFeedbackBoard = true;

                this.ParentForm.SystemConfig.Serial3BaudRate = 38400;
                this.ParentForm.SystemConfig.Serial3Mode = 98;
            }
            else
            {
                this.ParentForm.SystemConfig.IsFeedbackBoard = false;

                this.ParentForm.SystemConfig.Serial3BaudRate = 9200;
                this.ParentForm.SystemConfig.Serial3Mode = 0;
            }

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

            this.buttonSave.Visible = false;
            this.buttonBack.Visible = false;

            this.Enabled = false;
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormMenu);
        }
        #endregion
    }
}