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

using SmartX;
using INT69DB_2A_ImageDll;
using INT69DB_2A.Controls;
using INT69DB_2A.DialogForms;

namespace INT69DB_2A.Forms
{
    public partial class FormEquipmentTest : Form
    {
        #region Field
        private FormMain m_ParentForm;
        private ControlEquipmentTest ChildControl1;

        private string CurrentAngle;

        private Collection<SmartLabel> CollectionLabelWeightValue;
        private Collection<SmartLabel> CollectionLabelADC;
        private Collection<Label> CollectionLabelZero;
        private Collection<Label> CollectionLabelSensor;
        private Collection<SmartButton> CollectionButtonForward;
        private Collection<SmartButton> CollectionButtonReverse;
        #endregion

        #region Constructor
        public FormEquipmentTest(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeControl();
            this.DefaultSetting();
            // DefaultSetting() 뒤에 InitializeDesign() 놓을 것
            this.InitializeDesign();
        } 
        #endregion

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

        #region Method
        private void InitializeDesign()
        {
            ImageDll images = new ImageDll();

            if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
                this.labelTitle.Text = "Test";
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.labelTitle.Text = "设备测试";

                this.smartGroupBox1.Text = this.smartLabel1.Text = "重量";
                this.smartLabel12.Text = "通信节目播送日记";
                this.smartLabel8.Text = "ADC节目播送日记";

                this.labelTitleCommErrorCount.Text = "Comm Error CNT";

                this.buttonLogOpen.Text = this.buttonAdcLogOpen.Text = "开";
                this.buttonAdcLogClose.Text = this.buttonLogClose.Text = "关闭";
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.labelTitle.Text = "装置テスト";

                this.smartGroupBox1.Text = this.smartLabel1.Text = "重量";

                this.labelTitleCommErrorCount.Text = "通信エラㅡカウント";

                this.groupBoxStick.Text = "インペラㅡ";
                this.labelTitleImpeller.Text = "インペラㅡ";
                this.labelTitleCutInput.Text = "カット信号入力";
                this.checkBoxCutMainDisplayView.Text = "[CUT]ボタンメイン表示";
                this.buttonAllContinue.Text = "継続";
                this.buttonForwardDirection.Text = "順方向";
                this.buttonReverseDirection.Text = "逆方向";

                foreach (SmartButton button in this.CollectionButtonForward)
                    button.Text = "順方向";
                foreach (SmartButton button in this.CollectionButtonReverse)
                    button.Text = "逆方向";
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {

            }
            else
            {

            }
        }
        private void InitializeControl()
        {
        }
        private void DefaultSetting()
        {
            this.ChildControl1 = new ControlEquipmentTest(this);
            this.Controls.Add(this.ChildControl1);
            this.ChildControl1.Location = new Point(0, 60);
            this.ChildControl1.Visible = false;

            this.CollectionLabelWeightValue = new Collection<SmartLabel>();
            this.CollectionLabelWeightValue.Clear();
            this.CollectionLabelWeightValue.Add(this.labelWeight1);
            this.CollectionLabelWeightValue.Add(this.labelWeight2);
            this.CollectionLabelWeightValue.Add(this.labelWeight3);
            this.CollectionLabelWeightValue.Add(this.labelWeight4);
            this.CollectionLabelWeightValue.Add(this.labelWeight5);
            this.CollectionLabelWeightValue.Add(this.labelWeight6);
            this.CollectionLabelWeightValue.Add(this.labelWeight7);
            this.CollectionLabelWeightValue.Add(this.labelWeight8);
            this.CollectionLabelWeightValue.Add(this.labelWeight9);
            this.CollectionLabelWeightValue.Add(this.labelWeight10);

            this.CollectionLabelADC = new Collection<SmartLabel>();
            this.CollectionLabelADC.Clear();
            this.CollectionLabelADC.Add(this.labelADC1);
            this.CollectionLabelADC.Add(this.labelADC2);
            this.CollectionLabelADC.Add(this.labelADC3);
            this.CollectionLabelADC.Add(this.labelADC4);
            this.CollectionLabelADC.Add(this.labelADC5);
            this.CollectionLabelADC.Add(this.labelADC6);
            this.CollectionLabelADC.Add(this.labelADC7);
            this.CollectionLabelADC.Add(this.labelADC8);
            this.CollectionLabelADC.Add(this.labelADC9);
            this.CollectionLabelADC.Add(this.labelADC10);

            this.CollectionLabelZero = new Collection<Label>();
            this.CollectionLabelZero.Clear();
            this.CollectionLabelZero.Add(this.labelZero1);
            this.CollectionLabelZero.Add(this.labelZero2);
            this.CollectionLabelZero.Add(this.labelZero3);
            this.CollectionLabelZero.Add(this.labelZero4);
            this.CollectionLabelZero.Add(this.labelZero5);
            this.CollectionLabelZero.Add(this.labelZero6);
            this.CollectionLabelZero.Add(this.labelZero7);
            this.CollectionLabelZero.Add(this.labelZero8);
            this.CollectionLabelZero.Add(this.labelZero9);
            this.CollectionLabelZero.Add(this.labelZero10);

            this.CollectionLabelSensor = new Collection<Label>();
            this.CollectionLabelSensor.Clear();
            this.CollectionLabelSensor.Add(this.labelSensor1);
            this.CollectionLabelSensor.Add(this.labelSensor2);
            this.CollectionLabelSensor.Add(this.labelSensor3);
            this.CollectionLabelSensor.Add(this.labelSensor4);
            this.CollectionLabelSensor.Add(this.labelSensor5);
            this.CollectionLabelSensor.Add(this.labelSensor6);
            this.CollectionLabelSensor.Add(this.labelSensor7);
            this.CollectionLabelSensor.Add(this.labelSensor8);
            this.CollectionLabelSensor.Add(this.labelSensor9);
            this.CollectionLabelSensor.Add(this.labelSensor10);

            this.CollectionButtonForward = new Collection<SmartButton>();
            this.CollectionButtonForward.Clear();
            this.CollectionButtonForward.Add(this.buttonForwardDirection1);
            this.CollectionButtonForward.Add(this.buttonForwardDirection2);
            this.CollectionButtonForward.Add(this.buttonForwardDirection3);
            this.CollectionButtonForward.Add(this.buttonForwardDirection4);
            this.CollectionButtonForward.Add(this.buttonForwardDirection5);
            this.CollectionButtonForward.Add(this.buttonForwardDirection6);
            this.CollectionButtonForward.Add(this.buttonForwardDirection7);
            this.CollectionButtonForward.Add(this.buttonForwardDirection8);
            this.CollectionButtonForward.Add(this.buttonForwardDirection9);
            this.CollectionButtonForward.Add(this.buttonForwardDirection10);

            this.CollectionButtonReverse = new Collection<SmartButton>();
            this.CollectionButtonReverse.Clear();
            this.CollectionButtonReverse.Add(this.buttonReverseDirection1);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection2);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection3);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection4);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection5);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection6);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection7);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection8);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection9);
            this.CollectionButtonReverse.Add(this.buttonReverseDirection10);

            foreach (SmartLabel label in this.CollectionLabelWeightValue)
                label.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);

            foreach (SmartLabel label in this.CollectionLabelADC)
                label.Text = "0";

            for (int i = 0; i < 10; i++)
            {
                this.CollectionLabelZero[i].Visible = false;
                this.CollectionLabelSensor[i].Visible = false;
            }
        }

        private void TransferDataStreamASetting(string value)
        {
            string length = "";

            length = Helper.StringZeroFillDigits4(value.Length.ToString());

            this.ParentForm.TransferDataStream(CommunicationCommand.BypassToMotor, CommunicationID.MainBoard, CommunicationAddress.None, length + "A" + value);
        }
        private void SetlabelOnOff(Label control, bool isOn)
        {
            if (isOn == true)
            {
                if (control.Visible != true)
                    control.Visible = true;
            }
            else
            {
                if (control.Visible != false)
                    control.Visible = false;
            }
        }

        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            if (status == DataStore.EquipmentStatus.Start)
            {
                this.pictureBoxStart.Visible = true;
                this.pictureBoxStop.Visible = false;
                this.buttonBack.Enabled = false;
            }
            else
            {
                this.pictureBoxStart.Visible = false;
                this.pictureBoxStop.Visible = true;
                this.buttonBack.Enabled = true;
            }
        }
        public void UpdateStopWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            string value = "";

            if (status == DataStore.EquipmentStatus.Stop)
            {
                for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
                {
                    // 중량
                    value = Helper.DoubleToString(weightDatas[i].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                    if (this.CollectionLabelWeightValue[i].Text != value)
                        this.CollectionLabelWeightValue[i].Text = value;

                    // ADC
                    value = weightDatas[i].ADCValue;
                    if (this.CollectionLabelADC[i].Text != value)
                        this.CollectionLabelADC[i].Text = value;

                    // 영점표시
                    if (weightDatas[i].Status == DataStore.WeightStatus.WeightZero)
                        this.CollectionLabelZero[i].Visible = true;
                    else
                        this.CollectionLabelZero[i].Visible = false;
                }
            }
            else
            {
                for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
                {
                    // 영점표시
                    if (weightDatas[i].Status == DataStore.WeightStatus.WeightZero)
                        this.CollectionLabelZero[i].Visible = true;
                    else
                        this.CollectionLabelZero[i].Visible = false;
                }
            }
        }
        public void UpdateUpdateStartWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            this.UpdateUpdateStartWeightDisplay1(status, weightDatas[0]);
            this.UpdateUpdateStartWeightDisplay1(status, weightDatas[1]);
            this.UpdateUpdateStartWeightDisplay1(status, weightDatas[2]);
            this.UpdateUpdateStartWeightDisplay1(status, weightDatas[3]);
            this.UpdateUpdateStartWeightDisplay1(status, weightDatas[4]);
            this.UpdateUpdateStartWeightDisplay1(status, weightDatas[5]);   
        }
        public void UpdateUpdateStartWeightDisplay1(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight1.Text != value)
                this.labelWeight1.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC1.Text != value)
                this.labelADC1.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay2(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight2.Text != value)
                this.labelWeight2.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC2.Text != value)
                this.labelADC2.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay3(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight3.Text != value)
                this.labelWeight3.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC3.Text != value)
                this.labelADC3.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay4(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight4.Text != value)
                this.labelWeight4.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC4.Text != value)
                this.labelADC4.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay5(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight5.Text != value)
                this.labelWeight5.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC5.Text != value)
                this.labelADC5.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay6(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight6.Text != value)
                this.labelWeight6.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC6.Text != value)
                this.labelADC6.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay7(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight7.Text != value)
                this.labelWeight7.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC7.Text != value)
                this.labelADC7.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay8(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight8.Text != value)
                this.labelWeight8.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC8.Text != value)
                this.labelADC8.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay9(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight9.Text != value)
                this.labelWeight9.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC9.Text != value)
                this.labelADC9.Text = value;
        }
        public void UpdateUpdateStartWeightDisplay10(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight10.Text != value)
                this.labelWeight10.Text = value;

            value = weightData.ADCValue;
            if (this.labelADC10.Text != value)
                this.labelADC10.Text = value;
        }
        public void UpdateInputRead(Collection<string> values)
        {
            if (values.Count == 0 || values == null)
                return;

            for (int i = 0; i < this.CollectionLabelSensor.Count; i++)
                this.SetlabelOnOff(this.CollectionLabelSensor[i], values[i + 8] == "1" ? true : false);
        }
        public void UpdateZeroParameterDisplay(DataStore.EquipmentStatus status, ZeroParameterItem item)
        {
            this.ChildControl1.UpdateZeroParameterDisplay(status, item);
        }
        public void UpdateOptionParameterDisplay(DataStore.EquipmentStatus status, OptionParameterItem item, SystemConfigurationItem systemItem)
        {
            this.ChildControl1.UpdateOptionParameterDisplay(status, item, systemItem);
        }
        public void UpdateCalibrationItemDisplay(DataStore.EquipmentStatus status, CalibrationItem item)
        {
            this.ChildControl1.UpdateCalibrationDisplay(item);
        }

        public void DisplayRefresh()
        {
            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormEquipmentTest;

            if (this.ChildControl1 != null)
                this.ChildControl1.DisplayRefresh();

            this.ParentForm.TransferData(CommunicationCommand.ModeEquipmentTest, CommunicationID.MainBoard);
        }
        #endregion

        #region Event Handler
        private void pictureBoxStart_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        private void pictureBoxStop_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
        }

        private void labelIntervalAll_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelIntervalAll.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(280, 90);
            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1000 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
                    myMsg.Location = new Point(168, 192);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelIntervalAll.Text = myKeyPad.doubleValue.ToString();
                }
            }
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.StepMotorType != (int)DataStore.StepMotorType.Moons)
            {
                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR-" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR " + this.labelRotationAngle1.Text + "00");
            }
            else
            {
                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL-" + this.labelRotationAngle1.Text + "00");
            }
        }

        private void checkBoxCutMainDisplayView_Click(object sender, EventArgs e)
        {
            if (this.checkBoxCutMainDisplayView.Checked == true)
                this.ParentForm.SystemConfig.IsCutView = true;
            else
                this.ParentForm.SystemConfig.IsCutView = false;
        }

        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
        }
        private void buttonZero_Click(object sender, EventArgs e)
        {
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            if (button == this.buttonZero1)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard1);
            else if (button == this.buttonZero2)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard2);
            else if (button == this.buttonZero3)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard3);
            else if (button == this.buttonZero4)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard4);
            else if (button == this.buttonZero5)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard5);
            else if (button == this.buttonZero6)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard6);
            else if (button == this.buttonZero7)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard7);
            else if (button == this.buttonZero8)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard8);
            else if (button == this.buttonZero9)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard9);
            else if (button == this.buttonZero10)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard10);
        }
        private void buttonAdcLogOpen_Click(object sender, EventArgs e)
        {
            this.ParentForm.smartFileAdcLog.Close();
            this.ParentForm.smartFileAdcLog.Open();

            this.ParentForm.IsAdcLogOpen = true;
            this.ParentForm.timerAdcLog.Enabled = true;

            this.labelAdcLogOpen.Visible = true;
        }
        private void buttonAdcLogClose_Click(object sender, EventArgs e)
        {
            this.ParentForm.IsAdcLogOpen = false;
            this.ParentForm.timerAdcLog.Enabled = false;

            this.ParentForm.smartFileAdcLog.Close();

            this.labelAdcLogOpen.Visible = false;
        }
        private void buttonLogOpen_Click(object sender, EventArgs e)
        {
            this.ParentForm.IsCommunicationLogOpen = true;

            this.ParentForm.smartFileCommunicationLog.Close();
            this.ParentForm.smartFileCommunicationLog.Open();
        }
        private void buttonLogClose_Click(object sender, EventArgs e)
        {
            this.ParentForm.IsCommunicationLogOpen = true;

            this.ParentForm.smartFileCommunicationLog.Close();
        }

        private void buttonForwardDirection_Click(object sender, EventArgs e)
        {
            string deviceName = "";
            SmartX.SmartButton button = sender as SmartX.SmartButton;

            if (button == null)
                return;

            if (this.ParentForm.SystemConfig.StepMotorType != (int)DataStore.StepMotorType.Moons)
            {
                if (button == this.buttonForwardDirection1)
                    deviceName = "A";
                else if (button == this.buttonForwardDirection2)
                    deviceName = "B";
                else if (button == this.buttonForwardDirection3)
                    deviceName = "C";
                else if (button == this.buttonForwardDirection4)
                    deviceName = "D";
                else if (button == this.buttonForwardDirection5)
                    deviceName = "E";
                else if (button == this.buttonForwardDirection6)
                    deviceName = "F";
                else if (button == this.buttonForwardDirection7)
                    deviceName = "G";
                else if (button == this.buttonForwardDirection8)
                    deviceName = "H";
                else if (button == this.buttonForwardDirection9)
                    deviceName = "I";
                else if (button == this.buttonForwardDirection10)
                    deviceName = "J";

                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A(deviceName + "MR-" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A(deviceName + "MR " + this.labelRotationAngle1.Text + "00");
            }
            else
            {
                if (button == this.buttonForwardDirection1)
                    deviceName = "1";
                else if (button == this.buttonForwardDirection2)
                    deviceName = "2";
                else if (button == this.buttonForwardDirection3)
                    deviceName = "3";
                else if (button == this.buttonForwardDirection4)
                    deviceName = "4";
                else if (button == this.buttonForwardDirection5)
                    deviceName = "5";
                else if (button == this.buttonForwardDirection6)
                    deviceName = "6";
                else if (button == this.buttonForwardDirection7)
                    deviceName = "7";
                else if (button == this.buttonForwardDirection8)
                    deviceName = "8";
                else if (button == this.buttonForwardDirection9)
                    deviceName = "9";
                else if (button == this.buttonForwardDirection10)
                    deviceName = ":";

                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D(deviceName + "FL" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D(deviceName + "FL-" + this.labelRotationAngle1.Text + "00");
            }
        }
        private void buttonReverseDirection_Click(object sender, EventArgs e)
        {
            string deviceName = "";
            SmartX.SmartButton button = sender as SmartX.SmartButton;

            if (button == null)
                return;

            if (this.ParentForm.SystemConfig.StepMotorType != (int)DataStore.StepMotorType.Moons)
            {
                if (button == this.buttonReverseDirection1)
                    deviceName = "A";
                else if (button == this.buttonReverseDirection2)
                    deviceName = "B";
                else if (button == this.buttonReverseDirection3)
                    deviceName = "C";
                else if (button == this.buttonReverseDirection4)
                    deviceName = "D";
                else if (button == this.buttonReverseDirection5)
                    deviceName = "E";
                else if (button == this.buttonReverseDirection6)
                    deviceName = "F";
                else if (button == this.buttonReverseDirection7)
                    deviceName = "G";
                else if (button == this.buttonReverseDirection8)
                    deviceName = "H";
                else if (button == this.buttonReverseDirection9)
                    deviceName = "I";
                else if (button == this.buttonReverseDirection10)
                    deviceName = "J";

                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A(deviceName + "MR " + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A(deviceName + "MR-" + this.labelRotationAngle1.Text + "00");

                //if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                //    this.ParentForm.TransferData(CommunicationCommand.ImpellerMotorForward, deviceName);
                //else
                //    this.ParentForm.TransferData(CommunicationCommand.ImpellerMotorReverse, deviceName);
            }
            else
            {
                if (button == this.buttonReverseDirection1)
                    deviceName = "1";
                else if (button == this.buttonReverseDirection2)
                    deviceName = "2";
                else if (button == this.buttonReverseDirection3)
                    deviceName = "3";
                else if (button == this.buttonReverseDirection4)
                    deviceName = "4";
                else if (button == this.buttonReverseDirection5)
                    deviceName = "5";
                else if (button == this.buttonReverseDirection6)
                    deviceName = "6";
                else if (button == this.buttonReverseDirection7)
                    deviceName = "7";
                else if (button == this.buttonReverseDirection8)
                    deviceName = "8";
                else if (button == this.buttonReverseDirection9)
                    deviceName = "9";
                else if (button == this.buttonReverseDirection10)
                    deviceName = ":";

                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D(deviceName + "FL-" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D(deviceName + "FL" + this.labelRotationAngle1.Text + "00");
            }
        }

        private void buttonForwardDirectionAll_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.StepMotorType != (int)DataStore.StepMotorType.Moons)
            {
                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR-" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR " + this.labelRotationAngle1.Text + "00");
            }
            else
            {
                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL-" + this.labelRotationAngle1.Text + "00");
            }
        }
        private void buttonReverseDirectionAll_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.StepMotorType != (int)DataStore.StepMotorType.Moons)
            {
                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR " + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR-" + this.labelRotationAngle1.Text + "00");
            }
            else
            {
                if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL-" + this.labelRotationAngle1.Text + "00");
                else
                    this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL" + this.labelRotationAngle1.Text + "00");
            }
        }

        private void labelRotationAngle1_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelRotationAngle1.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 360)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelRotationAngle1.Text = myKeyPad.StringValue;
                    if (this.ParentForm.SystemConfig.StepMotorType == (int)DataStore.StepMotorType.Moons)
                        this.ParentForm.ChildFormMotorSetting.TransferDirectETX0x0D("FL" + this.labelRotationAngle1.Text + "00");
                    else if (this.ParentForm.SystemConfig.StepMotorType == (int)DataStore.StepMotorType.MDrive)
                        this.ParentForm.ChildFormMotorSetting.TransferDirectSTXETX0x0A("*MR" + this.labelRotationAngle1.Text + "00");
                    //else if (this.ParentForm.SystemConfig.StepMotorType == (int)DataStore.StepMotorType.EDB_ALL_P)
                    //    this.ParentForm.ChildFormMotorSetting.TransferDirectToEDBMotor
                    //        (this.ParentForm.ChildFormMotorSetting.SendCommand((byte)1, 9, 0, 2, 2));
                }
            }
        }
        private void buttonFeedingConveyor_Click(object sender, EventArgs e)
        {
            if (this.buttonFeedingConveyor.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, "7705", Helper.StringZeroFillDigits4("1"));
            else
                this.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, "7705", Helper.StringZeroFillDigits4("0"));
        }
        private void buttonRejectConveyorCW_Click(object sender, EventArgs e)
        {
            if (this.buttonRejectConveyorCW.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.buttonRejectConveyorCCW.Enabled = false;

                this.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, "7707", Helper.StringZeroFillDigits4("1"));
            }
            else
            {
                this.buttonRejectConveyorCCW.Enabled = true;

                this.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, "7707", Helper.StringZeroFillDigits4("0"));
            }
        }
        private void buttonRejectConveyorCCW_Click(object sender, EventArgs e)
        {
            if (this.buttonRejectConveyorCCW.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.buttonRejectConveyorCW.Enabled = false;

                this.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, "7708", Helper.StringZeroFillDigits4("1"));
            }
            else
            {
                this.buttonRejectConveyorCW.Enabled = true;

                this.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, "7708", Helper.StringZeroFillDigits4("0"));
            }
        }
        private void buttonCut_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.CutInput, CommunicationID.MainBoard);
        } 
        private void buttonAllContinue_Click(object sender, EventArgs e)
        {
            if (this.buttonAllContinue.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                this.timer.Interval = int.Parse(this.labelIntervalAll.Text);
                this.timer.Enabled = true;

                //this.buttonBack.Enabled = false;
                this.buttonForwardDirection.Enabled = false;
                this.buttonReverseDirection.Enabled = false;

                foreach (SmartButton button in this.CollectionButtonForward)
                    button.Enabled = false;
                foreach (SmartButton button in this.CollectionButtonReverse)
                    button.Enabled = false;
            }
            else
            {
                this.timer.Enabled = false;

                //this.buttonBack.Enabled = true;
                this.buttonForwardDirection.Enabled = true;
                this.buttonReverseDirection.Enabled = true;

                foreach (SmartButton button in this.CollectionButtonForward)
                    button.Enabled = true;
                foreach (SmartButton button in this.CollectionButtonReverse)
                    button.Enabled = true;
            }
        }
        private void buttonScreen_Click(object sender, EventArgs e)
        {
            if (this.ChildControl1.Visible == false)
            {
                this.ChildControl1.BringToFront();
                this.ChildControl1.Visible = true;
            }
            else
                this.ChildControl1.Visible = false;
        }
        #endregion
    }
}