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 System.Drawing.Imaging;

using SmartX;

using ITC81DB_2H.Forms;
using ITC81DB_2H.DialogForms;
using ITC81DB_2H_ImageDll;
using System.Threading;
using ITC81DB_2H.Datastore;
using ITC81DB_2H.Part11_UserManager;

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

        #region Constructor
        public ControlCenterEquipEngineer(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.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.labelTitleEquipmentType.Text = "Equipment Type";
                this.labelTitleCommunicationOption.Text = "Communication Option";
                this.labelTitleConveyorLength.Text = "Conveyor Length";
                this.buttonCapture.Text = "Capture";
                this.labelTitleOptionBoard.Text = "Option board";
                this.labelTitleBarcode.Text = "Barcode";
                this.labelTitleFileNameExtension.Text = "File Name Extension";
                this.labelTitleDataBackupFormat.Text = "Databackup Format";
                this.labelTitleStatPrintFormat.Text = "Statistics Print Format";
                this.labelTitleBLDC.Text = "BLDC Motor Setting";
                this.labelTitleMotorNum.Text = "Motor Number(1~4)";

                this.comboBoxEquipmentType.SelectedIndexChanged -= new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);
                this.comboBoxEquipmentType.Items.Clear();
                this.comboBoxEquipmentType.Items.Add("Conveyor");
                this.comboBoxEquipmentType.Items.Add("Stop-Weight");
                this.comboBoxEquipmentType.Items.Add("Updown");
                this.comboBoxEquipmentType.SelectedIndexChanged += new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);

                this.comboBoxOptionBoard.SelectedIndexChanged -= new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
                this.comboBoxOptionBoard.Items.Clear();
                this.comboBoxOptionBoard.Items.Add("None");
                this.comboBoxOptionBoard.Items.Add("OPT1");
                this.comboBoxOptionBoard.Items.Add("OPT2");
                this.comboBoxOptionBoard.SelectedIndexChanged += new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);

                this.buttonBarcode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonBarcode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                this.buttonCommunicationOption.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonCommunicationOption.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.labelTitleEquipmentType.Text = "设备类型";
                this.labelTitleCommunicationOption.Text = "通讯选项";
                this.labelTitleConveyorLength.Text = "输送带长度";
                this.buttonCapture.Text = "捕获";
                this.labelTitleOptionBoard.Text = "选项板";
                this.labelTitleBarcode.Text = "条形码";
                this.labelTitleFileNameExtension.Text = "数据备份:文件扩展名";
                this.labelTitleDataBackupFormat.Text = "数据备份:格式";
                this.labelTitleStatPrintFormat.Text = "数据统计:列印格式";
                this.labelTitleBLDC.Text = "BLDC Motor Setting";
                this.labelTitleMotorNum.Text = "Motor Number(1~4)";

                this.comboBoxEquipmentType.SelectedIndexChanged -= new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);
                this.comboBoxEquipmentType.Items.Clear();
                this.comboBoxEquipmentType.Items.Add("输送带");
                this.comboBoxEquipmentType.Items.Add("停止后重量");
                this.comboBoxEquipmentType.Items.Add("上下操作");
                this.comboBoxEquipmentType.SelectedIndexChanged += new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);

                this.comboBoxOptionBoard.SelectedIndexChanged -= new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
                this.comboBoxOptionBoard.Items.Clear();
                this.comboBoxOptionBoard.Items.Add("不使用");
                this.comboBoxOptionBoard.Items.Add("OPT1");
                this.comboBoxOptionBoard.Items.Add("OPT2");
                this.comboBoxOptionBoard.SelectedIndexChanged += new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);

                this.buttonBarcode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON));
                this.buttonBarcode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF));
                this.buttonCommunicationOption.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON));
                this.buttonCommunicationOption.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.labelTitleEquipmentType.Text = "Тип оборудования";
                this.labelTitleCommunicationOption.Text = "Варианты связи";
                this.labelTitleConveyorLength.Text = "Длина конвейера";
                this.buttonCapture.Text = "Заголовок";
                this.labelTitleOptionBoard.Text = "Опции";
                this.labelTitleBarcode.Text = "Штрих-код";
                this.labelTitleFileNameExtension.Text = "Расширение файла";
                this.labelTitleDataBackupFormat.Text = "Формат";
                this.labelTitleStatPrintFormat.Text = "Формат печати(Статистика)";
                this.labelTitleBLDC.Text = "BLDC Motor Setting";
                this.labelTitleMotorNum.Text = "Motor Number(1~4)";

                this.comboBoxEquipmentType.SelectedIndexChanged -= new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);
                this.comboBoxEquipmentType.Items.Clear();
                this.comboBoxEquipmentType.Items.Add("Конвейер");
                this.comboBoxEquipmentType.Items.Add("Взвешивание с остановкой");
                this.comboBoxEquipmentType.Items.Add("Вверх-вниз");
                this.comboBoxEquipmentType.SelectedIndexChanged += new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);

                this.comboBoxOptionBoard.SelectedIndexChanged -= new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
                this.comboBoxOptionBoard.Items.Clear();
                this.comboBoxOptionBoard.Items.Add("Нет");
                this.comboBoxOptionBoard.Items.Add("OPT1");
                this.comboBoxOptionBoard.Items.Add("OPT2");
                this.comboBoxOptionBoard.SelectedIndexChanged += new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);

                this.buttonBarcode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusON));
                this.buttonBarcode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusOFF));
                this.buttonCommunicationOption.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusON));
                this.buttonCommunicationOption.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusOFF));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.labelTitleEquipmentType.Text = "Waagentyp";
                this.labelTitleCommunicationOption.Text = "Kommunikationsmöglichkeiten";
                this.labelTitleConveyorLength.Text = "Fördererlänge";
                this.buttonCapture.Text = "Fang";
                this.labelTitleOptionBoard.Text = "Optionsplatine";
                this.labelTitleBarcode.Text = "Barcode";
                this.labelTitleFileNameExtension.Text = "Dateinamenerweiterung";
                this.labelTitleDataBackupFormat.Text = "Datensicherung Format";
                this.labelTitleStatPrintFormat.Text = "Statistik-Druckformat";
                this.labelTitleBLDC.Text = "BLDC Motor Setting";
                this.labelTitleMotorNum.Text = "Motor Number(1~4)";

                this.comboBoxEquipmentType.SelectedIndexChanged -= new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);
                this.comboBoxEquipmentType.Items.Clear();
                this.comboBoxEquipmentType.Items.Add("Förderer");
                this.comboBoxEquipmentType.Items.Add("Stoppen");
                this.comboBoxEquipmentType.Items.Add("Obenunten");
                this.comboBoxEquipmentType.SelectedIndexChanged += new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);

                this.comboBoxOptionBoard.SelectedIndexChanged -= new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
                this.comboBoxOptionBoard.Items.Clear();
                this.comboBoxOptionBoard.Items.Add("Keiner");
                this.comboBoxOptionBoard.Items.Add("OPT1");
                this.comboBoxOptionBoard.Items.Add("OPT2");
                this.comboBoxOptionBoard.SelectedIndexChanged += new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);

                this.buttonBarcode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerON));
                this.buttonBarcode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerOFF));
                this.buttonCommunicationOption.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerON));
                this.buttonCommunicationOption.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerOFF));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {

            }
            else
            {
                this.labelTitleEquipmentType.Text = "장비타입";
                this.labelTitleCommunicationOption.Text = "통신모드 옵션 사용";
                this.labelTitleConveyorLength.Text = "컨베어 길이";
                this.buttonCapture.Text = "Capture";
                this.labelTitleOptionBoard.Text = "옵션보드";
                this.labelTitleBarcode.Text = "바코드";
                this.labelTitleFileNameExtension.Text = "데이터백업 확장자";
                this.labelTitleDataBackupFormat.Text = "데이터백업 포맷";
                this.labelTitleStatPrintFormat.Text = "데이터집계 출력 포맷";
                this.labelTitleBLDC.Text = "BLDC 모터 설정";
                this.labelTitleMotorNum.Text = "모터개수(1~4)";

                this.comboBoxEquipmentType.SelectedIndexChanged -= new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);
                this.comboBoxEquipmentType.Items.Clear();
                this.comboBoxEquipmentType.Items.Add("컨베어");
                this.comboBoxEquipmentType.Items.Add("정지계량");
                this.comboBoxEquipmentType.Items.Add("업다운");
                this.comboBoxEquipmentType.SelectedIndexChanged += new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);

                this.comboBoxOptionBoard.SelectedIndexChanged -= new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
                this.comboBoxOptionBoard.Items.Clear();
                this.comboBoxOptionBoard.Items.Add("None");
                this.comboBoxOptionBoard.Items.Add("OPT1");
                this.comboBoxOptionBoard.Items.Add("OPT2");
                this.comboBoxOptionBoard.SelectedIndexChanged += new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);

                this.buttonBarcode.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonBarcode.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                this.buttonCommunicationOption.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonCommunicationOption.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
            }
        }
        private void DefaultSetting()
        {
            this.comboBoxDataBackupFormat.SelectedIndexChanged -= new EventHandler(this.comboBoxFormat_SelectedIndexChanged);
            this.comboBoxDataBackupFormat.Items.Clear();
            this.comboBoxDataBackupFormat.Items.Add("STD1");
            this.comboBoxDataBackupFormat.Items.Add("OPT1"); // 종근당
            this.comboBoxDataBackupFormat.SelectedIndexChanged += new EventHandler(this.comboBoxFormat_SelectedIndexChanged);

            this.comboBoxFilenameExtension.SelectedIndexChanged -= new EventHandler(this.comboBoxFilenameExtension_SelectedIndexChanged);
            this.comboBoxFilenameExtension.Items.Clear();
            this.comboBoxFilenameExtension.Items.Add("CSV");
            this.comboBoxFilenameExtension.Items.Add("TXT");
            this.comboBoxFilenameExtension.SelectedIndexChanged += new EventHandler(this.comboBoxFilenameExtension_SelectedIndexChanged);

            this.comboBoxStatisticsPrintFormat.SelectedIndexChanged -= new EventHandler(this.comboBoxStatisticsPrintFormat_SelectedIndexChanged);
            this.comboBoxStatisticsPrintFormat.Items.Clear();
            this.comboBoxStatisticsPrintFormat.Items.Add("STD1");
            this.comboBoxStatisticsPrintFormat.Items.Add("OPT1"); // 삼천당제약
            this.comboBoxStatisticsPrintFormat.SelectedIndexChanged += new EventHandler(this.comboBoxStatisticsPrintFormat_SelectedIndexChanged);
        }

        private void UpdateParameterDisplay(SystemConfigurationItem1 item, SystemConfigurationItem2 item2, SystemConfigurationItem3 item3, SystemParameter1 parameter)
        {
            int index = 0;
            string value = "";

            // 장비타입
            this.comboBoxEquipmentType.SelectedIndexChanged -= new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);
            switch (int.Parse(parameter.EquipmentType))
            {
                case 0: // 컨베어
                    this.comboBoxEquipmentType.SelectedIndex = 0;
                    break;
                case 4: // 업다운
                    this.comboBoxEquipmentType.SelectedIndex = 2;
                    break;
                case 6: // 정지계량
                    this.comboBoxEquipmentType.SelectedIndex = 1;
                    break;
                default:
                    this.comboBoxEquipmentType.SelectedIndex = 0;
                    break;
            }
            this.comboBoxEquipmentType.SelectedIndexChanged += new EventHandler(this.comboBoxEquipmentType_SelectedIndexChanged);

            // 통신옵션 사용
            if (item2.IsCommunicationOption == true)
                this.buttonCommunicationOption.ButtonDown();
            else
                this.buttonCommunicationOption.ButtonUp();

            // 컨베어 입력
            value = item2.ConveyorLength.ToString();
            if (this.labelConveyorLength.Text != value)
                this.labelConveyorLength.Text = value;

            // BLDC 모터 설정
            if (item.IsBLDCON == false)
                this.buttonBLDCUsing.ButtonUp();
            else
                this.buttonBLDCUsing.ButtonDown();

            // BLDC 모터 개수
            value = item2.BLDCTotalMotorNum.ToString();
            if (this.labelMotorNum.Text != value)
                this.labelMotorNum.Text = value;

            // 옵션보드
            index = int.Parse(parameter.OptionBoard.Trim());
            if (this.comboBoxOptionBoard.SelectedIndex != index)
            {
                this.comboBoxOptionBoard.SelectedIndexChanged -= new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
                this.comboBoxOptionBoard.SelectedIndex = index;
                this.comboBoxOptionBoard.SelectedIndexChanged += new EventHandler(this.comboBoxOptionBoard_SelectedIndexChanged);
            }

            // 데이터백업 포맷
            index = item.DatabackupFormat;
            if (this.comboBoxDataBackupFormat.SelectedIndex != index)
            {
                this.comboBoxDataBackupFormat.SelectedIndexChanged -= new EventHandler(this.comboBoxFormat_SelectedIndexChanged);
                this.comboBoxDataBackupFormat.SelectedIndex = index;
                this.comboBoxDataBackupFormat.SelectedIndexChanged += new EventHandler(this.comboBoxFormat_SelectedIndexChanged);
            }

            // 데이터백업 확장자
            index = item2.FileNameExtension;
            if (this.comboBoxFilenameExtension.SelectedIndex != index)
            {
                this.comboBoxFilenameExtension.SelectedIndexChanged -= new EventHandler(this.comboBoxFilenameExtension_SelectedIndexChanged);
                this.comboBoxFilenameExtension.SelectedIndex = index;
                this.comboBoxFilenameExtension.SelectedIndexChanged += new EventHandler(this.comboBoxFilenameExtension_SelectedIndexChanged);
            }

            // 데이터집계 출력 포맷
            index = item.StatisticsPrintFormat;
            if (this.comboBoxStatisticsPrintFormat.SelectedIndex != index)
            {
                this.comboBoxStatisticsPrintFormat.SelectedIndexChanged -= new EventHandler(this.comboBoxStatisticsPrintFormat_SelectedIndexChanged);
                this.comboBoxStatisticsPrintFormat.SelectedIndex = index;
                this.comboBoxStatisticsPrintFormat.SelectedIndexChanged += new EventHandler(this.comboBoxStatisticsPrintFormat_SelectedIndexChanged);
            }

            // 바코드
            if (item.IsBarcodeEnable == false)
                this.buttonBarcode.ButtonUp();
            else
                this.buttonBarcode.ButtonDown();

            // Part11
            if (item3.IsPart11 == false)
                this.buttonPart11.ButtonUp();
            else
                this.buttonPart11.ButtonDown();

            // 데이터 저장 기간
            value = item3.StoragePeriod.ToString();
            if (this.labelStoragePeriod.Text != value)
                this.labelStoragePeriod.Text = value;
        }

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

            this.UpdateParameterDisplay(this.ParentForm.ParentForm.SystemConfig1, this.ParentForm.ParentForm.SystemConfig2,
                this.ParentForm.ParentForm.SystemConfig3, this.ParentForm.ParentForm.CurrentSystemParameter1);
        }
        #endregion

        #region Event Handler
        private void comboBoxEquipmentType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string value = "";

            switch (this.comboBoxEquipmentType.SelectedIndex)
            {
                case 0: // 컨베어
                    this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType = "0";
                    break;
                case 1: // 정지계량
                    this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType = "6";
                    break;
                case 2: // 업다운
                    this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType = "4";
                    break;
                default:
                    this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType = "0";
                    break;
            }

            value = Helper.StringZeroFillDigits4(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType);
            this.ParentForm.CenterSystemJudgment.ChangeScreen();
            this.ParentForm.CenterInforSystem2.ReInitializeDesign();
            this.ParentForm.ParentForm.SaveSystemParameter1File(this.ParentForm.ParentForm.CurrentSystemParameter1);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.EquipmentType, value);
        }
        private void buttonCommunicationOption_Click(object sender, EventArgs e)
        {
            if (this.buttonCommunicationOption.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.SystemConfig2.IsCommunicationOption = true;
            else
                this.ParentForm.ParentForm.SystemConfig2.IsCommunicationOption = false;

            this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);

            this.ParentForm.ParentForm.ChildFormMenu.CenterConfiSerial.ChangeCommunicationMode();
            this.ParentForm.ParentForm.ChildFormMenu.CenterConfiEthernet.ChangeCommunicationMode();
        }
        private void labelConveyorLength_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelConveyorLength.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue < 1 || myKeyPad.IntValue > 2000)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelConveyorLength.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.SystemConfig2.ConveyorLength = myKeyPad.IntValue;

                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);
                }
            }
        }

        private void buttonBLDCUsing_Click(object sender, EventArgs e)
        {
            if (this.buttonBLDCUsing.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.SystemConfig1.IsBLDCON = true;
            else
                this.ParentForm.ParentForm.SystemConfig1.IsBLDCON = false;

            this.ParentForm.CenterSystemHelp.ButtonBLDCVisible(this.ParentForm.ParentForm.SystemConfig1.IsBLDCON);

            this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
            this.ParentForm.ParentForm.ChildFormMenu.CenterInforSystem3.DisplayGroupBox();
        }
        private void labelMotorNum_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelMotorNum.Text, 1, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue < 1 || myKeyPad.IntValue > 4)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelMotorNum.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.ChildFormMenu.CenterSystemBLDCMotorSetting.VisibleMotorNum(myKeyPad.IntValue);

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.SystemConfig2.BLDCTotalMotorNum = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);
                }
            }
        }

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

            if (this.comboBoxOptionBoard.SelectedIndex == 2)
            {
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI7 = 1;
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI6 = 1;
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI5 = 1;
            }
            else
            {
                if (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.OptionBoard) == 2)
                {
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI7 = 0;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI6 = 0;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI5 = 0;
                }
            }

            value = Helper.StringZeroFillDigits4(this.comboBoxOptionBoard.SelectedIndex.ToString());
            this.ParentForm.ParentForm.CurrentSystemParameter1.OptionBoard = value;

            this.ParentForm.ParentForm.ChildFormMenu.CenterConfiOptionBoard.InitializeDesign();

            this.ParentForm.ParentForm.ChildFormMenu.CenterConfiHelp.OptionBoardVisible();
            this.ParentForm.ParentForm.ChildFormMenu.BottomConfiguration.OptionBoardVisible();

            this.ParentForm.ParentForm.SaveSystemParameter1File(this.ParentForm.ParentForm.CurrentSystemParameter1);
            this.ParentForm.ParentForm.TransferParameter1();
        }
        private void comboBoxFilenameExtension_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.SystemConfig2.FileNameExtension = this.comboBoxFilenameExtension.SelectedIndex;
            this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);
        }
        private void comboBoxStatisticsPrintFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            string value = "";

            value = Helper.StringZeroFillDigits4(this.comboBoxStatisticsPrintFormat.SelectedIndex.ToString());
            this.ParentForm.ParentForm.SystemConfig1.StatisticsPrintFormat = this.comboBoxStatisticsPrintFormat.SelectedIndex;
            this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
        }
        private void buttonBarcode_Click(object sender, EventArgs e)
        {
            DialogFormYesNo myDlg;

            if (this.buttonBarcode.ButtonStatus == SmartButton.BUTSTATUS.UP)
                myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 18); // 사용을 중지하시겠습니까?
            else
                myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 17); // 사용하시겠습니까?

            if (myDlg.ShowDialog() == DialogResult.Yes)
            {
                if (this.buttonBarcode.ButtonStatus == SmartButton.BUTSTATUS.UP)
                    this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable = false;
                else
                    this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable = true;

                this.ParentForm.ParentForm.SystemConfig1.SerialCOM3BaudRate = 0;
                this.ParentForm.ParentForm.SystemConfig1.SerialCOM3Mode = 0;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);

                if (this.ParentForm.ParentForm.SystemConfig2.IsUsingRandomMode == true)
                {
                    this.ParentForm.ParentForm.SystemConfig2.IsGroup1UsingRandomMode = false;
                    this.ParentForm.ParentForm.SystemConfig2.IsGroup2UsingRandomMode = false;
                    this.ParentForm.ParentForm.SystemConfig2.IsGroup3UsingRandomMode = false;
                    this.ParentForm.ParentForm.SystemConfig2.IsGroup4UsingRandomMode = false;
                    this.ParentForm.ParentForm.SystemConfig2.IsGroup5UsingRandomMode = false;

                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);
                }

                DialogFormMessage msg = new DialogFormMessage(18, this.ParentForm.ParentForm.SystemConfig1.Language);
                msg.ShowDialog();
            }
            else
            {
                if (this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable == false)
                    this.buttonBarcode.ButtonUp();
                else
                    this.buttonBarcode.ButtonDown();
            }
        }
        private void comboBoxFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            string value = "";

            value = Helper.StringZeroFillDigits4(this.comboBoxDataBackupFormat.SelectedIndex.ToString());
            this.ParentForm.ParentForm.SystemConfig1.DatabackupFormat = this.comboBoxDataBackupFormat.SelectedIndex;
            this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
        }
        private void buttonPart11_Click(object sender, EventArgs e)
        {
            DialogFormYesNo myDlg;

            if (this.buttonPart11.ButtonStatus == SmartX.SmartButton.BUTSTATUS.UP)
                myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 16);
            else
                myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 15);

            if (myDlg.ShowDialog() == DialogResult.Yes)
            {
                if (this.buttonPart11.ButtonStatus == SmartButton.BUTSTATUS.UP)
                {
                    this.ParentForm.ParentForm.SystemConfig3.IsPart11 = false;
                    this.ParentForm.ParentForm.SystemConfig1.IsLogin = false;
                    this.ParentForm.LoginVisible(false);

                    // User 삭제
                    UserManager.UserManager_UserAllDel();
                }
                else
                {
                    this.ParentForm.ParentForm.SystemConfig1.IsLogin = true;
                    this.ParentForm.ParentForm.SystemConfig3.IsPart11 = true;
                    this.ParentForm.LoginVisible(true);
                }

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

                DialogFormMessage msg = new DialogFormMessage(18, this.ParentForm.ParentForm.SystemConfig1.Language);
                msg.ShowDialog();
            }
            else
            {
                this.buttonPart11.Click -= new EventHandler(this.buttonPart11_Click);

                if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == false)
                    this.buttonPart11.ButtonUp();
                else
                    this.buttonPart11.ButtonDown();

                this.buttonPart11.Click += new EventHandler(this.buttonPart11_Click);
            }
        }
        private void labelStoragePeriod_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelStoragePeriod.Text, 2, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

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

                    this.ParentForm.ParentForm.SystemConfig3.StoragePeriod = int.Parse(this.labelStoragePeriod.Text);
                    this.ParentForm.ParentForm.SaveSystemConfigurationFile3(this.ParentForm.ParentForm.SystemConfig3);
                }
            }
        }

        private void buttonCapture_Click(object sender, EventArgs e)
        {
            string filePath = "";
            Bitmap bitMap = new Bitmap(800, 600);

            bitMap = IntechGraphics.CopyFromScreen();
            filePath = string.Format("{0}\\{1}_EngineerSetting.jpg", this.ParentForm.ParentForm.PathDataLogFolder, DateTime.Now.ToString("yyyyMMdd"));
            bitMap.Save(filePath, ImageFormat.Jpeg);
        }
        #endregion
    }
}
