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;
        // 이전 단계 번호(Index 아님) 저장용 변수
        private Define.E_ProcessStatus PreviousStageNum;

        int testIndex;
        private Define.E_ProcessStatus ProcessStatus;

        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<Point> CollectionLabelPoint;
        private Collection<SmartLabel> CollectionLabelResult;
        private Collection<SmartLabel> CollectionLabelProgress;
        private Collection<SmartLabel> CollectionLabelProgress2;
        private Collection<PictureBox> CollectionPictureBoxSelected;
        private Collection<PictureBox> CollectionPictureBoxUnselected;
        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();
            this.InitializeLanguage();
        }
        #endregion

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

        #region Method
        private void DefaultSetting()
        {
            int testIndex = 0;

            this.FlagIgnoreCNT = 0;
            this.MessageBoxRange = "";
            this.ProcessStatus = Define.E_ProcessStatus._0_None;
            this.PreviousStageNum = Define.E_ProcessStatus._0_None;

            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.CollectionLabelPoint = new Collection<Point>();
            this.CollectionLabelPoint.Clear();
            for (int i = 0; i < this.CollectionLabelProgress.Count; i++)
                this.CollectionLabelPoint.Add(new Point(this.CollectionLabelProgress[i].Location.X, this.CollectionLabelProgress[i].Location.Y));

            // 문구가 적힌 라벨
            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);

            // pictureBox - Selected
            this.CollectionPictureBoxSelected = new Collection<PictureBox>();
            this.CollectionPictureBoxSelected.Clear();
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress0Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress1Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress2Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress3Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress4Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress6Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress7Selected);
            this.CollectionPictureBoxSelected.Add(this.pictureBoxProgress8Selected);

            // pictureBox - Unselected
            this.CollectionPictureBoxUnselected = new Collection<PictureBox>();
            this.CollectionPictureBoxUnselected.Clear();
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress0);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress1);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress2);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress3);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress4);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress6);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress7);
            this.CollectionPictureBoxUnselected.Add(this.pictureBoxProgress8);

            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.buttonRecipeNo.ButtonText = this.ParentForm.SystemConfig.RECIPE_NUMBER.ToString();
            this.UpdateDisplayUser(this.ParentForm.CurrentSystemStatus.CurrentUser);
        }
        private void InitializeData()
        {
            for (int i = 0; i < this.ParentForm.SystemConfig.EQUIPMENT_LANE; i++)
            {
                this.CollectionLabelResult[i].Visible = false;
                this.CollectionLabelPressure[i].Text = "0.0";
                this.CollectionLabelLeakRatePerSec[i].Text = "0.0";
                this.CollectionLabelSbAlarm[i].Visible = false;
            }
        }
        private void InitializeLanguage()
        {
            switch (this.ParentForm.SystemConfig.LANGUAGE)
            {
                case Define.E_LanguageID.Korean:
                    this.labelProgress0_1.Text = "초기상태";
                    this.labelProgress1_1.Text = "제품진입";
                    this.labelProgress2_1.Text = "챔버결합";
                    this.labelProgress3_1.Text = "진공시작";
                    this.labelProgress4_1.Text = "검사 진행중";
                    this.labelProgress6_1.Text = "진공파기";
                    this.labelProgress7_1.Text = "챔버분리";
                    this.labelProgress8_1.Text = "배출";
                    break;
                case Define.E_LanguageID.English:
                    this.labelProgress0_1.Text = "Ready";
                    this.labelProgress1_1.Text = "Entry";
                    this.labelProgress2_1.Text = "Linkage";
                    this.labelProgress3_1.Text = "V. Start";
                    this.labelProgress4_1.Text = "Measurement";
                    this.labelProgress6_1.Text = "V. Break";
                    this.labelProgress7_1.Text = "Separation";
                    this.labelProgress8_1.Text = "Release";
                    break;
                default:
                    break;
            }
        }

        private void SelectProcessLabelRefresh(int index)
        {
            this.CollectionLabelProgress[index].Location = new Point(this.CollectionLabelProgress[index].Location.X - 17, this.CollectionLabelProgress[index].Location.Y - 15);
            this.CollectionLabelProgress[index].Size = this.SizeProgressOn;
            this.CollectionLabelProgress[index].RoundRectFillColor = this.ColorProgressOn;
            // 문구가 적히는 label
            this.CollectionLabelProgress2[index].BackGroundColor = this.ColorProgressOn;

            this.CollectionPictureBoxSelected[index].Visible = true;
            this.CollectionPictureBoxSelected[index].BringToFront();
        }
        private void UnselectProcessLabelRefresh(int index)
        {
            this.CollectionLabelProgress[index].Location = this.CollectionLabelPoint[index];
            this.CollectionLabelProgress[index].Size = this.SizeProgressOff;
            this.CollectionLabelProgress[index].RoundRectFillColor = this.ColorProgressOff;
            // 문구가 적히는 label
            this.CollectionLabelProgress2[index].BackGroundColor = this.ColorProgressOff;

            this.CollectionPictureBoxSelected[index].Visible = false;
            this.CollectionPictureBoxUnselected[index].BringToFront();
        }
        private void InitializeProcessLabelRefresh()
        {
            for (int i = 0; i < this.CollectionLabelProgress.Count; i++)
                this.CollectionLabelProgress[i].RoundRectFillColor = this.CollectionLabelProgress[i].RoundRectFillColor;
        }

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

            switch (user.Group)
            {
                case Define.E_UserGroup.None:
                    break;
                case Define.E_UserGroup.Level1:
                    id = user.ID;
                    group = user.Group.ToString();

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

                    this.buttonUser.ButtonDown();
                    this.buttonRecipeNo.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductChange;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear;
                    this.buttonInspection.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    break;
                case Define.E_UserGroup.Level2:
                    id = user.ID;
                    group = user.Group.ToString();

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

                    this.buttonUser.ButtonDown();
                    this.buttonRecipeNo.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductChange;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear;
                    this.buttonInspection.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    break;
                case Define.E_UserGroup.Level3:
                    id = user.ID;
                    group = user.Group.ToString();

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

                    this.buttonUser.ButtonDown();
                    this.buttonRecipeNo.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductChange;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear;
                    this.buttonInspection.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    break;
                case Define.E_UserGroup.Admin:
                    id = user.ID;
                    group = user.Group.ToString();

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

                    this.buttonUser.ButtonDown();
                    this.buttonRecipeNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonInspection.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    break;
                case Define.E_UserGroup.Developer:
                    id = user.ID;
                    group = user.Group.ToString();

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

                    this.buttonUser.ButtonDown();
                    this.buttonRecipeNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonInspection.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    break;
                case Define.E_UserGroup.NotLogin:
                    id = "";
                    group = "";

                    this.buttonRecipeNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonInspection.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    break;
                case Define.E_UserGroup.LogOut:
                    id = "Log Off";
                    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;
                    break;
                default:
                    break;
            }

            this.buttonRecipeNo.ButtonColor = this.ParentForm.ButtonColorChange(this.buttonRecipeNo.Enabled);
            this.buttonClear.ButtonColor = this.ParentForm.ButtonColorChange(this.buttonClear.Enabled);
            this.buttonInspection.ButtonColor = this.ParentForm.ButtonColorChange(this.buttonInspection.Enabled);
            this.buttonMenu.ButtonColor = this.ParentForm.ButtonColorChange(this.buttonMenu.Enabled);

            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, false, false);
            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.Group = Define.E_UserGroup.LogOut;
            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;
        }
        private void ProgressBarSetting(Define.E_ProcessStatus status)
        {
            switch (status)
            {
                case Define.E_ProcessStatus._1_Ready:
                    this.progressBar3.Visible = false;
                    this.progressBar4.Visible = false;
                    this.progressBar6.Visible = false;
                    if (this.smartTimerProgressBar.IsStart == true)
                        this.smartTimerProgressBar.Stop();
                    break;
                case Define.E_ProcessStatus._4_MoveToCheck:
                    this.progressBar3.Maximum = this.ParentForm.CurrentRecipe.VACUUM_RELIEF * 10;
                    this.progressBar3.Value = this.progressBar3.Maximum;

                    this.progressBar3.Visible = true;
                    this.smartTimerProgressBar.Start();
                    break;
                case Define.E_ProcessStatus._5_ChamberMerge:
                    this.progressBar4.Maximum = this.ParentForm.CurrentRecipe.VACUUM_HOLD1 * 10;
                    this.progressBar4.Value = this.progressBar4.Maximum;

                    if (this.smartTimerProgressBar.IsStart == true)
                        this.smartTimerProgressBar.Stop();
                    this.progressBar3.Visible = false;
                    this.progressBar4.Visible = true;
                    this.smartTimerProgressBar.Start();
                    break;
                case Define.E_ProcessStatus._7_VacuumHold:
                    this.progressBar6.Maximum = this.ParentForm.CurrentRecipe.VACUUM_BLOWOFF * 10;
                    this.progressBar6.Value = this.progressBar6.Maximum;

                    if (this.smartTimerProgressBar.IsStart == true)
                        this.smartTimerProgressBar.Stop();
                    this.progressBar4.Visible = false;
                    this.progressBar6.Visible = true;
                    this.smartTimerProgressBar.Start();
                    break;
                case Define.E_ProcessStatus._8_Judgment:
                    if (this.smartTimerProgressBar.IsStart == true)
                        this.smartTimerProgressBar.Stop();
                    this.progressBar6.Visible = false;
                    break;
                default:
                    break;
            }
        }

        public void UpdateProcessStatusDisplay(Define.E_ProcessStatus status)
        {
            this.ProcessStatus = status;

            switch (this.PreviousStageNum)
            {
                case Define.E_ProcessStatus._0_None:
                    break;
                case Define.E_ProcessStatus._1_Ready:
                    for (int i = 0; i < this.CollectionLabelProgress.Count; i++)
                        this.CollectionLabelProgress[i].Location = this.CollectionLabelPoint[i];

                    this.UnselectProcessLabelRefresh(0);
                    break;
                case Define.E_ProcessStatus._2_ProductEntry:
                    this.UnselectProcessLabelRefresh(1);
                    break;
                case Define.E_ProcessStatus._3_MoveToLeak:
                    this.UnselectProcessLabelRefresh(2);
                    break;
                case Define.E_ProcessStatus._4_MoveToCheck:
                    this.UnselectProcessLabelRefresh(3);
                    break;
                case Define.E_ProcessStatus._5_ChamberMerge:
                    this.UnselectProcessLabelRefresh(4);
                    break;
                case Define.E_ProcessStatus._6_VacuumStart:
                    break;
                case Define.E_ProcessStatus._7_VacuumHold:
                    this.UnselectProcessLabelRefresh(5);
                    break;
                case Define.E_ProcessStatus._8_Judgment:
                    this.UnselectProcessLabelRefresh(6);
                    break;
                case Define.E_ProcessStatus._9_VacuumBreak:
                    this.UnselectProcessLabelRefresh(7);
                    break;
                default:
                    break;
            }

            switch (status)
            {
                case Define.E_ProcessStatus._0_None:
                    break;
                case Define.E_ProcessStatus._1_Ready:
                    for (int i = 0; i < this.CollectionLabelProgress.Count; i++)
                        this.CollectionLabelProgress[i].Location = this.CollectionLabelPoint[i];

                    this.SelectProcessLabelRefresh(0);
                    break;
                case Define.E_ProcessStatus._2_ProductEntry:
                    this.SelectProcessLabelRefresh(1);
                    break;
                case Define.E_ProcessStatus._3_MoveToLeak:
                    this.SelectProcessLabelRefresh(2);
                    break;
                case Define.E_ProcessStatus._4_MoveToCheck:
                    this.SelectProcessLabelRefresh(3);
                    break;
                case Define.E_ProcessStatus._5_ChamberMerge:
                    this.SelectProcessLabelRefresh(4);
                    break;
                case Define.E_ProcessStatus._6_VacuumStart:
                    break;
                case Define.E_ProcessStatus._7_VacuumHold:
                    this.SelectProcessLabelRefresh(5);
                    break;
                case Define.E_ProcessStatus._8_Judgment:
                    this.SelectProcessLabelRefresh(6);
                    break;
                case Define.E_ProcessStatus._9_VacuumBreak:
                    this.SelectProcessLabelRefresh(7);
                    break;
                default:
                    break;
            }

            this.PreviousStageNum = status;
            this.ProgressBarSetting(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 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, 30);
            this.labelAlarm.Text = value;

            if (this.labelAlarm.Width > 400)
            {
                if (this.labelAlarm.Text != "")
                    this.smartTimerAlarm.Start();
            }
            else
            {
                this.smartTimerAlarm.Stop();
                this.labelAlarm.Location = new Point(3, 26);
            }
        }
        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;

                this.InitializeData();
                #endregion
            }
        }
        public void UpdateDisplayDiffData(Collection<DiffData> datas)
        {
            for (int i = 0; i < this.ParentForm.SystemConfig.EQUIPMENT_LANE; 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.SystemConfig.EQUIPMENT_LANE; i++)
                this.CollectionLabelPressure[i].Text = datas[i].WorkingChamber.Trim();
        }
        public void UpdateDisplayJudgmentData(LeakData datas)
        {
            for (int i = 0; i < this.ParentForm.SystemConfig.EQUIPMENT_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 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.InitializeProcessLabelRefresh();

            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);

            this.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.EquipmentStart, "");
        }
        private void labelStart_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);

            this.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.EquipmentStop, "");
        }

        private void buttonProductNo_Click(object sender, EventArgs e)
        {
            string before = "", after = "";

            before = 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 = before;
                    this.smartTimerMessageShow.Start();
                    return;
                }

                this.buttonRecipeNo.ButtonText = "**";
                this.ParentForm.TransferRecipeParameter9043(myKeypad.IntValue);
                after = myKeypad.StringValue;

                this.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.RecipeNumber, "", before, after);
            }
        }
        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.Group == Define.E_UserGroup.LogOut)
            {
                this.Login();
            }
            else
            {
                DialogFormYesNo msg = new DialogFormYesNo(this.ParentForm.SystemConfig.LANGUAGE, 12);
                if (msg.ShowDialog() == DialogResult.Yes)
                {
                    this.Logout();
                }
            }
            this.InitializeProcessLabelRefresh();
        }
        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();
        }
        private void smartTimerProgressBar_Tick(object sender, EventArgs e)
        {
            switch (this.ProcessStatus)
            {
                case Define.E_ProcessStatus._4_MoveToCheck:
                    if (this.progressBar3.Value > 0)
                        this.progressBar3.Value -= 10;
                    else
                        this.smartTimerProgressBar.Stop();
                    break;
                case Define.E_ProcessStatus._5_ChamberMerge:
                    if (this.progressBar4.Value > 0)
                        this.progressBar4.Value -= 10;
                    else
                        this.smartTimerProgressBar.Stop();
                    break;
                case Define.E_ProcessStatus._7_VacuumHold:
                    if (this.progressBar6.Value > 0)
                        this.progressBar6.Value -= 10;
                    else
                        this.smartTimerProgressBar.Stop();
                    break;
                default:
                    break;
            }
        }
        #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 * 8, 20);
            this.labelAlarm.Text = value;

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

        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 * 8, 20);
            this.labelAlarm.Text = value;

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

        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 * 8, 20);
            this.labelAlarm.Text = value;

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

        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 * 8, 20);
            this.labelAlarm.Text = value;

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

        private void smartButton5_Click(object sender, EventArgs e)
        {
            switch (this.testIndex)
            {
                case 0:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._1_Ready);
                    break;
                case 1:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._2_ProductEntry);
                    break;
                case 2:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._3_MoveToLeak);
                    break;
                case 3:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._4_MoveToCheck);
                    break;
                case 4:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._5_ChamberMerge);
                    break;
                case 5:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._7_VacuumHold);
                    break;
                case 6:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._8_Judgment);
                    break;
                case 7:
                    this.UpdateProcessStatusDisplay(Define.E_ProcessStatus._9_VacuumBreak);
                    break;
                default:
                    break;
            }

            if (this.testIndex >= 7)
                this.testIndex = 0;
            else
                this.testIndex++;
        }
    }
}