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

using SmartX;
using INT63DC_6CH.Forms;
using INT63DC_6CH.DialogForms;

namespace INT63DC_6CH.Controls
{
    public partial class ControlMainDisplayFeedback : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;

        private Collection<SmartLabel> CollectionLane;
        private Collection<SmartLabel> CollectionSampleCount;
        private Collection<SmartLabel> CollectionIgnoreCount;
        private Collection<SmartLabel> CollectionFeedbackWeight;
        private Collection<SmartLabel> CollectionCurrentWeight;
        #endregion

        #region Constructor
        public ControlMainDisplayFeedback(FormMainDisplay parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.CreateCollection();
            this.InitializeControl();
        } 
        #endregion

        #region Property
        public FormMainDisplay ParentForm
        {
            get { return this.m_ParentForm; }
            private set { this.m_ParentForm = value; }
        }
        #endregion

        #region Method
        private void CreateCollection()
        {
            this.CollectionLane = new Collection<SmartLabel>();
            this.CollectionLane.Add(this.labelLane1);
            this.CollectionLane.Add(this.labelLane2);
            this.CollectionLane.Add(this.labelLane3);
            this.CollectionLane.Add(this.labelLane4);
            this.CollectionLane.Add(this.labelLane5);
            this.CollectionLane.Add(this.labelLane6);

            this.CollectionSampleCount = new Collection<SmartLabel>();
            this.CollectionSampleCount.Add(this.labelSampleCount1);
            this.CollectionSampleCount.Add(this.labelSampleCount2);
            this.CollectionSampleCount.Add(this.labelSampleCount3);
            this.CollectionSampleCount.Add(this.labelSampleCount4);
            this.CollectionSampleCount.Add(this.labelSampleCount5);
            this.CollectionSampleCount.Add(this.labelSampleCount6);
            
            this.CollectionIgnoreCount = new Collection<SmartLabel>();
            this.CollectionIgnoreCount.Add(this.labelIgnoreCount1);
            this.CollectionIgnoreCount.Add(this.labelIgnoreCount2);
            this.CollectionIgnoreCount.Add(this.labelIgnoreCount3);
            this.CollectionIgnoreCount.Add(this.labelIgnoreCount4);
            this.CollectionIgnoreCount.Add(this.labelIgnoreCount5);
            this.CollectionIgnoreCount.Add(this.labelIgnoreCount6);            
            
            this.CollectionFeedbackWeight = new Collection<SmartLabel>();
            this.CollectionFeedbackWeight.Add(this.labelFeedbackWeight1);
            this.CollectionFeedbackWeight.Add(this.labelFeedbackWeight2);
            this.CollectionFeedbackWeight.Add(this.labelFeedbackWeight3);
            this.CollectionFeedbackWeight.Add(this.labelFeedbackWeight4);
            this.CollectionFeedbackWeight.Add(this.labelFeedbackWeight5);
            this.CollectionFeedbackWeight.Add(this.labelFeedbackWeight6);

            this.CollectionCurrentWeight = new Collection<SmartLabel>();
            this.CollectionCurrentWeight.Add(this.labelCurrentWeight1);
            this.CollectionCurrentWeight.Add(this.labelCurrentWeight2);
            this.CollectionCurrentWeight.Add(this.labelCurrentWeight3);
            this.CollectionCurrentWeight.Add(this.labelCurrentWeight4);
            this.CollectionCurrentWeight.Add(this.labelCurrentWeight5);
            this.CollectionCurrentWeight.Add(this.labelCurrentWeight6);
        }
        private void InitializeControl()
        {
            for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EquipmentColumns; i++)
            {
                this.CollectionLane[i].Visible = true;
                this.CollectionSampleCount[i].Visible = true;
                this.CollectionSampleCount[i].Text = "0";
                this.CollectionIgnoreCount[i].Visible = true;
                this.CollectionIgnoreCount[i].Text = "0";
                this.CollectionFeedbackWeight[i].Visible = true;
                this.CollectionFeedbackWeight[i].Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.CollectionCurrentWeight[i].Visible = true;
                this.CollectionCurrentWeight[i].Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            }
        }

        public void UpdateFeedbackDisplay(FeedbackConfiguration feedback, SystemConfigurationItem system, ProductItem product)
        {
            int passRange = 0, underRange = 0, overRange = 0, deadZone = 0, deadZoneHigh = 0, deadZoneLow = 0, lowLimit = 0, highLimit = 0;
            string value = "";

            underRange = int.Parse(product.UnderRange);
            passRange = int.Parse(product.PassRange);
            overRange = int.Parse(product.OverRange);
            deadZone = int.Parse(feedback.DeadZone);
            deadZoneHigh = passRange + deadZone;
            deadZoneLow = passRange - deadZone;
            lowLimit = int.Parse(feedback.LowLimit);
            highLimit = int.Parse(feedback.HighLimit);

            // SampleCount
            value = system.FeedbackSampleCount.ToString();
            if (this.labelSampleCount.Text != value)
                this.labelSampleCount.Text = value;

            // IgnorePackages
            value = system.FeedbackIgnorePackages.ToString();
            if (this.labelIgnorePackages.Text != value)
                this.labelIgnorePackages.Text = value;

            // DeadZone
            value = Helper.StringToDecimalPlaces(feedback.DeadZone, system.DecimalPlaces);
            if (this.labelDeadZone.Text != value)
                this.labelDeadZone.Text = value;
            // HightLimit
            value = Helper.StringToDecimalPlaces(feedback.HighLimit, system.DecimalPlaces);
            if (this.labelHighLimitRange.Text != value)
            {
                this.labelHighLimitRange.Text = value;
                this.labelHighLimitRange1.Text = value;
            }
            // LowLimit
            value = Helper.StringToDecimalPlaces(feedback.LowLimit, system.DecimalPlaces);
            if (this.labelLowLimitRange.Text != value)
            {
                this.labelLowLimitRange.Text = value;
                this.labelLowLimitRange1.Text = value;
            }
            // DeadZoneLowLimit
            value = Helper.StringToDecimalPlaces(deadZoneLow.ToString(), system.DecimalPlaces);
            if (this.labelDeadZoneLowLimitRange.Text != value)
                this.labelDeadZoneLowLimitRange.Text = value;
            // DeadZoneHighLimit
            value = Helper.StringToDecimalPlaces(deadZoneHigh.ToString(), system.DecimalPlaces);
            if (this.labelDeadZoneHighLimitRange.Text != value)
                this.labelDeadZoneHighLimitRange.Text = value;
            // OverRange
            value = Helper.StringToDecimalPlaces(product.OverRange, system.DecimalPlaces);
            if (this.labelOverRange.Text != value)
                this.labelOverRange.Text = value;
            // PassRange
            value = Helper.StringToDecimalPlaces(product.PassRange, system.DecimalPlaces);
            if (this.labelPassRange.Text != value)
                this.labelPassRange.Text = value;
            // UnderRange
            value = Helper.StringToDecimalPlaces(product.UnderRange, system.DecimalPlaces);
            if (this.labelUnderRange.Text != value)
                this.labelUnderRange.Text = value;

            // Information Feedback Range
            if (highLimit > overRange && lowLimit < underRange)
            {
                this.pictureBoxFeedback1.Visible = false;
                this.pictureBoxFeedback2.Visible = false;
                this.pictureBoxFeedback3.Visible = false;
                this.pictureBoxFeedback4.Visible = true;

                this.labelOverRange.Location = new Point(898, 123);
                this.labelHighLimitRange1.Location = new Point(898, 85);
                this.labelLowLimitRange1.Location = new Point(898, 392);
                this.labelUnderRange.Location = new Point(898, 353);
            }
            else if (highLimit > overRange)
            {
                this.pictureBoxFeedback1.Visible = false;
                this.pictureBoxFeedback2.Visible = true;
                this.pictureBoxFeedback3.Visible = false;
                this.pictureBoxFeedback4.Visible = false;

                this.labelOverRange.Location = new Point(898, 123);
                this.labelHighLimitRange1.Location = new Point(898, 85);
                this.labelLowLimitRange1.Location = new Point(898, 353);
                this.labelUnderRange.Location = new Point(898, 392);
            }
            else if (lowLimit < underRange)
            {
                this.pictureBoxFeedback1.Visible = false;
                this.pictureBoxFeedback2.Visible = false;
                this.pictureBoxFeedback3.Visible = true;
                this.pictureBoxFeedback4.Visible = false;

                this.labelOverRange.Location = new Point(898, 85);
                this.labelHighLimitRange1.Location = new Point(898, 123);
                this.labelLowLimitRange1.Location = new Point(898, 392);
                this.labelUnderRange.Location = new Point(898, 353); 
            }
            else
            {
                this.pictureBoxFeedback1.Visible = true;
                this.pictureBoxFeedback2.Visible = false;
                this.pictureBoxFeedback3.Visible = false;
                this.pictureBoxFeedback4.Visible = false;

                this.labelOverRange.Location = new Point(898, 85);
                this.labelHighLimitRange1.Location = new Point(898, 123);
                this.labelLowLimitRange1.Location = new Point(898, 353);
                this.labelUnderRange.Location = new Point(898, 392);
            }
        }
        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            this.UpdateFeedbackDataDisplay(status, this.ParentForm.ParentForm.CollectionFeedbackStatus);

            if (status == DataStore.EquipmentStatus.Start)
            {

            }
            else
            { 

            }
        }
        public void UpdateFeedbackDataDisplay(DataStore.EquipmentStatus status, Collection<FeedBackSystem> feedbackData)
        {
            this.UpdateFeedbackDataDisplay1(status, feedbackData[0]);
            this.UpdateFeedbackDataDisplay2(status, feedbackData[1]);
            this.UpdateFeedbackDataDisplay3(status, feedbackData[2]);
            this.UpdateFeedbackDataDisplay4(status, feedbackData[3]);
            this.UpdateFeedbackDataDisplay5(status, feedbackData[4]);
            this.UpdateFeedbackDataDisplay6(status, feedbackData[5]);
        }
        public void UpdateFeedbackDataDisplay1(DataStore.EquipmentStatus status, FeedBackSystem feedbackData)
        {
            string value = "";
            // Sample Count
            value = feedbackData.WeightList.Count.ToString();
            if (this.labelSampleCount1.Text != value)
                this.labelSampleCount1.Text = value;
            // Ignore Count
            value = feedbackData.IgnoreCount.ToString();
            if (this.labelIgnoreCount1.Text != value)
                this.labelIgnoreCount1.Text = value;
            // Feedback Weight
            if (feedbackData.FeedbackWeight <= 0)
                value = Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            else
                value = string.Format("+{0}", Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));

            if (this.labelFeedbackWeight1.Text != value)
                this.labelFeedbackWeight1.Text = value;
        }
        public void UpdateFeedbackDataDisplay2(DataStore.EquipmentStatus status, FeedBackSystem feedbackData)
        {
            string value = "";
            // Sample Count
            value = feedbackData.WeightList.Count.ToString();
            if (this.labelSampleCount2.Text != value)
                this.labelSampleCount2.Text = value;
            // Ignore Count
            value = feedbackData.IgnoreCount.ToString();
            if (this.labelIgnoreCount2.Text != value)
                this.labelIgnoreCount2.Text = value;
            // Feedback Weight
            if (feedbackData.FeedbackWeight <= 0)
                value = Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            else
                value = string.Format("+{0}", Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));

            if (this.labelFeedbackWeight2.Text != value)
                this.labelFeedbackWeight2.Text = value;
        }
        public void UpdateFeedbackDataDisplay3(DataStore.EquipmentStatus status, FeedBackSystem feedbackData)
        {
            string value = "";
            // Sample Count
            value = feedbackData.WeightList.Count.ToString();
            if (this.labelSampleCount3.Text != value)
                this.labelSampleCount3.Text = value;
            // Ignore Count
            value = feedbackData.IgnoreCount.ToString();
            if (this.labelIgnoreCount3.Text != value)
                this.labelIgnoreCount3.Text = value;
            // Feedback Weight
            if (feedbackData.FeedbackWeight <= 0)
                value = Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            else
                value = string.Format("+{0}", Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));

            if (this.labelFeedbackWeight3.Text != value)
                this.labelFeedbackWeight3.Text = value;
        }
        public void UpdateFeedbackDataDisplay4(DataStore.EquipmentStatus status, FeedBackSystem feedbackData)
        {
            string value = "";
            // Sample Count
            value = feedbackData.WeightList.Count.ToString();
            if (this.labelSampleCount4.Text != value)
                this.labelSampleCount4.Text = value;
            // Ignore Count
            value = feedbackData.IgnoreCount.ToString();
            if (this.labelIgnoreCount4.Text != value)
                this.labelIgnoreCount4.Text = value;
            // Feedback Weight
            if (feedbackData.FeedbackWeight <= 0)
                value = Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            else
                value = string.Format("+{0}", Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));

            if (this.labelFeedbackWeight4.Text != value)
                this.labelFeedbackWeight4.Text = value;
        }
        public void UpdateFeedbackDataDisplay5(DataStore.EquipmentStatus status, FeedBackSystem feedbackData)
        {
            string value = "";
            // Sample Count
            value = feedbackData.WeightList.Count.ToString();
            if (this.labelSampleCount5.Text != value)
                this.labelSampleCount5.Text = value;
            // Ignore Count
            value = feedbackData.IgnoreCount.ToString();
            if (this.labelIgnoreCount5.Text != value)
                this.labelIgnoreCount5.Text = value;
            // Feedback Weight
            if (feedbackData.FeedbackWeight <= 0)
                value = Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            else
                value = string.Format("+{0}", Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));

            if (this.labelFeedbackWeight5.Text != value)
                this.labelFeedbackWeight5.Text = value;
        }
        public void UpdateFeedbackDataDisplay6(DataStore.EquipmentStatus status, FeedBackSystem feedbackData)
        {
            string value = "";
            // Sample Count
            value = feedbackData.WeightList.Count.ToString();
            if (this.labelSampleCount6.Text != value)
                this.labelSampleCount6.Text = value;
            // Ignore Count
            value = feedbackData.IgnoreCount.ToString();
            if (this.labelIgnoreCount6.Text != value)
                this.labelIgnoreCount6.Text = value;
            // Feedback Weight
            if (feedbackData.FeedbackWeight <= 0)
                value = Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            else
                value = string.Format("+{0}", Helper.DoubleToString(feedbackData.FeedbackWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));

            if (this.labelFeedbackWeight6.Text != value)
                this.labelFeedbackWeight6.Text = value;
        }
        public void UpdateStopWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            string value = "";

            if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns > weightDatas.Count)
                return;

            if (status == DataStore.EquipmentStatus.Stop)
            {
                for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EquipmentColumns; i++)
                {
                    // 중량
                    value = Helper.StringToDecimalPlaces(weightDatas[i].WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    if (this.CollectionCurrentWeight[i].Text != value)
                        this.CollectionCurrentWeight[i].Text = value;
                }
            }
        }
        public void UpdateStartWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            this.UpdateStartWeightDisplay1(status, weightDatas[0]);
            this.UpdateStartWeightDisplay2(status, weightDatas[1]);
            this.UpdateStartWeightDisplay3(status, weightDatas[2]);
            this.UpdateStartWeightDisplay4(status, weightDatas[3]);
            this.UpdateStartWeightDisplay5(status, weightDatas[4]);
            this.UpdateStartWeightDisplay6(status, weightDatas[5]);
        }
        public void UpdateStartWeightDisplay1(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.StringToDecimalPlaces(weightData.WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelCurrentWeight1.Text != value)
                this.labelCurrentWeight1.Text = value;
        }
        public void UpdateStartWeightDisplay2(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.StringToDecimalPlaces(weightData.WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelCurrentWeight2.Text != value)
                this.labelCurrentWeight2.Text = value;
        }
        public void UpdateStartWeightDisplay3(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.StringToDecimalPlaces(weightData.WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelCurrentWeight3.Text != value)
                this.labelCurrentWeight3.Text = value;
        }
        public void UpdateStartWeightDisplay4(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.StringToDecimalPlaces(weightData.WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelCurrentWeight4.Text != value)
                this.labelCurrentWeight4.Text = value;
        }
        public void UpdateStartWeightDisplay5(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.StringToDecimalPlaces(weightData.WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelCurrentWeight5.Text != value)
                this.labelCurrentWeight5.Text = value;
        }
        public void UpdateStartWeightDisplay6(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.StringToDecimalPlaces(weightData.WeightString, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelCurrentWeight6.Text != value)
                this.labelCurrentWeight6.Text = value;
        }
        public void Clear()
        {
            for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EquipmentColumns; i++)
            {
                this.ParentForm.ParentForm.CollectionFeedbackStatus[i].ClearDataAll();
                this.ParentForm.ParentForm.Update30000ModbusData(i);
            }

            this.UpdateFeedbackDataDisplay(this.ParentForm.ParentForm.EquipmentStatus, this.ParentForm.ParentForm.CollectionFeedbackStatus);
        }

        public void DisplayRefresh()
        {
            this.UpdateFeedbackDisplay(this.ParentForm.ParentForm.CurrentFeedbackItem, this.ParentForm.ParentForm.SystemConfig, this.ParentForm.ParentForm.CurrentProductItem);
        }
        #endregion

        #region Event Handler
        private void labelSampleCount_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSampleCount.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    this.ParentForm.ParentForm.SystemConfig.FeedbackSampleCount = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                    this.ParentForm.ParentForm.Update30000ModbusData();
                    this.ParentForm.ParentForm.ModbusCommonDataSend();

                    this.Clear();
                }
            }
        }
        private void labelIgnorePackages_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelIgnorePackages.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    this.ParentForm.ParentForm.SystemConfig.FeedbackIgnorePackages = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                    this.ParentForm.ParentForm.Update30000ModbusData();
                    this.ParentForm.ParentForm.ModbusCommonDataSend();

                    this.Clear();
                }
            }
        }
        private void labelDeadZone_Click(object sender, EventArgs e)
        {
            int passRange = 0, deadZone = 0, deadZoneHigh = 0, deadZoneLow = 0;

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                passRange = int.Parse(this.ParentForm.ParentForm.CurrentProductItem.PassRange);
                deadZone = int.Parse(myKeyPad.StringValue.Replace(".", ""));
                deadZoneHigh = passRange + deadZone;
                deadZoneLow = passRange - deadZone;

                if (deadZoneLow < int.Parse(this.ParentForm.ParentForm.CurrentFeedbackItem.LowLimit) ||
                    deadZoneLow < int.Parse(this.ParentForm.ParentForm.CurrentProductItem.UnderRange) ||
                    deadZoneHigh > int.Parse(this.ParentForm.ParentForm.CurrentFeedbackItem.HighLimit) ||
                    deadZoneHigh > int.Parse(this.ParentForm.ParentForm.CurrentProductItem.OverRange))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelDeadZone.Text = myKeyPad.StringValue;
                    this.labelDeadZoneHighLimitRange.Text = Helper.StringToDecimalPlaces(deadZoneHigh.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    this.labelDeadZoneLowLimitRange.Text = Helper.StringToDecimalPlaces(deadZoneLow.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);

                    this.ParentForm.ParentForm.CurrentFeedbackItem.DeadZone = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.SaveFeedbackItemFile(this.ParentForm.ParentForm.CurrentFeedbackItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);

                    this.ParentForm.ParentForm.Update30000ModbusData();
                    this.ParentForm.ParentForm.ModbusCommonDataSend();
                }
            }
        }
        private void labelHighLimitRange_Click(object sender, EventArgs e)
        {
            bool saveEnable = false;
            int passRange = 0, deadZone = 0, deadZoneHigh = 0;
            string data = "";

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

            passRange = int.Parse(this.ParentForm.ParentForm.CurrentProductItem.PassRange);
            deadZone = int.Parse(this.ParentForm.ParentForm.CurrentFeedbackItem.DeadZone);
            deadZoneHigh = passRange + deadZone;

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(deadZoneHigh.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    data = string.Format("{0} ~ {1}", Helper.StringToDecimalPlaces(deadZoneHigh.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces),
                        Helper.StringToDecimalPlaces("99999", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language, data);
                    myMsg.ShowDialog();
                }
                else
                {
                    //if (myKeyPad.doubleValue > Helper.StringToWeight(this.ParentForm.ParentForm.CurrentProductItem.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                    //{
                    //    DialogFormYesNo myMsgYesNo = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig.Language, 6);
                    //    if (myMsgYesNo.ShowDialog() == DialogResult.Yes)
                    //        saveEnable = true;
                    //}
                    //else
                    //    saveEnable = true;

                    //if (saveEnable == true)
                    //{
                        this.labelHighLimitRange.Text = myKeyPad.StringValue;
                        this.labelHighLimitRange1.Text = myKeyPad.StringValue;
                        this.ParentForm.ParentForm.CurrentFeedbackItem.HighLimit = myKeyPad.StringValue.Replace(".", "");
                        this.ParentForm.ParentForm.SaveFeedbackItemFile(this.ParentForm.ParentForm.CurrentFeedbackItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);

                        this.ParentForm.ParentForm.Update30000ModbusData();
                        this.ParentForm.ParentForm.ModbusCommonDataSend();

                        this.Clear();
                        this.UpdateFeedbackDisplay(this.ParentForm.ParentForm.CurrentFeedbackItem, this.ParentForm.ParentForm.SystemConfig, this.ParentForm.ParentForm.CurrentProductItem);
                    //}
                }
            }
        }
        private void labelLowLimitRange_Click(object sender, EventArgs e)
        {
            bool saveEnable = false;
            int passRange = 0, deadZone = 0, deadZoneLow = 0;
            string data = "";

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

            passRange = int.Parse(this.ParentForm.ParentForm.CurrentProductItem.PassRange);
            deadZone = int.Parse(this.ParentForm.ParentForm.CurrentFeedbackItem.DeadZone);
            deadZoneLow = passRange - deadZone;

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(deadZoneLow.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    data = string.Format("{0} ~ {1}", Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces), 
                        Helper.StringToDecimalPlaces(deadZoneLow.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces));
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language, data);
                    myMsg.ShowDialog();
                }
                else
                {
                    //if (myKeyPad.doubleValue < Helper.StringToWeight(this.ParentForm.ParentForm.CurrentProductItem.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces))
                    //{
                    //    DialogFormYesNo myMsgYesNo = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig.Language, 7);
                    //    if (myMsgYesNo.ShowDialog() == DialogResult.Yes)
                    //        saveEnable = true;
                    //}
                    //else
                    //    saveEnable = true;

                    //if (saveEnable == true)
                    //{
                        this.labelLowLimitRange.Text = myKeyPad.StringValue;
                        this.labelLowLimitRange1.Text = myKeyPad.StringValue;
                        this.ParentForm.ParentForm.CurrentFeedbackItem.LowLimit = myKeyPad.StringValue.Replace(".", "");
                        this.ParentForm.ParentForm.SaveFeedbackItemFile(this.ParentForm.ParentForm.CurrentFeedbackItem, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);

                        this.ParentForm.ParentForm.Update30000ModbusData();
                        this.ParentForm.ParentForm.ModbusCommonDataSend();

                        this.Clear();
                        this.UpdateFeedbackDisplay(this.ParentForm.ParentForm.CurrentFeedbackItem, this.ParentForm.ParentForm.SystemConfig, this.ParentForm.ParentForm.CurrentProductItem);
                    //}
                }
            }
        }
        #endregion
    }
}
