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 ITC81DB_2.Forms;
using ITC81DB_2_ImageDll;
using ITC81DB_2.DialogForms;

namespace ITC81DB_2.Controls
{
    public partial class ControlConfiEthernetAddon : UserControl
    {
        #region Field
        private FormMenu m_ParentForm; 
        #endregion

        #region Constructor
        public ControlConfiEthernetAddon(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()
        {
            Class1 images = new Class1();

            if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.English)
            {
                this.labelTitleSelectLane.Text = "Select lane";
                this.labelTitleAddon.Text = "Add-on";
                this.labelTitleTransmissionDelayTime.Text = "Transmission delay time(ms)";
                //this.labelTitleCommControlCharacter.Text = "Com- control character";
                this.labelTitleCharacterToFill.Text = "Character to fill in the weight value blank";
                this.labelTitleTransmitCondition.Text = "Transmission conditions";

                this.buttonTransmitCondition.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPassUp));
                this.buttonTransmitCondition.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engEveryUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleSelectLane.Text = "选择列";
                this.labelTitleAddon.Text = "附加功能";
                this.labelTitleTransmissionDelayTime.Text = "传送延迟时间(ms)";
                //this.labelTitleCommControlCharacter.Text = "通信制御文字";
                this.labelTitleCharacterToFill.Text = "重量值填空字符";
                this.labelTitleTransmitCondition.Text = "传输条件";

                this.buttonTransmitCondition.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPassUp));
                this.buttonTransmitCondition.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engEveryUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Russian)
            {
                this.labelTitleSelectLane.Text = "Выберите столбец";
                this.labelTitleAddon.Text = "Дополнения";
                this.labelTitleTransmissionDelayTime.Text = "Время задержки передачи(ms)";
                //this.labelTitleCommControlCharacter.Text = "Коммуникационный управляющий персонаж";
                this.labelTitleCharacterToFill.Text = "Символ для заполнения поля значения веса";
                this.labelTitleTransmitCondition.Text = "Условия передачи";

                this.buttonTransmitCondition.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPassUp));
                this.buttonTransmitCondition.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engEveryUp));

            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.German)
            {
                this.labelTitleSelectLane.Text = "Spalte auswählen";
                this.labelTitleAddon.Text = "Erweiterung";
                this.labelTitleTransmissionDelayTime.Text = "Übertragungsverzögerungszeit(ms)";
                //this.labelTitleCommControlCharacter.Text = "Kommunikationssteuerungszeichen";
                this.labelTitleCharacterToFill.Text = "Zeichen zum Ausfüllen des Leerzeichens für den Gewichtswert";
                this.labelTitleTransmitCondition.Text = "Übertragungsbedingungen";

                this.buttonTransmitCondition.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPassUp));
                this.buttonTransmitCondition.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engEveryUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.labelTitleSelectLane.Text = "Seleccionar columna";
                this.labelTitleAddon.Text = "Complementos";
                this.labelTitleTransmissionDelayTime.Text = "Tiempo de retardo de transmisión(ms)";
                //this.labelTitleCommControlCharacter.Text = "Carácter de control de comm";
                this.labelTitleCharacterToFill.Text = "Carácter para llenar en blanco";
                this.labelTitleTransmitCondition.Text = "Condiciones de transmisión";

                this.buttonTransmitCondition.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPassUp));
                this.buttonTransmitCondition.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engEveryUp));
            }
            else
            {
                this.labelTitleSelectLane.Text = "열 선택";
                this.labelTitleAddon.Text = "추가설정";
                this.labelTitleTransmissionDelayTime.Text = "전송 지연시간(ms)";
                //this.labelTitleCommControlCharacter.Text = "통신 제어 문자";
                this.labelTitleCharacterToFill.Text = "중량값 빈 자리 채울 문자";
                this.labelTitleTransmitCondition.Text = "전송 조건";

                this.buttonTransmitCondition.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korPassUp));
                this.buttonTransmitCondition.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korEveryUp));
            }
        }
        private void DefaultSetting()
        {
            this.comboBoxSelectLane.Items.Clear();
            this.comboBoxSelectLane.SelectedIndexChanged -= new EventHandler(this.comboBoxSelectLane_SelectedIndexChanged);
            this.comboBoxSelectLane.Items.Add("All");
            this.comboBoxSelectLane.Items.Add("1");
            this.comboBoxSelectLane.Items.Add("2");
            this.comboBoxSelectLane.SelectedIndex = 0;
            this.comboBoxSelectLane.SelectedIndexChanged += new EventHandler(this.comboBoxSelectLane_SelectedIndexChanged);
        }

        private void UpdateSerialParameterDisplay(SystemConfigurationItem item)
        {
            this.labelTransmissionDelayTime.Text = item.TransmissionDelayTimeEthernet.ToString();

            if (item.IsCharToFillZeroEthernet == true)
                this.buttonCharacterToFill.ButtonDown();
            else
                this.buttonCharacterToFill.ButtonUp();

            if (item.IsTransmitWhenPassEthernet == true)
                this.buttonTransmitCondition.ButtonDown();
            else
                this.buttonTransmitCondition.ButtonUp();

            // 열 선택
            this.comboBoxSelectLane.SelectedIndexChanged -= new EventHandler(this.comboBoxSelectLane_SelectedIndexChanged);
            this.comboBoxSelectLane.SelectedIndex = item.SelectLaneEthernet;
            this.comboBoxSelectLane.SelectedIndexChanged += new EventHandler(this.comboBoxSelectLane_SelectedIndexChanged);
        }

        public void DisplayRefresh()
        {
            this.UpdateSerialParameterDisplay(this.ParentForm.ParentForm.SystemConfig);
        }        
        #endregion

        #region Event Handler
        private void comboBoxSelectLane_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.SystemConfig.SelectLaneEthernet = this.comboBoxSelectLane.SelectedIndex;
            this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig);
        }

        private void labelTransmissionDelayTime_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelTransmissionDelayTime.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelTransmissionDelayTime.Text = myKeyPad.StringValue;

                    value = Helper.StringZeroFillDigits4(this.labelTransmissionDelayTime.Text);

                    this.ParentForm.ParentForm.SystemConfig.TransmissionDelayTimeEthernet = myKeyPad.IntValue;

                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig);
                }
            }
        }
        private void buttonCharacterToFill_Click(object sender, EventArgs e)
        {
            if (this.buttonCharacterToFill.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.SystemConfig.IsCharToFillZeroEthernet = true;
            else
                this.ParentForm.ParentForm.SystemConfig.IsCharToFillZeroEthernet = false;

            this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig);
        }
        private void buttonTransmitCondition_Click(object sender, EventArgs e)
        {
            if (this.buttonTransmitCondition.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.SystemConfig.IsTransmitWhenPassEthernet = true;
            else
                this.ParentForm.ParentForm.SystemConfig.IsTransmitWhenPassEthernet = false;

            this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig);
        }
        #endregion
    }
}
