using System;
using System.Linq;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using ITC81DB.Forms;
using ITC81DB_ImageDll;
using ITC81DB.DialogForms;

namespace ITC81DB
{
    public partial class ControlConfiMULTiJET : UserControl
    {
        #region Field
        private FormMenu m_ParentForm; 
        #endregion

        #region Constructor
        public ControlConfiMULTiJET(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.SystemConfig1.Language == DataStore.LanguageID.English)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundBottomAddOn));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundBottomAddOn));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundBottomAddOn));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundBottomAddOn));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundBottomAddOn));
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundBottomAddOn));
            }
        }
        private void DefaultSetting()
        {
        }

        public void DisplayRefresh(DataStore.MenuBottomConfiguration menu)
        {
            if (menu == DataStore.MenuBottomConfiguration.SerialCOM1)
            {
                this.labelSlaveAddress.Text = this.ParentForm.ParentForm.SystemConfig2.MULTiJETSlaveAddressCOM1.ToString();
            }
            else if (menu == DataStore.MenuBottomConfiguration.SerialCOM3)
            {
                this.labelSlaveAddress.Text = this.ParentForm.ParentForm.SystemConfig2.MULTiJETSlaveAddressCOM3.ToString();
            }
            else if (menu == DataStore.MenuBottomConfiguration.SerialCOM4)
            {
                this.labelSlaveAddress.Text = this.ParentForm.ParentForm.SystemConfig2.MULTiJETSlaveAddressCOM4.ToString();
            }
        }
        #endregion
        
        #region Event Handler
        private void labelSlaveAddress_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSlaveAddress.Text, 3, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

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

                    DataStore.MenuBottomConfiguration temp = this.ParentForm.CurrentConfigurationMenu();
                    if (temp == DataStore.MenuBottomConfiguration.SerialCOM1)
                        this.ParentForm.ParentForm.SystemConfig2.MULTiJETSlaveAddressCOM1 = myKeyPad.IntValue;
                    else if (temp == DataStore.MenuBottomConfiguration.SerialCOM3)
                        this.ParentForm.ParentForm.SystemConfig2.MULTiJETSlaveAddressCOM3 = myKeyPad.IntValue;
                    else if (temp == DataStore.MenuBottomConfiguration.SerialCOM4)
                        this.ParentForm.ParentForm.SystemConfig2.MULTiJETSlaveAddressCOM4 = myKeyPad.IntValue;

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

    }
}
