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_2.Controls;
using ITC81DB_2.DialogForms;
using ITC81DB_2_ImageDll;

namespace ITC81DB_2.Forms
{
    public partial class FormMainDisplay : Form
    {
        #region Field
        private bool BeforeEthernetStatus;

        private FormMain m_ParentForm;

        private List<bool> AlarmListBool;

        private Define.E_MainDisplayStore CurrentDisplay;

        public ControlMainAlarm MainAlarm;
        public ControlMainBarGraph MainBarGraph;
        public ControlMainDataStatistics MainDataStatistics;
        public ControlMainFeedback MainFeedback;
        public ControlMainLineGraph MainLineGraph;
        public ControlMainModbus MainModbus;
        public ControlMainList MainList;
        public ControlMainSubMenu MainSubMenu;
        public ControlMainWeightScreen MainWeightScreen;
        #endregion

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

            this.ParentForm = parent;

            this.InitializeDesign();
            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.SystemConfig.Language == Define.E_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.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.engFormMainDisplayLogOffDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOffDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOffUp));
                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));
            }
            else if (this.ParentForm.SystemConfig.Language == Define.E_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.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.chnMainLogOffDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLogOffDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnMainLogOffUp));
                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));
            }
            else if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayZeroUp));
                this.buttonWeightInputMode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayDeviationUp));
                this.buttonWeightInputMode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayWeightUp));
                this.buttonClear.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayClearDisable));
                this.buttonClear.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayClearDown));
                this.buttonClear.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayClearUp));
                this.buttonUser.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayLogOffDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayLogOffDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayLogOffUp));
                this.buttonPrint.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayPrintDisable));
                this.buttonPrint.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayPrintDown));
                this.buttonPrint.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnFormMainDisplayPrintUp));
            }
            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.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.engFormMainDisplayLogOffDisable));
                this.buttonUser.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOffDown));
                this.buttonUser.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormMainDisplayLogOffUp));
                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));
            }

            if (this.ParentForm.CurrentSystemStatus.CurrentWeightInputMode == Define.E_WeightInputMode.Deviation)
                this.buttonWeightInputMode.ButtonDown();
            else
                this.buttonWeightInputMode.ButtonUp();
        }
        private void InitializeControl()
        {
            this.MainBarGraph = new ControlMainBarGraph(this);
            this.MainDataStatistics = new ControlMainDataStatistics(this);
            this.MainList = new ControlMainList(this);
            this.MainLineGraph = new ControlMainLineGraph(this);
            this.MainSubMenu = new ControlMainSubMenu(this);
            this.MainAlarm = new ControlMainAlarm();
            this.MainFeedback = new ControlMainFeedback(this);
            this.MainWeightScreen = new ControlMainWeightScreen(this);
            this.MainModbus = new ControlMainModbus(this);

            this.MainBarGraph.Location = new Point(0, 90);
            this.MainDataStatistics.Location = new Point(0, 90);
            this.MainList.Location = new Point(0, 90);
            this.MainLineGraph.Location = new Point(0, 90);
            this.MainSubMenu.Location = new Point(0, 90);
            this.MainAlarm.Location = new Point(390, 60);
            this.MainFeedback.Location = new Point(0, 90);
            this.MainWeightScreen.Location = new Point(536, 90);
            this.MainModbus.Location = new Point(0, 90);

            this.Controls.Add(this.MainBarGraph);
            this.Controls.Add(this.MainDataStatistics);
            this.Controls.Add(this.MainList);
            this.Controls.Add(this.MainLineGraph);
            this.Controls.Add(this.MainSubMenu);
            this.Controls.Add(this.MainAlarm);
            this.Controls.Add(this.MainFeedback);
            this.Controls.Add(this.MainWeightScreen);
            this.Controls.Add(this.MainModbus);

            if (this.ParentForm.SystemConfig.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;
            }
        }
        private void DefaultSetting()
        {
            this.BeforeEthernetStatus = false;

            if (this.ParentForm.IsBootingComplete == false)
                this.buttonProductNo.Text = "**";
            else
                this.buttonProductNo.Text = this.ParentForm.SystemConfig.ProductNumber.ToString();

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

            this.InitializeControl();
            this.UpdateIcomDisplay();
            this.DisplayPrintButton(this.ParentForm.SystemConfig);

            // 알람 표시
            this.pictureBoxIconAlarm.Visible = false;
            this.MainAlarm.Visible = false;
            this.MainAlarm.BringToFront();
            this.AlarmListBool = new List<bool>();

            if (this.ParentForm.SystemConfig.EquipmentType == 4)
                this.UpdateControlVisible(true);
            else
                this.UpdateControlVisible(false);

            if (this.ParentForm.SystemConfig.IsLogin == true)
                this.UpdateDisplayUser(this.ParentForm.CurrentSystemStatus);
            else
                this.ParentForm.CurrentSystemStatus.CurrentUser.Group = Define.E_UserGroup.Developer;
                        
            this.CurrentDisplay = Define.E_MainDisplayStore.BarGraph;
            this.DisplayBottomMain(this.CurrentDisplay);
        }

        private void UpdateDisplayAlarmView(WeightData data1, WeightData data2)
        {
            bool flagAlarm = false;
            bool flagChange = false;

            if (this.AlarmListBool.Count > 0)
            {
                if (this.AlarmListBool[0] != data1.IsLoadCellError) flagChange = true;
                if (this.AlarmListBool[1] != data2.IsLoadCellError) flagChange = true;
                if (this.AlarmListBool[2] != data1.IsEmergencyStop) flagChange = true;
                if (this.AlarmListBool[3] != data1.IsEntrySensorError) flagChange = true;
                if (this.AlarmListBool[4] != data2.IsEntrySensorError) flagChange = true;
                if (this.AlarmListBool[5] != data1.IsEntryNotDetected) flagChange = true;
                if (this.AlarmListBool[6] != data2.IsEntryNotDetected) flagChange = true;
                if (this.AlarmListBool[7] != data1.IsEntryStucked) flagChange = true;
                if (this.AlarmListBool[8] != data2.IsEntryStucked) flagChange = true;
            }

            this.AlarmListBool.Clear();
            this.AlarmListBool.Add(data1.IsLoadCellError);
            this.AlarmListBool.Add(data2.IsLoadCellError);
            this.AlarmListBool.Add(data1.IsEmergencyStop);
            this.AlarmListBool.Add(data1.IsEntrySensorError);
            this.AlarmListBool.Add(data2.IsEntrySensorError);
            this.AlarmListBool.Add(data1.IsEntryNotDetected);
            this.AlarmListBool.Add(data2.IsEntryNotDetected);
            this.AlarmListBool.Add(data1.IsEntryStucked);
            this.AlarmListBool.Add(data2.IsEntryStucked);

            foreach (bool listBool in this.AlarmListBool)
            {
                if (listBool == true)
                {
                    flagAlarm = true;
                    break;
                }
            }

            if (flagAlarm == true)
            {
                if (this.pictureBoxIconAlarm.Visible == false)
                    this.pictureBoxIconAlarm.Visible = true;
            }
            else
            {
                this.pictureBoxIconAlarm.Visible = false;
                this.MainAlarm.Visible = false;

                return;
            }

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

            if (data1.IsLoadCellError == true)
                this.MainAlarm.listBoxMessage.Items.Add("#1 LoadCell Error");
            if (data2.IsLoadCellError == true)
                this.MainAlarm.listBoxMessage.Items.Add("#2 LoadCell Error");
            if (data1.IsEmergencyStop == true)
                this.MainAlarm.listBoxMessage.Items.Add("Emergency Stop");
            if (data1.IsEntrySensorError == true)
                this.MainAlarm.listBoxMessage.Items.Add("#1 Entry Sensor Error");
            if (data2.IsEntrySensorError == true)
                this.MainAlarm.listBoxMessage.Items.Add("#2 Entry Sensor Error");
            if (data1.IsEntryNotDetected == true)
            {
                this.MainAlarm.listBoxMessage.Items.Add("#1 Entry Not Detected");
                if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Korean)
                    this.PopUpWarning("#1 제품진입 미감지");
                else
                    this.PopUpWarning("#1 Entry not detected");
            }
            if (data2.IsEntryNotDetected == true)
            {
                this.MainAlarm.listBoxMessage.Items.Add("#2 Entry Not Detected");
                if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Korean)
                    this.PopUpWarning("#2 제품진입 미감지");
                else
                    this.PopUpWarning("#2 Entry not detected");
            }
            if (data1.IsEntryStucked == true)
            {
                this.MainAlarm.listBoxMessage.Items.Add("#1 Entry Sensor Stucked");
                if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Korean)
                    this.PopUpWarning("#1 진입센서 이상");
                else
                    this.PopUpWarning("#1 Entry Sensor Stucked");
            }
            if (data2.IsEntryStucked == true)
            {
                this.MainAlarm.listBoxMessage.Items.Add("#2 Entry Sensor Stucked");
                if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Korean)
                    this.PopUpWarning("#2 진입센서 이상");
                else
                    this.PopUpWarning("#2 Entry Sensor Stucked");
            }

            if (flagChange == true && this.MainAlarm.listBoxMessage.Items.Count > 0)
            {
                // 로그
                if (this.ParentForm.IsCommunicationLogOpen == true)
                {
                    for (int i = 0; i < this.MainAlarm.listBoxMessage.Items.Count; i++)
                        this.ParentForm.smartFileCommunicationLog.WriteString(
                            string.Format("Alarm ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, this.MainAlarm.listBoxMessage.Items[i]));
                }
            }
        }
        public void ProductChange(int productNumber)
        {
            this.buttonProductNo.Text = "**";

            this.ParentForm.TransferProductParameter1(productNumber);
        }
        public void RescaleControl()
        {
            this.MainBarGraph.RescaleProgressBar1();
            this.MainBarGraph.RescaleProgressBar2();
        }
        public void Clear()
        {
            this.ParentForm.CurrentWeightData1.ClearCount();
            this.ParentForm.CurrentWeightData2.ClearCount();
            this.ParentForm.SaveCounterFile1(this.ParentForm.CurrentWeightData1, this.ParentForm.SystemConfig.ProductNumber - 1);
            this.ParentForm.SaveCounterFile2(this.ParentForm.CurrentWeightData2, this.ParentForm.SystemConfig.ProductNumber - 1);

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

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

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

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

        public void TimerServer(bool value)
        {
            if (value == false)
            {
                if (this.timerServerMainDisplay.Enabled == true)
                    this.timerServerMainDisplay.Enabled = false;
            }
            else
            {
                if (this.timerServerMainDisplay.Enabled == false)
                    this.timerServerMainDisplay.Enabled = true;
            }
        }

        public void MainBottomModbusIconAdd(bool bValue)
        {
            this.ParentForm.IsOPCModbusUsing = bValue;
            this.CurrentBottomMenuControlEnable();
        }
        public void DisplayPrintButton(SystemConfigurationItem system)
        {
            if (system.SerialCOM1Mode == 3 || system.SerialCOM3Mode == 3)
            {
                this.buttonPrint.Visible = true;
            }
            else
            {
                this.buttonPrint.Visible = false;
            }
        }
        public void UpdateIcomDisplay()
        {
            // Icon - 데이터 백업
            if (this.ParentForm.SystemConfig.IsDataBackup == true)
            {
                this.pictureBoxIconUsbEnable.Visible = true;
                this.pictureBoxIconUsbDesable.Visible = false;
            }
            else
            {
                this.pictureBoxIconUsbEnable.Visible = false;
                this.pictureBoxIconUsbDesable.Visible = true;
            }

            // Icon - COM1
            if (this.ParentForm.SystemConfig.SerialCOM1Mode == 0)
            {
                this.pictureBoxCOM1Enable.Visible = false;
                this.pictureBoxCOM1Disable.Visible = true;
            }
            else
            {
                this.pictureBoxCOM1Enable.Visible = true;
                this.pictureBoxCOM1Disable.Visible = false;
            }

            // Icon - COM3
            if (this.ParentForm.SystemConfig.SerialCOM3Mode == 0)
            {
                this.pictureBoxCOM3Enable.Visible = false;
                this.pictureBoxCOM3Disable.Visible = true;
            }
            else
            {
                this.pictureBoxCOM3Enable.Visible = true;
                this.pictureBoxCOM3Disable.Visible = false;
            }

            // Icon - COM4
            if (this.ParentForm.SystemConfig.SerialCOM4Mode == 0)
            {
                this.pictureBoxCOM4Enable.Visible = false;
                this.pictureBoxCOM4Disable.Visible = true;
            }
            else
            {
                this.pictureBoxCOM4Enable.Visible = true;
                this.pictureBoxCOM4Disable.Visible = false;
            }

            // Icon - Feedback
            if (this.MainFeedback.IsUsingFeedback() == true) // Feedback
            {
                this.pictureBoxFeedbackDisable.Visible = false;
                this.pictureBoxFeedbackEnable.Visible = true;
            }
            else
            {
                this.pictureBoxFeedbackDisable.Visible = true;
                this.pictureBoxFeedbackEnable.Visible = false;
            }
        }
        /// <summary>
        /// 사용안함(Modbus 유료화 추가되면 사용할 것)
        /// </summary>
        public void UpdateIconDisplay()
        {
            int value = 0;

            // Icon - COM1 
            if (this.ParentForm.SystemConfig.SerialCOM1Mode == 0)
            {
                this.pictureBoxCOM1Enable.Visible = false;
                this.pictureBoxCOM1Disable.Visible = true;
            }
            else
            {
                if (this.ParentForm.SystemConfig.SerialCOM1Mode == (int)Define.E_CommMode.f99_Modbus && this.ParentForm.SystemConfig.IsModbus == false)
                {
                    this.pictureBoxCOM1Enable.Visible = false;
                    this.pictureBoxCOM1Disable.Visible = true;
                }
                else
                {
                    this.pictureBoxCOM1Enable.Visible = true;
                    this.pictureBoxCOM1Disable.Visible = false;
                }
            }

            // Icon - COM3
            if (this.ParentForm.SystemConfig.SerialCOM3Mode == (int)Define.E_CommMode.f0_None)
            {
                this.pictureBoxCOM3Enable.Visible = false;
                this.pictureBoxCOM3Disable.Visible = true;
            }
            else
            {
                if (this.ParentForm.SystemConfig.SerialCOM3Mode == (int)Define.E_CommMode.f99_Modbus && this.ParentForm.SystemConfig.IsModbus == false)
                {
                    this.pictureBoxCOM3Enable.Visible = false;
                    this.pictureBoxCOM3Disable.Visible = true;
                }
                else
                {
                    this.pictureBoxCOM3Enable.Visible = true;
                    this.pictureBoxCOM3Disable.Visible = false;
                }
            }

            // Icon - COM3
            if (this.ParentForm.SystemConfig.SerialCOM4Mode == 0)
            {
                this.pictureBoxCOM4Enable.Visible = false;
                this.pictureBoxCOM4Disable.Visible = true;
            }
            else
            {
                if (this.ParentForm.SystemConfig.SerialCOM4Mode == (int)Define.E_CommMode.f99_Modbus && this.ParentForm.SystemConfig.IsModbus == false)
                {
                    this.pictureBoxCOM4Enable.Visible = false;
                    this.pictureBoxCOM4Disable.Visible = true;
                }
                else
                {
                    this.pictureBoxCOM4Enable.Visible = true;
                    this.pictureBoxCOM4Disable.Visible = false;
                }
            }

            // 옵션보드
            try
            {
                value = int.Parse(this.ParentForm.CurrentSystemParameter9507.OptionBoard);
            }
            catch
            {
                value = 0;
            }
            if (value == 1 && int.Parse(this.ParentForm.CurrentSystemParameter9508.OPT1SamplingCount) != 0) // Feedback
            {
                this.pictureBoxFeedbackDisable.Visible = false;
                this.pictureBoxFeedbackEnable.Visible = true;
            }
            else
            {
                this.pictureBoxFeedbackDisable.Visible = true;
                this.pictureBoxFeedbackEnable.Visible = false;
            }
        }
        private void UpdateDisplayUser(SystemStatus status) 
        {
            string id = "", group = "";

            switch (status.CurrentUser.Group)
            {
                case Define.E_UserGroup.LogOut:
                    id = "";
                    if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
                        group = "关闭";
                    else if (this.ParentForm.SystemConfig.Language == Define.E_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.buttonMenu.Enabled = false;
                    break;
                case Define.E_UserGroup.Level1:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
                        group = "级别1";
                    else if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
                        group = "Nivel 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.labelProductName.Enabled = true;

                    if (status.Equipment == Define.E_EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case Define.E_UserGroup.Level2:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
                        group = "级别2";
                    else if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
                        group = "Nivel 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.labelProductName.Enabled = true;

                    if (status.Equipment == Define.E_EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case Define.E_UserGroup.Level3:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
                        group = "级别3";
                    else if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
                        group = "Nivel 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.labelProductName.Enabled = true;

                    if (status.Equipment == Define.E_EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                case Define.E_UserGroup.Developer:
                    id = status.CurrentUser.ID;
                    if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
                        group = "级别4";
                    else if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
                        group = "Nivel 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.labelProductName.Enabled = true;

                    if (status.Equipment == Define.E_EquipmentStatus.Stop)
                        this.buttonMenu.Enabled = true;
                    else
                        this.buttonMenu.Enabled = false;
                    break;
                default:
                    id = "";
                    if (this.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
                        group = "关闭";
                    else if (this.ParentForm.SystemConfig.Language == Define.E_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 UpdateEquipmentStatusDisplay(Define.E_EquipmentStatus status)
        {
            this.MainBarGraph.UpdateEquipmentStatusDisplay(status);
            this.MainWeightScreen.UpdateEquipmentStatusDisplay(status);

            if (status == Define.E_EquipmentStatus.Start)
            {
                this.pictureBoxStart.Visible = true;
                this.pictureBoxStop.Visible = false;
                this.buttonProductNo.Enabled = false;
                this.labelProductName.Enabled = false;

                this.buttonConveyorUpDown.Enabled = false;
                this.buttonMenu.Enabled = false;
            }
            else
            {
                this.pictureBoxStart.Visible = false;
                this.pictureBoxStop.Visible = true;

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

                if (this.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.LogOut)
                {
                    this.buttonProductNo.Enabled = false;
                    this.labelProductName.Enabled = false;
                    this.buttonMenu.Enabled = false;
                }
                else
                {
                    this.buttonProductNo.Enabled = true;
                    this.labelProductName.Enabled = true;
                    this.buttonMenu.Enabled = true;
                }
            }
        }
        public void UpdateCurrentProductDisplay(Define.E_EquipmentStatus status, ProductItem pItem1, ProductItem pItem2, WeightData wData1, WeightData wData2)
        {
            string value = "";

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

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

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

            if (this.MainBarGraph != null)
                this.MainBarGraph.UpdateCurrentProductDisplay(status, pItem1, pItem2, wData1, wData2);
            if (this.MainDataStatistics != null)
                this.MainDataStatistics.UpdateCurrentProductDisplay(status, pItem1, pItem2, wData1, wData2);
            if (this.MainWeightScreen != null)
                this.MainWeightScreen.UpdateCurrentProductDisplay(status, pItem1, pItem2, wData1, wData2);
            if (this.MainLineGraph != null)
                this.MainLineGraph.UpdateCurrentProductDisplay(status, pItem1, pItem2, wData1, wData2);
        }
        public void UpdateStopWeightDisplay(Define.E_EquipmentStatus status, WeightData data1, WeightData data2)
        {
            // 알람표시
            this.UpdateDisplayAlarmView(data1, data2);

            if (this.MainBarGraph != null)
                this.MainBarGraph.UpdateStopWeightDisplay(status, data1, data2);
            if (this.MainWeightScreen != null)
                this.MainWeightScreen.UpdateStopWeightDisplay(status, data1, data2);
        }
        public void UpdateStartWeightDisplay1(Define.E_EquipmentStatus status, WeightData data)
        {
            // 알람표시
            this.UpdateDisplayAlarmView(data, this.ParentForm.CurrentWeightData2);

            if (data.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return;

            if (this.MainBarGraph != null)
                this.MainBarGraph.UpdateStartWeightDisplay1(status, data);
            if (this.MainDataStatistics != null)
                this.MainDataStatistics.UpdateStartWeightDisplay1(status, data);
            if (this.MainList != null)
                this.MainList.UpdateStartWeightDisplay1(status, data);
            if (this.MainLineGraph != null)
                this.MainLineGraph.UpdateStartWeightDisplay1(status, data);
            if (this.MainWeightScreen != null)
                this.MainWeightScreen.UpdateStartWeightDisplay1(status, data);
        }
        public void UpdateStartWeightDisplay2(Define.E_EquipmentStatus status, WeightData data)
        {
            // 알람표시
            this.UpdateDisplayAlarmView(this.ParentForm.CurrentWeightData1, data);

            if (data.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return;

            if (this.MainBarGraph != null)
                this.MainBarGraph.UpdateStartWeightDisplay2(status, data);
            if (this.MainDataStatistics != null)
                this.MainDataStatistics.UpdateStartWeightDisplay2(status, data);
            if (this.MainList != null)
                this.MainList.UpdateStartWeightDisplay2(status, data);
            if (this.MainLineGraph != null)
                this.MainLineGraph.UpdateStartWeightDisplay2(status, data);
            if (this.MainWeightScreen != null)
                this.MainWeightScreen.UpdateStartWeightDisplay2(status, data);
        }
        public void UpdateEthernetStatusDisplay(bool status)
        {
            //Console.Write("\n" + string.Format("UpdateEthernetStatusDisplay {0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.Now, status.ToString()));

            if (this.BeforeEthernetStatus == status)
                return;
            else
                this.BeforeEthernetStatus = status;

            if (status == true)
            {
                this.pictureBoxEthernetConnection.Visible = true;
                this.pictureBoxEthernetDisconnection.Visible = false;
            }
            else
            {
                this.pictureBoxEthernetConnection.Visible = false;
                this.pictureBoxEthernetDisconnection.Visible = true;
            }
        }
        public void PopUpWarning(string warning)
        {
            this.labelAlarmWindow.Text = warning;
            this.labelAlarmWindow.BringToFront();
            this.labelAlarmWindow.Visible = true;
        }
        public void PopUpWarningClose()
        {
            if (this.labelAlarmWindow.Visible == true)
            {
                this.labelAlarmWindow.Visible = false;

                this.ParentForm.TransferData(CommunicationCommand.BuzzerOnContinuousDisable, CommunicationID.MainBoard);
            }
        }

        #region Icon
        public void InitialEthernetIcon()
        {
            // 이더넷
            if (this.ParentForm.SystemConfig.IsEthernetEnable == true)
            {
                this.pictureBoxEthernetDisable.Visible = false;
                this.pictureBoxEthernetDisconnection.Visible = true;
                this.pictureBoxEthernetConnection.Visible = false;
            }
            else
            {
                this.pictureBoxEthernetDisable.Visible = true;
                this.pictureBoxEthernetDisconnection.Visible = false;
                this.pictureBoxEthernetConnection.Visible = false;
            }
        }
        #endregion

        public void BottomButtonLocation(int buttonNo, SmartX.SmartButton button)
        {
            switch (buttonNo)
            {
                case 1:
                    button.Location = new Point(385, 0);
                    break;
                case 2:
                    button.Location = new Point(456, 0);
                    break;
                case 3:
                    button.Location = new Point(527, 0);
                    break;
                default:
                    break;
            }
        }
        public void CurrentBottomMenuControlEnable()
        {
            Collection<SmartButton> buttons = new Collection<SmartButton>();
            bool feedback = this.MainFeedback.IsUsingFeedback();
            int sampleCount = int.Parse(this.ParentForm.CurrentSystemParameter9508.OPT1SamplingCount);
            bool modbus = this.ParentForm.IsOPCModbusUsing;

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

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

                    if (this.ParentForm.CurrentSystemParameter9508.OPT1OverRange1Int <= 0 && this.ParentForm.CurrentSystemParameter9508.OPT1UnderRange1Int <= 0)
                    {
                        this.ParentForm.UpdateFeedbackData1(this.ParentForm.CurrentProductItem1, this.ParentForm.CurrentSystemParameter9508);
                        this.ParentForm.UpdateFeedbackDeviation1(this.ParentForm.CurrentProductItem1, this.ParentForm.CurrentSystemParameter9508);
                    }
                    else
                        this.ParentForm.UpdateFeedbackDeviation1(this.ParentForm.CurrentProductItem1, this.ParentForm.CurrentSystemParameter9508);

                    if (this.ParentForm.CurrentSystemParameter9508.OPT1OverRange2Int <= 0 && this.ParentForm.CurrentSystemParameter9508.OPT1UnderRange2Int <= 0)
                    {
                        this.ParentForm.UpdateFeedbackData2(this.ParentForm.CurrentProductItem2, this.ParentForm.CurrentSystemParameter9508);
                        this.ParentForm.UpdateFeedbackDeviation2(this.ParentForm.CurrentProductItem2, this.ParentForm.CurrentSystemParameter9508);
                    }
                    else
                        this.ParentForm.UpdateFeedbackDeviation2(this.ParentForm.CurrentProductItem2, this.ParentForm.CurrentSystemParameter9508);
                }
                if (modbus == true)
                    buttons.Add(this.buttonModbus);
            }
            else
            {
                this.CurrentDisplay = Define.E_MainDisplayStore.BarGraph;
                this.DisplayBottomMain(this.CurrentDisplay);
            }

            for (int i = 0; i < buttons.Count; i++)
            {
                this.BottomButtonLocation(i + 1, buttons[i]);
                buttons[i].Visible = true;
            }
        }
        public void UpdateDisplayMenuButton(Define.E_MainDisplayStore main)
        {
            this.buttonStop.ButtonUp();
            this.buttonStartMenu.ButtonUp();
            this.buttonBargraph.ButtonUp();
            this.buttonLinegraph.ButtonUp();
            this.buttonFeedback.ButtonUp();
            this.buttonList.ButtonUp();
            this.buttonDataStat.ButtonUp();

            switch (main)
            {
                case Define.E_MainDisplayStore.SubMenu:
                    if (this.buttonStartMenu.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonStartMenu.ButtonDown();
                    break;
                case Define.E_MainDisplayStore.BarGraph:
                    if (this.buttonBargraph.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonBargraph.ButtonDown();
                    break;
                case Define.E_MainDisplayStore.LineGraph:
                    if (this.buttonLinegraph.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonLinegraph.ButtonDown();
                    break;
                case Define.E_MainDisplayStore.List:
                    if (this.buttonList.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonList.ButtonDown();
                    break;
                case Define.E_MainDisplayStore.DataStat:
                    if (this.buttonDataStat.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonDataStat.ButtonDown();
                    break;
                case Define.E_MainDisplayStore.Feedback:
                    if (this.buttonFeedback.ButtonStatus != SmartButton.BUTSTATUS.DOWN)
                        this.buttonFeedback.ButtonDown();
                    break;
                default:
                    break;
            }
        }
        public void DisplayBottomMain(Define.E_MainDisplayStore main)
        {
            this.UpdateDisplayMenuButton(main);

            switch (main)
            {
                case Define.E_MainDisplayStore.SubMenu:
                    this.MainSubMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainSubMenu.BringToFront();
                    this.MainWeightScreen.BringToFront();
                    break;
                case Define.E_MainDisplayStore.BarGraph:
                    this.MainBarGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainBarGraph.BringToFront();
                    break;
                case Define.E_MainDisplayStore.LineGraph:
                    this.MainLineGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainLineGraph.BringToFront();
                    this.MainWeightScreen.BringToFront();
                    break;
                case Define.E_MainDisplayStore.List:
                    this.MainList.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainList.BringToFront();
                    this.MainWeightScreen.BringToFront();
                    break;
                case Define.E_MainDisplayStore.DataStat:
                    this.MainDataStatistics.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainDataStatistics.BringToFront();
                    this.MainWeightScreen.BringToFront();
                    break;
                case Define.E_MainDisplayStore.Feedback:
                    this.MainFeedback.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.MainFeedback.BringToFront();
                    this.MainWeightScreen.BringToFront();
                    break;
                default:
                    break;
            }
        }
        public void UpdateControlVisible(bool enable)
        {
            this.buttonConveyorUpDown.Visible = enable;
        }

        public void UpdateTimeDisplay()
        {
            this.labelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");        
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.MainDisplay;
            this.ParentForm.SetDisplayMode(Define.E_DisplayMode.Normal);

            this.UpdateDisplayUser(status);
            this.UpdateIcomDisplay();

            if (this.ParentForm.SystemConfig.EquipmentType == 4)
                this.buttonConveyorUpDown.ButtonUp();

            if (this.CurrentDisplay == Define.E_MainDisplayStore.Feedback)
            {
                if (this.MainFeedback.IsUsingFeedback() == false)
                {
                    this.CurrentDisplay = Define.E_MainDisplayStore.BarGraph;
                    this.DisplayBottomMain(this.CurrentDisplay);
                }
            }

            this.MainBarGraph.DisplayRefresh(status);
            this.MainList.DisplayRefresh(status);
            this.MainSubMenu.DisplayRefresh(status);
            this.MainLineGraph.DisplayRefresh(status);
            this.MainDataStatistics.DisplayRefresh(status);
            this.MainFeedback.DisplayRefresh(status);
            this.MainWeightScreen.DisplayRefresh(status);
            
            this.ProductChange(this.ParentForm.SystemConfig.ProductNumber);

            if (this.ParentForm.SystemConfig.IsPrintPerProductEnable == true)
                this.buttonPrint.ButtonDown();
            else
                this.buttonPrint.ButtonUp();
        }
        #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.MainBoard);
        }

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

            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.ParentForm.SystemConfig.ProductNumber = myKeyPad.IntValue;
                    this.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.SystemConfig);

                    this.ProductChange(this.ParentForm.SystemConfig.ProductNumber);
                }
            }
        }
        private void labelProductName_Click(object sender, EventArgs e)
        {
            int listIndex = 0, listViewIndex = 0;
            Collection<string> productNames = new Collection<string>();

            this.ParentForm.LoadProductName1(ref productNames);

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

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

            if (product.ShowDialog() == DialogResult.OK)
            {
                this.ParentForm.SystemConfig.ProductNumber = product.SelectedProductNumber;
                this.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.SystemConfig);

                this.ProductChange(product.SelectedProductNumber);
            }
        }

        private void pictureBoxStart_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        private void pictureBoxStop_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
        }

        private void timerPrinting_Tick(object sender, EventArgs e)
        {
            //this.timerPrinting.Enabled = false;
            //this.buttonPrint.Enabled = true;
            //this.buttonClear.Enabled = true;
        }

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

        private void labelAlarmWindow_Click(object sender, EventArgs e)
        {
            this.PopUpWarningClose();
        }

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

                this.ParentForm.PrintingHeadLine();
            }
            else
            {
                this.ParentForm.SystemConfig.IsPrintPerProductEnable = false;

                if (this.ParentForm.SystemConfig.SerialCOM1Mode == 3)
                {
                    this.ParentForm.TransferSerialCOM1("\n--------------------------------");
                    this.ParentForm.TransferSerialCOM1("\n\n\n\n\n\n");
                }
                else if (this.ParentForm.SystemConfig.SerialCOM3Mode == 3)
                {
                    this.ParentForm.TransferSerialCOM3("\n--------------------------------");
                    this.ParentForm.TransferSerialCOM3("\n\n\n\n\n\n");
                }
            }

            this.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.SystemConfig);

            //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)
        {
            DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 8);
            if (myDlg.ShowDialog() == DialogResult.Yes)
            {
                this.Clear();
            }
        }
        private void buttonUser_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentSystemStatus.CurrentUser.Group == Define.E_UserGroup.LogOut)
            {
                DialogFormLogOn logOn = new DialogFormLogOn(this.ParentForm, this.ParentForm.SystemConfig.Language);
                if (logOn.ShowDialog() == DialogResult.OK)
                {
                    this.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                    this.buttonUser.ButtonDown();

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

                    this.DisplayRefresh(this.ParentForm.CurrentSystemStatus);

                    switch (this.CurrentDisplay)
                    {
                        case Define.E_MainDisplayStore.SubMenu:
                            this.MainSubMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case Define.E_MainDisplayStore.BarGraph:
                            this.MainBarGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case Define.E_MainDisplayStore.LineGraph:
                            this.MainLineGraph.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case Define.E_MainDisplayStore.List:
                            this.MainList.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                            break;
                        case Define.E_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 = Define.E_WeightInputMode.Deviation;
            else
                this.ParentForm.CurrentSystemStatus.CurrentWeightInputMode = Define.E_WeightInputMode.Weight;

            this.UpdateCurrentProductDisplay(this.ParentForm.CurrentSystemStatus.Equipment, this.ParentForm.CurrentProductItem1, this.ParentForm.CurrentProductItem2,
                this.ParentForm.CurrentWeightData1, this.ParentForm.CurrentWeightData2);
        }
        private void buttonMenu_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.SystemConfig.IsLogin == false)
            {
                if (this.ParentForm.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)Define.E_FormStore.FormMenu);
                    this.ParentForm.ChildFormMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                }
            }
            else
            {
                if (this.ParentForm.CurrentSystemStatus.Equipment == Define.E_EquipmentStatus.Stop)
                {
                    ((FormMain)(Owner)).smartForm.Show((int)Define.E_FormStore.FormMenu);
                    this.ParentForm.ChildFormMenu.DisplayRefresh(this.ParentForm.CurrentSystemStatus);
                }
            }
        }

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

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

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

            this.DisplayBottomMain(this.CurrentDisplay);
        }
        private void buttonList_Click(object sender, EventArgs e)
        {
            this.CurrentDisplay = Define.E_MainDisplayStore.List;

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

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

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

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

            this.DisplayBottomMain(this.CurrentDisplay);
        }

        private void timerServerMainDisplay_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)
        {
            this.ParentForm.CloseSmartUartLink();
            this.ParentForm.smartFileCommunicationLog.Close();
            this.ParentForm.Close();
        }

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