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

using SmartX;
using INT89DB_26_ImageDll;
using INT89DB_26.Controls;
using INT89DB_26.DialogForms;

namespace INT89DB_26.Forms
{
    public partial class FormMainDisplay : Form
    {
        #region Field
        private FormMain m_ParentForm;

        private Color ColorButtonAccessTrue;
        private Color ColorButtonAccessFalse;

        private ControlMainDisplayAlarm MainDisplayAlarmList;
        private ControlFeedback MainDisplayFeedback;

        private ControlMainDisplay2 MainDisplay2;
        private ControlMainDisplay3 MainDisplay3;
        private ControlMainDisplay4 MainDisplay4;
        private ControlMainDisplay5 MainDisplay5;
        private ControlMainDisplay6 MainDisplay6;
        #endregion

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

            this.ParentForm = parent;
        }
        #endregion

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

        #region Method
        /// <summary>
        /// 언어별 화면 디자인
        /// </summary>
        private void InitializeDesign()
        {
            Class1 images = new Class1();

            if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Korean)
            {
                if (this.ParentForm.SystemConfig.IsLogin == true)
                {
                    this.buttonMenu.Location = new Point(743, 525);

                    this.buttonMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korMainDisplayMenuDisable));
                    this.buttonMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korMainDisplayMenuDown));
                    this.buttonMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korMainDisplayMenuUp));
                }
                else
                {
                    this.buttonMenu.Location = new Point(687, 525);

                    this.buttonMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korMainDisplayMenuBigDisable));
                    this.buttonMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korMainDisplayMenuBigDown));
                    this.buttonMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korMainDisplayMenuBigUp));
                }
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.English)
            {
                this.labelStaticRow.Text = "Lane";
                this.labelStaticUnder.Text = "Under";
                this.labelStaticPass.Text = "Pass";
                this.labelStaticOver.Text = "Over";
                this.labelStaticSum.Text = "Total";

                this.groupBoxSorter.Text = "Sorter settings";
                this.labelStaticSorterDelayTime.Text = "Delay time";
                this.labelStaticSorterRunTime.Text = "Run time";

                this.buttonClose.Text = "Close";

                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayClearUp));
                if (this.ParentForm.SystemConfig.IsLogin == true)
                {
                    this.buttonMenu.Location = new Point(743, 525);

                    this.buttonMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayMenuDisable));
                    this.buttonMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayMenuDown));
                    this.buttonMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayMenuUp));
                }
                else
                {
                    this.buttonMenu.Location = new Point(687, 525);

                    this.buttonMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayMenuBigDisable));
                    this.buttonMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayMenuBigDown));
                    this.buttonMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplayMenuBigUp));
                }
                this.buttonSubMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplaySubMenuDisable));
                this.buttonSubMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplaySubMenuDown));
                this.buttonSubMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engMainDisplaySubMenuUp));

                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBypassCountUp));

                this.buttonOver.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainOverDisable));
                this.buttonOver.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainOverDown));
                this.buttonOver.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainOverUp));
                this.buttonPass.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainPassDisable));
                this.buttonPass.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainPassDown));
                this.buttonPass.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainPassUp));
                this.buttonTare.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainTareDisable));
                this.buttonTare.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainTareDown));
                this.buttonTare.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainTareUp));
                this.buttonUnder.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainUnderDisable));
                this.buttonUnder.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainUnderDown));
                this.buttonUnder.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainUnderUp));                
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
            {
                this.labelStaticRow.Text = "列";
                this.labelStaticUnder.Text = "低于";
                this.labelStaticPass.Text = "通过";
                this.labelStaticOver.Text = "超过";
                this.labelStaticExNG.Text = "其他不良";
                this.labelStaticSum.Text = "总共";

                this.labelStaticTotalCount.Text = "计数";
                this.smartLabel3.Text = "不良";

                this.labelTitleBypass.Text = "旁路";

                this.groupBoxSorter.Text = "筛选设定";
                this.labelStaticSorterDelayTime.Text = "延迟时间";
                this.labelStaticSorterRunTime.Text = "运行时间";

                this.buttonClose.Text = "关闭";
                
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayLogOutUp));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayLoginUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayClearUp));
                if (this.ParentForm.SystemConfig.IsLogin == true)
                {
                    this.buttonMenu.Location = new Point(743, 525);

                    this.buttonMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayMenuDisable));
                    this.buttonMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayMenuDown));
                    this.buttonMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayMenuUp));
                }
                else
                {
                    this.buttonMenu.Location = new Point(687, 525);

                    this.buttonMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayMenuBigDisable));
                    this.buttonMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayMenuBigDown));
                    this.buttonMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplayMenuBigUp));
                }
                this.buttonSubMenu.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplaySubMenuDisable));
                this.buttonSubMenu.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplaySubMenuDown));
                this.buttonSubMenu.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDisplaySubMenuUp));

                this.buttonBypassDirection.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassOccasionDown));
                this.buttonBypassDirection.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassOccasionUp));
                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassCountUp));

                this.buttonOver.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainOverDisable));
                this.buttonOver.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainOverDown));
                this.buttonOver.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainOverUp));
                this.buttonPass.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainPassDisable));
                this.buttonPass.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainPassDown));
                this.buttonPass.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainPassUp));
                this.buttonTare.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainTareDisable));
                this.buttonTare.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainTareDown));
                this.buttonTare.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainTareUp));
                this.buttonUnder.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainUnderDisable));
                this.buttonUnder.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainUnderDown));
                this.buttonUnder.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormMainUnderUp));           
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
            {

            }
            else
            {

            }
        }
        private void InitializeControl()
        {
            if (this.ParentForm.IsBootingComplete == false)
                this.buttonProductNo.Text = "**";
            else
                this.buttonProductNo.Text = this.ParentForm.SystemConfig.ProductNumber.ToString();

            this.buttonUnder.Text = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.UnderRange, this.ParentForm.SystemConfig.DecimalPlaces);
            this.buttonPass.Text = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.PassRange, this.ParentForm.SystemConfig.DecimalPlaces);
            this.buttonOver.Text = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.OverRange, this.ParentForm.SystemConfig.DecimalPlaces);
            this.buttonTare.Text = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.TareRange, this.ParentForm.SystemConfig.DecimalPlaces);

            this.labelProductName.Text = this.ParentForm.CurrentProductItem.Name;
            this.labelLotNo.Text = this.ParentForm.CurrentProductItem.LotNo;

            this.pictureBoxUSBBackOn.Visible = this.ParentForm.SystemConfig.IsDataBackup;
           
            if (this.ParentForm.SystemConfig.Serial3Mode == 0)
                this.labelIconSerial3.Visible = false;
            else
                this.labelIconSerial3.Visible = true;

            this.labelIconBypassMode.Visible = this.ParentForm.SystemConfig.IsBypassMode;

            this.MainDisplayAlarmList = new ControlMainDisplayAlarm();
            this.Controls.Add(this.MainDisplayAlarmList);
            this.MainDisplayAlarmList.Location = new Point(539, 59);
            this.MainDisplayAlarmList.Visible = false;

            if (this.ParentForm.SystemConfig.IsFeedback == true)
            {
                this.MainDisplayFeedback = new ControlFeedback(this);
                this.Controls.Add(this.MainDisplayFeedback);
                this.MainDisplayFeedback.Location = new Point(0, 64);
                this.MainDisplayFeedback.Visible = false;

                this.UpdateDisplayFeedbackVisible();
            }
            this.buttonFeedback.Visible = this.ParentForm.SystemConfig.IsFeedback;

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2 = new ControlMainDisplay2(this);
                    this.MainDisplay2.Location = new Point(0, 90);

                    this.Controls.Add(this.MainDisplay2);
                    break;
                case 3:
                    this.MainDisplay3 = new ControlMainDisplay3(this);
                    this.MainDisplay3.Location = new Point(0, 90);

                    this.Controls.Add(this.MainDisplay3);
                    break;
                case 4:
                    this.MainDisplay4 = new ControlMainDisplay4(this);
                    this.MainDisplay4.Location = new Point(0, 90);

                    this.Controls.Add(this.MainDisplay4);
                    break;
                case 5:
                    this.MainDisplay5 = new ControlMainDisplay5(this);
                    this.MainDisplay5.Location = new Point(0, 90);

                    this.Controls.Add(this.MainDisplay5);
                    break;
                case 6:
                    this.MainDisplay6 = new ControlMainDisplay6(this);
                    this.MainDisplay6.Location = new Point(0, 90);

                    this.Controls.Add(this.MainDisplay6);
                    break;
                default:
                    break;
            }
        }
        private void DefaultSetting()
        {
            this.RescaleProgressBar();

            this.ColorButtonAccessTrue = Color.Black;
            this.ColorButtonAccessFalse = Color.DimGray;

            this.panelSetting.Location = new Point(60, 91);
            this.panelSetting.Visible = false;

            this.panelSubMenu.Location = new Point(10, 525);
            this.panelSubMenu.Visible = false;
            this.panelSubMenu.BringToFront();

            // buttonBypassDirection
            if (this.ParentForm.SystemConfig.IsBypassDirectionPass == true)
                this.buttonBypassDirection.ButtonUp();
            else
                this.buttonBypassDirection.ButtonDown();

            // buttonBypassOnce
            if (this.ParentForm.SystemConfig.IsBypassOnce == true)
            {
                this.buttonBypassOnce.ButtonUp();
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.NORMAL;
            }
            else
            {
                this.buttonBypassOnce.ButtonDown();
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.PUSH;
            }

            // Login
            if (this.ParentForm.SystemConfig.IsLogin == true)
                this.UpdateDisplayUser(this.ParentForm.SystemConfig.CurrentUser);
            else
            {
                this.buttonUser.Visible = false;
                this.labelUserID.Visible = false;
                this.labelUserLevel.Visible = false;

                this.ParentForm.SystemConfig.CurrentUser.Group = DataStore.UserGroup.Level3Manager;
            }

            // Ethernet 
            if (this.ParentForm.SystemConfig.IsEthernetEnable == false)
            {
                this.pictureBoxEthernetConnection.Visible = false;
                this.pictureBoxEthernetDisconnection.Visible = false;
            }
            else
            {
                this.pictureBoxEthernetConnection.Visible = false;
                this.pictureBoxEthernetDisconnection.Visible = true;
            }
        }

        private void RescaleProgressBar()
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2.RescaleProgressBar();
                    break;
                case 3:
                    this.MainDisplay3.RescaleProgressBar();
                    break;
                case 4:
                    this.MainDisplay4.RescaleProgressBar();
                    break;
                case 5:
                    this.MainDisplay5.RescaleProgressBar();
                    break;
                case 6:
                    this.MainDisplay6.RescaleProgressBar();
                    break;
                default:
                    break;
            }
        }
        private void UpdateDisplayUser(User user)
        {
            string id = "", group = "";
            Color colorButtonText;

            switch (user.Group)
            {
                case DataStore.UserGroup.Level1Operator:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别1";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň1`";
                    else
                        group = "Level1";

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

                    this.buttonUser.ButtonDown();
                    this.buttonProductNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    this.buttonSubMenu.Enabled = false;
                    this.buttonUnder.Enabled = false;
                    this.buttonPass.Enabled = false;
                    this.buttonOver.Enabled = false;
                    this.buttonTare.Enabled = false;
                    this.buttonFeedback.Enabled = false;

                    colorButtonText = this.ColorButtonAccessFalse;
                    break;
                case DataStore.UserGroup.Level2Engineer:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别2";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň2`";
                    else
                        group = "Level2";

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

                    this.buttonUser.ButtonDown();
                    this.buttonProductNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    this.buttonSubMenu.Enabled = true;
                    this.buttonUnder.Enabled = true;
                    this.buttonPass.Enabled = true;
                    this.buttonOver.Enabled = true;
                    this.buttonTare.Enabled = true;
                    this.buttonFeedback.Enabled = true;

                    colorButtonText = this.ColorButtonAccessTrue;
                    break;
                case DataStore.UserGroup.Level3Manager:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别3";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň3`";
                    else
                        group = "Level3";

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

                    this.buttonUser.ButtonDown();
                    this.buttonProductNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    this.buttonSubMenu.Enabled = true;
                    this.buttonUnder.Enabled = true;
                    this.buttonPass.Enabled = true;
                    this.buttonOver.Enabled = true;
                    this.buttonTare.Enabled = true;
                    this.buttonFeedback.Enabled = true;

                    colorButtonText = this.ColorButtonAccessTrue;
                    break;
                case DataStore.UserGroup.Level4Developer:
                    id = user.ID;
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "级别4";
                    else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
                        group = "Úroveň4`";
                    else
                        group = "Level4";

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

                    this.buttonUser.ButtonDown();
                    this.buttonProductNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.buttonMenu.Enabled = true;
                    this.buttonSubMenu.Enabled = true;
                    this.buttonUnder.Enabled = true;
                    this.buttonPass.Enabled = true;
                    this.buttonOver.Enabled = true;
                    this.buttonTare.Enabled = true;
                    this.buttonFeedback.Enabled = true;

                    colorButtonText = this.ColorButtonAccessTrue;
                    break;
                case DataStore.UserGroup.LogOff:
                    id = "";
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "关闭";
                    else
                        group = "Off";

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

                    this.buttonUser.ButtonUp();
                    this.buttonProductNo.Enabled = false;
                    this.buttonClear.Enabled = false;
                    this.buttonMenu.Enabled = false;
                    this.buttonSubMenu.Enabled = false;
                    this.buttonUnder.Enabled = false;
                    this.buttonPass.Enabled = false;
                    this.buttonOver.Enabled = false;
                    this.buttonTare.Enabled = false;
                    this.buttonFeedback.Enabled = false;

                    colorButtonText = this.ColorButtonAccessFalse;
                    break;
                default:
                    id = "";
                    if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
                        group = "关闭";
                    else
                        group = "Off";

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

                    this.buttonUser.ButtonUp();
                    this.buttonProductNo.Enabled = false;
                    this.buttonClear.Enabled = false;
                    this.buttonMenu.Enabled = false;
                    this.buttonUnder.Enabled = false;
                    this.buttonPass.Enabled = false;
                    this.buttonOver.Enabled = false;
                    this.buttonTare.Enabled = false;
                    this.buttonFeedback.Enabled = false;

                    colorButtonText = this.ColorButtonAccessFalse;
                    break;
            }

            if (this.labelUserLevel.Text != group)
                this.labelUserLevel.Text = group;
            if (this.labelUserID.Text != id)
                this.labelUserID.Text = id;

            if (this.buttonUnder.TextColor != colorButtonText)
            {
                this.buttonUnder.TextColor = colorButtonText;
                this.buttonPass.TextColor = colorButtonText;
                this.buttonOver.TextColor = colorButtonText;
                this.buttonTare.TextColor = colorButtonText;
            }
        }

        public void UpdateDisplayFeedbackVisible()
        {
            // Feedback
            this.MainDisplayFeedback.UpdateFeedbackBoardVisible(this.ParentForm.SystemConfig.IsFeedbackBoard);
        }
        public void UpdateCurrentProductDisplay(DataStore.EquipmentStatus status, ProductItem pItem, JudgmentSetItem jItem,Collection<WeightData> weightDatas)
        {
            string value = "";

            value = pItem.Number.ToString();
            if (this.buttonProductNo.Text != value)
                this.buttonProductNo.Text = value;

            value = pItem.Name;
            if (this.labelProductName.Text != value)
                this.labelProductName.Text = value;

            value = pItem.LotNo;
            if (this.labelLotNo.Text != value)
                this.labelLotNo.Text = value;

            value = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.UnderRange, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.buttonUnder.Text != value)
                this.buttonUnder.Text = value;

            value = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.PassRange, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.buttonPass.Text != value)
                this.buttonPass.Text = value;

            value = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.OverRange, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.buttonOver.Text != value)
                this.buttonOver.Text = value;

            value = Helper.StringToDecimalPlaces(this.ParentForm.CurrentProductItem.TareRange, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.buttonTare.Text != value)
                this.buttonTare.Text = value;

            value = jItem.Sorter1DelayTime.ToString();
            if (this.labelSorterDelayTime.Text != value)
                this.labelSorterDelayTime.Text = value;

            value = jItem.Sorter1RunTime.ToString();
            if (this.labelSorterRunTime.Text != value)
                this.labelSorterRunTime.Text = value;

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    if (this.MainDisplay2 != null)
                        this.MainDisplay2.UpdateCurrentProductDisplay(status, weightDatas);
                    break;
                case 3:
                    if (this.MainDisplay3 != null)
                        this.MainDisplay3.UpdateCurrentProductDisplay(status, weightDatas);
                    break;
                case 4:
                    if (this.MainDisplay4 != null)
                        this.MainDisplay4.UpdateCurrentProductDisplay(status, weightDatas);
                    break;
                case 5:
                    if (this.MainDisplay5 != null)
                        this.MainDisplay5.UpdateCurrentProductDisplay(status, weightDatas);
                    break;
                case 6:
                    if (this.MainDisplay6 != null)
                        this.MainDisplay6.UpdateCurrentProductDisplay(status, weightDatas);
                    break;
                default:
                    break;
            }

            this.RescaleProgressBar();

            if (this.ParentForm.SystemConfig.IsLogin == false)
            {
                this.buttonProductNo.Enabled = true;
                this.buttonMenu.Enabled = true;
                this.buttonSubMenu.Enabled = true;
                this.buttonUnder.Enabled = true;
                this.buttonPass.Enabled = true;
                this.buttonOver.Enabled = true;
                this.buttonTare.Enabled = true;
            }
        }
        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            if (status == DataStore.EquipmentStatus.Start)
            {
                #region Start
                this.pictureBoxStart.Visible = true;
                this.pictureBoxStop.Visible = false;
                this.buttonProductNo.Enabled = false;
                this.labelProductName.Enabled = false;

                switch (this.ParentForm.SystemConfig.EquipmentColumns)
                {
                    case 2:
                        this.MainDisplay2.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 3:
                        this.MainDisplay3.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 4:
                        this.MainDisplay4.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 5:
                        this.MainDisplay5.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 6:
                        this.MainDisplay6.UpdateEquipmentStatusDisplay(status);
                        break;
                    default:
                        break;
                } 
                #endregion
            }
            else
            {
                #region Stop
                this.ParentForm.SaveCounterFile(this.ParentForm.CollectionWeightData, this.ParentForm.SystemConfig.ProductNumber - 1);

                this.pictureBoxStart.Visible = false;
                this.pictureBoxStop.Visible = true;
                this.buttonProductNo.Enabled = true;
                this.labelProductName.Enabled = true;

                if (this.panelSetting.Visible == true)
                    this.panelSetting.Visible = false;

                switch (this.ParentForm.SystemConfig.EquipmentColumns)
                {
                    case 2:
                        this.MainDisplay2.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 3:
                        this.MainDisplay3.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 4:
                        this.MainDisplay4.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 5:
                        this.MainDisplay5.UpdateEquipmentStatusDisplay(status);
                        break;
                    case 6:
                        this.MainDisplay6.UpdateEquipmentStatusDisplay(status);
                        break;
                    default:
                        break;
                } 
                #endregion
            }
        }
        public void UpdateStopWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            if(this.ParentForm.SystemConfig.IsFeedback == true)
                this.MainDisplayFeedback.UpdateStopWeightDisplay(status, weightDatas);

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2.UpdateStopWeightDisplay(status, weightDatas);
                    break;
                case 3:
                    this.MainDisplay3.UpdateStopWeightDisplay(status, weightDatas);
                    break;
                case 4:
                    this.MainDisplay4.UpdateStopWeightDisplay(status, weightDatas);
                    break;
                case 5:
                    this.MainDisplay5.UpdateStopWeightDisplay(status, weightDatas);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStopWeightDisplay(status, weightDatas);
                    break;
                default:
                    break;
            }
        }
        public void UpdateUpdateStartWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2.UpdateStartWEightDisplay(status, weightDatas);
                    break;
                case 3:
                    this.MainDisplay3.UpdateStartWEightDisplay(status,weightDatas);
                    break;
                case 4:
                    this.MainDisplay4.UpdateStartWEightDisplay(status, weightDatas);
                    break;
                case 5:
                    this.MainDisplay5.UpdateStartWEightDisplay(status, weightDatas);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWEightDisplay(status, weightDatas);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }
        public void UpdateUpdateStartWeightDisplay1(DataStore.EquipmentStatus status, WeightData weightData)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2.UpdateStartWeightDisplay1(status, weightData);
                    break;
                case 3:
                    this.MainDisplay3.UpdateStartWeightDisplay1(status, weightData);
                    break;
                case 4:
                    this.MainDisplay4.UpdateStartWeightDisplay1(status, weightData);
                    break;
                case 5:
                    this.MainDisplay5.UpdateStartWeightDisplay1(status, weightData);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWeightDisplay1(status, weightData);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }
        public void UpdateUpdateStartWeightDisplay2(DataStore.EquipmentStatus status, WeightData weightData)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2.UpdateStartWeightDisplay2(status, weightData);
                    break;
                case 3:
                    this.MainDisplay3.UpdateStartWeightDisplay2(status, weightData);
                    break;
                case 4:
                    this.MainDisplay4.UpdateStartWeightDisplay2(status, weightData);
                    break;
                case 5:
                    this.MainDisplay5.UpdateStartWeightDisplay2(status, weightData);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWeightDisplay2(status, weightData);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }
        public void UpdateUpdateStartWeightDisplay3(DataStore.EquipmentStatus status, WeightData weightData)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    break;
                case 3:
                    this.MainDisplay3.UpdateStartWeightDisplay3(status, weightData);
                    break;
                case 4:
                    this.MainDisplay4.UpdateStartWeightDisplay3(status, weightData);
                    break;
                case 5:
                    this.MainDisplay5.UpdateStartWeightDisplay3(status, weightData);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWeightDisplay3(status, weightData);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }
        public void UpdateUpdateStartWeightDisplay4(DataStore.EquipmentStatus status, WeightData weightData)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    this.MainDisplay4.UpdateStartWeightDisplay4(status, weightData);
                    break;
                case 5:
                    this.MainDisplay5.UpdateStartWeightDisplay4(status, weightData);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWeightDisplay4(status, weightData);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }
        public void UpdateUpdateStartWeightDisplay5(DataStore.EquipmentStatus status, WeightData weightData)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    this.MainDisplay5.UpdateStartWeightDisplay5(status, weightData);
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWeightDisplay5(status, weightData);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }
        public void UpdateUpdateStartWeightDisplay6(DataStore.EquipmentStatus status, WeightData weightData)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    this.MainDisplay6.UpdateStartWeightDisplay6(status, weightData);
                    break;
                default:
                    break;
            }

            this.SetTotalCount();
        }

        public void ClearRefreshFeedbackDisplay()
        {
            if (this.ParentForm.SystemConfig.IsFeedback == true)
            {
                this.MainDisplayFeedback.Clear();
                this.MainDisplayFeedback.UpdateFeedbackDisplay(this.ParentForm.CurrentFeedbackItem, this.ParentForm.SystemConfig, this.ParentForm.CurrentProductItem);
                for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
                    this.ParentForm.Update30000ModbusData(i);
            }
        }
        public void UpdateFeedbackDataDisplay(DataStore.EquipmentStatus status, Collection<FeedBackSystem> feedbackData, Collection<WeightData> weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay(status, feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay(status, weightData);
            }
        }
        public void UpdateFeedbackDataDisplay1(DataStore.EquipmentStatus status, FeedBackSystem feedbackData, WeightData weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay1(feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay1(status, weightData);
            }
        }
        public void UpdateFeedbackDataDisplay2(DataStore.EquipmentStatus status, FeedBackSystem feedbackData, WeightData weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay2(feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay2(status, weightData);
            }
        }
        public void UpdateFeedbackDataDisplay3(DataStore.EquipmentStatus status, FeedBackSystem feedbackData, WeightData weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay3(feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay3(status, weightData);
            }
        }
        public void UpdateFeedbackDataDisplay4(DataStore.EquipmentStatus status, FeedBackSystem feedbackData, WeightData weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay4(feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay4(status, weightData);
            }
        }
        public void UpdateFeedbackDataDisplay5(DataStore.EquipmentStatus status, FeedBackSystem feedbackData, WeightData weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay5(feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay5(status, weightData);
            }
        }
        public void UpdateFeedbackDataDisplay6(DataStore.EquipmentStatus status, FeedBackSystem feedbackData, WeightData weightData)
        {
            if (this.MainDisplayFeedback != null)
            {
                this.MainDisplayFeedback.UpdateFeedbackDataDisplay6(feedbackData);
                this.MainDisplayFeedback.UpdateStartWeightDisplay6(status, weightData);
            }
        }
        public void UpdateFeedbackBoardStatusDisplay(bool booting)
        {
            if (this.MainDisplayFeedback != null)
                this.MainDisplayFeedback.UpdateBoardStatusDisplay(booting);
        }

        public void UpdateDisplayAlarmView(AlarmList alarm)
        {
            this.MainDisplayAlarmList.listBoxMessage.Items.Clear();

            if (alarm.IsCurrentAlarm == false)
            {
                this.pictureBoxIconAlarm.Visible = false;
                this.MainDisplayAlarmList.Visible = false;
            }
            else
            {
                this.pictureBoxIconAlarm.Visible = true;

                if (alarm.IsLoadcellError == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("LoadCell Error");
                if (alarm.IsPressureError == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Pressure Error");
                if (alarm.IsDoorAlarm == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Door Interlock");

                if (alarm.IsRejectAlarm == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Reject Alarm");
                if (alarm.IsEmergencyStop == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Emergency Stop");

                if (alarm.IsInverterAlarm == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Inverter Alarm");
                if (alarm.IsServoAlarm == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Servo Alarm");
                if (alarm.IsCommunicationError == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Communication Error");
                if (alarm.IsServoTorqueAlarm == true)
                    this.MainDisplayAlarmList.listBoxMessage.Items.Add("Servo Torque Alarm");
            }
        }
        public void UpdateEthernetStatusDisplay(bool status)
        {
            if (status == true)
            {
                this.pictureBoxEthernetConnection.Visible = true;
                this.pictureBoxEthernetDisconnection.Visible = false;
            }
            else
            {
                this.pictureBoxEthernetConnection.Visible = false;
                this.pictureBoxEthernetDisconnection.Visible = true;
            }
        }

        public void UpdateDisplayTime()
        {
            this.labelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        public void SetTotalCount()
        {
            int toTalAll = 0, toTalPass = 0, toTalNG = 0;

            for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
            {
                toTalAll += this.ParentForm.CollectionWeightData[i].TotalCount;
                toTalPass += this.ParentForm.CollectionWeightData[i].PassCount;
                toTalNG += this.ParentForm.CollectionWeightData[i].TotalNGCount;
            }

            // Total All Count
            // Total Pass Count
            if (this.labelStaticTotalCount.Text == "Pass")
            {
                if (this.labelTotalCount.Text != toTalPass.ToString())
                    this.labelTotalCount.Text = toTalPass.ToString();
            }
            else
            {
                if (this.labelTotalCount.Text != toTalAll.ToString())
                    this.labelTotalCount.Text = toTalAll.ToString();
            }

            // Total NG Count
            if (this.labelTotalNGCount.Text != toTalNG.ToString())
                this.labelTotalNGCount.Text = toTalNG.ToString();
        }
        public void TimerServer(bool value)
        {
            if (value == false)
            {
                if (this.timerServer.Enabled == true)
                    this.timerServer.Enabled = false;
            }
            else
            {
                if (this.timerServer.Enabled == false)
                    this.timerServer.Enabled = true;
            }
        }
        public void Clear()
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.MainDisplay2.Clear();
                    break;
                case 3:
                    this.MainDisplay3.Clear();
                    break;
                case 4:
                    this.MainDisplay4.Clear();
                    break;
                case 5:
                    this.MainDisplay5.Clear();
                    break;
                case 6:
                    this.MainDisplay6.Clear();
                    break;
                default:
                    break;
            }
        }
        public void ProductChange(int productNumber)
        {
            this.buttonProductNo.Text = "**";

            this.buttonProductNo.Enabled = false;
            this.buttonMenu.Enabled = false;
            this.buttonSubMenu.Enabled = false;
            this.buttonUnder.Enabled = false;
            this.buttonPass.Enabled = false;
            this.buttonOver.Enabled = false;
            this.buttonTare.Enabled = false;
            //this.panelSubMenu.Visible = false;

            this.ParentForm.TransferProductParameter(productNumber);
        }
        public void UpdateUnderRangeChange(string weight)
        {
            string value = "";
           
            this.buttonUnder.Text = weight;
            this.ParentForm.CurrentProductItem.UnderRange = weight.Replace(".", "");
            this.ParentForm.SaveProductFile(this.ParentForm.CurrentProductItem, this.ParentForm.SystemConfig.ProductNumber - 1);

            value = Helper.StringZeroFillDigits7(this.ParentForm.CurrentProductItem.UnderRange);
            this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.UnderRange, value);

            this.RescaleProgressBar();
        }
        public void UpdatePassRangeChange(string weight)
        {
            string value = "";
           
            this.buttonPass.Text = weight;
            this.ParentForm.CurrentProductItem.PassRange = weight.Replace(".", "");
            this.ParentForm.SaveProductFile(this.ParentForm.CurrentProductItem, this.ParentForm.SystemConfig.ProductNumber - 1);

            value = Helper.StringZeroFillDigits7(this.ParentForm.CurrentProductItem.PassRange);
            this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PassRange, value);

            this.RescaleProgressBar();
        }
        public void UpdateOverRangeChange(string weight)
        {
            string value = "";

            this.buttonOver.Text = weight;
            this.ParentForm.CurrentProductItem.OverRange = weight.Replace(".", "");
            this.ParentForm.SaveProductFile(this.ParentForm.CurrentProductItem, this.ParentForm.SystemConfig.ProductNumber - 1);

            value = Helper.StringZeroFillDigits7(this.ParentForm.CurrentProductItem.OverRange);
            this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.OverRange, value);

            this.RescaleProgressBar();
        }
        public void UpdateTareRangeChange(string weight)
        {
            string value = "";

            this.buttonTare.Text = weight;
            this.ParentForm.CurrentProductItem.TareRange = weight.Replace(".", "");
            this.ParentForm.SaveProductFile(this.ParentForm.CurrentProductItem, this.ParentForm.SystemConfig.ProductNumber - 1);

            value = Helper.StringZeroFillDigits7(this.ParentForm.CurrentProductItem.TareRange);
            this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.TareRange, value);
        }

        public void DisplayRefresh()
        {
            this.ParentForm.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard);
            this.ParentForm.SystemConfig.CurrentForm = DataStore.E_FormStore.FormMainDisplay;
            this.UpdateDisplayUser(this.ParentForm.SystemConfig.CurrentUser);

            if (this.ParentForm.EquipmentStatus == DataStore.EquipmentStatus.Stop)
            {
                this.buttonProductNo.Text = "**";
                // 전체 파라미터 메인보드 Write
                this.ParentForm.TransferProductParameter(this.ParentForm.SystemConfig.ProductNumber); 
            }

            this.pictureBoxUSBBackOn.Visible = this.ParentForm.SystemConfig.IsDataBackup;
            this.labelIconBypassMode.Visible = this.ParentForm.SystemConfig.IsBypassMode;
            
            if (this.ParentForm.SystemConfig.Serial3Mode == 0)
                this.labelIconSerial3.Visible = false;
            else
                this.labelIconSerial3.Visible = true;

            this.buttonSubMenu.ButtonUp();
            this.panelSubMenu.Visible = false;

            if (this.ParentForm.SystemConfig.IsFeedback == true)
            {
                this.buttonFeedback.ButtonUp();
                this.MainDisplayFeedback.Visible = false;
            }

            // Ethernet 
            if (this.ParentForm.SystemConfig.IsEthernetEnable == true)
            {
                this.pictureBoxEthernetDisconnection.Visible = true;

                if (this.ParentForm.SystemConfig.EthernetOperationMode == 1)
                {
                    this.ParentForm.EthernetClientDisconnect();

                    if (this.ParentForm.smartTCPMultiServer.IsStart == false)
                        this.ParentForm.smartTCPMultiServer.Start();
                }
            }
            else
            {
                this.pictureBoxEthernetDisconnection.Visible = false;
                this.pictureBoxEthernetConnection.Visible = false;

                if (this.ParentForm.SystemConfig.EthernetOperationMode == 2)
                    this.ParentForm.EthernetClientDisconnect();
                else
                {
                    if (this.ParentForm.smartTCPMultiServer.IsStart == true)
                        this.ParentForm.smartTCPMultiServer.Stop();
                }
            }
        }
        #endregion

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

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

        #region Event Handler
        private void pictureBoxStart_Click(object sender, EventArgs e)
        {

        }
        private void pictureBoxStop_Click(object sender, EventArgs e)
        {

        }
        private void pictureBoxIconAlarm_Click(object sender, EventArgs e)
        {
            if (this.MainDisplayAlarmList.Visible == true)
                this.MainDisplayAlarmList.Visible = false;
            else
            {
                this.MainDisplayAlarmList.BringToFront();
                this.MainDisplayAlarmList.Visible = true;
            }
        }

        private void buttonProductNo_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonProductNo.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(280, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 1000)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ProductChange(myKeyPad.IntValue);
                }
            }
        }
        private void buttonUnder_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonUnder.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(270, 70);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(this.ParentForm.CurrentProductItem.PassRange, this.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.UpdateUnderRangeChange(myKeyPad.StringValue);
                    this.ParentForm.Update30000ModbusData();

                    this.ClearRefreshFeedbackDisplay();
                }
            }
        }
        private void buttonPass_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonPass.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(270, 70);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if ((myKeyPad.doubleValue > Helper.StringToWeight(this.ParentForm.CurrentProductItem.OverRange, this.ParentForm.SystemConfig.DecimalPlaces))
                    || (myKeyPad.doubleValue < Helper.StringToWeight(this.ParentForm.CurrentProductItem.UnderRange, this.ParentForm.SystemConfig.DecimalPlaces)))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.UpdatePassRangeChange(myKeyPad.StringValue);
                    this.ParentForm.Update30000ModbusData();

                    this.ClearRefreshFeedbackDisplay();
                }
            }
        }
        private void buttonOver_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonOver.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(270, 70);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(this.ParentForm.CurrentProductItem.PassRange, this.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.UpdateOverRangeChange(myKeyPad.StringValue);
                    this.ParentForm.Update30000ModbusData();

                    this.ClearRefreshFeedbackDisplay();
                }
            }
        }
        private void buttonTare_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonTare.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(270, 70);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 999.99)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.UpdateTareRangeChange(myKeyPad.StringValue);
                    this.ParentForm.Update30000ModbusData();

                    this.ClearRefreshFeedbackDisplay();
                }
            }
        }
        private void buttonClear_Click(object sender, EventArgs e)
        {
            DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 8);
            if (myDlg.ShowDialog() == DialogResult.Yes)
            {
                this.Clear();

                this.ClearRefreshFeedbackDisplay();
            }
        }
        private void buttonMenu_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.EquipmentStatus == DataStore.EquipmentStatus.Stop)
            {
                this.ParentForm.ChildFormMenu.DisplayRefresh();
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormMenu);
            }
            else
            {
                this.panelSetting.Visible = true;
                this.panelSetting.BringToFront();
            }
        }
        private void buttonUser_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.LogOff)
            {
                DialogFormLogOn logOn = new DialogFormLogOn(this.ParentForm);
                if (logOn.ShowDialog() == DialogResult.OK)
                {
                    this.DisplayRefresh();
                    this.buttonUser.ButtonDown();
                }
                else
                {
                    this.buttonUser.ButtonUp();
                }
            }
            else
            {
                DialogFormYesNo msg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 12);
                if (msg.ShowDialog() == DialogResult.Yes)
                {
                    this.ParentForm.SystemConfig.CurrentUser.Group = DataStore.UserGroup.LogOff;
                    this.buttonUser.ButtonUp();

                    this.DisplayRefresh();
                }
            }
        }
        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.panelSetting.Visible = false;
        }
        private void buttonBypassDirection_Click(object sender, EventArgs e)
        {
            if (this.buttonBypassDirection.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsBypassDirectionPass = false;
            else
                this.ParentForm.SystemConfig.IsBypassDirectionPass = true;
        }
        private void buttonBypassOnce_Click(object sender, EventArgs e)
        {
            if (this.buttonBypassOnce.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.SystemConfig.IsBypassOnce = false;
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.PUSH;
            }
            else
            {
                this.ParentForm.SystemConfig.IsBypassOnce = true;
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.NORMAL;
            }
        }
        private void buttonBypassRun_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.IsBypassOnce == true)
            {
                if (this.ParentForm.SystemConfig.IsBypassDirectionPass == true)
                    this.ParentForm.TransferData(CommunicationCommand.BypassOnce, CommunicationID.MainBoard);
                else
                    this.ParentForm.TransferData(CommunicationCommand.ByNGOnce, CommunicationID.MainBoard);
            }
            else
            {
                if (this.buttonBypassRun.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                {
                    this.buttonBypassDirection.Enabled = false;
                    this.buttonBypassOnce.Enabled = false;

                    if (this.ParentForm.SystemConfig.IsBypassDirectionPass == true)
                        this.ParentForm.TransferData(CommunicationCommand.BypassON, CommunicationID.MainBoard);
                    else
                        this.ParentForm.TransferData(CommunicationCommand.ByNGON, CommunicationID.MainBoard);
                }
                else
                {
                    this.buttonBypassDirection.Enabled = true;
                    this.buttonBypassOnce.Enabled = true;

                    if (this.ParentForm.SystemConfig.IsBypassDirectionPass == true)
                        this.ParentForm.TransferData(CommunicationCommand.BypassOFF, CommunicationID.MainBoard);
                    else
                        this.ParentForm.TransferData(CommunicationCommand.ByNGOFF, CommunicationID.MainBoard);
                }
            }
        }
        private void buttonSubMenu_Click(object sender, EventArgs e)
        {
            if (this.buttonSubMenu.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.panelSubMenu.BringToFront();
                this.panelSubMenu.Visible = true;
            }
            else
                this.panelSubMenu.Visible = false;
        }
        private void buttonFeedback_Click(object sender, EventArgs e)
        {
            if (this.buttonFeedback.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                if (this.MainDisplayFeedback != null)
                {
                    this.MainDisplayFeedback.DisplayRefresh();
                    this.MainDisplayFeedback.BringToFront();
                    this.MainDisplayFeedback.Visible = true;
                }
            }
            else
            {
                this.MainDisplayFeedback.Visible = false;

                switch (this.ParentForm.SystemConfig.EquipmentColumns)
                {
                    case 2:
                        this.MainDisplay2.BringToFront();
                        break;
                    case 3:
                        this.MainDisplay3.BringToFront();
                        break;
                    case 4:
                        this.MainDisplay4.BringToFront();
                        break;
                    case 5:
                        this.MainDisplay5.BringToFront();
                        break;
                    case 6:
                        this.MainDisplay6.BringToFront();
                        break;
                    default:
                        break;
                }
            }
        }

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

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSorterDelayTime.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelSorterDelayTime.Text = myKeyPad.StringValue;
                    this.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelSorterDelayTime.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.Sorter1DelayTime, value);

                    this.ParentForm.SaveJudgmentSetFile(this.ParentForm.CurrentJudgmentSetItem, this.ParentForm.SystemConfig.ProductNumber - 1);
                }
            }
        }
        private void labelSorterRunTime_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSorterRunTime.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelSorterRunTime.Text = myKeyPad.StringValue;
                    this.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelSorterRunTime.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.Sorter1RunTime, value);

                    this.ParentForm.SaveJudgmentSetFile(this.ParentForm.CurrentJudgmentSetItem, this.ParentForm.SystemConfig.ProductNumber - 1);
                }
            }
        }
        private void labelTotalCount_Click(object sender, EventArgs e)
        {
            if (this.labelStaticTotalCount.Text != "Total")
                this.labelStaticTotalCount.Text = "Total";
            else
                this.labelStaticTotalCount.Text = "Pass";

            this.SetTotalCount();
        }

        private void timerServer_Tick(object sender, EventArgs e)
        {
            if (this.ParentForm.smartTCPMultiServer.IsStart == true)
            {
                if (this.ParentForm.smartTCPMultiServer.ClientInfoList == null)
                {
                    this.UpdateEthernetStatusDisplay(false);
                }
                else
                {
                    this.UpdateEthernetStatusDisplay(true);
                }
            }
        }
        #endregion

        private void buttonExit_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.IsCommunicationLogOpen == true)
                this.ParentForm.smartFileCommunicationLog.Close();
            this.ParentForm.CloseSmartUartLink();
            this.ParentForm.Close();
        }
    }
}