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

using INT69DC_ImageDll;
using INT69DC_7C.DialogForms;
using INT69DC_7C.Part11_UserManager;

namespace INT69DC_7C.Forms
{
    public partial class FormEquipmentSetting : Form
    {
        #region Field
        private FormMain m_ParentForm;
        #endregion

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

            this.ParentForm = parent;
            this.InitializeControl();
        }
        #endregion

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

        #region Method
        private void InitializeDesign()
        {
            ImageDll images = new ImageDll();

            if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
                this.labelTitle.Text = "Equipment settings";

                this.labelStaticType.Text = "Type";
                this.labelStaticLine.Text = "Line";
                this.labelStaticOrder.Text = "Order";
                this.labelStaticIndividualNG.Text = "Individual NG";
                this.labelStaticIndividualTransmission.Text = "Individual transmission";
                this.labelStaticRejectCV.Text = "Reject conveyor";
                this.labelStaticFeedingCV.Text = "Feeding conveyor";
                this.labelStaticEquipmentID.Text = "Equipment ID";
                this.labelStaticDataStoragePeriod.Text = "Data storage period";
                this.labelStaticImpellerBaudrate.Text = "Step motor buadrate";
                this.labelStaticImpellerRotation.Text = "Step motor rotation";
                this.labelStaticLanguage.Text = "Language";
                this.labelStaticInputSensorSelect.Text = "InputSensor select";
                this.labelStaticEmergencyStopEntrySensorError.Text = "Emergency stop due to entry sensor error";
                this.labelStaticLogin.Text = "Login";
                this.labelTitleStepMotorType.Text = "Step Motor Type";
                this.labelStaticIntegratedTransmission.Text = "Integrated transmission";

                this.radioButtonEquipmentModeConveyor.Text = "Conveyor";
                this.radioButtonEquipmentModeStick1.Text = "Stick-I";
                this.radioButtonEquipmentModeStick2.Text = "Stick-II";
                this.radioButtonEquipmentModeStick3.Text = "Stick-III";
                this.radioButtonEquipmentModeDual.Text = "Dual";

                this.labelBuadrateWarning.Text = "※ After changing setting, Turn the power off and back on";
                this.labelBuadrateWarning2.Text = "※ Do not change the value except engineer";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.labelTitle.Text = "设备设置";

                this.labelStaticType.Text = "设备类型";
                this.labelStaticLine.Text = "列";
                this.labelStaticOrder.Text = "重量显示";
                this.labelStaticIndividualNG.Text = "单独NG";
                this.labelStaticIndividualTransmission.Text = "个人传输";
                this.labelStaticRejectCV.Text = "筛选输送带";
                this.labelStaticFeedingCV.Text = "进料输送带";
                this.labelStaticEquipmentID.Text = "设备编号";
                this.labelStaticDataStoragePeriod.Text = "数据保存期限";
                this.labelStaticImpellerBaudrate.Text = "波特率";
                this.labelStaticImpellerRotation.Text = "排放输送带旋转方向";
                this.labelStaticLanguage.Text = "语言";
                this.labelStaticInputSensorSelect.Text = "选择输入传感器";
                this.labelStaticEmergencyStopEntrySensorError.Text = "由于进入传感器错误导致紧急停止";
                this.labelStaticLogin.Text = "登錄";
                this.labelTitleStepMotorType.Text = "步进电机类型";
                this.labelStaticIntegratedTransmission.Text = "综合传输";

                this.radioButtonWeightViewForward.Text = "正向(1~12)";
                this.radioButtonWeightViewReverse.Text = "反向(12~1)";

                this.radioButtonEquipmentModeConveyor.Text = "输送带";
                this.radioButtonEquipmentModeStick1.Text = "球杆-I";
                this.radioButtonEquipmentModeStick2.Text = "球杆-II";
                this.radioButtonEquipmentModeStick3.Text = "球杆-III";
                this.radioButtonEquipmentModeDual.Text = "双重的";

                this.labelBuadrateWarning.Text = "※ 电源重启后，设置会自动更新";
                this.labelBuadrateWarning2.Text = "※ 除了工程师之外，不要改变这个值";

                this.labelTitleCautionIndividualNG.Text = "球杆-I";
                this.labelTitleCautionIndividualTransmission.Text = this.labelTitleCautionInputSensorSelect.Text = "球杆-I,III";
                this.labelTitleCautionIntegratedTransmission.Text = "球杆-II";

                this.buttonEachNG.DownImage = this.buttonLogin.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonEachNG.UpImage = this.buttonLogin.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));
                this.buttonDischargeConveyor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonDischargeConveyor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));
                this.buttonEmergencyStopEntrySensorError.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonEmergencyStopEntrySensorError.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));
                this.buttonFeedingConveyor.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonFeedingConveyor.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));
                this.buttonIndividualTransmission.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonIndividualTransmission.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
                this.labelTitle.Text = "Nastavení zařízení";

                this.labelStaticType.Text = "Type";
                this.labelStaticLine.Text = "Line";
                this.labelStaticOrder.Text = "Order";
                this.labelStaticIndividualNG.Text = "Individual NG";
                this.labelStaticIndividualTransmission.Text = "Individual transmission";
                this.labelStaticRejectCV.Text = "Reject conveyor";
                this.labelStaticFeedingCV.Text = "Feeding conveyor";
                this.labelStaticEquipmentID.Text = "Equipment ID";
                this.labelStaticDataStoragePeriod.Text = "Doba uložení dat";
                this.labelStaticImpellerBaudrate.Text = "Step motor buadrate";
                this.labelStaticImpellerRotation.Text = "Step motor rotation";
                this.labelStaticLanguage.Text = "Language";
                this.labelStaticInputSensorSelect.Text = "InputSensor select";
                this.labelStaticEmergencyStopEntrySensorError.Text = "Nouzové zastavení z důvodu chyby snímače";
                this.labelStaticLogin.Text = "Přihlásit se";
                this.labelTitleStepMotorType.Text = "Krokový typ motoru";
                this.labelStaticIntegratedTransmission.Text = "Integrovaná převodovka";

                this.radioButtonEquipmentModeConveyor.Text = "Conveyor";
                this.radioButtonEquipmentModeStick1.Text = "Stick-I";
                this.radioButtonEquipmentModeStick2.Text = "Stick-II";
                this.radioButtonEquipmentModeStick3.Text = "Stick-III";
                this.radioButtonEquipmentModeDual.Text = "Dual";

                this.labelBuadrateWarning.Text = "※ After changing setting, Turn the power off and back on";
                this.labelBuadrateWarning2.Text = "※ Do not change the value except engineer";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
            {
                this.labelTitle.Text = "Vorrichtungeinstellung";

                this.radioButtonWeightViewForward.Text = "Vorwärts(1~12)";
                this.radioButtonWeightViewReverse.Text = "Rückwärts(1~12)";

                this.radioButtonFeedingConveyorRunPass.Text = "Bestehen";
                this.radioButtonFeedingConveyorRunNg.Text = "Leer";

                this.labelStaticType.Text = "Waagentyp";
                this.labelStaticLine.Text = "Reihe";
                this.labelStaticOrder.Text = "Gewichtsanzeige";
                this.labelStaticIndividualNG.Text = "Individuelle Aussortierung";
                this.labelStaticIndividualTransmission.Text = "Individuelle übermittlung";
                this.labelStaticRejectCV.Text = "Aussortierförderer";
                this.labelStaticFeedingCV.Text = "Zuführförderer";
                this.labelStaticEquipmentID.Text = "ID-Vorrichtung";
                this.labelStaticDataStoragePeriod.Text = "Dauer der Datenspeicherung";
                this.labelStaticImpellerBaudrate.Text = "Schrittmotor Buadrate";
                this.labelStaticImpellerRotation.Text = "Schrittmotor Drehrichtung";
                this.labelStaticLanguage.Text = "Sprache";
                this.labelStaticInputSensorSelect.Text = "Schnitt - Eingang";
                this.labelStaticEmergencyStopEntrySensorError.Text = "Nothalt wegen Sensorfehler";
                this.labelStaticLogin.Text = "Anmelden";
                this.labelTitleStepMotorType.Text = "Schrittmotortyp";
                this.labelStaticIntegratedTransmission.Text = "integrierte übertragung";

                this.radioButtonEquipmentModeConveyor.Text = "Förderer";
                this.radioButtonEquipmentModeStick1.Text = "Beutel-I";
                this.radioButtonEquipmentModeStick2.Text = "Beutel-II";
                this.radioButtonEquipmentModeStick3.Text = "Beutel-III";
                this.radioButtonEquipmentModeDual.Text = "Dual";

                this.labelBuadrateWarning.Text = "※ Stellen Sie nach dem Einstellen des Servoantriebs sicher, Mit dem Hauptschalter aus- und einschalten";
                this.labelBuadrateWarning2.Text = "※ Werte dürfen nur vom Servicetechniker des Herstellers geändert werden";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.labelTitle.Text = "装置設定";

                this.labelStaticType.Text = "タイプ";
                this.labelStaticLine.Text = "ライン";
                this.labelStaticOrder.Text = "重量表示";
                this.labelStaticIndividualNG.Text = "個別NG";
                this.labelStaticIndividualTransmission.Text = "個別搬送";
                this.labelStaticRejectCV.Text = "排出コンベア";
                this.labelStaticFeedingCV.Text = "供給コンベア";
                this.labelStaticEquipmentID.Text = "装置ID";
                this.labelStaticDataStoragePeriod.Text = "保管期間";
                this.labelStaticImpellerBaudrate.Text = "ステップモㅡタㅡボㅡレㅡト";
                this.labelStaticImpellerRotation.Text = "ステップモㅡタㅡ回転";
                this.labelStaticLanguage.Text = "言語";
                this.labelStaticInputSensorSelect.Text = "入力センサㅡの選択";
                this.labelStaticEmergencyStopEntrySensorError.Text = "入力センサエラㅡにより停止しました。";
                this.labelStaticLogin.Text = "ログイン";
                this.labelTitleStepMotorType.Text = "ステップモㅡタㅡタイプ";
                this.labelStaticIntegratedTransmission.Text = "統合搬送";
                this.labelTitleMonths.Text = "月";
                this.labelTitleCautionLogin.Text = "OFF時、ユㅡザㅡリストは削除されます。";

                this.radioButtonEquipmentModeConveyor.Font = new Font("새굴림", 9, FontStyle.Bold);
                this.radioButtonEquipmentModeConveyor.Text = "コンベア";
                this.radioButtonEquipmentModeStick1.Font = new Font("새굴림", 9, FontStyle.Bold);
                this.radioButtonEquipmentModeStick1.Text = "スティックI";
                this.radioButtonEquipmentModeStick2.Font = new Font("새굴림", 9, FontStyle.Bold);
                this.radioButtonEquipmentModeStick2.Text = "スティックII";
                this.radioButtonEquipmentModeStick3.Font = new Font("새굴림", 9, FontStyle.Bold);
                this.radioButtonEquipmentModeStick3.Text = "スティックIII";
                this.radioButtonEquipmentModeDual.Font = new Font("새굴림", 10, FontStyle.Bold);
                this.radioButtonEquipmentModeDual.Text = "両型";

                this.labelTitleCautionIndividualNG.Text = "スティック1モㅡドでのみ有効";
                this.labelTitleCautionIntegratedTransmission.Text = "スティック2モㅡド(OPT2,3,5)でのみ有効";
                this.labelTitleCautionIndividualTransmission.Text = "スティック1,3モㅡドでのみ有効";
                this.labelTitleCautionInputSensorSelect.Text = "スティック1,3モㅡドでのみ有効";

                this.labelBuadrateWarning.Text = "※ 設定を変更した後、電源をオフにして再度オンにします";
                this.labelBuadrateWarning2.Text = "※ エンジニア以外は値を変更しないでください";

                this.buttonSave.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveDisable));
                this.buttonSave.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnSaveUp));

                this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDisable));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackUp));
            }
            else
            {

            }
        }
        private void InitializeControl()
        {
            // 장비 열
            this.comboBoxEquipmentColumn.Items.Clear();
            this.comboBoxEquipmentColumn.Items.Add(7);
            this.comboBoxEquipmentColumn.Items.Add(8);
            this.comboBoxEquipmentColumn.Items.Add(10);
            this.comboBoxEquipmentColumn.Items.Add(11);
            this.comboBoxEquipmentColumn.Items.Add(12);
            this.comboBoxEquipmentColumn.SelectedItem = this.ParentForm.SystemConfig.EquipmentColumns;

            // 입력센서 선택
            this.comboBoxInputSensorSelect.Items.Clear();
            this.comboBoxInputSensorSelect.Items.Add(1);
            this.comboBoxInputSensorSelect.Items.Add(2);
            this.comboBoxInputSensorSelect.Items.Add(3);
            this.comboBoxInputSensorSelect.Items.Add(4);
            this.comboBoxInputSensorSelect.Items.Add(5);
            this.comboBoxInputSensorSelect.Items.Add(6);
            this.comboBoxInputSensorSelect.Items.Add(7);
            this.comboBoxInputSensorSelect.Items.Add(8);
            this.comboBoxInputSensorSelect.Items.Add(9);
            this.comboBoxInputSensorSelect.Items.Add(10);
            this.comboBoxInputSensorSelect.Items.Add(11);
            this.comboBoxInputSensorSelect.Items.Add(12);
            this.comboBoxInputSensorSelect.SelectedItem = this.ParentForm.SystemConfig.InputSensorSelect;

            // 스텝모터 종류
            this.comboBoxStepMotorType.Items.Clear();
            this.comboBoxStepMotorType.Items.Add("MDrive");
            this.comboBoxStepMotorType.Items.Add("EDB_ALL_P");
            this.comboBoxStepMotorType.Items.Add("Moons");
        }

        private void UpdateDisplay()
        {
            // 장비열
            this.comboBoxEquipmentColumn.SelectedItem = this.ParentForm.SystemConfig.EquipmentColumns;
            // 입력센서 선택
            this.comboBoxInputSensorSelect.SelectedItem = this.ParentForm.SystemConfig.InputSensorSelect;
            
            // 장비타입
            if (this.ParentForm.SystemConfig.EquipmentMode == 0)
                this.radioButtonEquipmentModeConveyor.Checked = true;
            else if (this.ParentForm.SystemConfig.EquipmentMode == 1)
                this.radioButtonEquipmentModeStick1.Checked = true;
            else if (this.ParentForm.SystemConfig.EquipmentMode == 2)
                this.radioButtonEquipmentModeStick2.Checked = true;
            else if (this.ParentForm.SystemConfig.EquipmentMode == 3)
                this.radioButtonEquipmentModeStick3.Checked = true;
            else if (this.ParentForm.SystemConfig.EquipmentMode == 7)
                this.radioButtonEquipmentModeDual.Checked = true;
            
            // 중량표시
            if (this.ParentForm.SystemConfig.IsWeightViewForward == true)
                this.radioButtonWeightViewForward.Checked = true;
            else
                this.radioButtonWeightViewReverse.Checked = true;

            // 개별 NG
            if (this.ParentForm.SystemConfig.IsIndividualNG == true)
                this.buttonEachNG.ButtonDown();
            else
                this.buttonEachNG.ButtonUp();

            // 통합 전송
            if (this.ParentForm.SystemConfig.IsIntegratedTransmission == true)
                this.buttonIntegratedTransmission.ButtonDown();
            else
                this.buttonIntegratedTransmission.ButtonUp();

            // 개별 전송
            if (this.ParentForm.SystemConfig.IsIndividualTransmission == true)
                this.buttonIndividualTransmission.ButtonDown();
            else
                this.buttonIndividualTransmission.ButtonUp();

            // 입력센서 연속입력 시 정지
            if (this.ParentForm.SystemConfig.IsEmergencyStopEntrySensorError == true)
                this.buttonEmergencyStopEntrySensorError.ButtonDown();
            else
                this.buttonEmergencyStopEntrySensorError.ButtonUp();

            // 배출 컨베어
            if (this.ParentForm.SystemConfig.IsDischargeConveyor == true)
                this.buttonDischargeConveyor.ButtonDown();
            else
                this.buttonDischargeConveyor.ButtonUp();

            // 배출 컨베어 회전방향
            if (this.ParentForm.SystemConfig.DischargeConveyorDirectionCW == DataStore.DischargeConveyorDirection.CW)
                this.radioButtonDischargeConveyorDirectionCW.Checked = true;
            else if (this.ParentForm.SystemConfig.DischargeConveyorDirectionCW == DataStore.DischargeConveyorDirection.CCW)
                this.radioButtonDischargeConveyorDirectionCCW.Checked = true;
            else
                this.radioButtonDischargeConveyorDirectionCWCCW.Checked = true;

            // Feeding 컨베어
            if (this.ParentForm.SystemConfig.IsFeedingConveyor == true)
                this.buttonFeedingConveyor.ButtonDown();
            else
                this.buttonFeedingConveyor.ButtonUp();

            // Feeding 컨베어 구동
            if (this.ParentForm.SystemConfig.IsFeedingConveyorRunPass == true)
                this.radioButtonFeedingConveyorRunPass.Checked = true;
            else
                this.radioButtonFeedingConveyorRunNg.Checked = true;

            // 장비 ID
            if (this.labelEquipmentID.Text != this.ParentForm.SystemConfig.EquipmentID.ToString())
                this.labelEquipmentID.Text = this.ParentForm.SystemConfig.EquipmentID.ToString();

            // 데이터 저장기간
            if (this.labelDataStoragePeriod.Text != this.ParentForm.SystemConfig.DataStoragePeriod.ToString())
                this.labelDataStoragePeriod.Text = this.ParentForm.SystemConfig.DataStoragePeriod.ToString();

            // 임펠러모터 통신속도
            if (this.ParentForm.SystemConfig.ImpellerMotorBaudrate == 1)
                this.radioButtonImpellerMotorBaudrate9600.Checked = true;
            else if (this.ParentForm.SystemConfig.ImpellerMotorBaudrate == 2)
                this.radioButtonImpellerMotorBaudrate19200.Checked = true;
            else if (this.ParentForm.SystemConfig.ImpellerMotorBaudrate == 3)
                this.radioButtonImpellerMotorBaudrate38400.Checked = true;
            else
                this.radioButtonImpellerMotorBaudrate115200.Checked = true;

            // 임펠러모터 회전방향
            if (this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW == true)
                this.radioButtonImpellerMotorDirectionCW.Checked = true;
            else
                this.radioButtonImpellerMotorDirectionCCW.Checked = true;

            // 언어
            if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
                this.radioButtonLanguageChinese.Checked = true;
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
                this.radioButtonLanguageCzech.Checked = true;
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
                this.radioButtonLanguageEnglish.Checked = true;
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
                this.radioButtonLanguageKorean.Checked = true;
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
                this.radioButtonLanguageGerman.Checked = true;
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
                this.radioButtonLanguageJapanese.Checked = true;
            else
                this.radioButtonLanguageKorean.Checked = true;

            // 로그인
            if (this.ParentForm.SystemConfig.IsLogin == true)
                this.buttonLogin.ButtonDown();
            else
                this.buttonLogin.ButtonUp();

            // Step Motor
            switch (this.ParentForm.SystemConfig.StepMotorType)
            {
                case (int)DataStore.StepMotorType.MDrive:
                    this.comboBoxStepMotorType.SelectedIndex = 0;
                    break;
                case (int)DataStore.StepMotorType.EDB_ALL_P:
                    this.comboBoxStepMotorType.SelectedIndex = 1;
                    break;
                case (int)DataStore.StepMotorType.Moons:
                    this.comboBoxStepMotorType.SelectedIndex = 2;
                    break;
                default:
                    break;
            }

            // SerialDLL
            if (this.ParentForm.SystemConfig.IsSerialDLL == true)
                this.buttonSerialDLL.ButtonDown();
            else
                this.buttonSerialDLL.ButtonUp();

            this.buttonSave.Visible = false;
        }

        public void DisplayRefresh()
        {
            if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer)
            {
                this.labelStaticSerialDll.Visible = true;
                this.buttonSerialDLL.Visible = true;
            }
            else
            {
                this.labelStaticSerialDll.Visible = false;
                this.buttonSerialDLL.Visible = false;
            }

            this.UpdateDisplay();

            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormEquipmentSetting;
        }
        #endregion

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

            this.InitializeDesign();
        }
        #endregion

        #region Event Handler
        private void control_Click(object sender, EventArgs e)
        {
            if (this.buttonSave.Visible != true)
                this.buttonSave.Visible = true;

            SmartX.SmartButton button = sender as SmartX.SmartButton;
            if (button == this.buttonLogin)
            {
                if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                    this.buttonLogin.ButtonDown();
            }
        }

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (this.labelEquipmentID.Text != myKeyPad.StringValue)
                {
                    this.labelEquipmentID.Text = myKeyPad.StringValue;

                    if (this.buttonSave.Visible != true)
                        this.buttonSave.Visible = true;
                }
            }
        }
        private void labelDataStoragePeriod_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDataStoragePeriod.Text, 2, 0, false, this.ParentForm.SystemConfig.Language);
            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 99)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelDataStoragePeriod.Text = myKeyPad.StringValue;

                    if (this.buttonSave.Visible != true)
                        this.buttonSave.Visible = true;
                }
            }
        }
        private void buttonSerialDLL_Click(object sender, EventArgs e)
        {
            if (this.buttonSave.Visible != true)
                this.buttonSave.Visible = true;
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            // 장비 타입
            if (this.radioButtonEquipmentModeConveyor.Checked == true)
                this.ParentForm.SystemConfig.EquipmentMode = 0;
            else if (this.radioButtonEquipmentModeStick1.Checked == true)
                this.ParentForm.SystemConfig.EquipmentMode = 1;
            else if (this.radioButtonEquipmentModeStick2.Checked == true)
                this.ParentForm.SystemConfig.EquipmentMode = 2;
            else if (this.radioButtonEquipmentModeStick3.Checked == true)
                this.ParentForm.SystemConfig.EquipmentMode = 3;
            else if (this.radioButtonEquipmentModeDual.Checked == true)
                this.ParentForm.SystemConfig.EquipmentMode = 7;

            // 장비 열
            if (this.comboBoxEquipmentColumn.SelectedIndex == 0)
                this.ParentForm.SystemConfig.EquipmentColumns = 7;
            else if (this.comboBoxEquipmentColumn.SelectedIndex == 1)
                this.ParentForm.SystemConfig.EquipmentColumns = 8;
            else if (this.comboBoxEquipmentColumn.SelectedIndex == 2)
                this.ParentForm.SystemConfig.EquipmentColumns = 10;
            else if (this.comboBoxEquipmentColumn.SelectedIndex == 3)
                this.ParentForm.SystemConfig.EquipmentColumns = 11;
            else
                this.ParentForm.SystemConfig.EquipmentColumns = 12;

            // 중량표시
            if (this.radioButtonWeightViewForward.Checked == true)
                this.ParentForm.SystemConfig.IsWeightViewForward = true;
            else
                this.ParentForm.SystemConfig.IsWeightViewForward = false;

            // 개별 NG
            if (this.buttonEachNG.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsIndividualNG = true;
            else
                this.ParentForm.SystemConfig.IsIndividualNG = false;

            // 통합 전송
            if (this.buttonIntegratedTransmission.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsIntegratedTransmission = true;
            else
                this.ParentForm.SystemConfig.IsIntegratedTransmission = false;

            // 개별 전송
            if (this.buttonIndividualTransmission.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsIndividualTransmission = true;
            else
                this.ParentForm.SystemConfig.IsIndividualTransmission = false;

            // 입력센서 선택
            this.ParentForm.SystemConfig.InputSensorSelect = this.comboBoxInputSensorSelect.SelectedIndex + 1;

            // 입력센서 연속입력 시 정지
            if (this.buttonEmergencyStopEntrySensorError.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsEmergencyStopEntrySensorError = true;
            else
                this.ParentForm.SystemConfig.IsEmergencyStopEntrySensorError = false;

            // 선별 컨베어 
            if (this.buttonDischargeConveyor.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsDischargeConveyor = true;
            else
                this.ParentForm.SystemConfig.IsDischargeConveyor = false;

            // 선별 컨베어 회전방향
            if (this.radioButtonDischargeConveyorDirectionCW.Checked == true)
                this.ParentForm.SystemConfig.DischargeConveyorDirectionCW = DataStore.DischargeConveyorDirection.CW;
            else if (this.radioButtonDischargeConveyorDirectionCCW.Checked == true)
                this.ParentForm.SystemConfig.DischargeConveyorDirectionCW = DataStore.DischargeConveyorDirection.CCW;
            else
                this.ParentForm.SystemConfig.DischargeConveyorDirectionCW = DataStore.DischargeConveyorDirection.CW_CCW;

            // Feeding 컨베어
            if (this.buttonFeedingConveyor.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsFeedingConveyor = true;
            else
                this.ParentForm.SystemConfig.IsFeedingConveyor = false;

            // Feeding 컨베어 구동
            if (this.radioButtonFeedingConveyorRunPass.Checked == true)
                this.ParentForm.SystemConfig.IsFeedingConveyorRunPass = true;
            else
                this.ParentForm.SystemConfig.IsFeedingConveyorRunPass = false;

            // 장비 ID
            this.ParentForm.SystemConfig.EquipmentID = int.Parse(this.labelEquipmentID.Text);
            // 데이터 저장기간
            this.ParentForm.SystemConfig.DataStoragePeriod = int.Parse(this.labelDataStoragePeriod.Text);

            // 임펠러모터 통신속도
            if (this.radioButtonImpellerMotorBaudrate9600.Checked == true)
                this.ParentForm.SystemConfig.ImpellerMotorBaudrate = 1;
            else if (this.radioButtonImpellerMotorBaudrate19200.Checked == true)
                this.ParentForm.SystemConfig.ImpellerMotorBaudrate = 2;
            else if (this.radioButtonImpellerMotorBaudrate38400.Checked == true)
                this.ParentForm.SystemConfig.ImpellerMotorBaudrate = 3;
            else
                this.ParentForm.SystemConfig.ImpellerMotorBaudrate = 4;

            // 임펠러모터 회전방향
            if (this.radioButtonImpellerMotorDirectionCW.Checked == true)
                this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW = true;
            else
                this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW = false;

            // 언어
            if (this.radioButtonLanguageKorean.Checked == true)
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.Korean;
            else if (this.radioButtonLanguageEnglish.Checked == true)
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.English;
            else if (this.radioButtonLanguageChinese.Checked == true)
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.Chinese;
            else if (this.radioButtonLanguageCzech.Checked == true)
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.Czech;
            else if (this.radioButtonLanguageGerman.Checked == true)
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.German;
            else if (this.radioButtonLanguageJapanese.Checked == true)
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.Japanese;
            else
                this.ParentForm.SystemConfig.Language = DataStore.LanguageID.Korean;

            // 로그인
            if (this.ParentForm.SystemConfig.IsOptPart11 == true)
                this.ParentForm.SystemConfig.IsLogin = true;
            else
            {
                if (this.buttonLogin.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                    this.ParentForm.SystemConfig.IsLogin = true;
                else
                {
                    this.ParentForm.SystemConfig.IsLogin = false;

                    // Delete user list
                    UserManager.UserManager_UserAllDel();
                }
            }

            // 스텝모터 종류
            switch (this.comboBoxStepMotorType.SelectedIndex)
            {
                case (int)DataStore.StepMotorType.MDrive:
                    this.ParentForm.SystemConfig.StepMotorType = (int)DataStore.StepMotorType.MDrive;
                    break;
                case (int)DataStore.StepMotorType.EDB_ALL_P:
                    this.ParentForm.SystemConfig.StepMotorType = (int)DataStore.StepMotorType.EDB_ALL_P;
                    break;
                case (int)DataStore.StepMotorType.Moons:
                    this.ParentForm.SystemConfig.StepMotorType = (int)DataStore.StepMotorType.Moons;
                    break;
                default:
                    break;
            }

            // Serial DLL
            if (this.buttonSerialDLL.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsSerialDLL = true;
            else
                this.ParentForm.SystemConfig.IsSerialDLL = false;

            // SystemConfig  파일 저장
            this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

            DialogFormMessage myMsg = new DialogFormMessage(18, this.ParentForm.SystemConfig.Language);
            myMsg.ShowDialog();

            this.groupBoxSpecialMenu.Enabled = false;
            this.buttonSave.Enabled = false;
            this.buttonBack.Visible = false;
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
        }
        #endregion
    }
}