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 System.Threading;

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

namespace ITC81DB
{
    public partial class ControlConfiSerialBarcode : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        SmartSplash SplashForLoading;
        private bool IsSplashStart;
        #endregion

        #region Constructor
        public ControlConfiSerialBarcode(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));
                this.buttonUsingTimeout.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonUsingTimeout.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
                this.labelWarning.Text = "※ Press the Save button to save to ROM.";

                this.buttonConnect.Text = "Open";

                this.labelTitleMinAngle.Text = "Min angle";
                this.labelTitleMaxAngle.Text = "Max angle";
                this.labelTitleFrequency.Text = "Frequency(Hz)";
                this.labelTitleTimeout.Text = "Timeout";
                this.labelTitleReadingConditions.Text = "Reading conditions";

                // DS4800 모델 전용
                this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                this.comboBoxReadingConditions.Items.Clear();
                this.comboBoxReadingConditions.Items.Add("Standard");
                this.comboBoxReadingConditions.Items.Add("Cartons");
                this.comboBoxReadingConditions.Items.Add("Low Contrast");
                this.comboBoxReadingConditions.Items.Add("High Skew Angles");
                this.comboBoxReadingConditions.SelectedIndex = 0;
                this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);

            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundBottomAddOn));
                this.buttonUsingTimeout.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON_Black));
                this.buttonUsingTimeout.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF_Black));
                this.labelWarning.Text = "※ 按保存按钮保存到ROM。";

                this.buttonConnect.Text = "开";

                this.labelTitleMinAngle.Text = "最小角度";
                this.labelTitleMaxAngle.Text = "最大角度";
                this.labelTitleFrequency.Text = "频率(Hz)";
                this.labelTitleTimeout.Text = "暂停";
                this.labelTitleReadingConditions.Text = "阅读条件";

                // DS4800 모델 전용
                this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                this.comboBoxReadingConditions.Items.Clear();
                this.comboBoxReadingConditions.Items.Add("标准");
                this.comboBoxReadingConditions.Items.Add("纸箱");
                this.comboBoxReadingConditions.Items.Add("低对比度");
                this.comboBoxReadingConditions.Items.Add("高偏角");
                this.comboBoxReadingConditions.SelectedIndex = 0;
                this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            }
            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));
                this.buttonUsingTimeout.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusON_Black));
                this.buttonUsingTimeout.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusOFF_Black));
                this.labelWarning.Text = "※ Нажмите кнопку [Сохранить], чтобы сохранить в ROM.";

                this.buttonConnect.Text = "Открыть";

                this.labelTitleMinAngle.Text = "Минимальный угол";
                this.labelTitleMaxAngle.Text = "Максимальный угол";
                this.labelTitleFrequency.Text = "Частота(Hz)";
                this.labelTitleTimeout.Text = "Таймаут";
                this.labelTitleReadingConditions.Text = "Чтение состояния";

                // DS4800 모델 전용
                this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                this.comboBoxReadingConditions.Items.Clear();
                this.comboBoxReadingConditions.Items.Add("Standard");
                this.comboBoxReadingConditions.Items.Add("Cartons");
                this.comboBoxReadingConditions.Items.Add("Low Contrast");
                this.comboBoxReadingConditions.Items.Add("High Skew Angles");
                this.comboBoxReadingConditions.SelectedIndex = 0;
                this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundBottomAddOn));
                this.buttonUsingTimeout.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerON_Black));
                this.buttonUsingTimeout.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerOFF_Black));
                this.labelWarning.Text = "※ Klicken Sie auf die Schaltfläche Speichern, um im ROM zu speichern.";

                this.buttonConnect.Text = "Öffnen";

                this.labelTitleMinAngle.Text = "Min Winkel";
                this.labelTitleMaxAngle.Text = "Max Winkel";
                this.labelTitleFrequency.Text = "Frequenz(Hz)";
                this.labelTitleTimeout.Text = "Auszeit";
                this.labelTitleReadingConditions.Text = "Lesebedingung";

                // DS4800 모델 전용
                this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                this.comboBoxReadingConditions.Items.Clear();
                this.comboBoxReadingConditions.Items.Add("Standard");
                this.comboBoxReadingConditions.Items.Add("Kartons");
                this.comboBoxReadingConditions.Items.Add("Geringer Kontrast");
                this.comboBoxReadingConditions.Items.Add("Hohe Schrägwinkel");
                this.comboBoxReadingConditions.SelectedIndex = 0;
                this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundBottomAddOn));
                this.buttonUsingTimeout.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonUsingTimeout.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
                this.labelWarning.Text = "※ Presione el botón Guardar para guardar en ROM.";

                this.buttonConnect.Text = "Abierto";

                this.labelTitleMinAngle.Text = "Ángulo mínimo";
                this.labelTitleMaxAngle.Text = "Ángulo máximo";
                this.labelTitleFrequency.Text = "FRECUENCIA(Hz)";
                this.labelTitleTimeout.Text = "Se acabó el tiempo";
                this.labelTitleReadingConditions.Text = "Condiciones de lectura";

                // DS4800 모델 전용
                this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                this.comboBoxReadingConditions.Items.Clear();
                this.comboBoxReadingConditions.Items.Add("Estándar");
                this.comboBoxReadingConditions.Items.Add("Cartones");
                this.comboBoxReadingConditions.Items.Add("Contraste bajo");
                this.comboBoxReadingConditions.Items.Add("Ángulos de sesgo alto");
                this.comboBoxReadingConditions.SelectedIndex = 0;
                this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundBottomAddOn));
                this.buttonUsingTimeout.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonUsingTimeout.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
                this.labelWarning.Text = "※ 저장 버튼을 눌러 ROM에 저장해주십시오.";

                this.buttonConnect.Text = "Open";

                this.labelTitleMinAngle.Text = "Min angle";
                this.labelTitleMaxAngle.Text = "Max angle";
                this.labelTitleFrequency.Text = "Frequency(Hz)";
                this.labelTitleTimeout.Text = "Timeout";
                this.labelTitleReadingConditions.Text = "Reading conditions";

                // DS4800 모델 전용
                this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                this.comboBoxReadingConditions.Items.Clear();
                this.comboBoxReadingConditions.Items.Add("Standard");
                this.comboBoxReadingConditions.Items.Add("Cartons");
                this.comboBoxReadingConditions.Items.Add("Low Contrast");
                this.comboBoxReadingConditions.Items.Add("High Skew Angles");
                this.comboBoxReadingConditions.SelectedIndex = 0;
                this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            }
        }
        private void DefaultSetting()
        {
            this.IsSplashStart = false;

            // value = comboBox index값(0~80)
            this.comboBoxMinAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxMinAngle_SelectedIndexChanged);
            this.comboBoxMinAngle.Items.Clear();
            for (int i = -5; i < 36; i++)
            {
                this.comboBoxMinAngle.Items.Add(i.ToString());
                if (i != 35)
                    this.comboBoxMinAngle.Items.Add((i + 0.5).ToString());
            }
            this.comboBoxMinAngle.SelectedIndex = 0;
            this.comboBoxMinAngle.SelectedIndexChanged += new EventHandler(this.comboBoxMinAngle_SelectedIndexChanged);

            // value = comboBox index값(0~80)
            this.comboBoxMaxAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxMaxAngle_SelectedIndexChanged);
            this.comboBoxMaxAngle.Items.Clear();
            for (int i = -5; i < 36; i++)
            {
                this.comboBoxMaxAngle.Items.Add(i.ToString());
                if (i != 35)
                    this.comboBoxMaxAngle.Items.Add((i + 0.5).ToString());
            }
            this.comboBoxMaxAngle.SelectedIndex = 0;
            this.comboBoxMaxAngle.SelectedIndexChanged += new EventHandler(this.comboBoxMaxAngle_SelectedIndexChanged);

            // value = 콤보박스값 * 10 한 값
            this.comboBoxFrequency.SelectedIndexChanged -= new EventHandler(this.comboBoxFrequency_SelectedIndexChanged);
            this.comboBoxFrequency.Items.Clear();
            this.comboBoxFrequency.Items.Add("0.1");
            this.comboBoxFrequency.Items.Add("0.2");
            this.comboBoxFrequency.Items.Add("0.5");
            this.comboBoxFrequency.Items.Add("0.7");
            for (int i = 1; i < 11; i++)
            {
                this.comboBoxFrequency.Items.Add(i.ToString());
                if (i != 10)
                    this.comboBoxFrequency.Items.Add((i + 0.5).ToString());
            }
            this.comboBoxFrequency.SelectedIndex = 0;
            this.comboBoxFrequency.SelectedIndexChanged += new EventHandler(this.comboBoxFrequency_SelectedIndexChanged);
        }

        private void SettingBarcodeValue(string shortCut, int value)
        {
            this.ParentForm.ParentForm.CurrentBarcode.SaveGettingShortCut = "";
            this.ParentForm.ParentForm.CurrentBarcode.SaveSettingShortCut = shortCut;
            this.ParentForm.ParentForm.CurrentBarcode.SaveValue = value;
            StringBuilder sb = new StringBuilder();

            sb.Append("SS");
            sb.Append((char)0x20);
            sb.Append(shortCut);
            sb.Append(":");
            sb.Append(value.ToString());

            this.ParentForm.ParentForm.TransferSerialCOM3(sb.ToString());
            this.timeOut.Enabled = true;
        }
        private void GettingBarcodeValue(string shortCut)
        {
            this.ParentForm.ParentForm.CurrentBarcode.SaveGettingShortCut = shortCut;
            this.ParentForm.ParentForm.CurrentBarcode.SaveSettingShortCut = "";
            StringBuilder sb = new StringBuilder();

            sb.Append("GS");
            sb.Append((char)0x20);
            sb.Append(shortCut);

            this.ParentForm.ParentForm.TransferSerialCOM3(sb.ToString());
            this.timeOut.Enabled = true;
        }
        private void BarcodeAddonScreenActivation(bool bValue)
        {
            this.comboBoxMinAngle.Enabled = bValue;
            this.comboBoxMaxAngle.Enabled = bValue;
            this.comboBoxFrequency.Enabled = bValue;
            this.buttonUsingTimeout.Enabled = bValue;
            this.labelTimeout.Enabled = bValue;
            this.comboBoxReadingConditions.Enabled = bValue;
        }
        private void ConnectButtonInitiaization()
        {
            this.BarcodeAddonScreenActivation(false);
            this.buttonConnect.Enabled = true;
            this.buttonConnect.ButtonUp();

            if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.buttonConnect.Text = "Öffnen";
                this.DisplayStatus("> Trennen");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.buttonConnect.Text = "开";
                this.DisplayStatus("> 断开");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
            {
                this.buttonConnect.Text = "Abierto";
                this.DisplayStatus("> Desconectar");
            }
            else
            {
                this.buttonConnect.Text = "Open";
                this.DisplayStatus("> Disconnect");
            }
        }
             
        public void EnterOrExitCommandMode(byte byteTemp)
        {
            switch (byteTemp)//readByte[1]
            {
                case 0x48: // Enter Host Mode 전송 후 수신 : 0x1B 0x48 0x0D 0x0A : <ESC>H
                    this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.EnterTerminalMode);
                    break;
                case 0x52: // Enter Terminal Mode 전송 후 수신 : 0x1B 0x52 0x0D 0x0A : <ESC>R
                    this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.EnterProgrammingMode);
                    break;
                case 0x63: // Enter Programming Mode 전송 후 수신 : 0x1B 0x63 0x0D 0x0A : <ESC>c
                    this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode = true;
                    if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        this.DisplayStatus("> Verbinden");
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        this.DisplayStatus("> Conectar");
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        this.DisplayStatus("> 连接");
                    else
                        this.DisplayStatus("> Connect");
                    break;
                case 0x64: // Exit Programming Mode 전송 후 수신 : 0x1B 0x64 0x0D 0x0A : <ESC>d
                    this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.ExitTerminalMode);
                    break;
                case 0x4B: // Exit Terminal Mode 전송 후 수신 : 0x1B 0x4B 0x0D 0x0A : <ESC>K
                    this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.ExitHostMode);
                    break;
                case 0x58: // Exit Host Mode 전송 후 수신 : 0x1B 0x58 0x0D 0x0A : <ESC>:
                    this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode = false;
                    this.ParentForm.UpdateMenuExceptBarcodeDisplay(true);
                    this.BarcodeAddonScreenActivation(false);
                    this.ConnectButtonInitiaization();
                    break;
                case 0x5B: // Self Disconnection 전송 후 수신 : 0x1B 0x5B 0x41 : <ESC>[A
                    this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode = false;
                    this.ParentForm.UpdateMenuExceptBarcodeDisplay(true);
                    this.BarcodeAddonScreenActivation(false);
                    this.ConnectButtonInitiaization();
                    break;
                default:
                    break;
            }
        }
        public void DisplayLoadingValue(string gettingShortCut, string settingShortCut, string value)
        {
            this.timeOut.Enabled = false;

            switch (gettingShortCut)
            {
                case "5362": // MinAngle
                    this.comboBoxMinAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxMinAngle_SelectedIndexChanged);
                    this.comboBoxMinAngle.SelectedIndex = int.Parse(value);
                    this.comboBoxMinAngle.SelectedIndexChanged += new EventHandler(this.comboBoxMinAngle_SelectedIndexChanged);
                    this.GettingBarcodeValue(BarcodeShortCut.MaxAngle);
                    break;
                case "5363": // MaxAngle
                    this.comboBoxMaxAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxMaxAngle_SelectedIndexChanged);
                    this.comboBoxMaxAngle.SelectedIndex = int.Parse(value);
                    this.comboBoxMaxAngle.SelectedIndexChanged += new EventHandler(this.comboBoxMaxAngle_SelectedIndexChanged);
                    this.GettingBarcodeValue(BarcodeShortCut.Frequency);
                    break;
                case "5364": // Frequency
                    this.comboBoxFrequency.SelectedIndexChanged -= new EventHandler(this.comboBoxFrequency_SelectedIndexChanged);
                    double temp = int.Parse(value) / 10;
                    this.comboBoxFrequency.SelectedItem = temp.ToString();
                    this.comboBoxFrequency.SelectedIndexChanged += new EventHandler(this.comboBoxFrequency_SelectedIndexChanged);
                    this.GettingBarcodeValue(BarcodeShortCut.ReadingPhaseTimeout);
                    break;
                case "78": // Timeout 사용여부
                    this.buttonUsingTimeout.Click -= new EventHandler(this.buttonUsingTimeout_Click);
                    if (int.Parse(value) == 1)
                        this.buttonUsingTimeout.ButtonDown();
                    else
                        this.buttonUsingTimeout.ButtonUp();
                    this.buttonUsingTimeout.Click += new EventHandler(this.buttonUsingTimeout_Click);
                    this.GettingBarcodeValue(BarcodeShortCut.Timeout);
                    break;
                case "79": // Timeout
                    this.labelTimeout.Text = value;
                    this.GettingBarcodeValue(BarcodeShortCut.ReadingConditions);
                    break;
                case "5250": // Reading Conditions
                    this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
                    this.comboBoxReadingConditions.SelectedIndex = int.Parse(value);
                    this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);

                    if (this.IsSplashStart == true)
                    {
                        this.SplashForLoading.Finish();
                        this.SplashForLoading.Dispose();
                        this.IsSplashStart = false;
                    }
                    if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        this.DisplayStatus("> Laden abgeschlossen");
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        this.DisplayStatus("> Carga completa");
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        this.DisplayStatus("> 加载完成");
                    else
                        this.DisplayStatus("> Loading completed");
                    this.ParentForm.UpdateMenuExceptBarcodeDisplay(true);
                    this.BarcodeAddonScreenActivation(true);
                    this.buttonConnect.Enabled = true;
                    if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        this.buttonConnect.Text = "Schließen";
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        this.buttonConnect.Text = "Cerrar";
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        this.buttonConnect.Text = "关闭";
                    else
                        this.buttonConnect.Text = "Close";
                    break;
                default:
                    {
                        if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        {
                            switch (settingShortCut)
                            {
                                case "5362": // MinAngle
                                    this.DisplayStatus("> Erfolg : Min Winkel");
                                    break;
                                case "5363": // MaxAngle
                                    this.DisplayStatus("> Erfolg : Max Winkel");
                                    break;
                                case "5364": // Frequency
                                    this.DisplayStatus("> Erfolg : Frequenz");
                                    break;
                                case "78": // Timeout 사용여부
                                    this.DisplayStatus("> Erfolg : Verwenden auszeit");
                                    break;
                                case "79": // Timeout
                                    this.DisplayStatus("> Erfolg : Auszeit");
                                    break;
                                case "5250": // Reading Conditions
                                    this.DisplayStatus("> Erfolg : Lesebedingung");
                                    break;
                                default:
                                    this.DisplayStatus("> Erfolg");  //"> Success";
                                    break;
                            }
                        }
                        else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        {
                            switch (settingShortCut)
                            {
                                case "5362": // MinAngle
                                    this.DisplayStatus("> 成功 : 最小角度");
                                    break;
                                case "5363": // MaxAngle
                                    this.DisplayStatus("> 成功 : 最大角度");
                                    break;
                                case "5364": // Frequency
                                    this.DisplayStatus("> 成功 : 频率");
                                    break;
                                case "78": // Timeout 사용여부
                                    this.DisplayStatus("> 成功 : 使用暂停");
                                    break;
                                case "79": // Timeout
                                    this.DisplayStatus("> 成功 : 暂停");
                                    break;
                                case "5250": // Reading Conditions
                                    this.DisplayStatus("> 成功 : 阅读条件");
                                    break;
                                default:
                                    this.DisplayStatus("> 成功");  //"> Success";
                                    break;
                            }
                        }
                        else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        {
                            switch (settingShortCut)
                            {
                                case "5362": // MinAngle
                                    this.DisplayStatus("> Éxito : Ángulo mínimo");
                                    break;
                                case "5363": // MaxAngle
                                    this.DisplayStatus("> Éxito : Ángulo máximo");
                                    break;
                                case "5364": // Frequency
                                    this.DisplayStatus("> Éxito : FRECUENCIA");
                                    break;
                                case "78": // Timeout 사용여부
                                    this.DisplayStatus("> Éxito : Uso del tiempo de espera");
                                    break;
                                case "79": // Timeout
                                    this.DisplayStatus("> Éxito : Se acabó el tiempo");
                                    break;
                                case "5250": // Reading Conditions
                                    this.DisplayStatus("> Éxito : Condiciones de lectura");
                                    break;
                                default:
                                    this.DisplayStatus("> Éxito");  //"> Success";
                                    break;
                            }
                        }
                        else
                        {
                            switch (settingShortCut)
                            {
                                case "5362": // MinAngle
                                    this.DisplayStatus("> Success : Min angle");
                                    break;
                                case "5363": // MaxAngle
                                    this.DisplayStatus("> Success : Max angle");
                                    break;
                                case "5364": // Frequency
                                    this.DisplayStatus("> Success : Frequency");
                                    break;
                                case "78": // Timeout 사용여부
                                    this.DisplayStatus("> Success : Using timeout");
                                    break;
                                case "79": // Timeout
                                    this.DisplayStatus("> Success : Timeout");
                                    break;
                                case "5250": // Reading Conditions
                                    this.DisplayStatus("> Success : Reading conditions");
                                    break;
                                default:
                                    this.DisplayStatus("> Success");  //"> Success";
                                    break;
                            }
                        }
                    }
                    break;
            }
        }
        public void DisplayStatus(string strTemp)
        {
            this.labelStatus.Text = strTemp;
        }
        public void DisplayRefresh(DataStore.MenuBottomConfiguration menu)
        {
            this.comboBoxMinAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxMinAngle_SelectedIndexChanged);
            this.comboBoxMaxAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxMaxAngle_SelectedIndexChanged);
            this.comboBoxFrequency.SelectedIndexChanged -= new EventHandler(this.comboBoxFrequency_SelectedIndexChanged);
            this.comboBoxReadingConditions.SelectedIndexChanged -= new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            this.buttonUsingTimeout.Click -= new EventHandler(this.buttonUsingTimeout_Click);

            // ETXOnly
            this.ParentForm.ParentForm.ChangeSerialCOM3FrameSeparateType(DataStore.SeparateType.ETXONLY);
            this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.ExitProgrammingMode);

            this.ParentForm.UpdateMenuExceptBarcodeDisplay(true);
            this.ConnectButtonInitiaization();

            if(this.timeOut.Enabled == true)
                this.timeOut.Enabled = false;
            if(this.timerLoading.Enabled == true)
                this.timerLoading.Enabled = false;

            this.comboBoxMinAngle.SelectedIndex = 0;
            this.comboBoxMaxAngle.SelectedIndex = 0;
            this.comboBoxFrequency.SelectedIndex = 0;
            this.buttonUsingTimeout.ButtonUp();
            this.labelTimeout.Text = "0";
            this.comboBoxReadingConditions.SelectedIndex = 0;

            this.comboBoxMinAngle.SelectedIndexChanged += new EventHandler(this.comboBoxMinAngle_SelectedIndexChanged);
            this.comboBoxMaxAngle.SelectedIndexChanged += new EventHandler(this.comboBoxMaxAngle_SelectedIndexChanged);
            this.comboBoxFrequency.SelectedIndexChanged += new EventHandler(this.comboBoxFrequency_SelectedIndexChanged);
            this.comboBoxReadingConditions.SelectedIndexChanged += new EventHandler(this.comboBoxReadingConditions_SelectedIndexChanged);
            this.buttonUsingTimeout.Click += new EventHandler(this.buttonUsingTimeout_Click);
        }
        #endregion

        #region Event Handler
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.ChangeSerialCOM3FrameSeparateType(DataStore.SeparateType.ETXONLY);

            this.buttonConnect.Enabled = false;
            this.ParentForm.UpdateMenuExceptBarcodeDisplay(false);

            if (this.buttonConnect.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.EnterHostMode);

                this.SplashForLoading = new SmartSplash();
                this.SplashForLoading.CenterPosition = true;
                this.SplashForLoading.AnimationInterval = 200;
                this.SplashForLoading.LoadingImagePathname = "SmartLoading4";
                this.SplashForLoading.Start();
                this.IsSplashStart = true;

                this.timeOut.Enabled = true;
                this.timerLoading.Enabled = true;
            }
            else
            {
                this.ParentForm.ParentForm.TransferSerialCOM3RawData(Barcode.ExitProgrammingMode);
            }
        }
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true)
            {
                this.labelStatus.Text = "> Loading...";

                this.GettingBarcodeValue(BarcodeShortCut.MinAngle);
            }
        }

        private void comboBoxMinAngle_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SettingBarcodeValue(BarcodeShortCut.MinAngle, this.comboBoxMinAngle.SelectedIndex);
            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true && this.buttonSave.Visible == false)
            {
                this.buttonSave.Visible = true;
                this.labelWarning.Visible = true;
            }
        }
        private void comboBoxMaxAngle_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SettingBarcodeValue(BarcodeShortCut.MaxAngle, this.comboBoxMaxAngle.SelectedIndex);
            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true && this.buttonSave.Visible == false)
            {
                this.buttonSave.Visible = true;
                this.labelWarning.Visible = true;
            }
        }
        private void comboBoxFrequency_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SettingBarcodeValue(BarcodeShortCut.Frequency, this.comboBoxFrequency.SelectedIndex);
            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true && this.buttonSave.Visible == false)
            {
                this.buttonSave.Visible = true;
                this.labelWarning.Visible = true;
            }
        }

        private void buttonUsingTimeout_Click(object sender, EventArgs e)
        {
            if (this.buttonUsingTimeout.ButtonStatus == SmartButton.BUTSTATUS.UP)
                this.SettingBarcodeValue(BarcodeShortCut.ReadingPhaseTimeout, 0);
            else
                this.SettingBarcodeValue(BarcodeShortCut.ReadingPhaseTimeout, 1);

            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true && this.buttonSave.Visible == false)
            {
                this.buttonSave.Visible = true;
                this.labelWarning.Visible = true;
            }
        }
        private void labelTimeout_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelTimeout.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.SettingBarcodeValue(BarcodeShortCut.Timeout, myKeyPad.IntValue);
                    this.labelTimeout.Text = myKeyPad.StringValue;
                    if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true && this.buttonSave.Visible == false)
                    {
                        this.buttonSave.Visible = true;
                        this.labelWarning.Visible = true;
                    }
                }
            }
        }
        private void comboBoxReadingConditions_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SettingBarcodeValue(BarcodeShortCut.ReadingConditions, this.comboBoxReadingConditions.SelectedIndex);
            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true && this.buttonSave.Visible == false)
            {
                this.buttonSave.Visible = true;
                this.labelWarning.Visible = true;
            }
        }

        private void TimerLoading_Tick(object sender, EventArgs e)
        {
            if (this.ParentForm.ParentForm.CurrentBarcode.IsCommandMode == true)
            {
                this.timeOut.Enabled = false;
                this.timerLoading.Enabled = false;

                if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                    this.DisplayStatus("> Wird geladen...");
                else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                    this.DisplayStatus("> Cargar...");
                else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                    this.DisplayStatus("> 载入中...");
                else
                    this.DisplayStatus("> Loading...");
                this.GettingBarcodeValue(BarcodeShortCut.MinAngle);
            }
        }
        private void timeOut_Tick(object sender, EventArgs e)
        {
            if (this.timerLoading.Enabled == true)
                this.timerLoading.Enabled = false;

            this.timeOut.Enabled = false;

            if (this.IsSplashStart == true)
            {
                this.SplashForLoading.Finish();
                this.SplashForLoading.Dispose();
                this.IsSplashStart = false;
            }
            this.ParentForm.UpdateMenuExceptBarcodeDisplay(true);
            this.ConnectButtonInitiaization();

            // 바코드 스캐너 연결을 확인하십시오.
            DialogFormMessage myMsg = new DialogFormMessage(25, this.ParentForm.ParentForm.SystemConfig1.Language);
            myMsg.ShowDialog();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.ChangeSerialCOM3FrameSeparateType(DataStore.SeparateType.NONEFRAME_READTIMEOUT);
            this.ParentForm.ParentForm.TransferSerialCOM3(Barcode.SavePermanently);
            this.buttonSave.Visible = false;
            this.labelWarning.Visible = false;
        }
        #endregion

    }
}