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 string MessageBoxRange;

        private int LabelProcess0LocationX;
        private int LabelProcess0LocationY;
        private int LabelProcess0_1LocationX;
        private int LabelProcess0_1LocationY;

        private Color ColorProgressOn;
        private Size SizeProgressOn;
        private Color ColorProgressOff;
        private Size SizeProgressOff;
        private Color ColorResultPass;
        private Color ColorResultNG;
        private Color ColorResultNone;
        private Color ColorSensorNormal;
        private Color ColorSensorError;

        private Collection<SmartLabel> CollectionLabelResult;
        private Collection<SmartLabel> CollectionLabelProgress;
        private Collection<SmartLabel> CollectionLabelProgress2;
        private Collection<SmartLabel> CollectionLabelPressure;
        private Collection<SmartLabel> CollectionLabelLeakRatePerSec;
        private Collection<SmartLabel> CollectionLabelSbAlarm;

        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.MessageBoxRange = "";

            this.ColorProgressOff = Color.FromArgb(231, 231, 231);
            this.SizeProgressOff = new Size(155, 140);
            this.ColorProgressOn = Color.FromArgb(95, 196, 188);
            this.SizeProgressOn = new Size(190, 170);
            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.CollectionLabelProgress = new Collection<SmartLabel>();
            this.CollectionLabelProgress.Clear();
            this.CollectionLabelProgress.Add(this.labelProgress0);
            this.CollectionLabelProgress.Add(this.labelProgress1);
            this.CollectionLabelProgress.Add(this.labelProgress2);
            this.CollectionLabelProgress.Add(this.labelProgress3);
            this.CollectionLabelProgress.Add(this.labelProgress4);
            this.CollectionLabelProgress.Add(this.labelProgress6);
            this.CollectionLabelProgress.Add(this.labelProgress7);
            this.CollectionLabelProgress.Add(this.labelProgress8);

            this.CollectionLabelProgress2 = new Collection<SmartLabel>();
            this.CollectionLabelProgress2.Clear();
            this.CollectionLabelProgress2.Add(this.labelProgress0_1);
            this.CollectionLabelProgress2.Add(this.labelProgress1_1);
            this.CollectionLabelProgress2.Add(this.labelProgress2_1);
            this.CollectionLabelProgress2.Add(this.labelProgress3_1);
            this.CollectionLabelProgress2.Add(this.labelProgress4_1);
            this.CollectionLabelProgress2.Add(this.labelProgress6_1);
            this.CollectionLabelProgress2.Add(this.labelProgress7_1);
            this.CollectionLabelProgress2.Add(this.labelProgress8_1);

            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.CollectionLabelLeakRatePerSec = new Collection<SmartLabel>();
            this.CollectionLabelLeakRatePerSec.Clear();
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec1);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec2);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec3);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec4);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec5);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec6);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec7);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec8);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec9);
            this.CollectionLabelLeakRatePerSec.Add(this.labelLrSec10);

            this.CollectionLabelSbAlarm = new Collection<SmartLabel>();
            this.CollectionLabelSbAlarm.Clear();
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm1);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm2);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm3);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm4);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm5);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm6);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm7);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm8);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm9);
            this.CollectionLabelSbAlarm.Add(this.labelSbAlarm10);

            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;

            this.LabelProcess0LocationX = this.CollectionLabelProgress[0].Location.X;
            this.LabelProcess0LocationY = this.CollectionLabelProgress[0].Location.Y;
            this.LabelProcess0_1LocationX = this.CollectionLabelProgress2[0].Location.X;
            this.LabelProcess0_1LocationY = this.CollectionLabelProgress2[0].Location.Y;

            this.buttonRecipeNo.ButtonText = this.ParentForm.SystemConfig.RECIPE_NUMBER.ToString();
            this.UpdateDisplayUser(this.ParentForm.CurrentSystemStatus.CurrentUser);
        }
        private void InitializeData()
        {
            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                this.CollectionLabelResult[i].Visible = false;
                this.CollectionLabelPressure[i].Text = "0";
                this.CollectionLabelLeakRatePerSec[i].Text = "0";
                this.CollectionLabelSbAlarm[i].Visible = false;
            }
        }
        private void labelImageLocation(Define.E_ProcessStatus process)
        {
            int gap = 219;

            for (int i = 0; i < this.CollectionLabelProgress.Count; i++)
            {
                if (i < this.CollectionLabelProgress.Count / 2)
                {
                    this.CollectionLabelProgress[i].Location = new Point(this.LabelProcess0LocationX + (i * gap), this.LabelProcess0LocationY);
                    this.CollectionLabelProgress2[i].Location = new Point(this.LabelProcess0_1LocationX + (i * gap), this.LabelProcess0_1LocationY);
                }
                else
                {
                    this.CollectionLabelProgress[i].Location = new Point(
                        this.LabelProcess0LocationX + ((this.CollectionLabelProgress.Count - i) * gap), this.LabelProcess0LocationY + 194);
                    this.CollectionLabelProgress2[i].Location = new Point(
                        this.LabelProcess0_1LocationX + ((this.CollectionLabelProgress.Count - i) * gap), this.LabelProcess0_1LocationY + 291);
                }
            }

            switch (process)
            {
                case Define.E_ProcessStatus._0_None:
                    break;
                case Define.E_ProcessStatus._1_Initial:
                    this.CollectionLabelProgress[0].Location = new Point(this.CollectionLabelProgress[0].Location.X - 17, this.CollectionLabelProgress[0].Location.Y - 16);
                    break;
                case Define.E_ProcessStatus._2_ProductEntry:
                    this.CollectionLabelProgress[1].Location = new Point(this.CollectionLabelProgress[1].Location.X - 17, this.CollectionLabelProgress[1].Location.Y - 16);
                    break;
                case Define.E_ProcessStatus._3_ChamberConbined:
                    this.CollectionLabelProgress[2].Location = new Point(this.CollectionLabelProgress[2].Location.X - 17, this.CollectionLabelProgress[2].Location.Y - 16);
                    break;
                case Define.E_ProcessStatus._4_VacuumStart:
                    this.CollectionLabelProgress[3].Location = new Point(this.CollectionLabelProgress[3].Location.X - 17, this.CollectionLabelProgress[3].Location.Y - 16);
                    break;
                case Define.E_ProcessStatus._5_VacuumHold:
                    this.CollectionLabelProgress[4].Location = new Point(this.CollectionLabelProgress[4].Location.X - 17, this.CollectionLabelProgress[4].Location.Y - 15);
                    break;
                case Define.E_ProcessStatus._6_Judgment:
                    break;
                case Define.E_ProcessStatus._7_VacuumBreak:
                    this.CollectionLabelProgress[5].Location = new Point(this.CollectionLabelProgress[5].Location.X - 17, this.CollectionLabelProgress[5].Location.Y - 15);
                    break;
                case Define.E_ProcessStatus._8_ChamberSeparation:
                    this.CollectionLabelProgress[6].Location = new Point(this.CollectionLabelProgress[6].Location.X - 17, this.CollectionLabelProgress[6].Location.Y - 15);
                    break;
                case Define.E_ProcessStatus._9_ProductRelease:
                    this.CollectionLabelProgress[7].Location = new Point(this.CollectionLabelProgress[7].Location.X - 17, this.CollectionLabelProgress[7].Location.Y - 15);
                    break;
                default:
                    break;
            }
        }

        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 UpdateDisplayUser(UserItem user)
        {
            string id = "", group = "";

            if (user.Status == Define.E_UserStatus.NotLogin)
            {
                id = "";
                group = "";

                this.buttonRecipeNo.Enabled = true;
                this.buttonClear.Enabled = true;
                this.buttonInspection.Enabled = true;
                this.buttonMenu.Enabled = true;
            }
            else if (user.Status == Define.E_UserStatus.LogOff)
            {
                id = "LogOff";
                group = "";

                if (this.labelUserLevel.TextColor != this.ParentForm.ColorLogOff)
                    this.labelUserLevel.TextColor = this.labelUserID.TextColor = this.ParentForm.ColorLogOff;

                this.buttonUser.ButtonUp();
                this.buttonRecipeNo.Enabled = false;
                this.buttonClear.Enabled = false;
                this.buttonInspection.Enabled = false;
                this.buttonMenu.Enabled = false;
            }
            else
            {
                id = user.ID;
                group = user.Status.ToString();

                if (this.labelUserLevel.TextColor != this.ParentForm.ColorLogOn)
                    this.labelUserLevel.TextColor = this.labelUserID.TextColor = this.ParentForm.ColorLogOn;

                this.buttonUser.ButtonDown();
                this.buttonRecipeNo.Enabled = user.IsMainRecipeChange;
                this.buttonClear.Enabled = user.IsMainClear;
                this.buttonInspection.Enabled = true;
                this.buttonMenu.Enabled = true;
            }

            if (this.labelUserLevel.Text != group)
                this.labelUserLevel.Text = group;
            if (this.labelUserID.Text != id)
                this.labelUserID.Text = id;
        }
        private void Login()
        {
            DialogFormLogOn logOn = new DialogFormLogOn(this.ParentForm);
            if (logOn.ShowDialog() == DialogResult.OK)
            {
                this.DisplayRefresh();
                this.buttonUser.ButtonDown();
                this.buttonUser.ButtonText = "Logout";
                //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.CurrentSystemStatus.CurrentUser.Status = Define.E_UserStatus.LogOff;
            this.buttonUser.ButtonUp();
            this.buttonUser.ButtonText = "Login";
            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)
        {
            for (int i = 0; i < this.CollectionLabelProgress.Count; i++)
            {
                this.CollectionLabelProgress[i].Size = this.SizeProgressOff;
                this.CollectionLabelProgress[i].RoundRectFillColor = this.ColorProgressOff;
                this.CollectionLabelProgress2[i].BackGroundColor = this.ColorProgressOff;
            }
            this.labelProgress3sec.BackGroundColor = this.ColorProgressOff;
            this.labelProgress4sec.BackGroundColor = this.ColorProgressOff;

            switch (status)
            {
                case Define.E_ProcessStatus._0_None:
                    break;
                case Define.E_ProcessStatus._1_Initial:
                    this.CollectionLabelProgress[0].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[0].RoundRectFillColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[0].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._2_ProductEntry:
                    this.CollectionLabelProgress[1].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[1].RoundRectFillColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[1].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._3_ChamberConbined:
                    this.CollectionLabelProgress[2].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[2].RoundRectFillColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[2].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._4_VacuumStart:
                    this.CollectionLabelProgress[3].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[3].RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress3sec.BackGroundColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[3].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._5_VacuumHold:
                    this.CollectionLabelProgress[4].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[4].RoundRectFillColor = this.ColorProgressOn;
                    this.labelProgress4sec.BackGroundColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[4].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._6_Judgment:
                    break;
                case Define.E_ProcessStatus._7_VacuumBreak:
                    this.CollectionLabelProgress[5].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[5].RoundRectFillColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[5].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._8_ChamberSeparation:
                    this.CollectionLabelProgress[6].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[6].RoundRectFillColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[6].BackGroundColor = this.ColorProgressOn;
                    break;
                case Define.E_ProcessStatus._9_ProductRelease:
                    this.CollectionLabelProgress[7].Size = this.SizeProgressOn;
                    this.CollectionLabelProgress[7].RoundRectFillColor = this.ColorProgressOn;
                    this.CollectionLabelProgress2[7].BackGroundColor = this.ColorProgressOn;
                    break;
                default:
                    break;
            }

            this.labelImageLocation(status);
        }
        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)
        {
            string value = "";

            // ServoEmergencyStop
            if (alarm.IsServoEmergencyStop == true)
                value = "a1_Servo emergency stop     ";
            // Servo1Alarm
            if (alarm.IsServo1Alarm == true)
                value += "a2_Servo1     ";
            // Servo2Alarm
            if (alarm.IsServo2Alarm == true)
                value += "a3_Servo2     ";
            // ServoTorque1AlarmTorque 
            if (alarm.IsServoTorque1AlarmTorque == true)
                value += "a4_Servo1 Torque     ";
            // ServoTorque2AlarmTorque 
            if (alarm.IsServoTorque2AlarmTorque == true)
                value += "a5_Servo2 Torque     ";
            // PressureError
            if (alarm.IsPressureError == true)
                value += "a6_Pressure     ";

            // SB Alarm
            this.CollectionLabelSbAlarm[0].Visible = alarm.CollectionIsSensorBoardError[0];
            this.CollectionLabelSbAlarm[1].Visible = alarm.CollectionIsSensorBoardError[1];
            this.CollectionLabelSbAlarm[2].Visible = alarm.CollectionIsSensorBoardError[2];
            this.CollectionLabelSbAlarm[3].Visible = alarm.CollectionIsSensorBoardError[3];
            this.CollectionLabelSbAlarm[4].Visible = alarm.CollectionIsSensorBoardError[4];
            this.CollectionLabelSbAlarm[5].Visible = alarm.CollectionIsSensorBoardError[5];
            this.CollectionLabelSbAlarm[6].Visible = alarm.CollectionIsSensorBoardError[6];
            this.CollectionLabelSbAlarm[7].Visible = alarm.CollectionIsSensorBoardError[7];
            this.CollectionLabelSbAlarm[8].Visible = alarm.CollectionIsSensorBoardError[8];
            this.CollectionLabelSbAlarm[9].Visible = alarm.CollectionIsSensorBoardError[9];

            value = value.Trim();
            this.labelAlarm.Size = new Size(value.Length * 9, 20);
            this.labelAlarm.Text = value;

            if (this.labelAlarm.Width > 548)
            {
                if (this.labelAlarm.Text != "")
                    this.smartTimerAlarm.Start();
            }
            else
            {
                this.smartTimerAlarm.Stop();
                this.labelAlarm.Location = new Point(3, 27);
            }
        }
        public void UpdateDisplayDiffData(Collection<DiffData> datas)
        {
            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
                this.CollectionLabelLeakRatePerSec[i].Text = datas[i].SecBufDiff;
        }
        public void UpdateDisplayDispData(Collection<DispData> datas)
        {
           
        }
        public void UpdateDisplayPresData(Collection<PressureData> datas)
        {
            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
                this.CollectionLabelPressure[i].Text = datas[i].WorkingChamber.Trim() + " kPa";
        }
        public void UpdateDisplayJudgmentData(LeakData datas)
        {
            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                this.GetJudgmentResult(datas.CollJudgment[i], this.CollectionLabelResult[i]);
                this.CollectionLabelResult[i].Visible = true;
            }

            this.ParentForm.TrackingInspectionData(datas);
            this.ChildControl.UpdateStartLeakDataDisplay(datas);
        }
        public void UpdateDisplayRecipeData(Recipe data)
        {
            this.buttonRecipeNo.ButtonText = data.NUMBER.ToString();
        }
        public void UpdateDisplayTime()
        {
            this.labelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public void DisplayRefresh()
        {
            this.ParentForm.CurrentSystemStatus.CurrentForm = Define.E_FormStore.FormMainDisplay;
            this.ParentForm.CurrentSystemStatus.CurrentDisplayMode = Define.E_DisplayModeStore.MainDisplay;
            this.ParentForm.SetDisplayMode(Define.E_EquipmentMode.Normal);

            this.buttonRecipeNo.ButtonText = this.ParentForm.CurrentRecipe.NUMBER.ToString();

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

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

            this.smartTimerLogin.Start();
        }
        #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 buttonProductNo_Click(object sender, EventArgs e)
        {
            string afterValue = "";

            afterValue = this.buttonRecipeNo.ButtonText;
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad("NUMBER", this.buttonRecipeNo.ButtonText, 4, 0, false);

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

                this.buttonRecipeNo.ButtonText = "**";
                this.ParentForm.TransferRecipeParameter9043(myKeypad.IntValue);
            }
        }
        private void buttonDisplayGraph_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(1);
            this.ChildControl.Visible = true;
        }
        private void buttonInspection_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)
        {
            if (this.ParentForm.CurrentSystemStatus.CurrentUser.Status == Define.E_UserStatus.LogOff)
            {
                this.Login();
            }
            else
            {
                DialogFormYesNo msg = new DialogFormYesNo(this.ParentForm.SystemConfig.LANGUAGE, 12);
                if (msg.ShowDialog() == DialogResult.Yes)
                {
                    this.Logout();
                }
            }
        }
        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();
        }

        private void smartTimerAlarm_Tick(object sender, EventArgs e)
        {
            this.labelAlarm.Left = this.labelAlarm.Left - 5;
            if (this.labelAlarm.Left < 0 - this.labelAlarm.Width - 20)
                this.labelAlarm.Left = this.smartGroupBox1.Width - 10;
        }
        private void smartTimerMessageShow_Tick(object sender, EventArgs e)
        {
            this.smartTimerMessageShow.Stop();

            DialogFormMessage msg = new DialogFormMessage(1, this.ParentForm.SystemConfig.LANGUAGE, this.MessageBoxRange);
            msg.ShowDialog();
        }
        private void smartTimerLogin_Tick(object sender, EventArgs e)
        {
            this.smartTimerLogin.Stop();

            this.Login();
        }
        #endregion

        private void smartButton1_Click(object sender, EventArgs e)
        {
            string value = "";

            this.smartTimerAlarm.Stop();

            value = "a1_Servo emergency stop     ";
            //value += "a2_Servo1     ";
            //value += "a3_Servo2     ";
            //value += "a4_Servo1 Torque     ";
            //value += "a5_Servo2 Torque     ";
            //value += "a6_Pressure     ";

            value = value.Trim();
            this.labelAlarm.Size = new Size(value.Length * 9, 20);
            this.labelAlarm.Text = value;

            if (this.labelAlarm.Width > 548)
            {
                if (this.labelAlarm.Text != "")
                    this.smartTimerAlarm.Start();
            }
            else
            {
                this.smartTimerAlarm.Stop();
                this.labelAlarm.Location = new Point(3, 27);
            }
        }

        private void smartButton2_Click(object sender, EventArgs e)
        {
            string value = "";

            this.smartTimerAlarm.Stop();

            value = "a1_Servo emergency stop     ";
            value += "a2_Servo1     ";
            //value += "a3_Servo2     ";
            //value += "a4_Servo1 Torque     ";
            //value += "a5_Servo2 Torque     ";
            //value += "a6_Pressure     ";

            value = value.Trim();
            this.labelAlarm.Size = new Size(value.Length * 9, 20);
            this.labelAlarm.Text = value;

            if (this.labelAlarm.Width > 548)
            {
                if (this.labelAlarm.Text != "")
                    this.smartTimerAlarm.Start();
            }
            else
            {
                this.smartTimerAlarm.Stop();
                this.labelAlarm.Location = new Point(3, 27);
            }
        }

        private void smartButton3_Click(object sender, EventArgs e)
        {
            string value = "";

            this.smartTimerAlarm.Stop();

            value = "a1_Servo emergency stop     ";
            value += "a2_Servo1     ";
            value += "a3_Servo2     ";
            //value += "a4_Servo1 Torque     ";
            //value += "a5_Servo2 Torque     ";
            //value += "a6_Pressure     ";

            value = value.Trim();
            this.labelAlarm.Size = new Size(value.Length * 9, 20);
            this.labelAlarm.Text = value;

            if (this.labelAlarm.Width > 548)
            {
                if (this.labelAlarm.Text != "")
                    this.smartTimerAlarm.Start();
            }
            else
            {
                this.smartTimerAlarm.Stop();
                this.labelAlarm.Location = new Point(3, 27);
            }
        }

        private void smartButton4_Click(object sender, EventArgs e)
        {
            string value = "";

            this.smartTimerAlarm.Stop();

            value = "a1_Servo emergency stop     ";
            value += "a2_Servo1     ";
            value += "a3_Servo2     ";
            value += "a4_Servo1 Torque     ";
            //value += "a5_Servo2 Torque     ";
            //value += "a6_Pressure     ";

            value = value.Trim();
            this.labelAlarm.Size = new Size(value.Length * 9, 20);
            this.labelAlarm.Text = value;

            if (this.labelAlarm.Width > 548)
            {
                if (this.labelAlarm.Text != "")
                    this.smartTimerAlarm.Start();
            }
            else
            {
                this.smartTimerAlarm.Stop();
                this.labelAlarm.Location = new Point(3, 27);
            }
        }
    }
}