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

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

        private Color ColorEnable;
        private Color ColorDisable;

        private Collection<SmartLabel> CollLabelDiff;
        private Collection<SmartLabel> CollLabelDisp;
        private Collection<SmartLabel> CollLabelVacu;
        private Collection<SmartLabel> CollLabelInput;
        private Collection<SmartLabel> CollLabelSbAlarm;
        #endregion

        #region Constructor
        public ControlMenuManualIoTest(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 = "Manual > IO Test";

            this.ColorEnable = Color.Lime;
            this.ColorDisable = Color.Gainsboro;

            this.CollLabelDiff = new Collection<SmartLabel>();
            this.CollLabelDiff.Add(this.labelDiff1);
            this.CollLabelDiff.Add(this.labelDiff2);

            this.CollLabelDisp = new Collection<SmartLabel>();
            this.CollLabelDisp.Add(this.labelDisp1);
            this.CollLabelDisp.Add(this.labelDisp2);

            this.CollLabelVacu = new Collection<SmartLabel>();
            this.CollLabelVacu.Add(this.labelVacuum1);
            this.CollLabelVacu.Add(this.labelVacuum2);

            this.CollLabelSbAlarm = new Collection<SmartLabel>();
            this.CollLabelSbAlarm.Clear();
            this.CollLabelSbAlarm.Add(this.labelSbAlarm1);
            this.CollLabelSbAlarm.Add(this.labelSbAlarm2);

            this.CollLabelInput = new Collection<SmartLabel>();
            this.CollLabelInput.Add(this.labelInput1);
            this.CollLabelInput.Add(this.labelInput2);
            this.CollLabelInput.Add(this.labelInput3);
            this.CollLabelInput.Add(this.labelInput4);
            this.CollLabelInput.Add(this.labelInput4);

            for (int i = 0; i < this.CollLabelDiff.Count; i++)
            {
                this.CollLabelDiff[i].Text = "0.00";
                this.CollLabelDisp[i].Text = "0.00";
                this.CollLabelVacu[i].Text = "0.0";
                this.CollLabelSbAlarm[i].Visible = false;
            }

            for (int i = 0; i < this.CollLabelInput.Count; i++)
                this.CollLabelInput[i].RoundRectFillColor = this.ColorDisable;
        }

        private void OutputCommand(string address, string data)
        {
            string command = "", id = "";
            
            command = CommunicationCommand.IOTest;
            id = CommunicationID.MainBoard;

            this.ParentForm.ParentForm.TransferDataStream(command, id, address, data);
        }
        private void ServoParameterAllRead()
        {
            SmartSplash.Start(SmartSplash.BuiltInLoadingImages.PROCESSING1, 200);
            
            // ServoMotor 1
            this.labelMotor1Origin.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD23);
            this.labelMotorChamber1.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD1);
            this.labelMotorChamber2.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD2);
            this.labelMotorChamber3.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD3);
            this.labelMotorChamber4.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD4);
            this.labelMotorChamber5.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD5);
            this.labelMotorChamber6.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD6);
            this.labelMotorChamber7.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD7);
            this.labelMotorChamber8.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD8);
            this.labelMotorChamber9.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD9);
            this.labelMotorChamber10.Text = this.ParentForm.ParentForm.ServoMotorRead2(1, ServoMotorAddress.CMD10);

            SmartSplash.Finish();

            this.ParentForm.Enabled = true;
        }

        // 변위센서 데이터
        public void UpdateDisplayDispData(Collection<DispData> datas)
        {
            for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EQUIPMENT_LANE; i++)
                this.CollLabelDisp[i].Text = datas[i].RData;
        }
        public void UpdateDisplayDispData1(LeakData1 data)
        {
            this.CollLabelDisp[0].Text = data.DispData.RData;
        }
        public void UpdateDisplayDispData2(LeakData1 data)
        {
            this.CollLabelDisp[1].Text = data.DispData.RData;
        }
        // 차압센서 데이터
        public void UpdateDisplayDiffData(Collection<DiffData> datas)
        {
            for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EQUIPMENT_LANE; i++)
                this.CollLabelDiff[i].Text = datas[i].MAdc;
        }
        public void UpdateDisplayDiffData1(LeakData1 data)
        {
            this.CollLabelDiff[0].Text = data.DiffData.MAdc;
        }
        public void UpdateDisplayDiffData2(LeakData1 data)
        {
            this.CollLabelDiff[1].Text = data.DiffData.MAdc;
        }
        // 압력센서 데이터
        public void UpdateDisplayPresData(Collection<PressureData> datas)
        {
            for (int i = 0; i < this.CollLabelVacu.Count; i++)
                this.CollLabelVacu[i].Text = datas[i].WorkingChamber;
        }
        public void UpdateDisplayPresData1(LeakData1 data)
        {
            this.CollLabelVacu[0].Text = data.PresData.WorkingChamber;
        }
        public void UpdateDisplayPresData2(LeakData1 data)
        {
            this.CollLabelVacu[1].Text = data.PresData.WorkingChamber;
        }

        public void UpdateDisplayInputData(Collection<string> datas)
        {
            Color value = this.ColorDisable;
            for (int i = 0; i < datas.Count; i++)
            {
                if (datas[i] == "0")
                    value = this.ColorDisable;
                else
                    value = this.ColorEnable;

                this.CollLabelInput[i].RoundRectFillColor = value;
            }
        }
        public void UpdateDisplayAlarmView(AlarmList alarm)
        {
            this.CollLabelSbAlarm[0].Visible = alarm.CollectionIsSensorBoardError[0];
            this.CollLabelSbAlarm[1].Visible = alarm.CollectionIsSensorBoardError[1];
            this.CollLabelSbAlarm[2].Visible = alarm.CollectionIsSensorBoardError[2];
            this.CollLabelSbAlarm[3].Visible = alarm.CollectionIsSensorBoardError[3];
            this.CollLabelSbAlarm[4].Visible = alarm.CollectionIsSensorBoardError[4];
            this.CollLabelSbAlarm[5].Visible = alarm.CollectionIsSensorBoardError[5];
            this.CollLabelSbAlarm[6].Visible = alarm.CollectionIsSensorBoardError[6];
            this.CollLabelSbAlarm[7].Visible = alarm.CollectionIsSensorBoardError[7];
            this.CollLabelSbAlarm[8].Visible = alarm.CollectionIsSensorBoardError[8];
            this.CollLabelSbAlarm[9].Visible = alarm.CollectionIsSensorBoardError[9];
        }

        public void DisplayRefresh()
        {
            // 서보설정 읽는동안 Enable = false
            this.ParentForm.Enabled = false;

            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplayMode = Define.E_DisplayModeStore.IOTest;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_EquipmentMode.IOTest);

            // Servo Parameter Read
            this.smartTimer.Start();
        }
        #endregion

        #region Event Handler
        // Output 1~10
        private void buttonOut1_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7701_Output1);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut2_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7702_Output2);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut3_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7703_Output3);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut4_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7704_Output4);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut5_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7705_Output5);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut6_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7706_Output6);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut7_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7707_Output7);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut8_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7708_Output8);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut9_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7709_Output9);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut10_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7710_Output10);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut11_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7711_Output11);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }
        private void buttonOut12_Click(object sender, EventArgs e)
        {
            string address = "", data = "";
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            // adress
            address = Helper.StringBlankFillDigits4(CommunicationAddress._7712_Output12);

            // data
            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                data = Helper.StringBlankFillDigits4("1");
            else
                data = Helper.StringBlankFillDigits4("0");

            this.OutputCommand(address, data);
        }

        // Motor 1
        private void buttonMotor1Origin_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorOrigin, CommunicationID.SubBoard1);
        }
        private void buttonMotor1AlarmClear_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorAlarmReset, CommunicationID.SubBoard1);
        }
        private void buttonMotorChamber1_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard1);
        }
        private void buttonMotorChamber2_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard2);
        }
        private void buttonMotorChamber3_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard3);
        }
        private void buttonMotorChamber4_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard4);
        }
        private void buttonMotorChamber5_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard5);
        }
        private void buttonMotorChamber6_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard6);
        }
        private void buttonMotorChamber7_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard7);
        }
        private void buttonMotorChamber8_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard8);
        }
        private void buttonMotorChamber9_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard9);
        }
        private void buttonMotorChamber10_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard10);
        }
        private void labelMotor1Origin_Click(object sender, EventArgs e)
        {
            string caption = "Motor1 Origin", before = "", after = "";

            before = this.labelMotor1Origin.Text;
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotor1Origin.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD23, myKeyPad.IntValue, this.labelMotor1Origin);
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD12, myKeyPad.IntValue);
                    before = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Origin, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber1_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber1.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber1.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber1.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD1, myKeyPad.IntValue, this.labelMotorChamber1);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber1, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber2_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber2.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber2.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber2.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD2, myKeyPad.IntValue, this.labelMotorChamber2);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber2, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber3_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber3.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber3.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber3.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD3, myKeyPad.IntValue, this.labelMotorChamber3);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber3, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber4_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber4.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber4.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber4.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD4, myKeyPad.IntValue, this.labelMotorChamber4);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber4, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber5_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber5.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber5.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber5.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD5, myKeyPad.IntValue, this.labelMotorChamber5);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber5, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber6_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber6.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber6.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber6.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD6, myKeyPad.IntValue, this.labelMotorChamber6);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber6, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber7_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber7.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber7.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber7.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD7, myKeyPad.IntValue, this.labelMotorChamber7);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber7, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber8_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber8.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber8.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber8.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD8, myKeyPad.IntValue, this.labelMotorChamber8);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber8, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber9_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber9.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber9.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber9.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD9, myKeyPad.IntValue, this.labelMotorChamber9);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber9, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }
        private void labelMotorChamber10_Click(object sender, EventArgs e)
        {
            string caption = "", before = "", after = "";

            before = this.labelMotorChamber10.Text;
            caption = string.Format("{0} Location - {1}", this.buttonMotorChamber10.ButtonText, before);
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(caption, this.labelMotorChamber10.Text, 7, 0, false);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue == 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.LANGUAGE);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ServoMotorWrite2(1, ServoMotorAddress.CMD10, myKeyPad.IntValue, this.labelMotorChamber10);
                    after = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.M_Chamber10, "", before, after);

                    this.ParentForm.ParentForm.ServoMotorWrite1(1, ServoMotorAddress.SaveAllParameters, ServoMotorAddress.EEPROM);
                }
            }
        }

        private void smartTimer_Tick(object sender, EventArgs e)
        {
            this.smartTimer.Stop();

            this.ServoParameterAllRead();

            this.ParentForm.UpdateButtonColor();
        }
        #endregion
    }
}
