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

using SmartX;

using ITC81DB_2.Forms;
using ITC81DB_2.DialogForms;
using ITC81DB_2_ImageDll;
using System.Threading;

namespace ITC81DB_2.Controls
{
    public partial class ControlCenterEquipFunctionSetting : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        #endregion

        #region Constructor
        public ControlCenterEquipFunctionSetting(FormMenu parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

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

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

            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.English)
            {
                this.labelTitleEquipmentID.Text = "Equipment ID";
                this.labelTitleBuzzerONTime.Text = "Buzzer ON time";
                this.labelTitleSensorChattering.Text = "Sensor Chattering";
                this.labelTitleSwitchChattering.Text = "Switch Chattering";
                this.labelTitleRelayRunTime.Text = "Relay Run time";
                this.labelTitleEntryNotDetected.Text = "Entry Not Detected";
                this.labelTitleEntryNotDetectedIgnoreTime.Text = "Entry Not Detected(Ignore Time)";
                this.labelTitleSensorErrorDetectingTime.Text = "Sensor Error Detecting Time";
                this.labelTitleJudgmentDelay1.Text = "1 Judge Delay";
                this.labelTitleJudgmentDelay2.Text = "2 Judge Delay";
                this.labelTitleLogin.Text = "Login";
                this.labelTitleLanguage.Text = "Language";
                this.labelTitleCommunicationLog.Text = "Log";

                this.comboBoxLanguage.SelectedIndexChanged -= new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);
                this.comboBoxLanguage.Items.Clear();
                this.comboBoxLanguage.Items.Add("Korean");
                this.comboBoxLanguage.Items.Add("English");
                this.comboBoxLanguage.Items.Add("Chinese");
                this.comboBoxLanguage.Items.Add("Spanish");
                this.comboBoxLanguage.SelectedIndexChanged += new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);

                this.buttonLogin.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonLogin.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
                this.buttonCommunicationLog.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonCommunicationLog.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleBuzzerONTime.Text = "蜂鸣器开启时间";
                this.labelTitleRelayRunTime.Text = "继电器接通时间";
                this.labelTitleSensorChattering.Text = "传感器抖动";
                this.labelTitleSwitchChattering.Text = "开关喋喋不休";
                this.labelTitleLanguage.Text = "语言";
                this.labelTitleEquipmentID.Text = "设备编号";
                this.labelTitleEntryNotDetected.Text = "未检测到产品条目";
                this.labelTitleEntryNotDetectedIgnoreTime.Text = "忽略未检测到产品进入的时间";
                this.labelTitleSensorErrorDetectingTime.Text = "传感器错误检测时间";
                this.labelTitleJudgmentDelay1.Text = "第1列决策延迟值 :";
                this.labelTitleJudgmentDelay2.Text = "第2列决策延迟值 :";
                this.labelTitleLogin.Text = "登錄";
                this.labelTitleCommunicationLog.Text = "通讯日志";

                this.comboBoxLanguage.SelectedIndexChanged -= new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);
                this.comboBoxLanguage.Items.Clear();
                this.comboBoxLanguage.Items.Add("韩语");
                this.comboBoxLanguage.Items.Add("英语");
                this.comboBoxLanguage.Items.Add("中文");
                this.comboBoxLanguage.Items.Add("西班牙语");
                this.comboBoxLanguage.SelectedIndexChanged += new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);

                this.buttonLogin.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON_Black));
                this.buttonLogin.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF_Black));
                this.buttonCommunicationLog.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON_Black));
                this.buttonCommunicationLog.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF_Black));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.labelTitleEquipmentID.Text = "ID de equipo";
                this.labelTitleBuzzerONTime.Text = "Zumbador a tiempo";
                this.labelTitleSensorChattering.Text = "Vibración del sensor";
                this.labelTitleSwitchChattering.Text = "Cambiar de charla";
                this.labelTitleRelayRunTime.Text = "Relé a tiempo";
                this.labelTitleEntryNotDetected.Text = "Entrada no detectada";
                this.labelTitleEntryNotDetectedIgnoreTime.Text = "Entrada no detectada (Ignorar hora)";
                this.labelTitleSensorErrorDetectingTime.Text = "Tiempo de detección de errores del sensor";
                this.labelTitleJudgmentDelay1.Text = "1 Demora";
                this.labelTitleJudgmentDelay2.Text = "2 Demora";
                this.labelTitleLogin.Text = "Acceso";
                this.labelTitleLanguage.Text = "Idioma";
                this.labelTitleCommunicationLog.Text = "Log";

                this.comboBoxLanguage.SelectedIndexChanged -= new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);
                this.comboBoxLanguage.Items.Clear();
                this.comboBoxLanguage.Items.Add("Coreano");
                this.comboBoxLanguage.Items.Add("Inglés");
                this.comboBoxLanguage.Items.Add("Chino");
                this.comboBoxLanguage.Items.Add("Español");
                this.comboBoxLanguage.SelectedIndexChanged += new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);

                this.buttonLogin.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnON_Black));
                this.buttonLogin.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnOFF_Black));
                this.buttonCommunicationLog.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnON_Black));
                this.buttonCommunicationLog.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnOFF_Black));
            }
            else
            {
                this.labelTitleBuzzerONTime.Text = "부저 ON 시간";
                this.labelTitleRelayRunTime.Text = "릴레이 동작 시간";
                this.labelTitleSensorChattering.Text = "센서채터링";
                this.labelTitleSwitchChattering.Text = "스위치채터링";
                this.labelTitleLanguage.Text = "언어설정";
                this.labelTitleEquipmentID.Text = "장비 ID";
                this.labelTitleEntryNotDetected.Text = "제품진입 미감지";
                this.labelTitleEntryNotDetectedIgnoreTime.Text = "제품진입 미감지 무시시간";
                this.labelTitleSensorErrorDetectingTime.Text = "센서에러 감지시간";
                this.labelTitleJudgmentDelay1.Text = "1열 판정지연값 :";
                this.labelTitleJudgmentDelay2.Text = "2열 판정지연값 :";
                this.labelTitleLogin.Text = "로그인";
                this.labelTitleCommunicationLog.Text = "통신로그";

                this.comboBoxLanguage.SelectedIndexChanged -= new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);
                this.comboBoxLanguage.Items.Clear();
                this.comboBoxLanguage.Items.Add("한국어");
                this.comboBoxLanguage.Items.Add("영어");
                this.comboBoxLanguage.Items.Add("중국어");
                this.comboBoxLanguage.Items.Add("스페인어");
                this.comboBoxLanguage.SelectedIndexChanged += new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);

                this.buttonLogin.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonLogin.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
                this.buttonCommunicationLog.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
                this.buttonCommunicationLog.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
            }
        }
        private void DefaultSetting()
        {

        }

        private void UpdateParameterDisplay(SystemConfigurationItem item, SystemParameter9507 system)
        {
            string value = "";
            int index = 0;

            // Equipment ID
            value = item.EquipmentID.ToString();
            if (this.labelEquipmentID.Text != value)
                this.labelEquipmentID.Text = value;

            // 언어
            index = (int)item.Language;
            if (this.comboBoxLanguage.SelectedIndex != index)
            {
                this.comboBoxLanguage.SelectedIndexChanged -= new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);
                this.comboBoxLanguage.SelectedIndex = index;
                this.comboBoxLanguage.SelectedIndexChanged += new EventHandler(this.comboBoxLanguage_SelectedIndexChanged);
            }

            // 로그인
            if (item.IsLogin == false)
                this.buttonLogin.ButtonUp();
            else
                this.buttonLogin.ButtonDown();

            // 부저ON시간
            value = system.BuzzerOnTime.Trim();
            if (this.labelBuzzerOnTime.Text != value)
                this.labelBuzzerOnTime.Text = value;

            // 릴레이동작시간
            value = system.RelayOnTime.Trim();
            if (this.labelRelayOnTime.Text != value)
                this.labelRelayOnTime.Text = value;

            // 센서채터링
            value = system.SensorChattering.Trim();
            if (this.labelSensorChattering.Text != value)
                this.labelSensorChattering.Text = value;

            // 스위치채터링
            value = system.SwitchChattering.Trim();
            if (this.labelSwitchChattering.Text != value)
                this.labelSwitchChattering.Text = value;

            value = Helper.StringToDecimalPlaces(system.EntryNotDetectedWeight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelEntryNotDetected.Text != value)
                this.labelEntryNotDetected.Text = value;

            value = item.SensorErrorDetectingTime.ToString();
            if (this.labelSensorErrorDetectingTime.Text != value)
                this.labelSensorErrorDetectingTime.Text = value;

            value = item.EntryNotDetectedIgnoreTime.ToString();
            if (this.labelEntryNotDetectedIgnoreTime.Text != value)
                this.labelEntryNotDetectedIgnoreTime.Text = value;

            value = this.ParentForm.ParentForm.CurrentJudgmentSetItem1.JudgmentDelayTime.ToString();
            if (this.labelJudgmentValue1.Text != value)
                this.labelJudgmentValue1.Text = value;

            value = this.ParentForm.ParentForm.CurrentJudgmentSetItem2.JudgmentDelayTime.ToString();
            if (this.labelJudgmentValue2.Text != value)
                this.labelJudgmentValue2.Text = value;

            value = this.ParentForm.ParentForm.SystemConfig.Unit;
            if (this.labelUnit.Text != value)
                this.labelUnit.Text = value;
        }

        private void UpdateDisplayUser(UserItem user)
        {
            // 디버그 후 지울것
            this.labelTitleCommunicationLog.Visible = true;
            this.buttonCommunicationLog.Visible = true;

            //if (user.Group == Define.UserGroup.Level4Developer && this.ParentForm.ParentForm.SystemConfig.IsLogin == true)
            //{
            //    this.labelTitleCommunicationLog.Visible = true;
            //    this.buttonCommunicationLog.Visible = true;
            //}
            //else
            //{
            //    this.labelTitleCommunicationLog.Visible = false;
            //    this.buttonCommunicationLog.Visible = false;
            //}
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.EquipFuctionSetting;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.UpdateParameterDisplay(this.ParentForm.ParentForm.SystemConfig, this.ParentForm.ParentForm.CurrentSystemParameter9507);
            this.UpdateDisplayUser(status.CurrentUser);
        }
        #endregion

        #region Event Handler
        private void labelEquipmentID_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelEquipmentID.Text, 3, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    this.ParentForm.ParentForm.SystemConfig.EquipmentID = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig);
                }
            }
        }
        private void labelBuzzerOnTime_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelBuzzerOnTime.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6001_BuzzerOnTime, value);
                }
            }
        }
        private void labelRelayOnTime_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelRelayOnTime.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6002_RelayRunTime, value);
                }
            }
        }
        private void labelSensorChattering_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSensorChattering.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    value = Helper.StringZeroFillDigits4(this.labelSensorChattering.Text);
                    this.ParentForm.ParentForm.CurrentSystemParameter9507.SensorChattering = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6006_SensorChattering, value);
                }
            }
        }
        private void labelSwitchChattering_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSwitchChattering.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    value = Helper.StringZeroFillDigits4(this.labelSwitchChattering.Text);
                    this.ParentForm.ParentForm.CurrentSystemParameter9507.SwitchChattering = myKeyPad.StringValue;

                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6012_SwitchChattering, value);
                }
            }
        }
        private void labelEntryNotDeteced_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelEntryNotDetected.Text, 5, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces,
              false, this.ParentForm.ParentForm.SystemConfig.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0.0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelEntryNotDetected.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentSystemParameter9507.EntryNotDetectedWeight = myKeyPad.StringValue.Replace(".", "");

                    value = Helper.StringZeroFillDigits7(this.ParentForm.ParentForm.CurrentSystemParameter9507.EntryNotDetectedWeight);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6010_EntryNotDetectedWeight, value);
                }
            }
        }
        private void labelEntryNotDetectedIgnoreTime_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelEntryNotDetectedIgnoreTime.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

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

                    this.ParentForm.ParentForm.TimerEntryNotDetectedIgnoreTimeInverval();
                }
            }
        }
        private void labelSensorErrorDetectingTime_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSensorErrorDetectingTime.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);
            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue != 0 && (myKeyPad.IntValue < this.ParentForm.ParentForm.CurrentJudgmentSetItem1.JudgmentDelayTime
                    || myKeyPad.IntValue < this.ParentForm.ParentForm.CurrentJudgmentSetItem2.JudgmentDelayTime))
                {
                    // 센서에러감지시간은 판정지연 값 이상이어야 합니다.
                    DialogFormMessage myMsg = new DialogFormMessage(43, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelSensorErrorDetectingTime.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.SystemConfig.SensorErrorDetectingTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig);

                    this.ParentForm.ParentForm.TimerSensorErrorInterval();

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._6011_SensorErrorDetectingTime, value);
                }
            }
        }
        
        private void comboBoxLanguage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBoxLanguage.SelectedIndex == 0)
                this.ParentForm.ParentForm.SystemConfig.Language = Define.E_LanguageID.Korean;
            else if (this.comboBoxLanguage.SelectedIndex == 1)
                this.ParentForm.ParentForm.SystemConfig.Language = Define.E_LanguageID.English;
            else if (this.comboBoxLanguage.SelectedIndex == 2)
                this.ParentForm.ParentForm.SystemConfig.Language = Define.E_LanguageID.Chinese;
            else if (this.comboBoxLanguage.SelectedIndex == 3)
                this.ParentForm.ParentForm.SystemConfig.Language = Define.E_LanguageID.Spanish;
            else
                this.ParentForm.ParentForm.SystemConfig.Language = Define.E_LanguageID.Korean;

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

            // 각 화면 언어 적용
            SmartSplash splash = new SmartSplash();
            splash.CenterPosition = true;
            splash.AnimationInterval = 200;
            splash.LoadingImagePathname = "SmartLoading4";
            splash.Start();

            this.ParentForm.ParentForm.ChildFormMainDisplay.InitializeDesign();
            this.ParentForm.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.ParentForm.ChildFormMainDisplay.MainSubMenu.InitializeDesign();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainBarGraph.InitializeDesign();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainDataStatistics.InitializeDesign();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainList.InitializeDesign();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainLineGraph.InitializeDesign();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightScreen.InitializeDesign();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainFeedback.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.CenterBasicDataBackup.InitializeDesign();
            this.ParentForm.CenterBasicDataStatistics.InitializeDesign();
            this.ParentForm.CenterBasicHelp.InitializeDesign();
            this.ParentForm.CenterBasicProduct.InitializeDesign();
            this.ParentForm.CenterBasicTime.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.CenterConfiHelp.InitializeDesign();
            this.ParentForm.CenterConfiOptionBoard.InitializeDesign();
            this.ParentForm.CenterConfiSerial.InitializeDesign();
            this.ParentForm.CenterConfiEthernet.InitializeDesign();
            this.ParentForm.CenterConfiEthernet.ControlEthernetAddon.InitializeDesign();
            this.ParentForm.CenterConfiEthernet.ControlEthernetLocalIP.InitializeDesign();
            this.ParentForm.CenterConfiEthernet.ControlModbusTCP.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.CenterEquipFunctionSetting.InitializeDesign();
            this.ParentForm.CenterEquipHelp.InitializeDesign();
            this.ParentForm.CenterEquipInitialize.InitializeDesign();
            this.ParentForm.CenterEquipUpdate.InitializeDesign();
            this.ParentForm.CenterEquipUser.InitializeDesign();
            this.ParentForm.CenterEquipEngineer.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.CenterInforAS.InitializeDesign();
            this.ParentForm.CenterInforHelp.InitializeDesign();
            this.ParentForm.CenterInforSystemInformation.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.CenterSystemAutoZero.InitializeDesign();
            this.ParentForm.CenterSystemCalibration.InitializeDesign();
            this.ParentForm.CenterSystemHelp.InitializeDesign();
            this.ParentForm.CenterSystemIOTest.InitializeDesign();
            this.ParentForm.CenterSystemJudgmentSetting.InitializeDesign();
            this.ParentForm.CenterSystemSorterSetting.InitializeDesign();
            Thread.Sleep(50);

            this.ParentForm.CenterInforAS.DefaultSetting();

            splash.Finish();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig.Language, 15);
            if (myDlg.ShowDialog() == DialogResult.Yes)
            {
                if (this.buttonLogin.ButtonStatus == SmartX.SmartButton.BUTSTATUS.UP)
                    this.ParentForm.ParentForm.SystemConfig.IsLogin = false;
                else
                    this.ParentForm.ParentForm.SystemConfig.IsLogin = true;

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

                DialogFormMessage msg = new DialogFormMessage(18, this.ParentForm.ParentForm.SystemConfig.Language);
                msg.ShowDialog();
            }
            else
            {
                if (this.ParentForm.ParentForm.SystemConfig.IsLogin == false)
                    this.buttonLogin.ButtonUp();
                else
                    this.buttonLogin.ButtonDown();
            }
        }
        private void buttonCommunicationLog_Click(object sender, EventArgs e)
        {
            if (this.buttonCommunicationLog.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.ParentForm.smartFileCommunicationLog.Close();
                this.ParentForm.ParentForm.smartFileCommunicationLog.Open(this.ParentForm.ParentForm.BufferSmartUart);
                this.ParentForm.ParentForm.IsCommunicationLogOpen = true;
            }
            else
            {
                this.ParentForm.ParentForm.IsCommunicationLogOpen = false;
                this.ParentForm.ParentForm.smartFileCommunicationLog.Close();
            }
        }
        #endregion
    }
}
