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

using SmartX;
using INT_PT002.DataStore;
using INT_PT002.Controls;
using INT_PT002.Part11_UserManager;
using INT_PT002.DialogForms;

namespace INT_PT002.Forms
{
    public partial class FormMainDisplay2 : Form
    {
        #region Field
        private int FlagIgnoreCNT;

        private Color ColorProgressOn;
        private Color ColorProgressOff;
        private Color ColorResultPass;
        private Color ColorResultNG;
        private Color ColorResultNone;
        private Color ColorSensorNormal;
        private Color ColorSensorError;

        private Collection<SmartLabel> CollectionLabelResult;
        private Collection<SmartLabel> CollectionLabelPressure;
        private Collection<SmartLabel> CollectionLabelSensorStatus;
        private Collection<SmartProgressBar> CollectionProgressBarLeakRatePerSec;

        private FormMain m_ParentForm;

        private ControlMainDisplay ChildControl;
        #endregion

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

            this.ParentForm = parent;

            this.DefaultSetting();
            this.InitializeData();
        } 
        #endregion

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

        #region Method
        private void DefaultSetting()
        {
            this.FlagIgnoreCNT = 0;

            this.ColorProgressOff = Color.FromArgb(100, 101, 103);
            this.ColorProgressOn = Color.FromArgb(0, 118, 222);
            this.ColorResultPass = Color.FromArgb(39, 200, 64);
            this.ColorResultNG = Color.FromArgb(254, 70, 70);
            this.ColorResultNone = Color.FromArgb(42, 43, 45);
            this.ColorSensorNormal = Color.FromArgb(39, 200, 64);
            this.ColorSensorError = Color.FromArgb(254, 70, 70);

            this.CollectionLabelResult = new Collection<SmartLabel>();
            this.CollectionLabelResult.Clear();
            this.CollectionLabelResult.Add(this.labelResult1);
            this.CollectionLabelResult.Add(this.labelResult2);
            this.CollectionLabelResult.Add(this.labelResult3);
            this.CollectionLabelResult.Add(this.labelResult4);
            this.CollectionLabelResult.Add(this.labelResult5);
            this.CollectionLabelResult.Add(this.labelResult6);
            this.CollectionLabelResult.Add(this.labelResult7);
            this.CollectionLabelResult.Add(this.labelResult8);
            this.CollectionLabelResult.Add(this.labelResult9);
            this.CollectionLabelResult.Add(this.labelResult10);

            this.CollectionLabelPressure = new Collection<SmartLabel>();
            this.CollectionLabelPressure.Clear();
            this.CollectionLabelPressure.Add(this.labelPressure1);
            this.CollectionLabelPressure.Add(this.labelPressure2);
            this.CollectionLabelPressure.Add(this.labelPressure3);
            this.CollectionLabelPressure.Add(this.labelPressure4);
            this.CollectionLabelPressure.Add(this.labelPressure5);
            this.CollectionLabelPressure.Add(this.labelPressure6);
            this.CollectionLabelPressure.Add(this.labelPressure7);
            this.CollectionLabelPressure.Add(this.labelPressure8);
            this.CollectionLabelPressure.Add(this.labelPressure9);
            this.CollectionLabelPressure.Add(this.labelPressure10);

            this.CollectionLabelSensorStatus = new Collection<SmartLabel>();
            this.CollectionLabelSensorStatus.Clear();
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus1);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus2);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus3);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus4);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus5);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus6);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus7);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus8);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus9);
            this.CollectionLabelSensorStatus.Add(this.labelSensorStatus10);

            this.CollectionProgressBarLeakRatePerSec = new Collection<SmartProgressBar>();
            this.CollectionProgressBarLeakRatePerSec.Clear();
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec1);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec2);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec3);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec4);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec5);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec6);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec7);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec8);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec9);
            this.CollectionProgressBarLeakRatePerSec.Add(this.progressBarLeakRatePerSec10);

            this.ChildControl = new ControlMainDisplay(this.ParentForm);
            this.Controls.Add(this.ChildControl);
            this.ChildControl.Location = new Point(0, 118);
            this.ChildControl.BringToFront();
            this.ChildControl.Visible = false;
        }
        private void InitializeData()
        {
            for (int i = 0; i < FormMain.Lane; i++)
            {
                this.CollectionLabelResult[i].Visible = false;
                this.CollectionLabelPressure[i].Text = "0";
                this.CollectionProgressBarLeakRatePerSec[i].Value = 0;
            }
        }

        private bool UI_Invoke(ThreadStart invoker)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    if (this.IsDisposed)
                        return true;

                    this.Invoke(invoker);
                }
                else
                {
                    invoker();
                }

                return true;

            }
            catch (Exception e)
            {
                return false;
            }

        }

        private void Login()
        {
            DialogFormLogOn logOn = new DialogFormLogOn(this.ParentForm);
            if (logOn.ShowDialog() == DialogResult.OK)
            {
                this.DisplayRefresh();
                this.buttonUser.ButtonDown();
                //this.ParentForm.TimerAutomaticLogout(true, this.ParentForm.SystemConfig.AutomaticLogout);

                // Part 11
                this.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Login, "");
            }
            else
            {
                this.buttonUser.ButtonUp();
            }
        }
        public void Logout()
        {
            this.ParentForm.SystemConfig.CURRENT_USER.Status = Define.E_UserStatus.LogOff;
            this.buttonUser.ButtonUp();
            this.DisplayRefresh();

            // Part 11
            this.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Logout, "");
        }
        public void Part11AutomaticLogoutReset()
        {
            //UserManager.UserManager_AutoLogoutTimeoutReset();
        }

        public void CallBackUserListLoginTimeoutDataEvent(UserManager.UserMgr_login_timeout_t user)
        {
            string code = "", message1 = "", message2 = "";
            int warningTime = 0;

            if (user.remainder_time != 0)
            {
                switch (this.ParentForm.SystemConfig.LANGUAGE)
                {
                    case Define.E_LanguageID.Korean:
                        code = "로그인";
                        message1 = "잠시 후에 로그아웃 됩니다";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "Login";
                        message1 = "You will be logged out after a while";
                        message2 = "";
                        break;
                    default:
                        break;
                }

                warningTime = this.ParentForm.FlagAutomaticLogoutWarningTime - 2;

                this.UI_Invoke(delegate
                {
                    DialogFormMessage msg = new DialogFormMessage(Define.E_MessageBoxIcon.Asterisk, code, message1, message2, warningTime);
                    msg.ShowDialog();
                });
            }
            else
            {
                switch (this.ParentForm.SystemConfig.LANGUAGE)
                {
                    case Define.E_LanguageID.Korean:
                        code = "Login";
                        message1 = "자동 로그아웃 되었습니다";
                        message2 = "";
                        break;
                    case Define.E_LanguageID.English:
                        code = "Login";
                        message1 = "automatically logged out";
                        message2 = "";
                        break;
                    default:
                        break;
                }

                // User Logout
                UserManager.UserManager_UserLogout();

                this.UI_Invoke(delegate
                {
                    this.Logout();
                });

                this.UI_Invoke(delegate
                {
                    DialogFormMessage msg = new DialogFormMessage(Define.E_MessageBoxIcon.Asterisk, code, message1, message2, 0);
                    msg.ShowDialog();
                });
            }
        }

        private void GetJudgmentResult(Define.E_JudgmentStatus judg, SmartLabel label)
        {
            string value = "";

            switch (judg)
            {
                case Define.E_JudgmentStatus.None:
                    value = "-";
                    label.BackGroundColor = this.ColorResultNone;
                    break;
                case Define.E_JudgmentStatus.Pass:
                    value = "Pass";
                    label.BackGroundColor = this.ColorResultPass;
                    break;
                case Define.E_JudgmentStatus.Ng:
                    value = "Leak";
                    label.BackGroundColor = this.ColorResultNG;
                    break;
                case Define.E_JudgmentStatus.Error:
                    value = "Empty";
                    label.BackGroundColor = this.ColorResultNone;
                    break;
                default:
                    break;
            }

            if (label.Text != value)
                label.Text = value;
        }

        public void UpdateProcessStatusDisplay(Define.E_ProcessStatus status)
        {
            switch (status)
            {
                case Define.E_ProcessStatus._0_None:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._1_Initial:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._2_ProductEntry:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;

                    // Label Initialize
                    //this.InitializeLabel();
                    break;
                case Define.E_ProcessStatus._3_ChamberConbined:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._4_VacuumStart:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._5_VacuumHold:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._6_Judgment:
                    break;
                case Define.E_ProcessStatus._7_VacuumBreak:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._8_ChamberSeparation:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._9_ProductRelease:
                    this.labelProgress0.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress1.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress2.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress7.RoundRectFillColor = this.ColorProgressOff;
                    this.labelProgress8.RoundRectFillColor = this.ColorProgressOn;
                    break;
                default:
                    break;
            }
        }
        private void UpdateDisplayDotGraphDiff(SmartDraw draw, DiffData diff)
        {
            int iValue = 0;
            double dValue = 0.0;

            // 값 표시 범위
            // 15.000 ~ -2.000  (17.000 ~ 0)
            // 그래프 영역 높이 102
            // 17000 / 102 = 166.666666~
            //dValue = (int.Parse(data.CurrentValueSign + data.CurrentValue) + 2000) / 166.66666;

            if (dValue > 110)
                dValue = 110;
            if (dValue < 1)
                dValue = 1;

            iValue = int.Parse(string.Format("{0:f0}", dValue));
            
            draw.Chart.PutData(iValue);
        }
        private void UpdateDisplayDotGraphDisp(SmartDraw draw, DispData disp)
        {
            int iValue = 0;
            double dValue = 0.0;

            // 값 표시 범위
            // 15.000 ~ -2.000  (17.000 ~ 0)
            // 그래프 영역 높이 102
            // 17000 / 102 = 166.666666~
            //dValue = (int.Parse(data.CurrentValueSign + data.CurrentValue) + 2000) / 166.66666;

            if (dValue > 110)
                dValue = 110;
            if (dValue < 1)
                dValue = 1;

            iValue = int.Parse(string.Format("{0:f0}", dValue));

            draw.Chart.PutData(iValue);
        }
        public void UpdateEquipmentStatusDisplay(Define.E_EquipmentStatus status)
        {
            if (status == Define.E_EquipmentStatus.Start)
            {
                #region Start
                this.labelStart.Visible = true;
                this.labelStop.Visible = false;
                #endregion
            }
            else
            {
                #region Stop
                this.labelStart.Visible = false;
                this.labelStop.Visible = true;
                #endregion
            }
        }
        public void UpdateDisplayAlarmView(AlarmList alarm)
        {
            if (alarm.IsServoEmergencyStop == true)
                this.labelAlarm.Text = "a1_Servo emergency stop";
            if (alarm.IsServo1Alarm == true)
            {
                if(this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a2_Servo1";
            }
            if (alarm.IsServo2Alarm == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a3_Servo2";
            }
            if (alarm.IsServoTorque1AlarmTorque == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a4_Servo1 Torque";
            }
            if (alarm.IsServoTorque2AlarmTorque == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a5_Servo2 Torque";
            }
            if (alarm.IsPressureError == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a6_Pressure";
            }
            if (alarm.CollectionIsSensorBoardError[0] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a7_Sensor board 1";
            }
            if (alarm.CollectionIsSensorBoardError[1] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a8_Sensor board 2";
            }
            if (alarm.CollectionIsSensorBoardError[2] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a9_Sensor board 3";
            }
            if (alarm.CollectionIsSensorBoardError[3] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a10_Sensor board 4";
            }
            if (alarm.CollectionIsSensorBoardError[4] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a11_Sensor board 5";
            }
            if (alarm.CollectionIsSensorBoardError[5] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a12_Sensor board 6";
            }
            if (alarm.CollectionIsSensorBoardError[6] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a13_Sensor board 7";
            }
            if (alarm.CollectionIsSensorBoardError[7] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a14_Sensor board 8";
            }
            if (alarm.CollectionIsSensorBoardError[8] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a15_Sensor board 9";
            }
            if (alarm.CollectionIsSensorBoardError[9] == true)
            {
                if (this.labelAlarm.Text != "")
                    this.labelAlarm.Text += "     ";
                this.labelAlarm.Text += "a16_Sensor board 10";
            }
        }

        private void UpdateProgressBarPressure()
        {

        }
        private void UpdateProgressBarMaxLeakValue()
        {

        }

        public void UpdateDisplayDiffData(Collection<DiffData> datas)
        {
            string[] temp;

            for (int i = 0; i < FormMain.Lane; i++)
            {
                temp = datas[i].SecBufDiff.Split('.');
                this.CollectionProgressBarLeakRatePerSec[i].Value = int.Parse(temp[0]);
            }
        }
        public void UpdateDisplayDispData(Collection<DispData> datas)
        {
           
        }
        public void UpdateDisplayPresData(Collection<PressureData> datas)
        {
            for (int i = 0; i < FormMain.Lane; i++)
            {
                this.CollectionLabelPressure[i].Text = datas[i].WorkingChamber.Trim() + " kPa";
            }
        }
        public void UpdateDisplayJudgmentData(LeakData datas)
        {
            for (int i = 0; i < FormMain.Lane; i++)
            {
                this.GetJudgmentResult(datas.CollJudgment[i], this.CollectionLabelResult[i]);
                this.CollectionLabelResult[i].Visible = true;
            }

            this.ParentForm.TrackingInspectionData(datas);
            this.ChildControl.UpdateStartLeakDataDisplay(datas);
        }

        public void UpdateDisplayTime()
        {
            this.labelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public void DisplayRefresh()
        {
            this.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_FormStore.FormMainDisplay;
            this.ParentForm.SetDisplayMode(Define.E_DisplayMode.Normal);            
        }
        #endregion

        #region Event Handler
        private void labelStop_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
        }
        private void labelStart_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        
        private void buttonDisplayGraph_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(1);
            this.ChildControl.Visible = true;
        }
        private void buttonStart_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.CutInpupt, CommunicationID.MainBoard);

            this.InitializeData();
            this.ChildControl.ClearAllData();
        }
        private void buttonUser_Click(object sender, EventArgs e)
        {

        }
        private void buttonMenu_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentSystemStatus.EquipmentStatus == Define.E_EquipmentStatus.Stop)
            {
                this.ParentForm.ChildFormMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                this.ParentForm.FormChange((int)Define.E_FormStore.FormMenu);
            }
        }

        private void smartDraw1_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(1);
            this.ChildControl.Visible = true;
        }
        private void smartDraw2_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(2);
            this.ChildControl.Visible = true;
        }
        private void smartDraw3_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(3);
            this.ChildControl.Visible = true;
        }
        private void smartDraw4_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(4);
            this.ChildControl.Visible = true;
        }
        private void smartDraw5_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(5);
            this.ChildControl.Visible = true;
        }
        private void smartDraw6_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(6);
            this.ChildControl.Visible = true;
        }
        private void smartDraw7_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(7);
            this.ChildControl.Visible = true;
        }
        private void smartDraw8_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(8);
            this.ChildControl.Visible = true;
        }
        private void smartDraw9_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(9);
            this.ChildControl.Visible = true;
        }
        private void smartDraw10_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(10);
            this.ChildControl.Visible = true;
        }
        private void buttonClear_Click(object sender, EventArgs e)
        {
            this.InitializeData();
            this.ChildControl.ClearAllData();
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            this.ParentForm.CloseSmartUartLink();
            this.ParentForm.Dispose();
            this.ParentForm.Close();
        }
        #endregion
    }
}