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.Text;
using System.Threading;
using System.Windows.Forms;

using ITC81DB_0H.Forms;
using ITC81DB_0H_ImageDll;

namespace ITC81DB_0H
{
    public partial class ControlConfiSerialUserDefine : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        private string ForSaveUserDefine;

        Collection<List<string>> CollectionProtocolList;
        public List<string> ListUserDefinedProtocolCOM1;
        public List<string> ListUserDefinedProtocolCOM3;
        public List<string> ListUserDefinedProtocolCOM4;
        #endregion
        
        #region Constructor
        public ControlConfiSerialUserDefine(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.engBackgroundBottomUserDefine));

                this.buttonEnter.Text = "Enter";
                this.buttonSave.Text = "Save";
                this.buttonClearAll.Text = "Clear";
                this.buttonDirectInput.Text = "Direct input";

                this.buttonDate.Text = "Date[8]";
                this.buttonTime.Text = "Time[8]";
                this.buttonGrade.Text = "Grade[1]";
                this.buttonNo.Text = "No[4]";
                this.buttonSign.Text = "Sign[1]";
                this.buttonWeight.Text = "Weight[6]";
                this.buttonGap.Text = "Gap[6]";
                this.buttonUnderRange.Text = "Under range[7]";
                this.buttonPassRange.Text = "Pass range[7]";
                this.buttonOverRange.Text = "Over range[7]";
                this.buttonUnderCount.Text = "Under count[7]";
                this.buttonPassCount.Text = "Pass count[7]";
                this.buttonOverCount.Text = "Over count[7]";
                this.buttonNGCount.Text = "NG count[7]";
                this.buttonTotalCount.Text = "Total count[10]";
                this.buttonChecksum.Text = "Checksum[2]";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundBottomUserDefine));

                this.buttonEnter.Text = "确认";
                this.buttonSave.Text = "保存";
                this.buttonClearAll.Text = "消除";
                this.buttonDirectInput.Text = "直接输入";

                this.buttonDate.Text = "日期[8]";
                this.buttonTime.Text = "时间[8]";
                this.buttonGrade.Text = "等级[1]";
                this.buttonNo.Text = "编号[4]";
                this.buttonSign.Text = "信号[1]";
                this.buttonWeight.Text = "重量[6]";
                this.buttonGap.Text = "差异[6]";
                this.buttonUnderRange.Text = "低于[7]";
                this.buttonPassRange.Text = "通过[7]";
                this.buttonOverRange.Text = "超过[7]";
                this.buttonUnderCount.Text = "低于计数[7]";
                this.buttonPassCount.Text = "通过计数[7]";
                this.buttonOverCount.Text = "超过计数[7]";
                this.buttonNGCount.Text = "不良计数[7]";
                this.buttonTotalCount.Text = "总共计数[10]";
                this.buttonChecksum.Text = "校验和[2]";
            }
            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.buttonEnter.Text = "Ввод";
                this.buttonSave.Text = "Сохранить";
                this.buttonClearAll.Text = "Сброс";
                this.buttonDirectInput.Text = "Прямой вход";

                this.buttonDate.Text = "дату[8]";
                this.buttonTime.Text = "Время[8]";
                this.buttonGrade.Text = "Сортировка[1]";
                this.buttonNo.Text = "№[4]";
                this.buttonSign.Text = "Знак[1]";
                this.buttonWeight.Text = "Вес[6]";
                this.buttonGap.Text = "Разрыв[6]";
                this.buttonUnderRange.Text = "Мало[7]";
                this.buttonPassRange.Text = "Норма[7]";
                this.buttonOverRange.Text = "Много[7]";
                this.buttonUnderCount.Text = "Подсчет(Мало)[7]";
                this.buttonPassCount.Text = "Подсчет(Норма)[7]";
                this.buttonOverCount.Text = "Подсчет(Много)[7]";
                this.buttonNGCount.Text = "Подсчет(Дефект)[7]";
                this.buttonTotalCount.Text = "Подсчет(Итоги)[10]";
                this.buttonChecksum.Text = "Контрольная сумма[2]";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundBottomUserDefine));

                this.buttonEnter.Text = "Enter";
                this.buttonSave.Text = "Speichern";
                this.buttonClearAll.Text = "Löschen";
                this.buttonDirectInput.Text = "Direkteingabe";

                this.buttonDate.Text = "Datum[8]";
                this.buttonTime.Text = "Zeit[8]";
                this.buttonGrade.Text = "Grad[1]";
                this.buttonNo.Text = "Nr[4]";
                this.buttonSign.Text = "Zeichen[1]";
                this.buttonWeight.Text = "Gewicht[6]";
                this.buttonGap.Text = "Abstand[6]";
                this.buttonUnderRange.Text = "Min.[7]";
                this.buttonPassRange.Text = "Bestehen[7]";
                this.buttonOverRange.Text = "Max.[7]";
                this.buttonUnderCount.Text = "Min. zahl[7]";
                this.buttonPassCount.Text = "Bestehen zahl[7]";
                this.buttonOverCount.Text = "Max. zahl[7]";
                this.buttonNGCount.Text = "Schlecht zahl[7]";
                this.buttonTotalCount.Text = "Insgesamt zahl[10]";
                this.buttonChecksum.Text = "Prüfsumme[2]";
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundBottomUserDefine));

                this.buttonEnter.Text = "입력";
                this.buttonSave.Text = "저장";
                this.buttonClearAll.Text = "전체삭제";
                this.buttonDirectInput.Text = "직접입력";

                this.buttonDate.Text = "날짜[8]";
                this.buttonTime.Text = "시간[8]";
                this.buttonGrade.Text = "등급[1]";
                this.buttonNo.Text = "품번[4]";
                this.buttonSign.Text = "부호[1]";
                this.buttonWeight.Text = "중량[6]";
                this.buttonGap.Text = "차이[6]";
                this.buttonUnderRange.Text = "하한[7]";
                this.buttonPassRange.Text = "기준[7]";
                this.buttonOverRange.Text = "상한[7]";
                this.buttonUnderCount.Text = "하한수량[7]";
                this.buttonPassCount.Text = "기준수량[7]";
                this.buttonOverCount.Text = "상한수량[7]";
                this.buttonNGCount.Text = "NG수량[7]";
                this.buttonTotalCount.Text = "전체수량[10]";
                this.buttonChecksum.Text = "체크섬[2]";
            }
        }
        private void DefaultSetting()
        {
            this.ForSaveUserDefine = "";
            this.CollectionProtocolList = new Collection<List<string>>();

            this.ListUserDefinedProtocolCOM1 = new List<string>();
            this.ListUserDefinedProtocolCOM3 = new List<string>();
            this.ListUserDefinedProtocolCOM4 = new List<string>();

            this.CollectionProtocolList.Clear();
            this.CollectionProtocolList.Add(this.ListUserDefinedProtocolCOM1);
            this.CollectionProtocolList.Add(this.ListUserDefinedProtocolCOM3);
            this.CollectionProtocolList.Add(this.ListUserDefinedProtocolCOM4);

            for (int i = 0; i < 3; i++)
                this.CollectionProtocolList[i].Clear();
        }

        public void DisplayRefresh(SystemStatus status)
        {
            string[] strArray;
            this.labelWindow.Text = "";

            DataStore.MenuBottomConfiguration temp = this.ParentForm.CurrentConfigurationMenu();

            switch (temp)
            {
                case DataStore.MenuBottomConfiguration.SerialCOM1:
                    this.ListUserDefinedProtocolCOM1.Clear();
                    if (this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1.Contains(',') == true)
                    {
                        strArray = this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1.Split(',');
                        for (int i = 0; i < strArray.Length; i++)
                            this.ListUserDefinedProtocolCOM1.Add(strArray[i]);
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1 != ""
                        && this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1 != null)
                        this.ListUserDefinedProtocolCOM1.Add(this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1);

                    this.labelWindow.Text = this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1;
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM3:
                    this.ListUserDefinedProtocolCOM3.Clear();
                    if (this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3.Contains(',') == true)
                    {
                        strArray = this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3.Split(',');
                        for (int i = 0; i < strArray.Length; i++)
                            this.ListUserDefinedProtocolCOM3.Add(strArray[i]);
                    }
                    else if(this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3 != ""
                        && this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3 != null)
                        this.ListUserDefinedProtocolCOM3.Add(this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3);

                    this.labelWindow.Text = this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3;
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM4:
                    this.ListUserDefinedProtocolCOM4.Clear();
                    if (this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4.Contains(',') == true)
                    {
                        strArray = this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4.Split(',');
                        for (int i = 0; i < strArray.Length; i++)
                            this.ListUserDefinedProtocolCOM4.Add(strArray[i]);
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4 != ""
                        && this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4 != null)
                        this.ListUserDefinedProtocolCOM4.Add(this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4);

                    this.labelWindow.Text = this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4;
                    break;
                default:
                    break;
            }
        }

        private string LabelWindowRefresh()
        {
            string temp = "";

            DataStore.MenuBottomConfiguration currentMenu = this.ParentForm.CurrentConfigurationMenu();

            switch (currentMenu)
            {
                case DataStore.MenuBottomConfiguration.SerialCOM1:
                    for (int i = 0; i < this.ListUserDefinedProtocolCOM1.Count; i++)
                    {
                        if (i == 0)
                            temp += this.ListUserDefinedProtocolCOM1[i];
                        else
                            temp += "," + this.ListUserDefinedProtocolCOM1[i];
                    }
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM3:
                    for (int i = 0; i < this.ListUserDefinedProtocolCOM3.Count; i++)
                    {
                        if (i == 0)
                            temp += this.ListUserDefinedProtocolCOM3[i];
                        else
                            temp += "," + this.ListUserDefinedProtocolCOM3[i];
                    }
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM4:
                    for (int i = 0; i < this.ListUserDefinedProtocolCOM4.Count; i++)
                    {
                        if (i == 0)
                            temp += this.ListUserDefinedProtocolCOM4[i];
                        else
                            temp += "," + this.ListUserDefinedProtocolCOM4[i];
                    }
                    break;
                default:
                    break;
            }

            return temp;
        }
        private void AddProtocolToLabelAndList(string temp)
        {
            DataStore.MenuBottomConfiguration currentMenu = this.ParentForm.CurrentConfigurationMenu();

            if (this.labelWindow.Text.Length == 0)
                this.labelWindow.Text += temp;
            else
                this.labelWindow.Text += "," + temp;

            switch (currentMenu)
            {
                case DataStore.MenuBottomConfiguration.SerialCOM1:
                    this.ListUserDefinedProtocolCOM1.Add(temp);
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM3:
                    this.ListUserDefinedProtocolCOM3.Add(temp);
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM4:
                    this.ListUserDefinedProtocolCOM4.Add(temp);
                    break;
                default:
                    break;
            }

        }

        private double RandomWeight()
        {
            Random rd = new Random();
            double weight;
            weight = double.Parse(rd.Next(100, 300).ToString()) + rd.NextDouble();

            return weight;
        }
        private double RandomGap()
        {
            Random rd = new Random();
            double weight;
            weight = double.Parse(rd.Next(10, 20).ToString()) + rd.NextDouble();

            return weight;
        }
        private int RandomCount()
        {
            Random rd = new Random();
            int weight;
            weight = int.Parse(rd.Next(0, 9999999).ToString());

            return weight;
        }
        private string Checksumcalculator(string strTemp)
        {
            string chkSum = "";
            byte[] temp;
            int value = 0, first = 0, second = 0;
            char char1, char2;

            if (strTemp == null || strTemp.Length == 0)
                chkSum = "cc";
            else
            {
                temp = new UTF8Encoding().GetBytes(strTemp);

                for (int i = 0; i < temp.Length; i++)
                    value += temp[i];

                first = (value & 0x00f0) >> 4;
                if (first > 9)
                    char1 = (char)(first + 0x37);
                else
                    char1 = (char)(first + 0x30);

                second = value & 0x000f;
                if (second > 9)
                    char2 = (char)(second + 0x37);
                else
                    char2 = (char)(second + 0x30);

                chkSum = char1.ToString() + char2.ToString();
            }

            return chkSum;
        }
        public string ConvertProtocol(int collectionNumber)
        {
            string sValue = "";
            double dTemp = 0.0;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this.CollectionProtocolList[collectionNumber].Count; i++)
            {
                DateTime dt = DateTime.Now;

                switch (this.CollectionProtocolList[collectionNumber][i])
                {
                    case "STX":
                        sb.Append((char)0x02);
                        break;
                    case "ETX":
                        sb.Append((char)0x03);
                        break;
                    case "CR":
                        sb.Append((char)0x0D);
                        break;
                    case "LF":
                        sb.Append((char)0x0A);
                        break;
                    case "ESC":
                        sb.Append((char)0x1B);
                        break;
                    case "Date[8]":
                        sb.Append(string.Format("{0:yyyyMMdd}", dt));
                        break;
                    case "Time[8]":
                        sb.Append(string.Format("{0:HH:mm:ss}", dt));
                        break;
                    case "Grade[1]":
                        switch(this.ParentForm.ParentForm.CurrentWeightData.JudgmentStatus)
                        {
                            case DataStore.JudgmentStatus.Empty:
                                break;
                            case DataStore.JudgmentStatus.Under:
                                sb.Append("U");
                                break;
                            case DataStore.JudgmentStatus.Pass:
                                sb.Append("P");
                                break;
                            case DataStore.JudgmentStatus.Over:
                                sb.Append("O");
                                break;
                            case DataStore.JudgmentStatus.Double:
                                sb.Append("D");
                                break;
                            case DataStore.JudgmentStatus.Metal:
                                sb.Append("M");
                                break;
                            case DataStore.JudgmentStatus.ExNg:
                                sb.Append("E");
                                break;
                            default:
                                sb.Append("E");
                                break;
                        }
                        break;
                    case "No[4]":
                        sValue = string.Format("{0:0000}", this.ParentForm.ParentForm.SystemConfig1.ProductNumber);
                        sb.Append(sValue);
                        break;
                    case "ID[5]":
                        sValue = string.Format("{0:000}", this.ParentForm.ParentForm.SystemConfig1.EquipmentID);
                        sb.Append("IN" + sValue);
                        break;
                    case "Sign[1]":
                        dTemp = double.Parse(this.ParentForm.ParentForm.CurrentProductItem.PassRange)
                            - this.ParentForm.ParentForm.CurrentWeightData.Weight;
                        if(dTemp < 0)
                            sb.Append("-");
                        else
                            sb.Append(" ");
                        break;
                    case "Weight[6]":
                        sb.Append(string.Format("{0:0000.0}", this.ParentForm.ParentForm.CurrentWeightData.Weight));
                        break;
                    case "Checksum[2]":
                        sb.Append(this.Checksumcalculator(sb.ToString()));
                        break;
                    case "Gap[6]":
                        dTemp = double.Parse(this.ParentForm.ParentForm.CurrentProductItem.PassRange)
                            - this.ParentForm.ParentForm.CurrentWeightData.Weight;
                        sb.Append(string.Format("{0:0000.0}", dTemp));
                        break;
                    case "Under range[7]":
                        sb.Append(Helper.StringZeroFillDigits7(Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.UnderRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces)));
                        break;
                    case "Pass range[7]":
                        sb.Append(Helper.StringZeroFillDigits7(Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces)));
                        break;
                    case "Over range[7]":
                        sb.Append(Helper.StringZeroFillDigits7(Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.OverRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces)));
                        break;
                    case "Under Count[7]":
                        sb.Append(string.Format("{0:0000000}", this.ParentForm.ParentForm.CurrentWeightData.UnderCount));
                        break;
                    case "Pass Count[7]":
                        sb.Append(string.Format("{0:0000000}", this.ParentForm.ParentForm.CurrentWeightData.PassCount));
                        break;
                    case "Over Count[7]":
                        sb.Append(string.Format("{0:0000000}", this.ParentForm.ParentForm.CurrentWeightData.OverCount));
                        break;
                    case "NG Count[7]":
                        sb.Append(string.Format("{0:0000000}", this.ParentForm.ParentForm.CurrentWeightData.ExNGCount));
                        break;
                    case "Total Count[9]":
                        sb.Append(string.Format("{0:000000000}", this.ParentForm.ParentForm.CurrentWeightData.TotalCount));
                        break;
                    default:
                        if (this.CollectionProtocolList[collectionNumber][i] != null && this.CollectionProtocolList[collectionNumber][i] != "")
                        {
                            string strTemp = this.CollectionProtocolList[collectionNumber][i];
                            int intTemp = Convert.ToInt32(strTemp, 16);
                            char temp = (char)intTemp;
                            sb.Append(temp);
                        }
                        break;
                }
            }

            return sb.ToString();
        }
        #endregion

        #region Event Handler
        private void button_Click(object sender, EventArgs e)
        {
            SmartX.SmartButton button = sender as SmartX.SmartButton;

            if (button == null)
                return;

            this.AddProtocolToLabelAndList(button.Text);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DataStore.MenuBottomConfiguration temp = this.ParentForm.CurrentConfigurationMenu();

            switch (temp)
            {
                case DataStore.MenuBottomConfiguration.SerialCOM1:
                    if (this.ListUserDefinedProtocolCOM1.Count >= 1)
                        this.ListUserDefinedProtocolCOM1.RemoveAt(this.ListUserDefinedProtocolCOM1.Count - 1);
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM3:
                    if (this.ListUserDefinedProtocolCOM3.Count >= 1)
                        this.ListUserDefinedProtocolCOM3.RemoveAt(this.ListUserDefinedProtocolCOM3.Count - 1);
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM4:
                    if (this.ListUserDefinedProtocolCOM4.Count >= 1)
                        this.ListUserDefinedProtocolCOM4.RemoveAt(this.ListUserDefinedProtocolCOM4.Count - 1);
                    break;
                default:
                    break;
            }
            this.labelWindow.Text = this.LabelWindowRefresh();
        }

        private void buttonClearAll_Click(object sender, EventArgs e)
        {
            DataStore.MenuBottomConfiguration temp = this.ParentForm.CurrentConfigurationMenu();

            switch (temp)
            {
                case DataStore.MenuBottomConfiguration.SerialCOM1:
                    this.ListUserDefinedProtocolCOM1.Clear();
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM3:
                    this.ListUserDefinedProtocolCOM3.Clear();
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM4:
                    this.ListUserDefinedProtocolCOM4.Clear();
                    break;
                default:
                    break;
            }
            this.labelWindow.Text = this.LabelWindowRefresh();
        }

        private void buttonDirectInput_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(9, 176);
            this.smartKeyboard.Size = new Size(684, 274);
            this.smartKeyboard.Hide();

            this.smartKeyboard.TargetInputObject = this.textBox1;
            this.smartKeyboard.Show();

            this.textBox1.Select(this.textBox1.Text.Length, 0);
        }
        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            this.smartKeyboard.Hide();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            DataStore.MenuBottomConfiguration temp = this.ParentForm.CurrentConfigurationMenu();

            switch (temp)
            {
                case DataStore.MenuBottomConfiguration.SerialCOM1:
                    this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM1 = this.labelWindow.Text;
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM3:
                    this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM3 = this.labelWindow.Text;
                    break;
                case DataStore.MenuBottomConfiguration.SerialCOM4:
                    this.ParentForm.ParentForm.SystemConfig1.UserDefineCOM4 = this.labelWindow.Text;
                    break;
                default:
                    break;
            }

            this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
        }

        private void buttonEnter_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length != 4 || this.textBox1.Text.StartsWith("0x") == false)
            {
                MessageBox.Show("0x로 시작하고, 총 길이는 4여야 합니다");
                this.textBox1.Text = "0x";
                return;
            }
            else
            {
                string temp = this.textBox1.Text;

                if (this.labelWindow.Text.Length == 0)
                    this.labelWindow.Text += temp;
                else
                    this.labelWindow.Text += "," + temp;

                DataStore.MenuBottomConfiguration temp2 = this.ParentForm.CurrentConfigurationMenu();

                switch (temp2)
                {
                    case DataStore.MenuBottomConfiguration.SerialCOM1:
                        this.ListUserDefinedProtocolCOM1.Add(temp);
                        break;
                    case DataStore.MenuBottomConfiguration.SerialCOM3:
                        this.ListUserDefinedProtocolCOM3.Add(temp);
                        break;
                    case DataStore.MenuBottomConfiguration.SerialCOM4:
                        this.ListUserDefinedProtocolCOM4.Add(temp);
                        break;
                    default:
                        break;
                }
            }
        }
        #endregion
    }
}