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

using SmartX;

using ITC81DB.Forms;
using ITC81DB.DialogForms;
using ITC81DB_ImageDll;

namespace ITC81DB.Controls
{
    public partial class ControlCenterSystemExternalInput : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        private Collection<ComboBox> CollectionComboBox;
        #endregion

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

            this.ParentForm = parent;

            // 순서 바꾸지 말 것
            this.DefaultSetting(); 
            this.InitializeDesign();
        }
        #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);

            this.comboBoxPIN8.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN7.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN6.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN5.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN4.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN3.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPhotoB.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);

            if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.English)
            {
                #region English
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundExternalInput));

                this.labelExternalInputMessage.Text = "※ (Buzzer/Lamp) Applicable items : Entry Sensor Error, Loadcell Error, Entry not detected, Windproof Cover Open, Emergency Stop, Discharge Check, Air Check, Door Check, Stack up";

                for (int i = 0; i < this.CollectionComboBox.Count; i++)
                {
                    this.CollectionComboBox[i].Items.Clear();
                    this.CollectionComboBox[i].Items.Add("None");
                    this.CollectionComboBox[i].Items.Add("Metal");
                    this.CollectionComboBox[i].Items.Add("START");
                    this.CollectionComboBox[i].Items.Add("STOP");
                    this.CollectionComboBox[i].Items.Add("Discharge Check A");
                    this.CollectionComboBox[i].Items.Add("Air Check");
                    this.CollectionComboBox[i].Items.Add("Door Check");
                    this.CollectionComboBox[i].Items.Add("Stopper");
                    this.CollectionComboBox[i].Items.Add("Windproof Cover Check");
                    this.CollectionComboBox[i].Items.Add("External Operating");
                    this.CollectionComboBox[i].Items.Add("Dispenser Entry1");
                    this.CollectionComboBox[i].Items.Add("Dispenser Entry2");
                    this.CollectionComboBox[i].Items.Add("Stack up Check");
                    this.CollectionComboBox[i].Items.Add("ExNG1");
                    this.CollectionComboBox[i].Items.Add("ExNG2");
                    this.CollectionComboBox[i].Items.Add("External Input Check"); // 설정 시, 외부입력할 때마다 메인->LCD로 통신전송
                    this.CollectionComboBox[i].Items.Add("Discharge Check B");
                }

                this.buttonExternalInputBuzzer.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonExternalInputBuzzer.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                this.buttonExternalInputLamp.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonExternalInputLamp.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                #region Chinese
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundExternalInput));

                this.labelExternalInputMessage.Text = "※(蜂鸣器/灯)适用项目 : 入口传感器错误、称重传感器错误、未检测到产品入口, 排出确认, 气压确认, 门已打开, 积压确认, 紧急停止";

                for (int i = 0; i < this.CollectionComboBox.Count; i++)
                {
                    this.CollectionComboBox[i].Items.Clear();
                    this.CollectionComboBox[i].Items.Add("不使用");
                    this.CollectionComboBox[i].Items.Add("金属检出");
                    this.CollectionComboBox[i].Items.Add("开启");
                    this.CollectionComboBox[i].Items.Add("停止");
                    this.CollectionComboBox[i].Items.Add("排出确认 A");
                    this.CollectionComboBox[i].Items.Add("气压确认");
                    this.CollectionComboBox[i].Items.Add("门已打开");
                    this.CollectionComboBox[i].Items.Add("固定");
                    this.CollectionComboBox[i].Items.Add("防风罩检查");
                    this.CollectionComboBox[i].Items.Add("外部运转");
                    this.CollectionComboBox[i].Items.Add("分配器进入1");
                    this.CollectionComboBox[i].Items.Add("分配器进入2");
                    this.CollectionComboBox[i].Items.Add("积压确认");
                    this.CollectionComboBox[i].Items.Add("其他不良1");
                    this.CollectionComboBox[i].Items.Add("其他不良2");
                    this.CollectionComboBox[i].Items.Add("外部输入校验"); // 설정 시, 외부입력할 때마다 메인->LCD로 통신전송
                    this.CollectionComboBox[i].Items.Add("排出确认 B");
                }

                this.buttonExternalInputBuzzer.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON));
                this.buttonExternalInputBuzzer.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF));
                this.buttonExternalInputLamp.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON));
                this.buttonExternalInputLamp.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF));
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
            {
                #region Russian
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundExternalInput));

                this.labelExternalInputMessage.Text = "※ (зуммер / лампа) применимые позиции : ООшибка датчика входа, ошибка тензодатчика, вход не обнаружен, Аврийная остановка, закрытия дверцы, разрядки, давления, очередности";

                for (int i = 0; i < this.CollectionComboBox.Count; i++)
                {
                    this.CollectionComboBox[i].Items.Clear();
                    this.CollectionComboBox[i].Items.Add("Нет");
                    this.CollectionComboBox[i].Items.Add("Металл");
                    this.CollectionComboBox[i].Items.Add("Старт");
                    this.CollectionComboBox[i].Items.Add("Стоп");
                    this.CollectionComboBox[i].Items.Add("Проверка разрядки A");
                    this.CollectionComboBox[i].Items.Add("Проверка давления");
                    this.CollectionComboBox[i].Items.Add("Проверка дверцы");
                    this.CollectionComboBox[i].Items.Add("Стопор");
                    this.CollectionComboBox[i].Items.Add("Ветрозащитная проверка");
                    this.CollectionComboBox[i].Items.Add("Внешнее управление");
                    this.CollectionComboBox[i].Items.Add("Вход дозатора 1");
                    this.CollectionComboBox[i].Items.Add("Вход дозатора 2");
                    this.CollectionComboBox[i].Items.Add("Проверить отставание");
                    this.CollectionComboBox[i].Items.Add("Другие неисправности1");
                    this.CollectionComboBox[i].Items.Add("Другие неисправности2");
                    this.CollectionComboBox[i].Items.Add("Проверка внешнего входа"); // 외부입력확인, 설정 시, 외부입력할 때마다 메인->LCD로 통신전송
                    this.CollectionComboBox[i].Items.Add("Проверка разрядки B");
                }

                this.buttonExternalInputBuzzer.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusON));
                this.buttonExternalInputBuzzer.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusOFF));
                this.buttonExternalInputLamp.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusON));
                this.buttonExternalInputLamp.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusOFF));
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                #region German
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundExternalInput));

                this.labelExternalInputMessage.Text = "※ (Summer / Lampe)Anwendbare Gegenstände : Eintrittssensorfehler, Wiegezellenfehler, Eintritt nicht erkannt, Not-Halt, Entladung, Luft, Tür Prüfen, Stapeln Sie Prüfen";

                for (int i = 0; i < this.CollectionComboBox.Count; i++)
                {
                    this.CollectionComboBox[i].Items.Clear();
                    this.CollectionComboBox[i].Items.Add("Keiner");
                    this.CollectionComboBox[i].Items.Add("Metall");
                    this.CollectionComboBox[i].Items.Add("START");
                    this.CollectionComboBox[i].Items.Add("STOPP");
                    this.CollectionComboBox[i].Items.Add("Entladung Prüfen A");
                    this.CollectionComboBox[i].Items.Add("Luft Prüfen");
                    this.CollectionComboBox[i].Items.Add("Tür Prüfen");
                    this.CollectionComboBox[i].Items.Add("Stopper");
                    this.CollectionComboBox[i].Items.Add("Winddichte Abdeckung prüfen");
                    this.CollectionComboBox[i].Items.Add("Externer Betrieb");
                    this.CollectionComboBox[i].Items.Add("Spender Eintritt1");
                    this.CollectionComboBox[i].Items.Add("Spender Eintritt2");
                    this.CollectionComboBox[i].Items.Add("Stapeln Sie Prüfen");
                    this.CollectionComboBox[i].Items.Add("Andere Schlecht1");
                    this.CollectionComboBox[i].Items.Add("Andere Schlecht2");
                    this.CollectionComboBox[i].Items.Add("Externe Eingangsprüfung"); // 외부입력 확인. 설정 시, 외부입력할 때마다 메인->LCD로 통신전송
                    this.CollectionComboBox[i].Items.Add("Entladung Prüfen B");
                }

                this.buttonExternalInputBuzzer.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerON));
                this.buttonExternalInputBuzzer.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerOFF));
                this.buttonExternalInputLamp.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerON));
                this.buttonExternalInputLamp.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerOFF));
                #endregion
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Spanish)
            {
                #region 스페인어
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundExternalInput));

                this.labelExternalInputMessage.Text = "※ (Zumbador/Lámpara) Artículos aplicables : Ingångssensorfel, lastcellsfel, ingång inte upptäckt, Cubierta a prueba de viento abierta, Parada de emergencia, Control de descarga, Chequeo aéreo, Cheque de puerta, Amontonar";

                for (int i = 0; i < this.CollectionComboBox.Count; i++)
                {
                    this.CollectionComboBox[i].Items.Clear();
                    this.CollectionComboBox[i].Items.Add("Ninguna");
                    this.CollectionComboBox[i].Items.Add("Metal");
                    this.CollectionComboBox[i].Items.Add("Inicio");
                    this.CollectionComboBox[i].Items.Add("Paro");
                    this.CollectionComboBox[i].Items.Add("Control de descarga A");
                    this.CollectionComboBox[i].Items.Add("Chequeo aéreo");
                    this.CollectionComboBox[i].Items.Add("Cheque de puerta");
                    this.CollectionComboBox[i].Items.Add("Tapón");
                    this.CollectionComboBox[i].Items.Add("Cubierta a prueba de viento abierta");
                    this.CollectionComboBox[i].Items.Add("Funcionamiento externo");
                    this.CollectionComboBox[i].Items.Add("Entrada del dispensador1");
                    this.CollectionComboBox[i].Items.Add("Entrada del dispensador2");
                    this.CollectionComboBox[i].Items.Add("Apilar cheque");
                    this.CollectionComboBox[i].Items.Add("Otro rechazo1");
                    this.CollectionComboBox[i].Items.Add("Otro rechazo2");
                    this.CollectionComboBox[i].Items.Add("Comprobación de entrada externa"); // 설정 시, 외부입력할 때마다 메인->LCD로 통신전송
                    this.CollectionComboBox[i].Items.Add("Control de descarga B");
                }

                this.buttonExternalInputBuzzer.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonExternalInputBuzzer.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                this.buttonExternalInputLamp.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonExternalInputLamp.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                #endregion
            }
            else
            {
                #region Korean
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundExternalInput));

                this.labelExternalInputMessage.Text = "※ 부저/램프 적용 항목 : 진입센서 에러, 셀 에러, 제품진입 미감지, 방풍커버, 배출, 공압, 문열림, 비상정지, 적체";

                for (int i = 0; i < this.CollectionComboBox.Count; i++)
                {
                    this.CollectionComboBox[i].Items.Clear();
                    this.CollectionComboBox[i].Items.Add("사용안함");
                    this.CollectionComboBox[i].Items.Add("금속 검출");
                    this.CollectionComboBox[i].Items.Add("START");
                    this.CollectionComboBox[i].Items.Add("STOP");
                    this.CollectionComboBox[i].Items.Add("배출 확인 A");
                    this.CollectionComboBox[i].Items.Add("공압 확인"); // 5
                    this.CollectionComboBox[i].Items.Add("문열림 감지");
                    this.CollectionComboBox[i].Items.Add("진입스토퍼");
                    this.CollectionComboBox[i].Items.Add("방풍커버 확인");
                    this.CollectionComboBox[i].Items.Add("외부 운전");
                    this.CollectionComboBox[i].Items.Add("디스펜서 진입1"); // 10
                    this.CollectionComboBox[i].Items.Add("디스펜서 진입2");
                    this.CollectionComboBox[i].Items.Add("적체 확인");
                    this.CollectionComboBox[i].Items.Add("ExNG1");
                    this.CollectionComboBox[i].Items.Add("ExNG2");
                    this.CollectionComboBox[i].Items.Add("외부입력 확인"); // 15, 외부입력 확인. 설정 시, 외부입력할 때마다 메인->LCD로 통신전송
                    this.CollectionComboBox[i].Items.Add("배출 확인 B");
                }

                this.buttonExternalInputBuzzer.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonExternalInputBuzzer.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                this.buttonExternalInputLamp.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON));
                this.buttonExternalInputLamp.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF));
                #endregion
            }

            this.comboBoxPIN8.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN7.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN6.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN5.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN4.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN3.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPhotoB.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
        }
        private void DefaultSetting()
        {
            this.CollectionComboBox = new Collection<ComboBox>();
            this.CollectionComboBox.Clear();
            this.CollectionComboBox.Add(this.comboBoxPhotoB);
            this.CollectionComboBox.Add(this.comboBoxPIN3);
            this.CollectionComboBox.Add(this.comboBoxPIN4);
            this.CollectionComboBox.Add(this.comboBoxPIN5);
            this.CollectionComboBox.Add(this.comboBoxPIN6);
            this.CollectionComboBox.Add(this.comboBoxPIN7);
            this.CollectionComboBox.Add(this.comboBoxPIN8);
        }

        public void OptionBoardSet(SystemParameter1 parameter)
        {
            string value = "";

            this.comboBoxPIN7.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN6.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN5.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);

            if (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.OptionBoard) == 2)
            {
                if (this.comboBoxPIN7.SelectedIndex <= (int)DataStore.ExternalInputMode.IN0_None)
                {
                    this.comboBoxPIN7.SelectedIndex = (int)DataStore.ExternalInputMode.IN10_DispensorEntry1;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI7 = (int)DataStore.ExternalInputMode.IN10_DispensorEntry1;
                }
                if (this.comboBoxPIN6.SelectedIndex <= (int)DataStore.ExternalInputMode.IN0_None)
                {
                    this.comboBoxPIN6.SelectedIndex = (int)DataStore.ExternalInputMode.IN11_DispensorEntry2;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI6 = (int)DataStore.ExternalInputMode.IN11_DispensorEntry2;
                }
                if (this.comboBoxPIN5.SelectedIndex <= (int)DataStore.ExternalInputMode.IN0_None)
                {
                    this.comboBoxPIN5.SelectedIndex = (int)DataStore.ExternalInputMode.IN12_StackUp;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI5 = (int)DataStore.ExternalInputMode.IN12_StackUp;
                }
            }
            else
            {
                if (this.comboBoxPIN7.SelectedIndex == (int)DataStore.ExternalInputMode.IN10_DispensorEntry1)
                {
                    this.comboBoxPIN7.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI7 = 0;
                }
                if (this.comboBoxPIN6.SelectedIndex == (int)DataStore.ExternalInputMode.IN11_DispensorEntry2)
                {
                    this.comboBoxPIN6.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI6 = 0;
                }
                if (this.comboBoxPIN5.SelectedIndex == (int)DataStore.ExternalInputMode.IN12_StackUp)
                {
                    this.comboBoxPIN5.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI5 = 0;
                }
            }

            this.comboBoxPIN7.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN6.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            this.comboBoxPIN5.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);

            this.ParentForm.ParentForm.SaveSystemParameter1File(this.ParentForm.ParentForm.CurrentSystemParameter1);
            this.ParentForm.ParentForm.TransferParameter1();
        }
        private void SetControls(SystemConfigurationItem1 item, SystemParameter1 parameter)
        {
            bool change = false;
            string value = "";
            int index = 0;

            // 입력포트
            index = parameter.PI8;
            if (this.comboBoxPIN8.SelectedIndex != index)
            {
                this.comboBoxPIN8.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPIN8.Items.Count <= index)
                {
                    this.comboBoxPIN8.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI8 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI8, "0000");
                    change = true;
                }
                else
                    this.comboBoxPIN8.SelectedIndex = index;
                this.comboBoxPIN8.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
            index = parameter.PI7;
            if (this.comboBoxPIN7.SelectedIndex != index)
            {
                this.comboBoxPIN7.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPIN7.Items.Count <= index)
                {
                    this.comboBoxPIN7.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI7 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI7, "0000");
                    change = true;
                }
                else
                    this.comboBoxPIN7.SelectedIndex = index;
                this.comboBoxPIN7.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
            index = parameter.PI6;
            if (this.comboBoxPIN6.SelectedIndex != index)
            {
                this.comboBoxPIN6.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPIN6.Items.Count <= index)
                {
                    this.comboBoxPIN6.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI6 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI6, "0000");
                    change = true;
                }
                else
                    this.comboBoxPIN6.SelectedIndex = index;
                this.comboBoxPIN6.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
            index = parameter.PI5;
            if (this.comboBoxPIN5.SelectedIndex != index)
            {
                this.comboBoxPIN5.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPIN5.Items.Count <= index)
                {
                    this.comboBoxPIN5.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI5 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI5, "0000");
                    change = true;
                }
                else
                    this.comboBoxPIN5.SelectedIndex = index;
                this.comboBoxPIN5.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
            index = parameter.PI4;
            if (this.comboBoxPIN4.SelectedIndex != index)
            {
                this.comboBoxPIN4.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPIN4.Items.Count <= index)
                {
                    this.comboBoxPIN4.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI4 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI4, "0000");
                    change = true;
                }
                else
                    this.comboBoxPIN4.SelectedIndex = index;
                this.comboBoxPIN4.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
            index = parameter.PI3;
            if (this.comboBoxPIN3.SelectedIndex != index)
            {
                this.comboBoxPIN3.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPIN3.Items.Count <= index)
                {
                    this.comboBoxPIN3.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI3 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI3, "0000");
                    change = true;
                }
                else
                    this.comboBoxPIN3.SelectedIndex = index;
                this.comboBoxPIN3.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }
            index = parameter.PI2;
            if (this.comboBoxPhotoB.SelectedIndex != index)
            {
                this.comboBoxPhotoB.SelectedIndexChanged -= new EventHandler(this.comboBox_SelectedIndexChanged);
                if (this.comboBoxPhotoB.Items.Count <= index)
                {
                    this.comboBoxPhotoB.SelectedIndex = (int)DataStore.ExternalInputMode.IN0_None;
                    this.ParentForm.ParentForm.CurrentSystemParameter1.PI2 = 0;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI2, "0000");
                    change = true;
                }
                else
                    this.comboBoxPhotoB.SelectedIndex = index;
                this.comboBoxPhotoB.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged);
            }

            if(change == true)
                this.ParentForm.ParentForm.SaveSystemParameter1File(this.ParentForm.ParentForm.CurrentSystemParameter1);

            // 외부 입력 시 부저/램프
            if (item.IsExternalInputBuzzer == false)
                this.buttonExternalInputBuzzer.ButtonUp();
            else
                this.buttonExternalInputBuzzer.ButtonDown();

            if (item.IsExternalInputLamp == false)
                this.buttonExternalInputLamp.ButtonUp();
            else
                this.buttonExternalInputLamp.ButtonDown();
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.SystemExternalInput;
            this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.SetControls(this.ParentForm.ParentForm.SystemConfig1, this.ParentForm.ParentForm.CurrentSystemParameter1);
        }
        #endregion

        #region Event Handler
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            string value = "";
            ComboBox comboBox = sender as ComboBox;

            if (comboBox == null)
                return;

            if (comboBox == this.comboBoxPIN8)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPIN8.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI8 = this.comboBoxPIN8.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI8, value);
            }
            else if (comboBox == this.comboBoxPIN7)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPIN7.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI7 = this.comboBoxPIN7.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI7, value);
            }
            else if (comboBox == this.comboBoxPIN6)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPIN6.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI6 = this.comboBoxPIN6.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI6, value);
            }
            else if (comboBox == this.comboBoxPIN5)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPIN5.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI5 = this.comboBoxPIN5.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI5, value);
            }
            else if (comboBox == this.comboBoxPIN4)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPIN4.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI4 = this.comboBoxPIN4.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI4, value);
            }
            else if (comboBox == this.comboBoxPIN3)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPIN3.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI3 = this.comboBoxPIN3.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI3, value);
            }
            else if (comboBox == this.comboBoxPhotoB)
            {
                value = Helper.StringZeroFillDigits4(this.comboBoxPhotoB.SelectedIndex.ToString());
                this.ParentForm.ParentForm.CurrentSystemParameter1.PI2 = this.comboBoxPhotoB.SelectedIndex;

                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.PI2, value);
            }
            else
            {

            }

            this.ParentForm.ParentForm.SaveSystemParameter1File(this.ParentForm.ParentForm.CurrentSystemParameter1);

            this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightBigScreen.UpdateDisplay();
            this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightSmallScreen.UpdateDisplay();
        }

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

            this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
        }
        private void buttonExternalInputLamp_Click(object sender, EventArgs e)
        {
            if (this.buttonExternalInputLamp.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.SystemConfig1.IsExternalInputLamp = true;
            else
                this.ParentForm.ParentForm.SystemConfig1.IsExternalInputLamp = false;

            this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
        }
        #endregion

        private void checkBoxBuzzer_Click(object sender, EventArgs e)
        {
            SmartX.SmartCheckBox checkBox = sender as SmartX.SmartCheckBox;

            
        }

        private void checkBoxLamp_Click(object sender, EventArgs e)
        {
            SmartX.SmartCheckBox checkBox = sender as SmartX.SmartCheckBox;


        }
    }
}