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.Threading;
using System.Windows.Forms;

using SmartX;
using ITC81DB.Controls;
using ITC81DB.DialogForms;
using ITC81DB_ImageDll;

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

        public DataStore.MainDisplayStore CurrentDisplay;

        public ControlMainAlarm MainAlarm;
        public ControlMainAverageTracking MainAverageTracking;
        public ControlMainBarGraph MainBarGraph;
        public ControlMainDataStatistics MainDataStatistics;
        public ControlMainFeedback MainFeedback;
        public ControlMainLineGraph MainLineGraph;
        public ControlMainList MainList;
        public ControlMainListForRFID MainListForRFID;
        public ControlMainModbus MainModbus;
        public ControlMainSpotCheck MainSpotCheck;
        public ControlMainSubMenu MainSubMenu;
        public ControlMainStartMenu MainStartMenu;
        public ControlMainWeightBigScreen MainWeightBigScreen;
        public ControlMainWeightSmallScreen MainWeightSmallScreen;
        #endregion

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

            this.ParentForm = parent;

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

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

        #region Method
        public void InitializeDesign()
        {
            Class1 images = new Class1();

            if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.English)
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayZeroUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayPrintUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOutDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLoginUp));
            }
            else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainZeroUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainPrintUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLogOutDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLoginUp));
            }
            else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
            {
            }
            else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayZeroUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayPrintUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayLogOutDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusFormMainDisplayLoginUp));
            }
            else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayZeroUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayPrintUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayLogOutDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerFormMainDisplayLoginUp));
            }
            else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayZeroUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayPrintUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOutDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLoginUp));
            }
            else
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayZeroUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayPrintUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korFormMainDisplayClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLoginDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOutDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLoginUp));
            }

            if (this.ParentForm.CurrentSystemStatus.CurrentWeightInputMode == DataStore.WeightInputMode.Deviation)
                this.buttonWeightInputMode.ButtonDown();
            else
                this.buttonWeightInputMode.ButtonUp();

            if (this.ParentForm.SystemConfig1.IsLogin == true)
                this.buttonUser.ButtonDown();
        }
        private void InitializeControl()
        {
            this.MainWeightBigScreen = new ControlMainWeightBigScreen(this);
            this.MainWeightSmallScreen = new ControlMainWeightSmallScreen(this);
            this.MainDataStatistics = new ControlMainDataStatistics(this);
            this.MainBarGraph = new ControlMainBarGraph(this);
            this.MainLineGraph = new ControlMainLineGraph(this);
            this.MainList = new ControlMainList(this);
            this.MainModbus = new ControlMainModbus(this);
            this.MainSubMenu = new ControlMainSubMenu(this);
            this.MainStartMenu = new ControlMainStartMenu(this);
            this.MainAlarm = new ControlMainAlarm();
            this.MainFeedback = new ControlMainFeedback(this);
            this.MainSpotCheck = new ControlMainSpotCheck(this);
            this.MainAverageTracking = new ControlMainAverageTracking(this);
            this.MainListForRFID = new ControlMainListForRFID(this);

            this.MainWeightBigScreen.Location = new Point(0, 65);
            this.MainWeightSmallScreen.Location = new Point(0, 65);
            this.MainDataStatistics.Location = new Point(0, 313);
            this.MainBarGraph.Location = new Point(0, 313);
            this.MainLineGraph.Location = new Point(0, 313);
            this.MainList.Location = new Point(0, 213);
            this.MainSubMenu.Location = new Point(0, 213);
            this.MainStartMenu.Location = new Point(0, 313);
            this.MainAlarm.Location = new Point(390, 60);
            this.MainFeedback.Location = new Point(0, 313);
            this.MainSpotCheck.Location = new Point(0, 313);
            this.MainAverageTracking.Location = new Point(0, 313);
            this.MainListForRFID.Location = new Point(0, 213);
            this.MainModbus.Location = new Point(0, 213);

            this.Controls.Add(this.MainWeightBigScreen);
            this.Controls.Add(this.MainWeightSmallScreen);
            this.Controls.Add(this.MainDataStatistics);
            this.Controls.Add(this.MainBarGraph);
            this.Controls.Add(this.MainLineGraph);
            this.Controls.Add(this.MainList);
            this.Controls.Add(this.MainSubMenu);
            this.Controls.Add(this.MainStartMenu);
            this.Controls.Add(this.MainAlarm);
            this.Controls.Add(this.MainFeedback);
            this.Controls.Add(this.MainSpotCheck);
            this.Controls.Add(this.MainAverageTracking);
            this.Controls.Add(this.MainListForRFID);
            this.Controls.Add(this.MainModbus);

            this.DisplayRefreshLogin();
        }
        public void DisplayRefreshLogin()
        {
            if (this.ParentForm.SystemConfig1.IsLogin == true)
            {
                this.labelUserID.Visible = true;
                this.labelUserLevel.Visible = true;
                this.buttonUser.Visible = true;
            }
            else
            {
                this.labelUserID.Visible = false;
                this.labelUserLevel.Visible = false;
                this.buttonUser.Visible = false;
            }
        }
        public void DefaultSetting()
        {
            if (this.ParentForm.IsBootingComplete == false)
                this.buttonProductNo.Text = "**";
            else
                this.buttonProductNo.Text = this.ParentForm.SystemConfig1.ProductNumber.ToString();

            this.pictureBoxStop.Visible = true;
            this.pictureBoxStart.Visible = false;

            // 알람 표시
            this.pictureBoxIconAlarm.Visible = false;
            this.MainAlarm.Visible = false;
            this.MainAlarm.BringToFront();

            this.buttonPrint.Visible = this.ParentForm.SystemConfig1.IsPrinterEnable;
            if (this.ParentForm.SystemConfig1.IsPrintPerProductEnable == true)
                this.buttonPrint.ButtonDown();
            else
                this.buttonPrint.ButtonUp();

            if (int.Parse(this.ParentForm.CurrentSystemParameter1.EquipmentType) == 4)
                this.buttonConveyorUpDown.Visible = true;
            else
                this.buttonConveyorUpDown.Visible = false;

            if (this.ParentForm.SystemConfig1.IsLogin == false)
                this.ParentForm.CurrentSystemStatus.CurrentUser.Group = DataStore.UserGroup.NotLogin;
            else
                this.ParentForm.CurrentSystemStatus.CurrentUser.Group = DataStore.UserGroup.LogOut;

            this.UpdateDisplayUser(this.ParentForm.CurrentSystemStatus);

            this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;
            this.DisplayBottomMain(this.CurrentDisplay);
        }

        public void DisplayHiddenMenu(bool visible)
        {
            if (visible == false)
            {
                if (this.ParentForm.SystemConfig2.Barcode != 0)
                    this.labelBarcode.Visible = false;
                //this.labelComRetry.Visible = false;
                //this.labelComRetry3th.Visible = false;
                this.labelOverrun.Visible = false;
                this.labelBufferCNT.Visible = false;
                this.labelMissingCount.Visible = false;

                //this.labelBARCD.Visible = false;
            }
            else
            {
                if (this.ParentForm.SystemConfig2.Barcode != 0)
                {
                    this.labelBarcode.Text = "";
                    this.labelBarcode.Visible = true;
                }
                //this.labelComRetry.Visible = true;
                //this.labelComRetry3th.Visible = true;
                this.labelOverrun.Visible = true;
                this.labelBufferCNT.Visible = true;
                this.labelMissingCount.Visible = true;

                //this.labelBARCD.Text = "";
                //this.labelBARCD.Visible = true;
            }
        }

        public void BottomButtonLocation(int buttonNo, SmartX.SmartButton button)
        {
            switch (buttonNo)
            {
                case 1:
                    button.Location = new Point(456, 0);
                    break;
                case 2:
                    button.Location = new Point(527, 0);
                    break;
                case 3:
                    button.Location = new Point(598, 0);
                    break;
                default:
                    break;
            }
        }
        public void AlarmOccurs(string errorNameKor, string errorNameEng, string alarmRawData)
        {
            this.ParentForm.PrintAlarm(alarmRawData, errorNameEng);
            if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Korean)
            {
                this.PopUpWarning(errorNameKor);
                this.MainAlarm.listBoxMessage.Items.Add(errorNameKor);
            }
            else
            {
                this.PopUpWarning(errorNameEng);
                this.MainAlarm.listBoxMessage.Items.Add(errorNameEng);
            }
        }
        public void UpdateDisplayAlarmView(AlarmList alarm, string alarmData)
        {
            this.MainWeightBigScreen.UpdateDisplayAlarmView(alarm);
            this.MainWeightSmallScreen.UpdateDisplayAlarmView(alarm);

            if (alarm.IsLoadCellError == true || alarm.IsInverterError == true || alarm.IsEmergencyStop == true || alarm.IsDoorInterlock == true
                || alarm.IsPressureSensingError == true || alarm.IsSorterAError == true || alarm.IsStackUpSensorError == true
                || alarm.IsEntrySensorError == true || alarm.IsWindProofError == true || alarm.IsSorterBError == true || alarm.IsEntryNotDetected == true)
            {
                if (this.pictureBoxIconAlarm.Visible == false)
                    this.pictureBoxIconAlarm.Visible = true;

                if (alarm.IsEntryNotDetected == true)
                {
                    this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                    if (this.ParentForm.SystemConfig3.IsStartStopLog == true)
                        this.ParentForm.smartFileStartStopLog.WriteString(string.Format("Send Stop ({0:yyyy-MM-dd HH:mm:ss}): FormMainDisplay-UpdateDisplayAlarmView1", DateTime.Now));
                }
                if (alarm.IsStackUpSensorError == true)
                {
                    if (int.Parse(this.ParentForm.CurrentSystemParameter1.OptionBoard) != 2) // 디스펜서 사용 시, 컨베어 미정지
                    {
                        this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                        if (this.ParentForm.SystemConfig3.IsStartStopLog == true)
                            this.ParentForm.smartFileStartStopLog.WriteString(string.Format("Send Stop ({0:yyyy-MM-dd HH:mm:ss}): FormMainDisplay-UpdateDisplayAlarmView2", DateTime.Now));
                    }
                }

                if (alarm.Flag == true)
                {
                    if (this.ParentForm.SystemConfig1.IsExternalInputLamp == true && this.ParentForm.IsLampOnDataSend == false)
                        this.ParentForm.OnExternalInputLampSignal(true, true);
                    if (this.ParentForm.SystemConfig1.IsExternalInputBuzzer == true && this.ParentForm.IsBuzzerOnDataSend == false)
                        this.ParentForm.OnExternalInputBuzzerSignal(true, true);

                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut1Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousEnable, CommunicationID.SubBoard1);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut2Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousEnable, CommunicationID.SubBoard2);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut3Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousEnable, CommunicationID.SubBoard3);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut4Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousEnable, CommunicationID.SubBoard4);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut9Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousEnable, CommunicationID.SubBoard5);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut10Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousEnable, CommunicationID.SubBoard6);

                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut1Mode) == (int)DataStore.ExternalOutputMode.OUT14_Alarm_Pulse)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutput, CommunicationID.SubBoard1);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut2Mode) == (int)DataStore.ExternalOutputMode.OUT14_Alarm_Pulse)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutput, CommunicationID.SubBoard2);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut3Mode) == (int)DataStore.ExternalOutputMode.OUT14_Alarm_Pulse)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutput, CommunicationID.SubBoard3);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut4Mode) == (int)DataStore.ExternalOutputMode.OUT14_Alarm_Pulse)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutput, CommunicationID.SubBoard4);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut9Mode) == (int)DataStore.ExternalOutputMode.OUT14_Alarm_Pulse)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutput, CommunicationID.SubBoard5);
                    if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut10Mode) == (int)DataStore.ExternalOutputMode.OUT14_Alarm_Pulse)
                        this.ParentForm.TransferData(CommunicationCommand.ExternalOutput, CommunicationID.SubBoard6);
                }
            }
            else
            {
                this.pictureBoxIconAlarm.Visible = false;
                this.MainAlarm.Visible = false;
                this.PopUpWarningClose();

                if (this.ParentForm.SystemConfig1.IsExternalInputLamp == true && this.ParentForm.IsLampOnDataSend == true)
                    this.ParentForm.TransferData(CommunicationCommand.LampOnContinuousDisable, CommunicationID.MainBoard);
                if (this.ParentForm.SystemConfig1.IsExternalInputBuzzer == true && this.ParentForm.IsBuzzerOnDataSend == true)
                    this.ParentForm.TransferData(CommunicationCommand.BuzzerOnContinuousDisable, CommunicationID.MainBoard);

                if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut1Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                    this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard1);
                if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut2Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                    this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard2);
                if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut3Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                    this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard3);
                if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut4Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                    this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard4);
                if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut9Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                    this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard5);
                if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut10Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                    this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard6);

                this.ParentForm.IsLampOnDataSend = false;
                this.ParentForm.IsBuzzerOnDataSend = false;

                return;
            }

            this.MainAlarm.listBoxMessage.Items.Clear();

            if (alarm.IsLoadCellError == true)
                this.AlarmOccurs("a2_로드셀 에러", "a2_LoadCell Error", alarmData);
            if (alarm.IsInverterError == true)
                this.AlarmOccurs("a9_인버터 에러", "a9_Inverter Error", alarmData);
            if (alarm.IsEmergencyStop == true)
                this.AlarmOccurs("a8_비상정지", "a8_Emergency Stop", alarmData);
            if (alarm.IsDoorInterlock == true)
                this.AlarmOccurs("a4_문 열림 감지", "a4_Door Interlock", alarmData);
            if (alarm.IsPressureSensingError == true)
                this.AlarmOccurs("a3_공압 낮음", "a3_Low Pressure", alarmData);
            if (alarm.IsEntrySensorError == true)
                this.AlarmOccurs("a1_진입센서 에러", "a1_Entry Sensor Error", alarmData);
            if (alarm.IsSorterAError == true)
                this.AlarmOccurs("a7_선별부A 에러", "a7_Sorter A Error", alarmData);
            if (alarm.IsSorterBError == true)
                this.AlarmOccurs("a14_선별부B 에러", "a14_Sorter B Error", alarmData);
            if (alarm.IsWindProofError == true)
                this.AlarmOccurs("a13_방풍커버 열림", "a13_Windproof Error", alarmData);
            if (alarm.IsStackUpSensorError == true)
                this.AlarmOccurs("a6_적체 에러", "a6_Stack up Error", alarmData);
            if (alarm.IsEntryNotDetected == true)
                this.AlarmOccurs("a18_제품진입 미감지", "a18_Product entry undetected", alarmData);
        }
        public void UpdateDisplayAlarmView(string message, bool flag)
        {
            if (this.pictureBoxIconAlarm.Visible == false)
                this.pictureBoxIconAlarm.Visible = true;

            this.MainAlarm.listBoxMessage.Items.Add(message);

            if (flag == true)
            {
                if (this.ParentForm.SystemConfig1.IsExternalInputLamp == true && this.ParentForm.IsLampOnDataSend == false)
                    this.ParentForm.OnExternalInputLampSignal(true, true);
                if (this.ParentForm.SystemConfig1.IsExternalInputBuzzer == true && this.ParentForm.IsBuzzerOnDataSend == false)
                    this.ParentForm.OnExternalInputBuzzerSignal(true, true);
            }
        }
        public void ChangeProductNumber(int productNumber)
        {
            this.ParentForm.ClearAlarm(0);
            this.SendCommProductChange(productNumber);

            // 기준치 갱신
            if (this.ParentForm.SystemConfig1.IsAverageTracking == true)
                this.ParentForm.CurrentAverageTrackingItem.DataClear();
        }
        public void SendCommProductChange(int productNumber)
        {
            this.buttonProductNo.Text = "**";
            this.ParentForm.TransferProductParameter(productNumber);
        }
        public void RescaleControl(ProductItem item)
        {
            this.MainBarGraph.RescaleProgressBar(item);
        }
        public void ClearCurrentData()
        {
            this.ParentForm.CurrentWeightData.ClearCount();
            if (this.ParentForm.CurrentWeightData.StartTime.Year == 1111)
                this.ParentForm.CurrentWeightData.StartTime = DateTime.Now;
            this.ParentForm.SaveCounterFile(this.ParentForm.CurrentWeightData, this.ParentForm.SystemConfig1.ProductNumber - 1);

            if (this.MainBarGraph != null)
                this.MainBarGraph.Clear();

            if (this.MainLineGraph != null)
                this.MainLineGraph.Clear();

            if (this.MainList != null)
                this.MainList.Clear();

            if (this.MainDataStatistics != null)
                this.MainDataStatistics.Clear();

            if (this.MainSpotCheck != null)
                this.MainSpotCheck.Clear();

            this.ParentForm.ClearAlarm(0);
        }
        public void ClearAllData()
        {
            for (int i = 0; i < this.ParentForm.ProductCount; i++)
            {
                this.ParentForm.CollectionWeightData[i].ClearCount();
            }
            this.ParentForm.SaveCounterFile(this.ParentForm.CollectionWeightData);

            if (this.MainBarGraph != null)
                this.MainBarGraph.Clear();

            if (this.MainLineGraph != null)
                this.MainLineGraph.Clear();

            if (this.MainList != null)
                this.MainList.Clear();

            if (this.MainDataStatistics != null)
                this.MainDataStatistics.Clear();
        }
        public void Clear()
        {
            this.ParentForm.MissingCommIDCount = 0;
            this.ParentForm.ClearQueue();

            this.ClearCurrentData();
            this.ParentForm.TransferData(CommunicationCommand.Clear, CommunicationID.SubBoard1);

            if (this.ParentForm.SystemConfig2.Barcode != 0)
            {
                this.ParentForm.CurrentBarcode.Clear();
                this.UpdateBarcodeDisplay(this.ParentForm.CurrentBarcode);
            }

            if (this.ParentForm.SystemConfig2.IsRFIDSpeedwayR420 == true)
            {
                this.ParentForm.CurrentRFID.Clear();
                this.UpdateRFIDDisplay(this.ParentForm.CurrentRFID);
            }

            if (this.ParentForm.SystemConfig1.IsAverageTracking == true)
                this.MainAverageTracking.Clear();

            if (this.ParentForm.SystemConfig2.IsRFIDSpeedwayR420 == true)
                this.MainListForRFID.Clear();
        }

        public void PopUpWarning(string warning)
        {
            this.labelAlarmWindow.Text = warning;
            this.labelAlarmWindow.BringToFront();
            this.labelAlarmWindow.Visible = true;
        }
        public void PopUpWarning2(string warning)
        {
            this.labelAlarmWindow2.Text = warning;
            this.labelAlarmWindow2.BringToFront();
            this.labelAlarmWindow2.Visible = true;
        }
        public void PopUpWarningClose()
        {
            if (this.labelAlarmWindow.Visible == true)
                this.labelAlarmWindow.Visible = false;
        }
        public void PopUpWarning2Close()
        {
            if (this.labelAlarmWindow2.Visible == true)
                this.labelAlarmWindow2.Visible = false;
        }
        public void PopUpWarning2CloseWhenEntryNotDetected()
        {
            if (this.labelAlarmWindow2.Text.StartsWith("Entry Not") == true || this.labelAlarmWindow2.Text.StartsWith("제품진입") == true)
                this.PopUpWarning2Close();
        }

        public void UpdateModbusScreen()
        {
            if (this.CurrentDisplay == DataStore.MainDisplayStore.Modbus)
            {
                this.ParentForm.Update30000ModbusItem();
                this.MainModbus.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
            }
        }
        private void UpdateDisplayUser(SystemStatus status)
        {
            string id = "", group = "";

            switch (status.CurrentUser.Group)
            {
                case DataStore.UserGroup.LogOut:
                    id = "";
                    if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        group = "AUS";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        group = "关闭";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
                        group = "Выкл.";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        group = "Apagado";
                    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.labelProductName.Enabled = false;
                    this.buttonSubMenu.Enabled = false;

                    this.buttonMenu.Enabled = false;
                    break;
                case DataStore.UserGroup.Level1Operator:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        group = "Stufe1";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        group = "级别1";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
                        group = "Уровень1";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        group = "Nivel1";
                    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 = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplaySubMenu;

                    if (status.Equipment == DataStore.EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case DataStore.UserGroup.Level2Engineer:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        group = "Stufe2";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        group = "级别2";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
                        group = "Уровень2";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        group = "Nivel2";
                    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 = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplaySubMenu;

                    if (status.Equipment == DataStore.EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case DataStore.UserGroup.Level3Manager:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        group = "Stufe3";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        group = "级别3";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
                        group = "Уровень3";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        group = "Nivel3";
                    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 = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplaySubMenu;

                    if (status.Equipment == DataStore.EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case DataStore.UserGroup.Level4Developer:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        group = "Stufe4";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        group = "级别4";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
                        group = "Уровень4";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        group = "Nivel4";
                    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.labelProductName.Enabled = true;
                    this.buttonSubMenu.Enabled = true;

                    if (status.Equipment == DataStore.EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case DataStore.UserGroup.NotLogin:
                    this.buttonProductNo.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplaySubMenu;

                    if (status.Equipment == DataStore.EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                default:
                    id = "";
                    if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
                        group = "AUS";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
                        group = "关闭";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
                        group = "Выкл.";
                    else if (this.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
                        group = "Apagado";
                    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.labelProductName.Enabled = false;
                    break;
            }

            if (this.labelUserLevel.Text != group)
                this.labelUserLevel.Text = group;
            if (this.labelUserID.Text != id)
                this.labelUserID.Text = id;
        }
        public void UpdateMainDisplay(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case DataStore.UserGroup.LogOut:
                    this.buttonProductNo.Enabled = false;
                    this.buttonClear.Enabled = false;
                    this.labelProductName.Enabled = false;
                    this.buttonMenu.Enabled = false;
                    break;
                case DataStore.UserGroup.Level1Operator:
                    this.buttonProductNo.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsMainDisplaySubMenu;
                    break;
                case DataStore.UserGroup.Level2Engineer:
                    this.buttonProductNo.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsMainDisplaySubMenu;
                    break;
                case DataStore.UserGroup.Level3Manager:
                    this.buttonProductNo.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsMainDisplaySubMenu;
                    break;
                case DataStore.UserGroup.Level4Developer:
                    this.buttonProductNo.Enabled = true;
                    this.buttonClear.Enabled = true;
                    this.labelProductName.Enabled = true;
                    this.buttonSubMenu.Enabled = true;
                    break;
                case DataStore.UserGroup.NotLogin:
                    this.buttonProductNo.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayProductNo;
                    this.labelProductName.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayProductNo;
                    this.buttonClear.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplayClear;
                    this.buttonSubMenu.Enabled = this.ParentForm.CurrentUserGroup.NotLogin.IsMainDisplaySubMenu;
                    break;
                default:
                    this.buttonUser.ButtonUp();
                    this.buttonProductNo.Enabled = false;
                    this.buttonClear.Enabled = false;
                    this.buttonMenu.Enabled = false;
                    this.labelProductName.Enabled = false;
                    break;
            }
        }

        public void UpdateDisplayOverRun(string value)
        {
            this.labelOverrun.Text = value;
        }

        public void MainBottomModbusIconAdd(bool bValue)
        {
            this.ParentForm.IsOPCModbusUsing = bValue;
            this.CurrentBottomMenuControlEnable();
        }

        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            if (status == DataStore.EquipmentStatus.Start)
            {
                this.pictureBoxStart.Visible = true;
                this.pictureBoxStop.Visible = false;

                this.buttonProductNo.Enabled = false;
                this.labelProductName.Enabled = false;
                this.buttonConveyorUpDown.Enabled = false;

                //this.CurrentDisplay = DataStore.MainDisplayStore.DisplayStartBarGraph;
                //this.DisplayBottomMain(this.CurrentDisplay);
            }
            else
            {
                this.pictureBoxStart.Visible = false;
                this.pictureBoxStop.Visible = true;

                this.buttonConveyorUpDown.Enabled = true;
                this.buttonConveyorUpDown.ButtonUp();

                if (this.ParentForm.CurrentSystemStatus.CurrentUser.Group == DataStore.UserGroup.LogOut)
                {
                    this.buttonProductNo.Enabled = false;
                    this.labelProductName.Enabled = false;
                }
                else
                {
                    this.buttonProductNo.Enabled = true;
                    this.labelProductName.Enabled = true;
                }

                if (this.CurrentDisplay == DataStore.MainDisplayStore.StartMenu)
                {
                    this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;
                    this.DisplayBottomMain(this.CurrentDisplay);
                }
            }

            this.MainBarGraph.UpdateEquipmentStatusDisplay(status);
            this.MainLineGraph.UpdateEquipmentStatusDisplay(status);
            this.MainList.UpdateEquipmentStatusDisplay(status);
            this.MainWeightBigScreen.UpdateEquipmentStatusDisplay(status);
            this.MainWeightSmallScreen.UpdateEquipmentStatusDisplay(status);
            this.MainSubMenu.UpdateEquipmentStatusDisplay(status);
        }
        public void UpdateMainTitleDisplay(ProductItem pItem)
        {
            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;
        }
        public void UpdateCurrentProductDisplay(DataStore.EquipmentStatus status, ProductItem pItem, WeightData wData)
        {
            this.UpdateMainTitleDisplay(pItem);

            if (this.MainWeightBigScreen != null)
                this.MainWeightBigScreen.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainWeightSmallScreen != null)
                this.MainWeightSmallScreen.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainBarGraph != null)
                this.MainBarGraph.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainLineGraph != null)
                this.MainLineGraph.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainList != null)
                this.MainList.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainSpotCheck != null)
                this.MainSpotCheck.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainDataStatistics != null)
                this.MainDataStatistics.UpdateCurrentProductDisplay(status, pItem, wData);
            if (this.MainSubMenu != null && this.CurrentDisplay == DataStore.MainDisplayStore.SubMenu)
                this.MainSubMenu.UpdateControl(this.ParentForm.CurrentJudgmentSetItem, this.ParentForm.CurrentSystemParameter4, this.ParentForm.CurrentProductItem);
            if (this.MainAverageTracking != null)
                if (this.ParentForm.SystemConfig1.IsAverageTracking == true)
                    this.MainAverageTracking.UpdateCurrentProductDisplay(status, pItem, wData);
        }
        public void UpdateStopWeightDisplay(DataStore.EquipmentStatus status, WeightData data)
        {
            string value = "";

            // 알람표시
            //this.UpdateDisplayAlarmView(data);

            if (this.MainWeightBigScreen != null)
                this.MainWeightBigScreen.UpdateStopWeightDisplay(status, data);
            if (this.MainWeightSmallScreen != null)
                this.MainWeightSmallScreen.UpdateStopWeightDisplay(status, data);
        }
        public void UpdateStartWeightDisplay(DataStore.EquipmentStatus status, ProductItem pItem, WeightData wData)
        {
            string value = "";

            // 알람표시
            //this.UpdateDisplayAlarmView(wData);

            if (wData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            if (this.MainWeightBigScreen != null)
                this.MainWeightBigScreen.UpdateStartWeightDisplay(status, wData);
            if (this.MainWeightSmallScreen != null)
                this.MainWeightSmallScreen.UpdateStartWeightDisplay(status, wData);
            if (this.MainBarGraph != null)
                this.MainBarGraph.UpdateStartWeightDisplay(status, wData);
            if (this.MainLineGraph != null)
                this.MainLineGraph.UpdateStartWeightDisplay(status, wData);
            if (this.MainList != null)
                this.MainList.UpdateStartWeightDisplay(status, pItem, wData);
            if (this.MainDataStatistics != null)
                this.MainDataStatistics.UpdateStartWeightDisplay(status, wData);
            if (this.MainSpotCheck != null)
                this.MainSpotCheck.UpdateStartWeightDisplay(status, wData);
            if (this.MainAverageTracking != null)
                this.MainAverageTracking.UpdateStartWeightDisplay(status, wData);
            if (this.MainListForRFID != null)
                if (this.ParentForm.SystemConfig2.IsRFIDSpeedwayR420 == true)
                    this.MainListForRFID.UpdateStartWeightDisplay(status, pItem, wData, this.ParentForm.ReferenceTag);
        }
        public void UpdateBarcodeDisplay(Barcode barcode)
        {
            if (this.MainWeightBigScreen != null)
                this.MainWeightBigScreen.UpdateBarcodeDisplay(barcode);
            if (this.MainWeightSmallScreen != null)
                this.MainWeightSmallScreen.UpdateBarcodeDisplay(barcode);
        }
        public void UpdateRFIDDisplay(RFID_Impinj_Speedway_R420 rfid)
        {
            if (this.MainWeightBigScreen != null)
                this.MainWeightBigScreen.UpdateRFIDDisplay(rfid);
            if (this.MainWeightSmallScreen != null)
                this.MainWeightSmallScreen.UpdateRFIDDisplay(rfid);
        }
        public void UpdateEthernetStatusDisplay(bool status)
        {
            if (this.MainWeightBigScreen != null)
                this.MainWeightBigScreen.UpdateEthernetStatusDisplay(status);
            if (this.MainWeightSmallScreen != null)
                this.MainWeightSmallScreen.UpdateEthernetStatusDisplay(status);
        }

        public void CurrentBottomMenuControlEnable()
        {
            Collection<SmartButton> buttons = new Collection<SmartButton>();
            bool feedback = this.MainFeedback.IsUsingFeedback();
            bool averageTracking = this.ParentForm.SystemConfig1.IsAverageTracking;
            int sampleCount = int.Parse(this.ParentForm.CurrentSystemParameter2.OPT1SamplingCount);
            bool modbus = this.ParentForm.IsOPCModbusUsing;

            buttons.Clear();
            buttons.Add(this.buttonFeedback);
            buttons.Add(this.buttonAverageTracking);
            buttons.Add(this.buttonModbus);
            for (int i = 0; i < buttons.Count; i++)
                buttons[i].Visible = false;

            buttons.Clear();
            if (feedback == true && sampleCount != 0)
            {
                buttons.Add(this.buttonFeedback);

                if (this.ParentForm.CurrentSystemParameter2.OPT1OverRangeInt <= 0 && this.ParentForm.CurrentSystemParameter2.OPT1UnderRangeInt <= 0)
                {
                    this.ParentForm.UpdateFeedbackData(this.ParentForm.CurrentProductItem, this.ParentForm.CurrentSystemParameter2);
                    this.ParentForm.UpdateFeedbackDeviation(this.ParentForm.CurrentProductItem, this.ParentForm.CurrentSystemParameter2);
                }
                else
                    this.ParentForm.UpdateFeedbackDeviation(this.ParentForm.CurrentProductItem, this.ParentForm.CurrentSystemParameter2);
            }
            if (averageTracking == true)
                buttons.Add(this.buttonAverageTracking);
            if (modbus == true)
                buttons.Add(this.buttonModbus);

            for (int i = 0; i < buttons.Count; i++)
            {
                this.BottomButtonLocation(i + 1, buttons[i]);
                buttons[i].Visible = true;
            }
        }
        public void UpdateDisplayMenuButton(DataStore.MainDisplayStore main)
        {
            if (this.buttonSubMenu.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonSubMenu.ButtonUp();
            if (this.buttonBargraph.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonBargraph.ButtonUp();
            if (this.buttonLinegraph.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonLinegraph.ButtonUp();
            if (this.buttonList.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonList.ButtonUp();
            if (this.buttonDataStat.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonDataStat.ButtonUp();
            if (this.buttonFeedback.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonFeedback.ButtonUp();
            if (this.buttonAverageTracking.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonAverageTracking.ButtonUp();
            if (this.buttonSpotCheck.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonSpotCheck.ButtonUp();
            if (this.buttonModbus.ButtonStatus != SmartButton.BUTSTATUS.UP)
                this.buttonModbus.ButtonUp();

            switch (main)
            {
                case DataStore.MainDisplayStore.SubMenu:
                    if (this.buttonSubMenu.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonSubMenu.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.BarGraph:
                    if (this.buttonBargraph.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonBargraph.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.LineGraph:
                    if (this.buttonLinegraph.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonLinegraph.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.List:
                case DataStore.MainDisplayStore.ListForRFID:
                    if (this.buttonList.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonList.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.DataStat:
                    if (this.buttonDataStat.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonDataStat.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.Feedback:
                    if (this.buttonFeedback.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonFeedback.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.AverageTracking:
                    if (this.buttonAverageTracking.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonAverageTracking.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.SpotCheck:
                    if (this.buttonSpotCheck.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonSpotCheck.ButtonDown();
                    break;
                case DataStore.MainDisplayStore.Modbus:
                    if (this.buttonModbus.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonModbus.ButtonDown();
                    break;
                default:
                    break;
            }
        }
        public void DisplayBottomMain(DataStore.MainDisplayStore main)
        {
            switch (main)
            {
                case DataStore.MainDisplayStore.SubMenu:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.SubMenu);
                    this.MainSubMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainSubMenu.BringToFront();
                    this.MainWeightSmallScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.StartMenu:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.StartMenu);
                    this.MainStartMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainStartMenu.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.BarGraph:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.BarGraph);
                    this.MainBarGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainBarGraph.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.LineGraph:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.LineGraph);
                    this.MainLineGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainLineGraph.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.List:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.List);
                    this.MainList.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainList.BringToFront();
                    this.MainWeightSmallScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.ListForRFID:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.ListForRFID);
                    this.MainListForRFID.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainListForRFID.BringToFront();
                    this.MainWeightSmallScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.DataStat:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.DataStat);
                    this.MainDataStatistics.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainDataStatistics.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.SpotCheck:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.SpotCheck);
                    this.MainSpotCheck.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainSpotCheck.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.Feedback:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.Feedback);
                    this.MainFeedback.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainFeedback.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.AverageTracking:
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.AverageTracking);
                    this.MainAverageTracking.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainAverageTracking.BringToFront();
                    this.MainWeightBigScreen.BringToFront();
                    break;
                case DataStore.MainDisplayStore.Modbus:
                    this.ParentForm.Update30000ModbusItem();
                    this.UpdateDisplayMenuButton(DataStore.MainDisplayStore.Modbus);
                    this.MainModbus.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainModbus.BringToFront();
                    this.MainWeightSmallScreen.BringToFront();
                    break;
                default:
                    break;
            }
        }

        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 UpdateTimeDisplay()
        {
            this.labelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public void DisplayRefresh(SystemStatus status)
        {
            string feedbackValue = "";
            int value;

            this.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.MainDisplay;
            this.ParentForm.SetDisplayMode(DataStore.DisplayMode.Normal);

            #region 순서변경 금지(품번 중량 변경)
            this.ParentForm.TransferCurrentProductItem(this.ParentForm.CurrentProductItem);
            this.RescaleControl(this.ParentForm.CurrentProductItem);
            this.UpdateMainTitleDisplay(this.ParentForm.CurrentProductItem);
            //this.SendCommProductChange(this.ParentForm.SystemConfig1.ProductNumber);
            #endregion

            this.buttonPrint.Visible = this.ParentForm.SystemConfig1.IsPrinterEnable;

            if (this.ParentForm.SystemConfig1.IsPrintPerProductEnable == true)
                this.buttonPrint.ButtonDown();
            else
                this.buttonPrint.ButtonUp();

            if (int.Parse(this.ParentForm.CurrentSystemParameter1.EquipmentType) == 4)
            {
                this.buttonConveyorUpDown.Visible = true;
                this.buttonConveyorUpDown.ButtonUp();
            }
            else
                this.buttonConveyorUpDown.Visible = false;

            if (this.CurrentDisplay == DataStore.MainDisplayStore.Feedback)
            {
                if (this.buttonFeedback.Visible == false)
                    this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;
            }
            if (this.CurrentDisplay == DataStore.MainDisplayStore.AverageTracking)
            {
                if (this.buttonAverageTracking.Visible == false)
                    this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;
            }
            if (this.CurrentDisplay == DataStore.MainDisplayStore.Modbus)
            {
                if (this.buttonModbus.Visible == false)
                    this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;
            }

            this.DisplayBottomMain(this.CurrentDisplay);

            if (this.ParentForm.SystemConfig2.EthernetOperationMode == 2)
                this.ParentForm.UITimerWork(true);

            //this.CurrentDisplay = DataStore.MainDisplayStore.DisplayStartBarGraph;
            //this.DisplayBottomMain(this.CurrentDisplay);
            this.MainWeightBigScreen.DisplayRefresh(status);
            this.MainWeightSmallScreen.DisplayRefresh(status);
            //this.MainSubMenu.DisplayRefresh(status);
            //this.MainBarGraph.DisplayRefresh(status);
            //this.MainFeedback.DisplayRefresh(status);
            //this.MainLineGraph.DisplayRefresh(status);
        }
        #endregion

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

            //this.InitializeDesign();
            //this.DefaultSetting();

            //this.smartMemory1.ParentWindow = this;
            //this.smartMemory1.MemoryStatusInfomationShow(SmartX.SmartMemory.VIEWPOSITION.CENTER);
        }
        #endregion

        #region Event Handler
        private void buttonZero_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard1);
        }

        private void buttonProductNo_Click(object sender, EventArgs e)
        {
            string message = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonProductNo.Text, 4, 0, false, this.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > this.ParentForm.ProductCount)
                {
                    // 입력범위를 확인하세요
                    message = string.Format("1 ~ {0}", this.ParentForm.ProductCount);
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ChangeProductNumber(myKeyPad.IntValue);
                }
            }
        }
        private void labelProductName_Click(object sender, EventArgs e)
        {
            int listIndex = 0, listViewIndex = 0;
            Collection<string> productNames = new Collection<string>();

            this.ParentForm.LoadProductName(ref productNames);

            listIndex = this.ParentForm.SystemConfig1.ProductNumber - 1;
            listViewIndex = (listIndex / 10) * 10;
            if (listViewIndex > this.ParentForm.ProductCount - 10)
                listViewIndex = this.ParentForm.ProductCount - 10;

            DialogFormProductList product = new DialogFormProductList(productNames, listViewIndex);
            product.Location = new Point(79, 60);

            if (product.ShowDialog() == DialogResult.OK)
            {
                this.ParentForm.ClearAlarm(0);
                this.SendCommProductChange(product.SelectedProductNumber);

                // 기준치 갱신
                if (this.ParentForm.SystemConfig1.IsAverageTracking == true)
                    this.ParentForm.CurrentAverageTrackingItem.DataClear();
            }
        }

        private void pictureBoxStart_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
            if (this.ParentForm.SystemConfig3.IsStartStopLog == true)
                this.ParentForm.smartFileStartStopLog.WriteString(string.Format("Send Stop ({0:yyyy-MM-dd HH:mm:ss}): FormMainDisplay-pictureBoxStart_Click", DateTime.Now));
        }
        private void pictureBoxStop_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
            if (this.ParentForm.SystemConfig3.IsStartStopLog == true)
                this.ParentForm.smartFileStartStopLog.WriteString(string.Format("Send Start ({0:yyyy-MM-dd HH:mm:ss}): FormMainDisplay-pictureBoxStop_Click", DateTime.Now));
        }
        private void pictureBoxBypass_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
            if (this.ParentForm.SystemConfig3.IsStartStopLog == true)
                this.ParentForm.smartFileStartStopLog.WriteString(string.Format("Send Stop ({0:yyyy-MM-dd HH:mm:ss}): FormMainDisplay-pictureBoxBypass_Click", DateTime.Now));
        }

        private void timerPrinting_Tick(object sender, EventArgs e)
        {
            //this.timerPrinting.Enabled = false;
            //this.buttonPrint.Enabled = true;
            //this.buttonClear.Enabled = true;
        }
        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);
                }
            }
        }

        private void pictureBoxIconAlarm_Click(object sender, EventArgs e)
        {
            if (this.MainAlarm.Visible == true)
            {
                this.MainAlarm.Visible = false;

                if (this.MainAlarm.listBoxMessage.Items.Contains("a7_선별부A 에러") || this.MainAlarm.listBoxMessage.Items.Contains("a14_선별부B 에러")
                    || this.MainAlarm.listBoxMessage.Items.Contains("a7_Sorter A Error") || this.MainAlarm.listBoxMessage.Items.Contains("a14_Sorter B Error"))
                {
                    this.ParentForm.TransferData(CommunicationCommand.AlarmNgClearSorter, CommunicationID.MainBoard);
                    this.PopUpWarningClose();
                }
            }
            else
            {
                this.MainAlarm.BringToFront();
                this.MainAlarm.Visible = true;
            }

            if (this.ParentForm.SystemConfig1.IsExternalInputLamp == true && this.ParentForm.IsLampOnDataSend == true)
                this.ParentForm.TransferData(CommunicationCommand.LampOnContinuousDisable, CommunicationID.MainBoard);
            if (this.ParentForm.SystemConfig1.IsExternalInputBuzzer == true && this.ParentForm.IsBuzzerOnDataSend == true)
                this.ParentForm.TransferData(CommunicationCommand.BuzzerOnContinuousDisable, CommunicationID.MainBoard);

            if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut1Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard1);
            if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut2Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard2);
            if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut3Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard3);
            if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut4Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard4);
            if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut9Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard5);
            if (int.Parse(this.ParentForm.CurrentSystemParameter3.ExternalOut10Mode) == (int)DataStore.ExternalOutputMode.OUT13_Alarm_Level)
                this.ParentForm.TransferData(CommunicationCommand.ExternalOutputContinuousDisable, CommunicationID.SubBoard6);
        }
        private void labelAlarmWindow_Click(object sender, EventArgs e)
        {
            if (this.labelAlarmWindow.Text.Contains("a7") || this.labelAlarmWindow.Text.Contains("a14"))
                this.ParentForm.TransferData(CommunicationCommand.AlarmNgClearSorter, CommunicationID.MainBoard);
            if (this.ParentForm.SystemConfig1.IsExternalInputLamp == true && this.ParentForm.IsLampOnDataSend == true)
                this.ParentForm.TransferData(CommunicationCommand.LampOnContinuousDisable, CommunicationID.MainBoard);
            if (this.ParentForm.SystemConfig1.IsExternalInputBuzzer == true && this.ParentForm.IsBuzzerOnDataSend == true)
                this.ParentForm.TransferData(CommunicationCommand.BuzzerOnContinuousDisable, CommunicationID.MainBoard);
            this.PopUpWarningClose();
        }
        private void labelAlarmWindow2_Click(object sender, EventArgs e)
        {
            this.PopUpWarning2Close();
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            if (this.buttonPrint.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.SystemConfig1.IsPrintPerProductEnable = true;
                this.ParentForm.PrintingHeadLine();
            }
            else
            {
                this.ParentForm.SystemConfig1.IsPrintPerProductEnable = false;

                if (this.ParentForm.SystemConfig1.SerialCOM1Mode == 3)
                    this.ParentForm.TransferSerialCOM1("\n\n\n\n");
                else if (this.ParentForm.SystemConfig1.SerialCOM3Mode == 3)
                    this.ParentForm.TransferSerialCOM3("\n\n\n\n");
                else if (this.ParentForm.SystemConfig1.SerialCOM4Mode == 3)
                    this.ParentForm.TransferSerialCOM4("\n\n\n\n");
            }

            this.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.SystemConfig1);

            //this.buttonPrint.Enabled = false;
            //this.buttonClear.Enabled = false;
            //this.timerPrinting.Interval = 10000;
            //this.timerPrinting.Enabled = true;

            //this.ParentForm.PrintingWeight(this.ParentForm.CurrentWeightData, this.ParentForm.CurrentProductItem);
        }
        private void buttonClear_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentWeightData.TotalCount == 0 && this.ParentForm.SystemConfig2.Barcode != 0)
            {
                #region 바코드 사용 시 전체 품목 데이터 소거
                DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig1.Language, 19);
                if (myDlg.ShowDialog() == DialogResult.Yes)
                {
                    SmartSplash splash = new SmartSplash();
                    splash.CenterPosition = true;
                    splash.AnimationInterval = 200;
                    splash.LoadingImagePathname = "SmartLoading4";
                    splash.Start();

                    this.ClearAllData();

                    this.ParentForm.CurrentBarcode.Clear();
                    this.UpdateBarcodeDisplay(this.ParentForm.CurrentBarcode);

                    splash.Finish();
                }
                #endregion
            }
            else
            {
                #region 현재 품목 데이터 소거
                DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig1.Language, 8);
                if (myDlg.ShowDialog() == DialogResult.Yes)
                {
                    this.Clear();
                }
                #endregion
            }
        }
        private void buttonUser_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentSystemStatus.CurrentUser.Group == DataStore.UserGroup.LogOut)
            {
                DialogFormLogOn logOn = new DialogFormLogOn(this.ParentForm, this.ParentForm.SystemConfig1.Language);
                if (logOn.ShowDialog() == DialogResult.OK)
                {
                    this.ParentForm.ChildFormMenu.CenterEquipUserGroupEditor.UpdateAllMenu(this.ParentForm.CurrentSystemStatus);
                    this.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.UpdateDisplayUser(this.ParentForm.CurrentSystemStatus);
                    this.buttonUser.ButtonDown();

                    switch (this.CurrentDisplay)
                    {
                        case DataStore.MainDisplayStore.SubMenu:
                            this.MainSubMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.BarGraph:
                            this.MainBarGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.LineGraph:
                            this.MainLineGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.List:
                            this.MainList.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.DataStat:
                            this.MainDataStatistics.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    this.buttonUser.ButtonUp();
                }
            }
            else
            {
                DialogFormYesNo msg = new DialogFormYesNo(this.ParentForm.SystemConfig1.Language, 12);
                if (msg.ShowDialog() == DialogResult.Yes)
                {
                    this.ParentForm.CurrentSystemStatus.CurrentUser.Group = DataStore.UserGroup.LogOut;
                    this.buttonUser.ButtonUp();

                    this.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.UpdateDisplayUser(this.ParentForm.CurrentSystemStatus);

                    switch (this.CurrentDisplay)
                    {
                        case DataStore.MainDisplayStore.SubMenu:
                            this.MainSubMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.BarGraph:
                            this.MainBarGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.LineGraph:
                            this.MainLineGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.List:
                            this.MainList.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case DataStore.MainDisplayStore.DataStat:
                            this.MainDataStatistics.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        private void buttonWeightInputMode_Click(object sender, EventArgs e)
        {
            if (this.buttonWeightInputMode.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.CurrentSystemStatus.CurrentWeightInputMode = DataStore.WeightInputMode.Deviation;
            else
                this.ParentForm.CurrentSystemStatus.CurrentWeightInputMode = DataStore.WeightInputMode.Weight;

            this.UpdateCurrentProductDisplay(this.ParentForm.CurrentSystemStatus.Equipment, this.ParentForm.CurrentProductItem, this.ParentForm.CurrentWeightData);
        }
        private void buttonConveyorUpDown_Click(object sender, EventArgs e)
        {
            if (this.buttonConveyorUpDown.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.TransferData(CommunicationCommand.MotorDown, CommunicationID.MainBoard);
            else
                this.ParentForm.TransferData(CommunicationCommand.MotorUp, CommunicationID.MainBoard);
        }
        private void buttonHiddenMenu_Click(object sender, EventArgs e)
        {
            //this.labelBarcode.Visible = true;
            //this.labelBarcode.BringToFront();
            this.ParentForm.ChildFormMenu.DisplayHiddenMenu(this.ParentForm.CurrentSystemStatus.CurrentDisplay, this.ParentForm.SystemConfig1);
        }
        private void buttonMenu_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentSystemStatus.Equipment == DataStore.EquipmentStatus.Stop)
            {
                if (this.ParentForm.SystemConfig2.EthernetOperationMode == 2)
                    this.ParentForm.UITimerWork(false);

                this.ParentForm.ChildFormMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
            }
            else
            {
                if (this.ParentForm.SystemConfig2.EthernetOperationMode == 2)
                {
                    this.CurrentDisplay = DataStore.MainDisplayStore.StartMenu;

                    this.DisplayBottomMain(this.CurrentDisplay);
                }
            }
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonBargraph_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.BarGraph;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonLinegraph_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.LineGraph;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonList_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig2.IsRFIDSpeedwayR420 == true)
            {
                this.CurrentDisplay = DataStore.MainDisplayStore.ListForRFID;

                this.DisplayBottomMain(this.CurrentDisplay);
            }
            else
            {
                this.CurrentDisplay = DataStore.MainDisplayStore.List;

                this.DisplayBottomMain(this.CurrentDisplay);
            }
        }
        private void buttonDataStat_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.DataStat;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonSpotCheck_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.SpotCheck;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonStartMenu_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.SubMenu;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonFeedback_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.Feedback;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonAverageTracking_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.AverageTracking;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonCheckModbus_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = DataStore.MainDisplayStore.Modbus;

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        #endregion

        private void buttonExit_Click(object sender, EventArgs e)
        {
            this.ParentForm.CloseSmartSerialPort2();
            this.ParentForm.smartFileCommunicationLog.Close();
            this.ParentForm.smartFileCheckLog.Close();
            this.ParentForm.smartFileStartStopLog.Close();
            this.ParentForm.Close();
        }
        private void buttonMemory_Click(object sender, EventArgs e)
        {
            this.smartMemory1.ParentWindow = this;
            this.smartMemory1.MemoryStatusInfomationShow(SmartX.SmartMemory.VIEWPOSITION.CENTER);
        }

        private void smartButton1_Click(object sender, EventArgs e)
        {
            SmartX.CIPSetting.PINGRESULTINFO pingResultInfo = new CIPSetting.PINGRESULTINFO();
            pingResultInfo.dwRoundTripTime = 3000;
            this.labelBarcode.Visible = true;

            if (this.ParentForm.smartConfigs.IPSettings.PingIP("192.168.11.47", ref pingResultInfo) == true)
                this.labelBarcode.Text = "Ping정상";
            else
                this.labelBarcode.Text = "Ping에러";
        }
    }
}