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

namespace ITC81DB_2.Controls
{
    public partial class ControlConfiOptionBoard1 : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        private Collection<SmartX.SmartRadioButton> CollectionPulseWidth;
        private ProductItem CurrentProductItem1;
        private ProductItem CurrentProductItem2;
        #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.SystemConfig.Language == Define.E_LanguageID.English)
            {
                this.labelTitleSampleCount.Font = new Font("새굴림", 8, FontStyle.Bold);
                this.labelTitleSampleCount.Text = "Sample Count";
                this.labelTitleDelayCount.Font = new Font("새굴림", 8, FontStyle.Bold);
                this.labelTitleDelayCount.Text = "Ignore Count";
                this.labelTitlePulseWidth.Font = new Font("새굴림", 8, FontStyle.Bold);
                this.labelTitlePulseWidth.Text = " Pulse Width";

                this.labelTitleLane1.Text = "Lane 1";
                this.labelTitleLane2.Text = "Lane 2";

                this.labelTitleUpperLimit.Text = "Over";
                this.labelTitleStandard.Text = "Pass";
                this.labelTitleLowerLimit.Text = "Under";

                this.labelTitleHelp.Text = "Help";

                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.labelHelpPort1.Text = "Port5 : 1Lane - Feedback+, Port6 : 2Lane -  Feedback+";
                this.labelHelpPort2.Text = "Port7 : 1Lane - Feedback-, Port8 : 2Lane - Feedback-";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleSampleCount.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.labelTitleSampleCount.Text = "取样计数";
                this.labelTitleDelayCount.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.labelTitleDelayCount.Text = "延迟计数";
                this.labelTitlePulseWidth.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.labelTitlePulseWidth.Text = "脉冲幅度";

                this.labelTitleLane1.Text = "泳道1";
                this.labelTitleLane2.Text = "泳道2";

                this.labelTitleUpperLimit.Text = "上限";
                this.labelTitleStandard.Text = "标准";
                this.labelTitleLowerLimit.Text = "下限";

                this.labelTitleHelp.Text = "帮助";

                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.labelHelpPort1.Text = "端口 5：1 通道 - 反馈+，端口 6：2 通道 - 反馈+";
                this.labelHelpPort2.Text = "端口 7：1 通道 - 反馈-，端口 8：2 通道 - 反馈-";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.labelTitleSampleCount.Font = new Font("새굴림", 8, FontStyle.Bold);
                this.labelTitleSampleCount.Text = "Número de muestra";
                this.labelTitleDelayCount.Font = new Font("새굴림", 8, FontStyle.Bold);
                this.labelTitleDelayCount.Text = "Ignorar número";
                this.labelTitlePulseWidth.Font = new Font("새굴림", 8, FontStyle.Bold);
                this.labelTitlePulseWidth.Text = "Ancho de pulso";

                this.labelTitleLane1.Text = "Carril 1";
                this.labelTitleLane2.Text = "Carril 2";

                this.labelTitleUpperLimit.Text = "Superior";
                this.labelTitleStandard.Text = "Referencia";
                this.labelTitleLowerLimit.Text = "Inferior";

                this.labelTitleHelp.Text = "Ayudar";

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

                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 = "- Número de muestra: Promediar el número establecido de muestras para enviar datos de retroalimentación";
                this.labelHelp2.Text = "- Número de retraso: ignora una cierta cantidad de datos inmediatamente después de enviar comentarios";
                this.labelHelp3.Text = "- Ancho de pulso: Establecer ancho de transferencia de datos";
                this.labelHelp4.Text = "- Límite superior/inferior: valores máximos/mínimos en la medida en que la retroalimentación esté disponible";
                this.labelHelp5.Text = "※ Cuando 'Usar' no está marcado, el límite superior/inferior de retroalimentación se establece en el valor superior/inferior del número de producto actual.";

                this.labelHelpPort1.Text = "Puerto5 : 1Carril - Retroalimentación+, Puerto6 : 2Carril -  Retroalimentación+";
                this.labelHelpPort2.Text = "Puerto7 : 1Carril - Retroalimentación-, Puerto8 : 2Carril - Retroalimentación-";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Russian)
            {
                this.labelTitleSampleCount.Font = new Font("새굴림", 6, FontStyle.Bold);
                this.labelTitleSampleCount.Text = "Количество образцов";
                this.labelTitleDelayCount.Font = new Font("새굴림", 6, FontStyle.Bold);
                this.labelTitleDelayCount.Text = "Задержка сигнала";
                this.labelTitlePulseWidth.Font = new Font("새굴림", 6, FontStyle.Bold);
                this.labelTitlePulseWidth.Text = "Длительность импульса";

                this.labelTitleLane1.Text = "1";
                this.labelTitleLane2.Text = "2";

                this.labelTitleUpperLimit.Text = "Много";
                this.labelTitleStandard.Text = "Норма";
                this.labelTitleLowerLimit.Text = "Мало";

                this.labelTitleHelp.Text = "Помощь";

                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.labelHelpPort1.Text = "Порт 5: 1 линия - обратная связь+, Порт 6: 2 линии - обратная связь+";
                this.labelHelpPort2.Text = "Порт 7: 1 линия - обратная связь- Порт 8: 2 линии - обратная связь-";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.German)
            {
                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.labelHelpPort1.Text = "Port5 : 1Lane - Feedback+, Port6 : 2Lane -  Feedback+";
                this.labelHelpPort2.Text = "Port7 : 1Lane - Feedback-, Port8 : 2Lane - Feedback-";
            }
            else
            {
                this.labelTitleSampleCount.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.labelTitleSampleCount.Text = "샘플개수";
                this.labelTitleDelayCount.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.labelTitleDelayCount.Text = "무시개수";
                this.labelTitlePulseWidth.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.labelTitlePulseWidth.Text = "펄스폭";

                this.labelTitleLane1.Text = "1열";
                this.labelTitleLane2.Text = "2열";

                this.labelTitleUpperLimit.Text = "상한";
                this.labelTitleStandard.Text = "기준";
                this.labelTitleLowerLimit.Text = "하한";

                this.labelTitleHelp.Text = "도움말";

                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.labelHelpPort1.Text = "Port5 : 1열 Feedback+, Port6 : 2열 Feedback+";
                this.labelHelpPort2.Text = "Port7 : 1열 Feedback-, Port8 : 2열 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.CurrentProductItem1 = new ProductItem();
            this.CurrentProductItem2 = new ProductItem();

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

        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(SystemParameter9508 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;

                #region 1열
                this.labelUpperLimit1.ForeColor = Color.White;
                this.labelLowerLimit1.ForeColor = Color.White;
                this.labelUpperLimit1.Enabled = true;
                this.labelLowerLimit1.Enabled = true;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(parameter.OPT1OverRange1, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit1.Text != sValue)
                    this.labelUpperLimit1.Text = sValue;
                
                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(parameter.OPT1UnderRange1, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit1.Text != sValue)
                    this.labelLowerLimit1.Text = sValue;
                #endregion

                #region 2열
                this.labelUpperLimit2.ForeColor = Color.White;
                this.labelLowerLimit2.ForeColor = Color.White;
                this.labelUpperLimit2.Enabled = true;
                this.labelLowerLimit2.Enabled = true;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(parameter.OPT1OverRange2, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit2.Text != sValue)
                    this.labelUpperLimit2.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(parameter.OPT1UnderRange2, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit2.Text != sValue)
                    this.labelLowerLimit2.Text = sValue;
                #endregion
            }
            else
            {
                this.checkBoxUse.Checked = false;

                #region 1열
                this.labelUpperLimit1.ForeColor = Color.DarkGray;
                this.labelLowerLimit1.ForeColor = Color.DarkGray;
                this.labelUpperLimit1.Enabled = false;
                this.labelLowerLimit1.Enabled = false;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem1.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit1.Text != sValue)
                    this.labelUpperLimit1.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem1.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit1.Text != sValue)
                    this.labelLowerLimit1.Text = sValue;
                #endregion

                #region 2열
                this.labelUpperLimit2.ForeColor = Color.DarkGray;
                this.labelLowerLimit2.ForeColor = Color.DarkGray;
                this.labelUpperLimit2.Enabled = false;
                this.labelLowerLimit2.Enabled = false;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem2.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit2.Text != sValue)
                    this.labelUpperLimit2.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem2.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit2.Text != sValue)
                    this.labelLowerLimit2.Text = sValue;
                #endregion
            }
            
            sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem1.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelStandard1.Text != sValue)
                this.labelStandard1.Text = sValue;
            
            sValue = Helper.StringToDecimalPlaces(this.CurrentProductItem2.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelStandard2.Text != sValue)
                this.labelStandard2.Text = sValue;
        }
        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.ConfiOptionBoard1;

            int temp = this.ParentForm.ParentForm.SystemConfig.ProductNumber;
            this.ParentForm.ParentForm.LoadProductFile1(ref this.CurrentProductItem1, temp - 1);
            this.ParentForm.ParentForm.LoadProductFile2(ref this.CurrentProductItem2, temp - 1);

            this.UpdateDisplay(this.ParentForm.ParentForm.CurrentSystemParameter9508);
        }
        #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.SystemConfig.Language);

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

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

                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6201_OPT1SamplingCount, value);
                    this.ParentForm.ParentForm.ChildFormMainDisplay.CurrentBottomMenuControlEnable();
                }
            }
        }
        private void labelDelayCount_Click(object sender, EventArgs e)
        {
            string value = "";
             DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDelayCount.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

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

                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6202_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.CurrentSystemParameter9508.OPT1PulseWidth = temp.ToString();

            value = Helper.StringZeroFillDigits4(temp.ToString());
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6203_OPT1PulseWidth, value);
        }
        private void checkBoxUse_Click(object sender, EventArgs e)
        {
            string value = "", sValue = "";

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

                #region 1열
                this.labelUpperLimit1.ForeColor = Color.White;
                this.labelLowerLimit1.ForeColor = Color.White;
                this.labelUpperLimit1.Enabled = true;
                this.labelLowerLimit1.Enabled = true;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit1.Text != sValue)
                    this.labelUpperLimit1.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit1.Text != sValue)
                    this.labelLowerLimit1.Text = sValue;
                #endregion

                #region 1열
                this.labelUpperLimit2.ForeColor = Color.White;
                this.labelLowerLimit2.ForeColor = Color.White;
                this.labelUpperLimit2.Enabled = true;
                this.labelLowerLimit2.Enabled = true;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange2, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit2.Text != sValue)
                    this.labelUpperLimit2.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange2, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit2.Text != sValue)
                    this.labelLowerLimit2.Text = sValue;
                #endregion
            }
            else
            {
                value = "0000";
                this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1IsWeightSetting = "0";

                #region 1열
                this.labelUpperLimit1.ForeColor = Color.DarkGray;
                this.labelLowerLimit1.ForeColor = Color.DarkGray;
                this.labelUpperLimit1.Enabled = false;
                this.labelLowerLimit1.Enabled = false;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem1.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit1.Text != sValue)
                    this.labelUpperLimit1.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem1.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit1.Text != sValue)
                    this.labelLowerLimit1.Text = sValue; 
                #endregion

                #region 2열
                this.labelUpperLimit2.ForeColor = Color.DarkGray;
                this.labelLowerLimit2.ForeColor = Color.DarkGray;
                this.labelUpperLimit2.Enabled = false;
                this.labelLowerLimit2.Enabled = false;

                // 피드백 상한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem2.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelUpperLimit2.Text != sValue)
                    this.labelUpperLimit2.Text = sValue;

                // 피드백 하한
                sValue = Helper.StringToDecimalPlaces(this.ParentForm.ParentForm.CurrentProductItem2.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelLowerLimit2.Text != sValue)
                    this.labelLowerLimit2.Text = sValue;
                #endregion
            }

            this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1 = this.labelUpperLimit1.Text.Replace(".", "");
            this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1 = this.labelLowerLimit1.Text.Replace(".", "");
            this.ParentForm.ParentForm.CurrentFeedbackItem1.OverRangeDeviation =
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation1(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1Int);
            this.ParentForm.ParentForm.CurrentFeedbackItem1.UnderRangeDeviation =
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation1(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1Int);

            this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange2 = this.labelUpperLimit2.Text.Replace(".", "");
            this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange2 = this.labelLowerLimit2.Text.Replace(".", "");
            this.ParentForm.ParentForm.CurrentFeedbackItem2.OverRangeDeviation =
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation2(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange2Int);
            this.ParentForm.ParentForm.CurrentFeedbackItem2.UnderRangeDeviation =
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation2(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange2Int);

            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6204_OPT1RangeSetting, value);
            sValue = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6205_OPT1OverRange1, sValue);
            sValue = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6206_OPT1UnderRange1, sValue);
        }
        private void labelUpperLimit1_Click(object sender, EventArgs e)
        {
            string value = "";
            int digit = 0;

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

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(this.CurrentProductItem1.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelUpperLimit1.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1 = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CurrentFeedbackItem1.OverRangeDeviation =
                        this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation1(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1Int);

                    value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange1);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6205_OPT1OverRange1, value);
                }
            }
        }
        private void labelLowerLimit1_Click(object sender, EventArgs e)
        {
            string value = "";
            int digit = 0;

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

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(this.CurrentProductItem1.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelLowerLimit1.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1 = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CurrentFeedbackItem1.UnderRangeDeviation =
                        this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation1(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1Int);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6206_OPT1UnderRange1, value);
                }
            }
        }
        private void labelUpperLimit2_Click(object sender, EventArgs e)
        {
            string value = "";
            int digit = 0;

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

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(this.CurrentProductItem2.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelUpperLimit2.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange2 = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CurrentFeedbackItem2.OverRangeDeviation =
                        this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation2(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange2Int);

                    value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1OverRange2);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6216_OPT1OverRange2, value);
                }
            }
        }
        private void labelLowerLimit2_Click(object sender, EventArgs e)
        {
            string value = "";
            int digit = 0;

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

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(this.CurrentProductItem2.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelLowerLimit2.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange2 = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CurrentFeedbackItem2.UnderRangeDeviation =
                        this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.CaculateDeviation2(this.ParentForm.ParentForm.CurrentSystemParameter9508.OPT1UnderRange2Int);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6217_OPT1UnderRange2, value);
                }
            }
        }
        #endregion
    }
}
