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 INT99DC_7C.Controls;
using INT99DC_7C.DialogForms;
using INT99DC_ImageDll;

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

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

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

            this.ParentForm = parent;
        }
        #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 = "Equipment Test";

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp));
                this.buttonDisplay.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engScreenDisable));
                this.buttonDisplay.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engScreenDown));
                this.buttonDisplay.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engScreenUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.labelTitle.Text = "Equipment Test";

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp));
                this.buttonDisplay.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnScreenDisable));
                this.buttonDisplay.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnScreenDown));
                this.buttonDisplay.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnScreenUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
                this.labelTitle.Text = "Test zařízení";
                this.buttonPosition0.Text = "Pozice 0";
                this.buttonPosition1.Text = "Pozice 1";
                this.buttonPosition2.Text = "Pozice 2";
                this.buttonOrigin.Text = "Původ";
                this.buttonAlarmReset.Text = "Reset alarmu";
                this.buttonStep.Text = "Krok";

                this.buttonCOM3LogOpen.Text = this.buttonLogAdcOpen.Text = this.buttonLogOpen.Text = "Otevřít";
                this.buttonCOM3LogClose.Text = this.buttonLogAdcClose.Text = this.buttonLogClose.Text = "Zavřít";

                this.smartGroupBox1.Text = this.smartLabel1.Text = "Váha";

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp));
                this.buttonDisplay.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeScreenDisable));
                this.buttonDisplay.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeScreenDown));
                this.buttonDisplay.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeScreenUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
            {
                this.labelTitle.Text = "Vorrichtungstest";

                this.smartGroupBox1.Text = "Gewicht";
                this.labelStaticCommLog.Text = "Kommunikationsprotokoll";
                this.labelStaticLog.Text = "Protokoll(ADC)";
                this.labelStaticCOM3CommLog.Text = "COM3 Protokoll";

                this.buttonOrigin.Text = "Ursprung";
                this.buttonAlarmReset.Text = "Alarm-Reset";
                this.buttonStep.Text = "Schritt";

                this.smartLabel1.Text = "Gewicht";

                this.buttonLogAdcOpen.Text = this.buttonLogOpen.Text = this.buttonCOM3LogOpen.Text = "Öffnen";
                this.buttonLogAdcClose.Text = this.buttonLogClose.Text = this.buttonCOM3LogClose.Text = "Schließen";

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp));
                this.buttonDisplay.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerScreenDisable));
                this.buttonDisplay.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerScreenDown));
                this.buttonDisplay.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerScreenUp));
            }
            else
            {

            }
        }
        private void InitializeControl()
        {
            if (this.ParentForm.EquipmentStatus == DataStore.EquipmentStatus.Stop)
            {
                this.pictureBoxStop.Visible = true;
                this.pictureBoxStart.Visible = false;
            }
            else
            {
                this.pictureBoxStop.Visible = false;
                this.pictureBoxStart.Visible = true;
            }

            this.checkBoxCutView.Checked = this.ParentForm.SystemConfig.IsCutView;
        }
        private void DefaultSetting()
        {
            this.ChildControl1 = new ControlEquipmentTest(this);
            this.Controls.Add(this.ChildControl1);
            this.ChildControl1.Location = new Point(0, 70);
            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.CollectionLabelWeightValue.Add(this.labelWeight11);
            this.CollectionLabelWeightValue.Add(this.labelWeight12);
            this.CollectionLabelWeightValue.Add(this.labelWeight13);
            this.CollectionLabelWeightValue.Add(this.labelWeight14);
            this.CollectionLabelWeightValue.Add(this.labelWeight15);

            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.CollectionLabelADC.Add(this.labelADC11);
            this.CollectionLabelADC.Add(this.labelADC12);
            this.CollectionLabelADC.Add(this.labelADC13);
            this.CollectionLabelADC.Add(this.labelADC14);
            this.CollectionLabelADC.Add(this.labelADC15);

            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.CollectionLabelZero.Add(this.labelZero11);
            this.CollectionLabelZero.Add(this.labelZero12);
            this.CollectionLabelZero.Add(this.labelZero13);
            this.CollectionLabelZero.Add(this.labelZero14);
            this.CollectionLabelZero.Add(this.labelZero15);

            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.CollectionLabelSensor.Add(this.labelSensor11);
            this.CollectionLabelSensor.Add(this.labelSensor12);
            this.CollectionLabelSensor.Add(this.labelSensor13);
            this.CollectionLabelSensor.Add(this.labelSensor14);
            this.CollectionLabelSensor.Add(this.labelSensor15);

            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 < 15; 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 UpdateStartWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            this.UpdateStartWeightDisplay1(status, weightDatas[0]);
            this.UpdateStartWeightDisplay2(status, weightDatas[1]);
            this.UpdateStartWeightDisplay3(status, weightDatas[2]);
            this.UpdateStartWeightDisplay4(status, weightDatas[3]);
            this.UpdateStartWeightDisplay5(status, weightDatas[4]);
            this.UpdateStartWeightDisplay6(status, weightDatas[5]);
            this.UpdateStartWeightDisplay7(status, weightDatas[6]);
            this.UpdateStartWeightDisplay8(status, weightDatas[7]);
            this.UpdateStartWeightDisplay9(status, weightDatas[8]);
            this.UpdateStartWeightDisplay10(status, weightDatas[9]);
            this.UpdateStartWeightDisplay11(status, weightDatas[10]);
            this.UpdateStartWeightDisplay12(status, weightDatas[11]);
            this.UpdateStartWeightDisplay13(status, weightDatas[12]);
            this.UpdateStartWeightDisplay14(status, weightDatas[13]);
            this.UpdateStartWeightDisplay15(status, weightDatas[14]);
        }
        public void UpdateStartWeightDisplay1(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 UpdateStartWeightDisplay2(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 UpdateStartWeightDisplay3(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 UpdateStartWeightDisplay4(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 UpdateStartWeightDisplay5(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 UpdateStartWeightDisplay6(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 UpdateStartWeightDisplay7(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 UpdateStartWeightDisplay8(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 UpdateStartWeightDisplay9(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 UpdateStartWeightDisplay10(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 UpdateStartWeightDisplay11(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

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

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

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

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

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

            value = weightData.ADCValue;
            if (this.labelADC13.Text != value)
                this.labelADC13.Text = value;
        }

        public void UpdateStartWeightDisplay14(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

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

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

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

            value = weightData.ADCValue;
            if (this.labelADC15.Text != value)
                this.labelADC15.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] == "1" ? true : false);
        }
        public void UpdateZeroParameterDisplay(DataStore.EquipmentStatus status, ZeroParameterItem item)
        {
            this.ChildControl1.UpdateZeroParameterDisplay(status, item);
        }
        public void UpdateOptionParameterDisplay(DataStore.EquipmentStatus status, OptionParameterItem item)
        {
            this.ChildControl1.UpdateOptionParameterDisplay(status, item);
        }
        public void UpdateCalibrationItemDisplay(DataStore.EquipmentStatus status, CalibrationItem item)
        {
            this.ChildControl1.UpdateCalibrationDisplay(item);
        }

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

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

        #region Override Member
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.DefaultSetting();
            this.InitializeDesign();
            this.InitializeControl();
        }
        #endregion

        #region Event Handler
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.timerAdcLog.Enabled = false;
            this.ParentForm.IsAdcLogOpen = false;
            this.ParentForm.smartFileAdcLog.Close();
            this.labelAdcLogOpen.Visible = false;

            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);
            else if (button == this.buttonZero11)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard11);
            else if (button == this.buttonZero12)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard12);
            else if (button == this.buttonZero13)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard13);
            else if (button == this.buttonZero14)
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard14);
            else 
                this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard15);
        }
        private void buttonLogOpen_Click(object sender, EventArgs e)
        {
            this.ParentForm.smartFileCommunicationLog.Close();
            this.ParentForm.smartFileCommunicationLog.Open(this.ParentForm.BufferSmartUart);

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

            this.ParentForm.smartFileCommunicationLog.Close();
        }
        private void buttonCOM3LogOpen_Click(object sender, EventArgs e)
        {
            this.ParentForm.smartFileCom3Log.Close();
            this.ParentForm.smartFileCom3Log.Open(this.ParentForm.BufferSmartUart);

            this.ParentForm.IsCom3LogOpen = true;
        }
        private void buttonCOM3LogClose_Click(object sender, EventArgs e)
        {
            this.ParentForm.IsCom3LogOpen = false;

            this.ParentForm.smartFileCom3Log.Close();
        }
        private void buttonLogAdcOpen_Click(object sender, EventArgs e)
        {
            this.ParentForm.smartFileAdcLog.Close();
            this.ParentForm.smartFileAdcLog.Open(this.ParentForm.BufferSmartUart);

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

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

            this.ParentForm.smartFileAdcLog.Close();

            this.labelAdcLogOpen.Visible = false;
        }
        private void buttonCOM1LogOpen_Click(object sender, EventArgs e)
        {
            this.ParentForm.smartFileCom1Log.Close();
            this.ParentForm.smartFileCom1Log.Open(this.ParentForm.BufferSmartUart);

            this.ParentForm.IsCom1LogOpen = true;
        }
        private void buttonCOM1LogClose_Click(object sender, EventArgs e)
        {
            this.ParentForm.IsCom1LogOpen = false;

            this.ParentForm.smartFileCom1Log.Close();
        }
        private void buttonOrigin_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorOrigin, CommunicationID.MainBoard);
        }
        private void buttonPosition0_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorPosition0, CommunicationID.MainBoard);
        }
        private void buttonPosition1_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorPosition1, CommunicationID.MainBoard);
        }
        private void buttonPosition2_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorPosition2, CommunicationID.MainBoard);
        }
        private void buttonStep_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorStep, CommunicationID.MainBoard);
        }
        private void buttonAlarmReset_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorAlarmReset, CommunicationID.MainBoard);
        }
        private void buttonDisplay_Click(object sender, EventArgs e)
        {
            if (this.ChildControl1.Visible == false)
            {
                this.ChildControl1.BringToFront();
                this.ChildControl1.Visible = true;
            }
            else
                this.ChildControl1.Visible = false;
        }

        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 checkBoxCutView_Click(object sender, EventArgs e)
        {
            if (this.checkBoxCutView.Checked == true)
                this.ParentForm.SystemConfig.IsCutView = true;
            else
                this.ParentForm.SystemConfig.IsCutView = false;
        }
        #endregion
    }
}