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

using SmartX;
using ITC81DB_0H.DialogForms;
using ITC81DB_0H.Forms;
using ITC81DB_0H_ImageDll;

namespace ITC81DB_0H.Controls
{
    public partial class ControlMainDisplayMenu : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;
        #endregion

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

            this.ParentForm = parent;

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

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

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

            if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.English)
            {
                this.buttonBypassDirection.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korBypassOccasionDown));
                this.buttonBypassDirection.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korBypassOccasionUp));
                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBypassCountUp));

                this.labelTitleBypass.Text = "Bypass";

                this.labelTitleSorterSettings.Text = "Sorter settings";

                this.labelTitleSorterA.Text = "Sorter A";
                this.labelTitleSorterB.Text = "Sorter B";
                this.labelTitleSorterMode.Text = "Mode";
                this.labelTitleSorterDelayTime.Text = "Delay time";
                this.labelTitleSorterRunTime.Text = "Run time";
                this.labelTitleDryContact.Text = "Latch control";
                this.labelTitleDryContact1.Text = "Latch control1";
                this.labelTitleDryContact2.Text = "Latch control2";
                this.labelTitleDryContact3.Text = "Latch control3";
                this.labelTitleDryContact4.Text = "Latch control4";

                this.comboBoxSorterA.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);
                this.comboBoxSorterA.Items.Clear();
                this.comboBoxSorterA.Items.Add("None");
                this.comboBoxSorterA.Items.Add("Over");
                this.comboBoxSorterA.Items.Add("Under");
                this.comboBoxSorterA.Items.Add("NG");
                this.comboBoxSorterA.SelectedIndex = 1;
                this.comboBoxSorterA.SelectedIndexChanged += new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);

                this.comboBoxSorterB.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
                this.comboBoxSorterB.Items.Clear();
                this.comboBoxSorterB.Items.Add("None");
                this.comboBoxSorterB.Items.Add("Over");
                this.comboBoxSorterB.Items.Add("Under");
                this.comboBoxSorterB.Items.Add("NG");
                this.comboBoxSorterB.SelectedIndex = 2;
                this.comboBoxSorterB.SelectedIndexChanged += new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.buttonBypassDirection.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassOccasionDown));
                this.buttonBypassDirection.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassOccasionUp));
                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBypassCountUp));

                this.labelTitleBypass.Text = "旁路";

                this.labelTitleSorterSettings.Text = "筛选设定";

                this.labelTitleSorterA.Text = "分类机A";
                this.labelTitleSorterB.Text = "分类机B";
                this.labelTitleSorterMode.Text = "模式";
                this.labelTitleSorterDelayTime.Text = "延迟时间";
                this.labelTitleSorterRunTime.Text = "运行时间";
                this.labelTitleDryContact.Text = "闩锁控制";
                this.labelTitleDryContact1.Text = "闩锁控制1";
                this.labelTitleDryContact2.Text = "闩锁控制2";
                this.labelTitleDryContact3.Text = "闩锁控制3";
                this.labelTitleDryContact4.Text = "闩锁控制4";

                this.comboBoxSorterA.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);
                this.comboBoxSorterA.Items.Clear();
                this.comboBoxSorterA.Items.Add("不使用");
                this.comboBoxSorterA.Items.Add("超过");
                this.comboBoxSorterA.Items.Add("低于");
                this.comboBoxSorterA.Items.Add("不良");
                this.comboBoxSorterA.SelectedIndex = 1;
                this.comboBoxSorterA.SelectedIndexChanged += new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);

                this.comboBoxSorterB.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
                this.comboBoxSorterB.Items.Clear();
                this.comboBoxSorterB.Items.Add("不使用");
                this.comboBoxSorterB.Items.Add("超过");
                this.comboBoxSorterB.Items.Add("低于");
                this.comboBoxSorterB.Items.Add("不良");
                this.comboBoxSorterB.SelectedIndex = 2;
                this.comboBoxSorterB.SelectedIndexChanged += new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
            {
                this.buttonBypassDirection.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusBypassOccasionDown));
                this.buttonBypassDirection.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusBypassOccasionUp));
                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusBypassCountUp));

                this.labelTitleBypass.Text = "Транспортера";

                this.labelTitleSorterSettings.Text = "Настройка сортировки";

                this.labelTitleSorterA.Font = this.labelTitleSorterB.Font = new Font("새굴림", 9, FontStyle.Regular);
                this.labelTitleSorterA.Text = "Сортировщик А";
                this.labelTitleSorterB.Text = "Сортировщик В";
                this.labelTitleSorterMode.Text = "Режим";
                this.labelTitleSorterDelayTime.Text = "задержки";
                this.labelTitleSorterRunTime.Text = "выполнения";
                this.labelTitleDryContact.Text = "Сухой контакт";
                this.labelTitleDryContact1.Text = "контроль защелки1";
                this.labelTitleDryContact2.Text = "контроль защелки2";
                this.labelTitleDryContact3.Text = "контроль защелки3";
                this.labelTitleDryContact4.Text = "контроль защелки4";

                this.comboBoxSorterA.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);
                this.comboBoxSorterA.Items.Clear();
                this.comboBoxSorterA.Items.Add("Нет");
                this.comboBoxSorterA.Items.Add("Много");
                this.comboBoxSorterA.Items.Add("Мало");
                this.comboBoxSorterA.Items.Add("Дефект");
                this.comboBoxSorterA.SelectedIndex = 1;
                this.comboBoxSorterA.SelectedIndexChanged += new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);

                this.comboBoxSorterB.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
                this.comboBoxSorterB.Items.Clear();
                this.comboBoxSorterB.Items.Add("Нет");
                this.comboBoxSorterB.Items.Add("Много");
                this.comboBoxSorterB.Items.Add("Мало");
                this.comboBoxSorterB.Items.Add("Дефект");
                this.comboBoxSorterB.SelectedIndex = 2;
                this.comboBoxSorterB.SelectedIndexChanged += new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.buttonBypassDirection.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerBypassOccasionDown));
                this.buttonBypassDirection.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerBypassOccasionUp));
                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerBypassCountUp));

                this.labelTitleBypass.Text = "Bypass";

                this.labelTitleSorterSettings.Text = "Sortierereinstellung";

                this.labelTitleSorterA.Text = "Sortierer A";
                this.labelTitleSorterB.Text = "Sortierer B";
                this.labelTitleSorterMode.Text = "Modus";
                this.labelTitleSorterDelayTime.Text = "Vezögerung";
                this.labelTitleSorterRunTime.Text = "Laufzeit";
                this.labelTitleDryContact.Text = "Verriegelungssteuerung";
                this.labelTitleDryContact1.Text = "Verriegelungssteuerung1";
                this.labelTitleDryContact2.Text = "Verriegelungssteuerung2";
                this.labelTitleDryContact3.Text = "Verriegelungssteuerung3";
                this.labelTitleDryContact4.Text = "Verriegelungssteuerung4";

                this.comboBoxSorterA.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);
                this.comboBoxSorterA.Items.Clear();
                this.comboBoxSorterA.Items.Add("Keiner");
                this.comboBoxSorterA.Items.Add("Max.");
                this.comboBoxSorterA.Items.Add("Min.");
                this.comboBoxSorterA.Items.Add("Schlecht");
                this.comboBoxSorterA.SelectedIndex = 1;
                this.comboBoxSorterA.SelectedIndexChanged += new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);

                this.comboBoxSorterB.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
                this.comboBoxSorterB.Items.Clear();
                this.comboBoxSorterB.Items.Add("Keiner");
                this.comboBoxSorterB.Items.Add("Max.");
                this.comboBoxSorterB.Items.Add("Min.");
                this.comboBoxSorterB.Items.Add("Schlecht");
                this.comboBoxSorterB.SelectedIndex = 2;
                this.comboBoxSorterB.SelectedIndexChanged += new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
            }
            else
            {
                this.buttonBypassDirection.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korBypassOccasionDown));
                this.buttonBypassDirection.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korBypassOccasionUp));
                this.buttonBypassOnce.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korBypassCountDown));
                this.buttonBypassOnce.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korBypassCountUp));

                this.labelTitleBypass.Text = "Bypass";

                this.labelTitleSorterSettings.Text = "선별기 설정";

                this.labelTitleSorterA.Text = "선별부 A";
                this.labelTitleSorterB.Text = "선별부 B";
                this.labelTitleSorterMode.Text = "모드";
                this.labelTitleSorterDelayTime.Text = "지연시간";
                this.labelTitleSorterRunTime.Text = "동작시간";
                this.labelTitleDryContact.Text = "시건장치 제어";
                this.labelTitleDryContact1.Text = "시건장치 제어1";
                this.labelTitleDryContact2.Text = "시건장치 제어2";
                this.labelTitleDryContact3.Text = "시건장치 제어3";
                this.labelTitleDryContact4.Text = "시건장치 제어4";

                this.comboBoxSorterA.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);
                this.comboBoxSorterA.Items.Clear();
                this.comboBoxSorterA.Items.Add("사용안함");
                this.comboBoxSorterA.Items.Add("과량");
                this.comboBoxSorterA.Items.Add("경량");
                this.comboBoxSorterA.Items.Add("불량");
                this.comboBoxSorterA.SelectedIndex = 1;
                this.comboBoxSorterA.SelectedIndexChanged += new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);

                this.comboBoxSorterB.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
                this.comboBoxSorterB.Items.Clear();
                this.comboBoxSorterB.Items.Add("사용안함");
                this.comboBoxSorterB.Items.Add("과량");
                this.comboBoxSorterB.Items.Add("경량");
                this.comboBoxSorterB.Items.Add("불량");
                this.comboBoxSorterB.SelectedIndex = 2;
                this.comboBoxSorterB.SelectedIndexChanged += new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);
            }
        }
        private void DefaultSetting()
        {
            this.UpdateDryContactControl(this.ParentForm.ParentForm.CurrentSystemParameter3);
        }

        private void UpdateDisplayUser(UserItem user)
        {
            switch (user.Group)
            {
                case DataStore.UserGroup.LogOut:
                    this.groupBoxSorter.Enabled = false;
                    break;
                case DataStore.UserGroup.Level1Operator:
                    this.groupBoxSorter.Enabled = false;
                    break;
                case DataStore.UserGroup.Level2Engineer:
                    this.groupBoxSorter.Enabled = true;
                    break;
                case DataStore.UserGroup.Level3Manager:
                    this.groupBoxSorter.Enabled = true;
                    break;
                case DataStore.UserGroup.Level4Developer:
                    this.groupBoxSorter.Enabled = true;
                    break;
                default:
                    this.groupBoxSorter.Enabled = false;
                    break;
            }
        }
        public void UpdateDryContactControl(SystemParameter3 item)
        {
            int count = 0;

            if (item.ExternalOut1Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString()
                || item.ExternalOut2Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString()
                || item.ExternalOut3Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString()
                || item.ExternalOut4Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString())
            {
                this.labelTitleDryContact.Visible = true;
                this.buttonDry1.Visible = true;
                this.buttonDry2.Visible = true;
                this.buttonDry3.Visible = true;
                this.buttonDry4.Visible = true;
            }
            else
            {
                this.labelTitleDryContact.Visible = false;
                this.buttonDry1.Visible = false;
                this.buttonDry2.Visible = false;
                this.buttonDry3.Visible = false;
                this.buttonDry4.Visible = false;
            }

            if (item.ExternalOut1Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString())
            {
                this.labelTitleDryContact1.Visible = true;
                this.buttonDry1.Visible = true;
                count++;
            }
            else
            {
                this.labelTitleDryContact1.Visible = false;
                this.buttonDry1.Visible = false;
            }

            if (item.ExternalOut2Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString())
            {
                if (count == 1)
                {
                    this.labelTitleDryContact2.Location = new Point(480, 89);
                    this.buttonDry2.Location = new Point(640, 89);
                }
                else if (count == 0)
                {
                    this.labelTitleDryContact2.Location = new Point(480, 53);
                    this.buttonDry2.Location = new Point(640, 53);
                }
                this.labelTitleDryContact2.Visible = true;
                this.buttonDry2.Visible = true;
                count++;
            }
            else
            {
                this.labelTitleDryContact2.Visible = false;
                this.buttonDry2.Visible = false;
            }

            if (item.ExternalOut3Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString())
            {
                if (count == 2)
                {
                    this.labelTitleDryContact3.Location = new Point(480, 125);
                    this.buttonDry3.Location = new Point(640, 125);
                }
                else if (count == 1)
                {
                    this.labelTitleDryContact3.Location = new Point(480, 89);
                    this.buttonDry3.Location = new Point(640, 89);
                }
                else if (count == 0)
                {
                    this.labelTitleDryContact3.Location = new Point(480, 53);
                    this.buttonDry3.Location = new Point(640, 53);
                }
                this.labelTitleDryContact3.Visible = true;
                this.buttonDry3.Visible = true;
                count++;
            }
            else
            {
                this.labelTitleDryContact3.Visible = false;
                this.buttonDry3.Visible = false;
            }

            if (item.ExternalOut4Mode == ((int)DataStore.ExternalOutputMode.LatchCountrol).ToString())
            {
                if (count == 3)
                {
                    this.labelTitleDryContact4.Location = new Point(480, 161);
                    this.buttonDry4.Location = new Point(640, 161);
                }
                else if (count == 2)
                {
                    this.labelTitleDryContact4.Location = new Point(480, 125);
                    this.buttonDry4.Location = new Point(640, 125);
                }
                else if (count == 1)
                {
                    this.labelTitleDryContact4.Location = new Point(480, 89);
                    this.buttonDry4.Location = new Point(640, 89);
                }
                else if (count == 0)
                {
                    this.labelTitleDryContact4.Location = new Point(480, 53);
                    this.buttonDry4.Location = new Point(640, 53);
                }
                this.labelTitleDryContact4.Visible = true;
                this.buttonDry4.Visible = true;
            }
            else
            {
                this.labelTitleDryContact4.Visible = false;
                this.buttonDry4.Visible = false;
            }
        }
        public void UpdateControl(JudgmentSetItem item, SystemParameter4 parameter)
        {
            int iValue = 0;
            string value = "";

            #region Sorter
            this.comboBoxSorterA.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterA_SelectedIndexChanged);
            this.comboBoxSorterB.SelectedIndexChanged -= new EventHandler(this.comboBoxSorterB_SelectedIndexChanged);

            // 선별기A 모드
            iValue = item.Sorter1Mode;
            if (this.comboBoxSorterA.SelectedIndex != iValue)
                this.comboBoxSorterA.SelectedIndex = iValue;

            // 선별기A 지연시간
            iValue = item.Sorter1DelayTime;
            if (this.labelSorterADelayTime.Text != iValue.ToString())
                this.labelSorterADelayTime.Text = iValue.ToString();

            // 선별기A 동작시간
            iValue = item.Sorter1RunTime;
            if (this.labelSorterARunTime.Text != iValue.ToString())
                this.labelSorterARunTime.Text = iValue.ToString();

            // 선별기B 모드
            iValue = item.Sorter2Mode;
            if (this.comboBoxSorterB.SelectedIndex != iValue)
                this.comboBoxSorterB.SelectedIndex = iValue;

            // 선별기B 지연시간
            iValue = item.Sorter2DelayTime;
            if (this.labelSorterBDelayTime.Text != iValue.ToString())
                this.labelSorterBDelayTime.Text = iValue.ToString();

            // 선별기B 동작시간
            iValue = item.Sorter2RunTime;
            if (this.labelSorterBRunTime.Text != iValue.ToString())
                this.labelSorterBRunTime.Text = iValue.ToString(); 
            #endregion

            #region AutoZero
            // Mode 1
            //this.UpdateZero1ParameterDisplay(parameter);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.ParameterRead4901, "");
            #endregion
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.UpdateDisplayUser(status.CurrentUser);
            this.UpdateControl(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.CurrentSystemParameter4);
        }
        #endregion

        #region Event Handler
        private void comboBoxSorterA_SelectedIndexChanged(object sender, EventArgs e)
        {

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

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

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

                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    value = Helper.StringZeroFillDigits4(this.labelSorterADelayTime.Text);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.Sorter1DelayTime, value);
                }
            }
        }
        private void labelSorterRunTime_Click(object sender, EventArgs e)
        {
            string value = "";

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

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

                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    value = Helper.StringZeroFillDigits4(this.labelSorterARunTime.Text);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.Sorter1RunTime, value);
                }
            }
        }

        private void comboBoxSorterB_SelectedIndexChanged(object sender, EventArgs e)
        {

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

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

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

                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2DelayTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    value = Helper.StringZeroFillDigits4(this.labelSorterBDelayTime.Text);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.Sorter2DelayTime, value);
                }
            }
        }
        private void labelSorterBRunTime_Click(object sender, EventArgs e)
        {
            string value = "";

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

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

                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    value = Helper.StringZeroFillDigits4(this.labelSorterBRunTime.Text);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.Sorter2RunTime, value);
                }
            }
        }

        private void buttonBypassDirection_Click(object sender, EventArgs e)
        {
            if (this.buttonBypassDirection.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.SystemConfig2.IsBypassDirectionPass = false;
            else
                this.ParentForm.ParentForm.SystemConfig2.IsBypassDirectionPass = true;
        }
        private void buttonBypassOnce_Click(object sender, EventArgs e)
        {
            if (this.buttonBypassOnce.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.ParentForm.SystemConfig2.IsBypassOnce = false;
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.PUSH;
            }
            else
            {
                this.ParentForm.ParentForm.SystemConfig2.IsBypassOnce = true;
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.NORMAL;
            }
        }
        private void buttonBypassRun_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.ParentForm.SystemConfig2.IsBypassOnce == true)
            {
                if (this.ParentForm.ParentForm.SystemConfig2.IsBypassDirectionPass == true)
                    this.ParentForm.ParentForm.TransferData(CommunicationCommand.BypassOnce, CommunicationID.MainBoard);
                else
                    this.ParentForm.ParentForm.TransferData(CommunicationCommand.ByNGOnce, CommunicationID.MainBoard);
            }
            else
            {
                if (this.buttonBypassRun.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                {
                    this.buttonBypassDirection.Enabled = false;
                    this.buttonBypassOnce.Enabled = false;

                    if (this.ParentForm.ParentForm.SystemConfig2.IsBypassDirectionPass == true)
                        this.ParentForm.ParentForm.TransferData(CommunicationCommand.BypassON, CommunicationID.MainBoard);
                    else
                        this.ParentForm.ParentForm.TransferData(CommunicationCommand.ByNGON, CommunicationID.MainBoard);
                }
                else
                {
                    this.buttonBypassDirection.Enabled = true;
                    this.buttonBypassOnce.Enabled = true;

                    if (this.ParentForm.ParentForm.SystemConfig2.IsBypassDirectionPass == true)
                        this.ParentForm.ParentForm.TransferData(CommunicationCommand.BypassOFF, CommunicationID.MainBoard);
                    else
                        this.ParentForm.ParentForm.TransferData(CommunicationCommand.ByNGOFF, CommunicationID.MainBoard);
                }
            }
        }

        private void buttonDryContact_Click(object sender, EventArgs e)
        {
            SmartX.SmartButton button = sender as SmartX.SmartButton;

            if (button == null)
                return;

            if (button == this.buttonDry1)
                this.ParentForm.ParentForm.TransferData(CommunicationCommand.Output, CommunicationID.SubBoard1);
            else if (button == this.buttonDry2)
                this.ParentForm.ParentForm.TransferData(CommunicationCommand.Output, CommunicationID.SubBoard2);
            else if (button == this.buttonDry3)
                this.ParentForm.ParentForm.TransferData(CommunicationCommand.Output, CommunicationID.SubBoard3);
            else if (button == this.buttonDry4)
                this.ParentForm.ParentForm.TransferData(CommunicationCommand.Output, CommunicationID.SubBoard4);
        }
        #endregion
    }
}
