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 FormMainDisplay1 : Form
    {
        #region Field
        private int FlagIgnoreCNT;

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

        private FormMain m_ParentForm;

        private Collection<SmartLabel> CollectionResult;

        private Collection<SmartLabel> CollectionDispRData;
        private Collection<SmartLabel> CollectionDispMData;
        private Collection<SmartLabel> CollectionDispMDataDiff;
        private Collection<SmartLabel> CollectionDispSTD;

        private Collection<SmartLabel> CollectionDiffMadc;
        private Collection<SmartLabel> CollectionDiffSecDiff;
        private Collection<SmartLabel> CollectionDiffSecSum;
        private Collection<SmartLabel> CollectionDiffMean;

        private Collection<SmartLabel> CollectionPressureWork;
        private Collection<SmartLabel> CollectionPressureMaster;

        private ControlMainDisplay ChildControl;
        #endregion

        #region Constructor
        public FormMainDisplay1(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.Azure;
            this.ColorProgressOn = Color.Lime;
            this.ColorResultPass = Color.Green;
            this.ColorResultNG = Color.Red;
            this.ColorResultNone = Color.Black;

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

            this.CollectionDispRData = new Collection<SmartLabel>();
            this.CollectionDispRData.Add(this.labelDispRData1);
            this.CollectionDispRData.Add(this.labelDispRData2);
            this.CollectionDispRData.Add(this.labelDispRData3);
            this.CollectionDispRData.Add(this.labelDispRData4);
            this.CollectionDispRData.Add(this.labelDispRData5);
            this.CollectionDispRData.Add(this.labelDispRData6);
            this.CollectionDispRData.Add(this.labelDispRData7);
            this.CollectionDispRData.Add(this.labelDispRData8);
            this.CollectionDispRData.Add(this.labelDispRData9);
            this.CollectionDispRData.Add(this.labelDispRData10);

            this.CollectionDispMData = new Collection<SmartLabel>();
            this.CollectionDispMData.Add(this.labelDispMData1);
            this.CollectionDispMData.Add(this.labelDispMData2);
            this.CollectionDispMData.Add(this.labelDispMData3);
            this.CollectionDispMData.Add(this.labelDispMData4);
            this.CollectionDispMData.Add(this.labelDispMData5);
            this.CollectionDispMData.Add(this.labelDispMData6);
            this.CollectionDispMData.Add(this.labelDispMData7);
            this.CollectionDispMData.Add(this.labelDispMData8);
            this.CollectionDispMData.Add(this.labelDispMData9);
            this.CollectionDispMData.Add(this.labelDispMData10);

            this.CollectionDispMDataDiff = new Collection<SmartLabel>();
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff1);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff2);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff3);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff4);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff5);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff6);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff7);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff8);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff9);
            this.CollectionDispMDataDiff.Add(this.labelDispMDataDiff10);

            this.CollectionDispSTD = new Collection<SmartLabel>();
            this.CollectionDispSTD.Add(this.labelDispSTD1);
            this.CollectionDispSTD.Add(this.labelDispSTD2);
            this.CollectionDispSTD.Add(this.labelDispSTD3);
            this.CollectionDispSTD.Add(this.labelDispSTD4);
            this.CollectionDispSTD.Add(this.labelDispSTD5);
            this.CollectionDispSTD.Add(this.labelDispSTD6);
            this.CollectionDispSTD.Add(this.labelDispSTD7);
            this.CollectionDispSTD.Add(this.labelDispSTD8);
            this.CollectionDispSTD.Add(this.labelDispSTD9);
            this.CollectionDispSTD.Add(this.labelDispSTD10);

            this.CollectionDiffMadc = new Collection<SmartLabel>();
            this.CollectionDiffMadc.Add(this.labelDiffMadc1);
            this.CollectionDiffMadc.Add(this.labelDiffMadc2);
            this.CollectionDiffMadc.Add(this.labelDiffMadc3);
            this.CollectionDiffMadc.Add(this.labelDiffMadc4);
            this.CollectionDiffMadc.Add(this.labelDiffMadc5);
            this.CollectionDiffMadc.Add(this.labelDiffMadc6);
            this.CollectionDiffMadc.Add(this.labelDiffMadc7);
            this.CollectionDiffMadc.Add(this.labelDiffMadc8);
            this.CollectionDiffMadc.Add(this.labelDiffMadc9);
            this.CollectionDiffMadc.Add(this.labelDiffMadc10);

            this.CollectionDiffSecDiff = new Collection<SmartLabel>();
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff1);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff2);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff3);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff4);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff5);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff6);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff7);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff8);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff9);
            this.CollectionDiffSecDiff.Add(this.labelDiffSecDiff10);

            this.CollectionDiffSecSum = new Collection<SmartLabel>();
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum1);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum2);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum3);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum4);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum5);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum6);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum7);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum8);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum9);
            this.CollectionDiffSecSum.Add(this.labelDiffSecSum10);

            this.CollectionDiffMean = new Collection<SmartLabel>();
            this.CollectionDiffMean.Add(this.labelDiffMean1);
            this.CollectionDiffMean.Add(this.labelDiffMean2);
            this.CollectionDiffMean.Add(this.labelDiffMean3);
            this.CollectionDiffMean.Add(this.labelDiffMean4);
            this.CollectionDiffMean.Add(this.labelDiffMean5);
            this.CollectionDiffMean.Add(this.labelDiffMean6);
            this.CollectionDiffMean.Add(this.labelDiffMean7);
            this.CollectionDiffMean.Add(this.labelDiffMean8);
            this.CollectionDiffMean.Add(this.labelDiffMean9);
            this.CollectionDiffMean.Add(this.labelDiffMean10);

            this.CollectionPressureWork = new Collection<SmartLabel>();
            this.CollectionPressureWork.Add(this.labelPressureWork1);
            this.CollectionPressureWork.Add(this.labelPressureWork2);
            this.CollectionPressureWork.Add(this.labelPressureWork3);
            this.CollectionPressureWork.Add(this.labelPressureWork4);
            this.CollectionPressureWork.Add(this.labelPressureWork5);
            this.CollectionPressureWork.Add(this.labelPressureWork6);
            this.CollectionPressureWork.Add(this.labelPressureWork7);
            this.CollectionPressureWork.Add(this.labelPressureWork8);
            this.CollectionPressureWork.Add(this.labelPressureWork9);
            this.CollectionPressureWork.Add(this.labelPressureWork10);

            this.CollectionPressureMaster = new Collection<SmartLabel>();
            this.CollectionPressureMaster.Add(this.labelPressureMaster1);
            this.CollectionPressureMaster.Add(this.labelPressureMaster2);
            this.CollectionPressureMaster.Add(this.labelPressureMaster3);
            this.CollectionPressureMaster.Add(this.labelPressureMaster4);
            this.CollectionPressureMaster.Add(this.labelPressureMaster5);
            this.CollectionPressureMaster.Add(this.labelPressureMaster6);
            this.CollectionPressureMaster.Add(this.labelPressureMaster7);
            this.CollectionPressureMaster.Add(this.labelPressureMaster8);
            this.CollectionPressureMaster.Add(this.labelPressureMaster9);
            this.CollectionPressureMaster.Add(this.labelPressureMaster10);

            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 < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                this.CollectionResult[i].Text = "-";
                this.CollectionResult[i].TextColor = this.ColorResultNone;
                this.CollectionResult[i].Font = new Font("New Gulim", 20, FontStyle.Bold);
                this.CollectionDispRData[i].Text = "0.00";
                this.CollectionDispMData[i].Text = "0.00";
                this.CollectionDispMDataDiff[i].Text = "0.00";
                this.CollectionDispSTD[i].Text = "0.00";
                this.CollectionDiffMadc[i].Text = "0.00";
                this.CollectionDiffSecDiff[i].Text = "0.00";
                this.CollectionDiffSecSum[i].Text = "0.00";
                this.CollectionDiffMean[i].Text = "0.00";
                this.CollectionPressureWork[i].Text = "0.0";
                this.CollectionPressureMaster[i].Text = "0.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.CurrentSystemStatus.CurrentUser.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 label2)
        {
            string value = "";

            switch (judg)
            {
                case Define.E_JudgmentStatus.None:
                    value = "-";
                    label2.TextColor = this.ColorResultNone;
                    label2.Font = new Font("New Gulim", 20, FontStyle.Bold);
                    break;
                case Define.E_JudgmentStatus.Pass:
                    value = "Pass";
                    label2.TextColor = this.ColorResultPass;
                    label2.Font = new Font("New Gulim", 20, FontStyle.Bold);
                    break;
                case Define.E_JudgmentStatus.Ng:
                    value = "Leak";
                    label2.TextColor = this.ColorResultNG;
                    label2.Font = new Font("New Gulim", 20, FontStyle.Bold);
                    break;
                case Define.E_JudgmentStatus.Error:
                    value = "Empty";
                    label2.TextColor = this.ColorResultNone;
                    label2.Font = new Font("New Gulim", 20, FontStyle.Bold);
                    break;
                default:
                    break;
            }

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

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

                    this.timerOn.Enabled = false;
                    this.timerOff.Enabled = false;

                    if (this.CollectionResult[0].Text == "검사 중..")
                    {
                        for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
                        {
                            this.CollectionResult[i].Visible = true;
                            this.CollectionResult[i].Text = "-";
                            this.CollectionResult[i].TextColor = this.ColorResultNone;
                            this.CollectionResult[i].Font = new Font("New Gulim", 48, FontStyle.Bold);
                        }
                    }
                    break;
                case Define.E_ProcessStatus._2_ProductEntry:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress8.BackGroundColor = this.ColorProgressOff;

                    // Label Initialize
                    //this.InitializeLabel();
                    break;
                case Define.E_ProcessStatus._3_ChamberConbined:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress8.BackGroundColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._4_VacuumStart:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress8.BackGroundColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._5_VacuumHold:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress8.BackGroundColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._6_Judgment:
                    break;
                case Define.E_ProcessStatus._7_VacuumBreak:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress8.BackGroundColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._8_ChamberSeparation:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOn;
                    this.labelProgress8.BackGroundColor = this.ColorProgressOff;
                    break;
                case Define.E_ProcessStatus._9_ProductRelease:
                    this.labelProgress0.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress1.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress2.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress3.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress4.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress6.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress7.BackGroundColor = this.ColorProgressOff;
                    this.labelProgress8.BackGroundColor = 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 UpdateDisplayDiffData(Collection<DiffData> datas)
        {
            string value = "";
            bool bValue = false;

            if (this.FlagIgnoreCNT == this.ParentForm.SystemConfig.CHART1_DRAW_STEP)
            {
                bValue = true;
                this.FlagIgnoreCNT = 0;
            }
            else
                this.FlagIgnoreCNT++;

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                value = datas[i].MAdc;
                if (this.CollectionDiffMadc[i].Text != value)
                    this.CollectionDiffMadc[i].Text = value;

                value = datas[i].SecBufDiff;
                if (this.CollectionDiffSecDiff[i].Text != value)
                    this.CollectionDiffSecDiff[i].Text = value;

                value = datas[i].SecBufSum;
                if (this.CollectionDiffSecSum[i].Text != value)
                    this.CollectionDiffSecSum[i].Text = value;

                value = datas[i].DiffMean;
                if (this.CollectionDiffMean[i].Text != value)
                    this.CollectionDiffMean[i].Text = value;
            }
        }
        public void UpdateDisplayDispData(Collection<DispData> datas)
        {
            string value = "";
            bool bValue = false;

            if (this.FlagIgnoreCNT == this.ParentForm.SystemConfig.CHART1_DRAW_STEP)
            {
                bValue = true;
                this.FlagIgnoreCNT = 0;
            }
            else
                this.FlagIgnoreCNT++;

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                value = datas[i].RData;
                if (this.CollectionDispRData[i].Text != value)
                    this.CollectionDispRData[i].Text = value;

                value = datas[i].MData;
                if (this.CollectionDispMData[i].Text != value)
                    this.CollectionDispMData[i].Text = value;

                value = datas[i].MDataDiff;
                if (this.CollectionDispMDataDiff[i].Text != value)
                    this.CollectionDispMDataDiff[i].Text = value;

                value = datas[i].STD;
                if (this.CollectionDispSTD[i].Text != value)
                    this.CollectionDispSTD[i].Text = value;
            }
        }
        public void UpdateDisplayPresData(Collection<PressureData> datas)
        {
            string value = "";

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                value = datas[i].WorkingChamber;
                if (this.CollectionPressureWork[i].Text != value)
                    this.CollectionPressureWork[i].Text = value;

                value = datas[i].MasterChamber;
                if (this.CollectionPressureMaster[i].Text != value)
                    this.CollectionPressureMaster[i].Text = value;
            }
        }
        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";
            //}
        }

        public void UpdateDisplayJudgmentData(LeakData datas)
        {
            this.timerOn.Enabled = false;
            this.timerOff.Enabled = false;

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
                this.CollectionResult[i].Visible = true;

            this.UpdateDisplayJudgmentData1(datas);
            this.UpdateDisplayJudgmentData2(datas);
            this.UpdateDisplayJudgmentData3(datas);
            this.UpdateDisplayJudgmentData4(datas);
            this.UpdateDisplayJudgmentData5(datas);
            this.UpdateDisplayJudgmentData6(datas);
            this.UpdateDisplayJudgmentData7(datas);
            this.UpdateDisplayJudgmentData8(datas);
            this.UpdateDisplayJudgmentData9(datas);
            this.UpdateDisplayJudgmentData10(datas);

            this.ChildControl.UpdateStartLeakDataDisplay(datas);
        }
        private void UpdateDisplayJudgmentData1(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[0], this.labelResult1);
        }
        private void UpdateDisplayJudgmentData2(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[1], this.labelResult2);
        }
        private void UpdateDisplayJudgmentData3(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[2], this.labelResult3);
        }
        private void UpdateDisplayJudgmentData4(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[3], this.labelResult4);
        }
        private void UpdateDisplayJudgmentData5(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[4], this.labelResult5);
        }
        private void UpdateDisplayJudgmentData6(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[5], this.labelResult6);
        }
        private void UpdateDisplayJudgmentData7(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[6], this.labelResult7);
        }
        private void UpdateDisplayJudgmentData8(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[7], this.labelResult8);
        }
        private void UpdateDisplayJudgmentData9(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[8], this.labelResult9);
        }
        private void UpdateDisplayJudgmentData10(LeakData data)
        {
            this.GetJudgmentResult(data.CollJudgment[9], this.labelResult10);
        }
        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;
        }
        #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 buttonMenu_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
            this.ParentForm.FormChange((int)Define.E_FormStore.FormMenu);
        }
        private void buttonDisplayGraph_Click(object sender, EventArgs e)
        {
            this.ChildControl.DisplayRefresh(1);
            this.ChildControl.Visible = true;
        }
        private void buttonCut_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.CutInpupt, CommunicationID.MainBoard);

            this.InitializeData();
            this.ChildControl.ClearAllData();

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
            {
                this.CollectionResult[i].Font = new Font("New Gulim", 20, FontStyle.Bold);
                this.CollectionResult[i].Text = "검사 중..";
            }

            this.timerOn.Enabled = true;
        }

        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 timerOn_Tick(object sender, EventArgs e)
        {
            this.timerOn.Enabled = false;

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
                this.CollectionResult[i].Visible = false;

            this.timerOff.Enabled = true;
        }
        private void timerOff_Tick(object sender, EventArgs e)
        {
            this.timerOff.Enabled = false;

            for (int i = 0; i < this.ParentForm.CurrentSystemStatus.EquipmentColumn; i++)
                this.CollectionResult[i].Visible = true;

            this.timerOn.Enabled = true;
        }
        #endregion

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