using System;
using System.Linq;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using ITC81DB_0H.Forms;
using ITC81DB_0H_ImageDll;
using ITC81DB_0H.DialogForms;

namespace ITC81DB_0H.Controls
{
    public partial class ControlConfiOptionBoard1 : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        private Collection<SmartX.SmartRadioButton> CollectionPulseWidth;
        private ProductItem CurrentProductItem;
        #endregion

        #region Constructor
        public ControlConfiOptionBoard1(FormMenu parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.CreateCollection();
            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.engBackgroundFeedback));

                this.checkBoxUse.Font = new Font("새굴림", 14, FontStyle.Bold);
                this.checkBoxUse.Text = "Use";

                this.labelHelp1.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp2.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp3.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp4.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp5.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp1.Text = "- Sample Number:Averaging the set number of samples to send feedback data";
                this.labelHelp2.Text = "- Delay Number:Ignore a certain number of data immediately after sending feedback";
                this.labelHelp3.Text = "- Pulse Width:Set data transfer Width";
                this.labelHelp4.Text = "- Upper/lower Limit:Maximum/minimum values for the extent that feedback is available";
                this.labelHelp5.Text = "※ When 'Use' is not checked, the feedback upper/lower limit is set to the over/under value of the current product number";

                this.labelHelp.Font = new Font("새굴림", 11, FontStyle.Bold);
                this.labelHelp.Text = "※ External output 5, 6: Feedback +, External output 7, 8: Feedback-";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundFeedback));

                this.checkBoxUse.Font = new Font("새굴림", 14, FontStyle.Bold);
                this.checkBoxUse.Text = "使用";

                this.labelHelp1.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp2.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp3.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp4.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp5.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp1.Text = "- 取样计数:设定的个数内平均进行反馈数据传输(0:未使用)";
                this.labelHelp2.Text = "- 延迟计数:反馈数据传送后无视一定数量的数据";
                this.labelHelp3.Text = "- 脉冲幅度:传送数据Width设定";
                this.labelHelp4.Text = "- 反馈:超过/低于:反馈数据的范围内最大值和最小值";
                this.labelHelp5.Text = "※ 如果未选中“使用”,则反馈:超过/低于设置为当前产品编号超过/低于值";

                this.labelHelp.Font = new Font("새굴림", 13, FontStyle.Bold);
                this.labelHelp.Text = "※ 外部输出5, 6: 反馈+, 外部输出7, 8: 反馈-";
            }
            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.rusBackgroundFeedback));

                this.checkBoxUse.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.checkBoxUse.Text = "Использование";

                this.labelHelp1.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp2.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp3.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp4.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp5.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelHelp1.Text = "- Номер образца: усреднение заданного количества образцов для отправки данных обратной связи.";
                this.labelHelp2.Text = "- Отсчет задержки: игнорировать определенный объем данных после передачи данных обратной связи";
                this.labelHelp3.Text = "- Продолжительность импульса: настройка продолжительности передачи данных.";
                this.labelHelp4.Text = "- Обратная связь: выше / ниже: максимальные и минимальные значения в диапазоне данных обратной связи";
                this.labelHelp5.Text = "※ Когда «Использовать» не отмечено, верхний / нижний предел обратной связи устанавливается на значение «Много/ Мало» текущего номера продукта";

                this.labelHelp.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp.Text = "※ Внешний выход 5, 6 : Обратная связь+, Внешний выход 7, 8 : Обратная связь-";
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundFeedback));

                this.checkBoxUse.Font = new Font("새굴림", 11, FontStyle.Bold);
                this.checkBoxUse.Text = "Aktivieren";

                this.labelHelp1.Font = new Font("새굴림", 8, FontStyle.Regular);
                this.labelHelp2.Font = new Font("새굴림", 8, FontStyle.Regular);
                this.labelHelp3.Font = new Font("새굴림", 8, FontStyle.Regular);
                this.labelHelp4.Font = new Font("새굴림", 8, FontStyle.Regular);
                this.labelHelp5.Font = new Font("새굴림", 8, FontStyle.Regular);
                this.labelHelp1.Text = "- Probennummer : Mittelwert der festgelegten Anzahl von Proben zum Senden von Rückmeldedaten";
                this.labelHelp2.Text = "- Delay Number : Ignorieren Sie eine bestimmte Anzahl von Daten unmittelbar nach dem Senden von Feedback";
                this.labelHelp3.Text = "- Impulsbreite : Datenübertragungsbreite einstellen";
                this.labelHelp4.Text = "- Oberer / unterer Grenzwer t: Maximal-/Mindestwerte für den Umfang, in dem die Rückmeldung verfügbar ist";
                this.labelHelp5.Text = "※ Wenn 'Aktivieren' nicht aktiviert ist, wird die obere / untere Rückkopplungsgrenze auf die obere / untere Grenze der aktuellen Produktnummer gesetzt";

                this.labelHelp.Font = new Font("새굴림", 11, FontStyle.Bold);
                this.labelHelp.Text = "※ Externer Ausgang 5, 6: Feedback +, Externer Ausgang 7, 8: Feedback-";
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundFeedback));

                this.checkBoxUse.Font = new Font("새굴림", 14, FontStyle.Bold);
                this.checkBoxUse.Text = "사용";

                this.labelHelp1.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp2.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp3.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp4.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp5.Font = new Font("새굴림", 10, FontStyle.Regular);
                this.labelHelp1.Text = "- 샘플 개수:설정된 개수만큼 평균하여 피드백 데이터를 전송(0:미사용)";
                this.labelHelp2.Text = "- 지연개수:피드백 데이터 전송 직후 일정 개수만큼 데이터를 무시";
                this.labelHelp3.Text = "- 펄스폭:데이터 전송 Width 설정";
                this.labelHelp4.Text = "- 피드백 상한/하한:피드백이 가능한 범위의 최대값 및 최소값";
                this.labelHelp5.Text = "※ '사용' 미체크 시, 피드백 상한/하한은 현재 품번의 상한/하한값으로 설정";

                this.labelHelp.Font = new Font("새굴림", 13, FontStyle.Bold);
                this.labelHelp.Text = "※ 외부출력 5, 6 : Feedback+, 외부출력 7, 8 : Feedback-";
            }
        }
        private void CreateCollection()
        {
            this.CollectionPulseWidth = new Collection<SmartX.SmartRadioButton>();
            this.CollectionPulseWidth.Clear();
            this.CollectionPulseWidth.Add(this.radioButtonPulseWidth2);
            this.CollectionPulseWidth.Add(this.radioButtonPulseWidth4);
            this.CollectionPulseWidth.Add(this.radioButtonPulseWidth6);
            this.CollectionPulseWidth.Add(this.radioButtonPulseWidth8);
            this.CollectionPulseWidth.Add(this.radioButtonPulseWidth10);
        }
        private void DefaultSetting()
        {
            this.CurrentProductItem = new ProductItem();

            this.UpdateDisplay(this.ParentForm.ParentForm.CurrentSystemParameter2);
        }

        private void PulseWidthSelect(int iValue)
        {
            for (int i = 0; i < this.CollectionPulseWidth.Count; i++)
            {
                this.CollectionPulseWidth[i].Click -= new EventHandler(this.radioButtonPulseWidth_Click);
                this.CollectionPulseWidth[i].Checked = false;
            }

            switch (iValue)
            {
                case 0:
                    this.radioButtonPulseWidth2.Checked = true;
                    break;
                case 1:
                    this.radioButtonPulseWidth4.Checked = true;
                    break;
                case 2:
                    this.radioButtonPulseWidth6.Checked = true;
                    break;
                case 3:
                    this.radioButtonPulseWidth8.Checked = true;
                    break;
                case 4:
                    this.radioButtonPulseWidth10.Checked = true;
                    break;
                default:
                    break;
            }

            for (int i = 0; i < this.CollectionPulseWidth.Count; i++)
                this.CollectionPulseWidth[i].Click += new EventHandler(this.radioButtonPulseWidth_Click);
        }
        private void UpdateDisplay(SystemParameter2 parameter)
        {
            string sValue = "";

            // 샘플 개수
            sValue = parameter.OPT1SamplingCount;
            if (this.labelSampleCount.Text != sValue)
                this.labelSampleCount.Text = sValue;

            // 지연 개수
            sValue = parameter.OPT1DelayCount;
            if (this.labelDelayCount.Text != sValue)
                this.labelDelayCount.Text = sValue;

            // 펄스폭
            sValue = parameter.OPT1PulseWidth;
            this.PulseWidthSelect(int.Parse(sValue));

            // 사용/미사용
            sValue = parameter.OPT1IsWeightSetting;
            if (int.Parse(sValue) == 1)
            {
                this.checkBoxUse.Checked = true;

                this.labelUpperLimit.ForeColor = Color.White;
                this.labelLowerLimit.ForeColor = Color.White;
                this.labelUpperLimit.Enabled = true;
                this.labelLowerLimit.Enabled = true;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(parameter.OPT1OverRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelUpperLimit.Text != sValue)
                    this.labelUpperLimit.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(parameter.OPT1UnderRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelLowerLimit.Text != sValue)
                    this.labelLowerLimit.Text = sValue;
            }
            else
            {
                this.checkBoxUse.Checked = false;

                this.labelUpperLimit.ForeColor = Color.DarkGray;
                this.labelLowerLimit.ForeColor = Color.DarkGray;
                this.labelUpperLimit.Enabled = false;
                this.labelLowerLimit.Enabled = false;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem.OverRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelUpperLimit.Text != sValue)
                    this.labelUpperLimit.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem.UnderRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelLowerLimit.Text != sValue)
                    this.labelLowerLimit.Text = sValue;
            }

            sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelStandard1.Text != sValue)
                this.labelStandard1.Text = sValue;
        }
        public void DisplayRefresh(SystemStatus status)
        {
            int temp = this.ParentForm.ParentForm.SystemConfig1.ProductNumber;
            this.ParentForm.ParentForm.LoadProductFile(ref this.CurrentProductItem, temp - 1);

            this.UpdateDisplay(this.ParentForm.ParentForm.CurrentSystemParameter2);
        }
        #endregion

        #region Event Handler
        private void labelSampleCount_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSampleCount.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.labelSampleCount.Text = myKeyPad.StringValue;

                    value = Helper.StringZeroFillDigits4(this.labelSampleCount.Text);
                    this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1SamplingCount = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.ChildFormMainDisplay.CurrentBottomMenuControlEnable(DataStore.EquipmentStatus.Stop);

                    this.ParentForm.ParentForm.SaveSystemParameter2File(this.ParentForm.ParentForm.CurrentSystemParameter2);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1SamplingCount, value);
                }
            }
        }

        private void labelDelayCount_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDelayCount.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.labelDelayCount.Text = myKeyPad.StringValue;

                    value = Helper.StringZeroFillDigits4(this.labelDelayCount.Text);
                    this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1DelayCount = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SaveSystemParameter2File(this.ParentForm.ParentForm.CurrentSystemParameter2);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1DelayCount, value);
                }
            }
        }

        private void radioButtonPulseWidth_Click(object sender, EventArgs e)
        {
            int temp = 0;
            string value = "";
            SmartX.SmartRadioButton rb = sender as SmartX.SmartRadioButton;

            if (rb == null)
                return;

            switch (int.Parse(rb.Text))
            {
                case 2:
                    temp = 0;
                    break;
                case 4:
                    temp = 1;
                    break;
                case 6:
                    temp = 2;
                    break;
                case 8:
                    temp = 3;
                    break;
                case 10:
                    temp = 4;
                    break;
                default:
                    break;
            }

            this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1PulseWidth = temp.ToString();

            value = Helper.StringZeroFillDigits4(temp.ToString());
            this.ParentForm.ParentForm.SaveSystemParameter2File(this.ParentForm.ParentForm.CurrentSystemParameter2);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1PulseWidth, value);
        }

        private void checkBoxUse_Click(object sender, EventArgs e)
        {
            string value = "", sValue = "";

            if (this.checkBoxUse.Checked == true)
            {
                value = "0001";
                this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1IsWeightSetting = "1";

                this.labelUpperLimit.ForeColor = Color.White;
                this.labelLowerLimit.ForeColor = Color.White;
                this.labelUpperLimit.Enabled = true;
                this.labelLowerLimit.Enabled = true;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelUpperLimit.Text != sValue)
                    this.labelUpperLimit.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelLowerLimit.Text != sValue)
                    this.labelLowerLimit.Text = sValue;
            }
            else
            {
                value = "0000";
                this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1IsWeightSetting = "0";

                this.labelUpperLimit.ForeColor = Color.DarkGray;
                this.labelLowerLimit.ForeColor = Color.DarkGray;
                this.labelUpperLimit.Enabled = false;
                this.labelLowerLimit.Enabled = false;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.OverRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelUpperLimit.Text != sValue)
                    this.labelUpperLimit.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem.UnderRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                if (this.labelLowerLimit.Text != sValue)
                    this.labelLowerLimit.Text = sValue;
            }

            this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRange = this.labelUpperLimit.Text.Replace(".", "");
            this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRange = this.labelLowerLimit.Text.Replace(".", "");
            this.ParentForm.ParentForm.CurrentFeedbackItem.OverRangeDeviation =
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainDisplayFeedback.CaculateDeviation(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRangeInt);
            this.ParentForm.ParentForm.CurrentFeedbackItem.UnderRangeDeviation =
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainDisplayFeedback.CaculateDeviation(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRangeInt);

            this.ParentForm.ParentForm.SaveSystemParameter2File(this.ParentForm.ParentForm.CurrentSystemParameter2);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1RangeSetting, value);
            sValue = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRange);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1OverRange, sValue);
            sValue = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRange);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1UnderRange, sValue);

        }

        private void labelUpperLimit_Click(object sender, EventArgs e)
        {
            string value = "";
            int digit = 0;

            if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 0)
                digit = 4;
            // V6.2.0
            //else if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 1)
            //    digit = 5;
            //else if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 2)
            //    digit = 6;
            else
                digit = 5;

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelUpperLimit.Text, digit, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces,
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(this.CurrentProductItem.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelUpperLimit.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CurrentFeedbackItem.OverRangeDeviation =
                        this.ParentForm.ParentForm.ChildFormMainDisplay.MainDisplayFeedback.CaculateDeviation(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRangeInt);

                    value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1OverRange);
                    this.ParentForm.ParentForm.SaveSystemParameter2File(this.ParentForm.ParentForm.CurrentSystemParameter2);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1OverRange, value);
                }
            }
        }

        private void labelLowerLimit_Click(object sender, EventArgs e)
        {
            string value = "";
            int digit = 0;

            if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 0)
                digit = 4;
            // V6.2.0
            //else if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 1)
            //    digit = 5;
            //else if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 2)
            //    digit = 6;
            else
                digit = 5;

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLowerLimit.Text, digit, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces,
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(this.CurrentProductItem.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelLowerLimit.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CurrentFeedbackItem.UnderRangeDeviation =
                        this.ParentForm.ParentForm.ChildFormMainDisplay.MainDisplayFeedback.CaculateDeviation(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRangeInt);

                    value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter2.OPT1UnderRange);
                    this.ParentForm.ParentForm.SaveSystemParameter2File(this.ParentForm.ParentForm.CurrentSystemParameter2);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OPT1UnderRange, value);
                }
            }
        }
        #endregion
    }
}