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 INT_PT002.Forms;
using INT_PT002.DataStore;
using INT_PT002.DialogForms;

namespace INT_PT002.Controls
{
    public partial class ControlMenuRecipeSetting : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        private string MessageBoxRange;

        private Collection<SmartLabel> CollLabel;
        #endregion

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

            this.ParentForm = parent;
            this.Initialize();
        }
        #endregion

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

        #region Method
        private void Initialize()
        {
            this.smartGroupBox1.Text = "Recipe > Setting";
            this.MessageBoxRange = "";

            this.CollLabel = new Collection<SmartLabel>();
            this.CollLabel.Add(this.labelNumber);
            this.CollLabel.Add(this.labelPressureLevel);
            this.CollLabel.Add(this.labelDispEmptyLevel);
            this.CollLabel.Add(this.labelDispHoldDelay);
            this.CollLabel.Add(this.labelDispMinLevel);
            this.CollLabel.Add(this.labelDispStdLevel);
            this.CollLabel.Add(this.labelDiffHoldDelay);
            this.CollLabel.Add(this.labelDiffLrMean);
            this.CollLabel.Add(this.labelDiffLrSecond);
            this.CollLabel.Add(this.labelDiffLrTotal);
            this.CollLabel.Add(this.labelVacuumRelief);
            this.CollLabel.Add(this.labelVacuumHold1);
            this.CollLabel.Add(this.labelVacuumHold2);
            this.CollLabel.Add(this.labelVacuumBlowoff);
            this.CollLabel.Add(this.labelLcdDataPeriod);
            this.CollLabel.Add(this.labelChattering);
            this.CollLabel.Add(this.labelCutWait);
            this.CollLabel.Add(this.labelBuzzer);
            this.CollLabel.Add(this.labelSbDiffFilter);
        }

        private void UpdateDisplauUserControls(bool enable)
        {
            for (int i = 0; i < this.CollLabel.Count; i++)
                this.CollLabel[i].Enabled = enable;
        }
        private void UpdateDisplayUser(UserItem user)
        {
            switch (user.Status)
            {
                case Define.E_UserStatus.None:
                    this.UpdateDisplauUserControls(false);
                    break;
                case Define.E_UserStatus.Level1:
                    this.UpdateDisplauUserControls(this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuRecipe);
                    break;
                case Define.E_UserStatus.Level2:
                    this.UpdateDisplauUserControls(this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuRecipe);
                    break;
                case Define.E_UserStatus.Level3:
                    this.UpdateDisplauUserControls(this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuRecipe);
                    break;
                case Define.E_UserStatus.Admin:
                    this.UpdateDisplauUserControls(this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuRecipe);
                    break;
                case Define.E_UserStatus.Developer:
                    this.UpdateDisplauUserControls(true);
                    break;
                case Define.E_UserStatus.NotLogin:
                    this.UpdateDisplauUserControls(false);
                    break;
                case Define.E_UserStatus.LogOff:
                    this.UpdateDisplauUserControls(false);
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayControlData(Recipe item)
        {
            string value = "";

            // Number
            value = item.NUMBER.ToString();
            if (this.labelNumber.Text != value)
                this.labelNumber.Text = value;
            // Pressure Level
            value = item.VACUUM_GUAGE_LEVEL;
            if (this.labelPressureLevel.Text != value)
                this.labelPressureLevel.Text = value;

            // Displacement Sensor
            // STD_Level
            value = item.DISP_JUDG_STD_LEVEL;
            if (this.labelDispStdLevel.Text != value)
                this.labelDispStdLevel.Text = value;
            // Min_Level
            value = item.DISP_JUDG_MIN_LEVEL;
            if (this.labelDispMinLevel.Text != value)
                this.labelDispMinLevel.Text = value;
            // Empty_Level
            value = item.DISP_JUDG_EMPTY_LEVEL;
            if (this.labelDispEmptyLevel.Text != value)
                this.labelDispEmptyLevel.Text = value;
            // Hold_Delay
            value = item.DISP_HOLD_DELAY_MSEC.ToString();
            if (this.labelDispHoldDelay.Text != value)
                this.labelDispHoldDelay.Text = value;

            // Differential Pressure Sensor
            // LR_Second
            value = item.DIFF_LR_SECOND;
            if (this.labelDiffLrSecond.Text != value)
                this.labelDiffLrSecond.Text = value;
            // LR_Total
            value = item.DIFF_LR_TOTAL;
            if (this.labelDiffLrTotal.Text != value)
                this.labelDiffLrTotal.Text = value;
            // LR_Mean
            value = item.DIFF_LR_MEAN;
            if (this.labelDiffLrMean.Text != value)
                this.labelDiffLrMean.Text = value;
            // Hold_Delay
            value = item.DIFF_HOLD_DELAY_MSEC.ToString();
            if (this.labelDiffHoldDelay.Text != value)
                this.labelDiffHoldDelay.Text = value;

            // Pressure data
            // Vacuum Relief
            value = item.VACUUM_RELIEF.ToString();
            if (this.labelVacuumRelief.Text != value)
                this.labelVacuumRelief.Text = value;
            // Vacuum Hold1
            value = item.VACUUM_HOLD1.ToString();
            if (this.labelVacuumHold1.Text != value)
                this.labelVacuumHold1.Text = value;
            // Vacuum Hold2
            value = item.VACUUM_HOLD2.ToString();
            if (this.labelVacuumHold2.Text != value)
                this.labelVacuumHold2.Text = value;
            // Vacuum Blowoff
            value = item.VACUUM_BLOWOFF.ToString();
            if (this.labelVacuumBlowoff.Text != value)
                this.labelVacuumBlowoff.Text = value;
        }
        private void UpdateDisplayControlData(SystemConfiguration item)
        {
            string value = "";

            // LCD data period
            value = item.LCD_DATA_PERIOD.ToString();
            if (this.labelLcdDataPeriod.Text != value)
                this.labelLcdDataPeriod.Text = value;

            // Chattering
            value = item.CHATTERING.ToString();
            if (this.labelChattering.Text != value)
                this.labelChattering.Text = value;

            // Cut wait
            value = item.JUDGMENT_DELAY_MSEC.ToString();
            if (this.labelCutWait.Text != value)
                this.labelCutWait.Text = value;
            
            // Buzzer
            value = item.BUZZER_OP.ToString();
            if (this.labelBuzzer.Text != value)
                this.labelBuzzer.Text = value;

            // Diff filter
            value = item.SB_DIFF_FILTER.ToString();
            if (this.labelSbDiffFilter.Text != value)
                this.labelSbDiffFilter.Text = value;
        }

        public void DisplayRefresh()
        {
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_EquipmentMode.Menu);
            this.UpdateDisplayControlData(this.ParentForm.ParentForm.CurrentRecipe);
            this.UpdateDisplayControlData(this.ParentForm.ParentForm.SystemConfig);

            this.UpdateDisplayUser(this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser);
        }
        #endregion

        #region Event Handler
        private void labelNumber_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = this.labelNumber.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel17.Text, this.labelNumber.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 1 || myKeypad.IntValue > 1000)
                {
                    this.MessageBoxRange = "1 ~ 1000";
                    this.labelPressureLevel.Text = before;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelNumber.Text = "**";
                this.ParentForm.ParentForm.TransferRecipeParameter9043(myKeypad.IntValue);
            }
        }
        private void labelPressureLevel_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelPressureLevel.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel15.Text, this.labelPressureLevel.Text, 5, 1, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue > -50 || myKeypad.doubleValue < -100)
                {
                    this.MessageBoxRange = "-50.0 ~ -100.0";
                    this.labelPressureLevel.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelPressureLevel.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.VACUUM_GUAGE_LEVEL = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits6(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5517_VacuumGaugeStdLevel, value);
            }
        }

        // 밸브
        private void labelVacuumRelief_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelVacuumRelief.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel22.Text, this.labelVacuumRelief.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "0 ~ 9999";
                    this.labelVacuumRelief.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelVacuumRelief.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.VACUUM_RELIEF = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5504_VacuumRelief, value);
            }
        }
        private void labelVacuumHold1_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelVacuumHold1.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel24.Text, this.labelVacuumHold1.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "0 ~ 9999";
                    this.labelVacuumHold1.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelVacuumHold1.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.VACUUM_HOLD1 = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5505_VacuumHold1, value);
            }
        }
        private void labelVacuumHold2_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelVacuumHold2.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel26.Text, this.labelVacuumHold2.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > this.ParentForm.ParentForm.CurrentRecipe.VACUUM_HOLD1 - 1)
                {
                    this.MessageBoxRange = string.Format("0 ~ {0}", this.ParentForm.ParentForm.CurrentRecipe.VACUUM_HOLD1 - 1);
                    this.labelVacuumHold2.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelVacuumHold2.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.VACUUM_HOLD2 = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5506_VacuumHold2, value);
            }
        }
        private void labelVacuumBlowoff_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelVacuumBlowoff.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel2.Text, this.labelVacuumBlowoff.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "0 ~ 9999";
                    this.labelVacuumBlowoff.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelVacuumBlowoff.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.VACUUM_BLOWOFF = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5507_VacuumBlowoff, value);
            }
        }

        // 변위센서
        private void labelDispStdLevel_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDispStdLevel.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel9.Text, this.labelDispStdLevel.Text, 5, 2, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue < 0 || myKeypad.doubleValue > 100)
                {
                    this.MessageBoxRange = "0.00 ~ 100.00";
                    this.labelDispStdLevel.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDispStdLevel.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DISP_JUDG_STD_LEVEL = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits6(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5509_DispStdLevel, value);
            }
        }
        private void labelDispMinLevel_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDispMinLevel.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel7.Text, this.labelDispMinLevel.Text, 5, 2, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue < 0 || myKeypad.doubleValue > 100)
                {
                    this.MessageBoxRange = "0.00 ~ 100.00";
                    this.labelDispMinLevel.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDispMinLevel.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DISP_JUDG_MIN_LEVEL = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits6(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5510_DispMinLevel, value);
            }
        }
        private void labelDispEmptyLevel_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDispEmptyLevel.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel5.Text, this.labelDispEmptyLevel.Text, 5, 2, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue < 0 || myKeypad.doubleValue > 100)
                {
                    this.MessageBoxRange = "0.00 ~ 100.00";
                    this.labelDispEmptyLevel.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDispEmptyLevel.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DISP_JUDG_EMPTY_LEVEL = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits6(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5511_DispEmptyLevel, value);
            }
        }
        private void labelDispHoldDelay_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDispHoldDelay.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel3.Text, this.labelDispHoldDelay.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "0 ~ 9999";
                    this.labelDispHoldDelay.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDispHoldDelay.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DISP_HOLD_DELAY_MSEC = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5512_DispHoldDelay, value);
            }
        }

        // 차압센서
        private void labelDiffLrSecond_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDiffLrSecond.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel13.Text, this.labelDiffLrSecond.Text, 7, 2, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue < 0 || myKeypad.doubleValue > 99999.99)
                {
                    this.MessageBoxRange = "0.00 ~ 99999.99";
                    this.labelDiffLrSecond.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDiffLrSecond.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DIFF_LR_SECOND = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits8(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5513_DiffLrSecond, value);
            }
        }
        private void labelDiffLrTotal_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDiffLrTotal.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel11.Text, this.labelDiffLrTotal.Text, 7, 2, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue < 0 || myKeypad.doubleValue > 99999.99)
                {
                    this.MessageBoxRange = "0.00 ~ 99999.99";
                    this.labelDiffLrTotal.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDiffLrTotal.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DIFF_LR_TOTAL = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits8(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5514_DiffLrTotal, value);
            }
        }
        private void labelDiffLrMean_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDiffLrMean.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel8.Text, this.labelDiffLrMean.Text, 7, 2, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.doubleValue < 0 || myKeypad.doubleValue > 99999.99)
                {
                    this.MessageBoxRange = "0.00 ~ 99999.99";
                    this.labelDiffLrMean.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDiffLrMean.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DIFF_LR_MEAN = myKeypad.StringValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits8(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5515_DiffLrMean, value);
            }
        }
        private void labelDiffHoldDelay_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelDiffHoldDelay.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel4.Text, this.labelDiffHoldDelay.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "0 ~ 9999";
                    this.labelDiffHoldDelay.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelDiffHoldDelay.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.CurrentRecipe.DIFF_HOLD_DELAY_MSEC = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveRecipeFile(this.ParentForm.ParentForm.CurrentRecipe);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5516_DiffHoldDelay, value);
            }
        }

        // SysteConfiguration
        private void labelLcdDataPeriod_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelLcdDataPeriod.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel14.Text, this.labelLcdDataPeriod.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 100 || myKeypad.IntValue > 5000)
                {
                    this.MessageBoxRange = "100 ~ 5000";
                    this.labelLcdDataPeriod.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelLcdDataPeriod.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.SystemConfig.LCD_DATA_PERIOD = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._1710_LcdDataPeriod, value);
            }
        }
        private void labelChattering_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelChattering.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel18.Text, this.labelChattering.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 50 || myKeypad.IntValue > 500)
                {
                    this.MessageBoxRange = "50 ~ 500";
                    this.labelChattering.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelChattering.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.SystemConfig.CHATTERING = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6006_Chattering, value);
            }
        }
        private void labelCutWait_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelCutWait.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel20.Text, this.labelCutWait.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 100 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "100 ~ 9999";
                    this.labelCutWait.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelCutWait.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.SystemConfig.JUDGMENT_DELAY_MSEC = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5508_CuttingWait, value);
            }
        }
        private void labelBuzzer_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelBuzzer.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel23.Text, this.labelBuzzer.Text, 4, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 0 || myKeypad.IntValue > 9999)
                {
                    this.MessageBoxRange = "0 ~ 9999";
                    this.labelBuzzer.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelBuzzer.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.SystemConfig.BUZZER_OP = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6001_BuzzerOP, value);
            }
        }
        private void labelSbDiffFilter_Click(object sender, EventArgs e)
        {
            string value = "", afterValue = "";

            afterValue = this.labelSbDiffFilter.Text;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel27.Text, this.labelSbDiffFilter.Text, 2, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue < 1 || myKeypad.IntValue > 16)
                {
                    this.MessageBoxRange = "1 ~ 16";
                    this.labelSbDiffFilter.Text = afterValue;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.labelSbDiffFilter.Text = myKeypad.StringValue;
                this.ParentForm.ParentForm.SystemConfig.SB_DIFF_FILTER = myKeypad.IntValue;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile(this.ParentForm.ParentForm.SystemConfig);

                value = Helper.StringBlankFillDigits4(myKeypad.StringValue);
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._1706_SbDiffFilter, value);
            }
        }

        private void smartTimerMessageShow_Tick(object sender, EventArgs e)
        {
            this.smartTimerMessageShow.Stop();

            DialogFormMessage msg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE, this.MessageBoxRange);
            msg.ShowDialog();
        }
        #endregion
    }
}
