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_2H.DialogForms;
using ITC81DB_2H.Forms;
using ITC81DB_2H_ImageDll;
using ITC81DB_2H.Datastore;
using ITC81DB_2H.Part11_UserManager;

namespace ITC81DB_2H.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 == Define.E_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 == Define.E_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 == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_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 == Define.E_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 if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {

            }
            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 Define.E_UserGroup.LogOut:
                    this.groupBoxSorter.Enabled = false;
                    break;
                case Define.E_UserGroup.Level1:
                    this.groupBoxSorter.Enabled = false;
                    break;
                case Define.E_UserGroup.Level2:
                    this.groupBoxSorter.Enabled = true;
                    break;
                case Define.E_UserGroup.Level3:
                    this.groupBoxSorter.Enabled = true;
                    break;
                case Define.E_UserGroup.Admin:
                case Define.E_UserGroup.Developer:
                    this.groupBoxSorter.Enabled = true;
                    break;
                default:
                    this.groupBoxSorter.Enabled = true;
                    break;
            }
        }
        public void UpdateDryContactControl(SystemParameter3 item)
        {
            int count = 0;

            if (item.ExternalOut1Mode == ((int)Define.E_ExternalOutputMode.OUT10_LatchControl).ToString()
                || item.ExternalOut2Mode == ((int)Define.E_ExternalOutputMode.OUT10_LatchControl).ToString()
                || item.ExternalOut3Mode == ((int)Define.E_ExternalOutputMode.OUT10_LatchControl).ToString()
                || item.ExternalOut4Mode == ((int)Define.E_ExternalOutputMode.OUT10_LatchControl).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)Define.E_ExternalOutputMode.OUT10_LatchControl).ToString())
            {
                this.labelTitleDryContact1.Visible = true;
                this.buttonDry1.Visible = true;
                count++;
            }
            else
            {
                this.labelTitleDryContact1.Visible = false;
                this.buttonDry1.Visible = false;
            }

            if (item.ExternalOut2Mode == ((int)Define.E_ExternalOutputMode.OUT10_LatchControl).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)Define.E_ExternalOutputMode.OUT10_LatchControl).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)Define.E_ExternalOutputMode.OUT10_LatchControl).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
            //this.UpdateZero1ParameterDisplay(parameter);
            //this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.ParameterRead4907, "");
            #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)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            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
                {
                    string before = "", after = "";

                    before = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime.ToString();
                    after = 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);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.SorADelay, "", before, after);
                }
            }
        }
        private void labelSorterRunTime_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            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
                {
                    string before = "", after = "";

                    before = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime.ToString();
                    after = 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);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.SorARun, "", before, after);
                }
            }
        }

        private void comboBoxSorterB_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void labelSorterBDelayTime_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            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
                {
                    string before = "", after = "";

                    before = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2DelayTime.ToString();
                    after = 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);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.SorBDelay, "", before, after);
                }
            }
        }
        private void labelSorterBRunTime_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            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
                {
                    string before = "", after = "";

                    before = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime.ToString();
                    after = 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);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.SorBRun, "", before, after);
                }
            }
        }

        private void buttonBypassDirection_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            if (this.buttonBypassDirection.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.ParentForm.IsBypassDirectionPass = false;
            else
                this.ParentForm.ParentForm.IsBypassDirectionPass = true;
        }
        private void buttonBypassOnce_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            if (this.buttonBypassOnce.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.ParentForm.IsBypassOnce = false;
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.PUSH;
            }
            else
            {
                this.ParentForm.ParentForm.IsBypassOnce = true;
                this.buttonBypassRun.Mode = SmartButton.BUTTONMODE.NORMAL;
            }
        }
        private void buttonBypassRun_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            if (this.buttonBypassOnce.ButtonStatus == SmartButton.BUTSTATUS.UP)
            {
                this.ParentForm.ParentForm.IsBypassOnce = true;
                this.ParentForm.ParentForm.IsBypassUse = true;
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightBigScreen.UpdateSpotOrBypassImageVisibleStatus(true);
                this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightSmall.UpdateSpotOrBypassImageVisibleStatus(true);

                if (this.ParentForm.ParentForm.IsBypassDirectionPass == true)
                    this.ParentForm.ParentForm.TransferData(CommunicationCommand.BypassOnce, CommunicationID.MainBoard);
                else
                    this.ParentForm.ParentForm.TransferData(CommunicationCommand.ByNGOnce, CommunicationID.MainBoard);

                this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Bypass, "Once");
            }
            else
            {
                if (this.buttonBypassRun.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                {
                    this.buttonBypassDirection.Enabled = false;
                    this.buttonBypassOnce.Enabled = false;
                    this.ParentForm.ParentForm.IsBypassUse = true;
                    this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightBigScreen.UpdateSpotOrBypassImageVisibleStatus(true);
                    this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightSmall.UpdateSpotOrBypassImageVisibleStatus(true);

                    if (this.ParentForm.ParentForm.IsBypassDirectionPass == true)
                        this.ParentForm.ParentForm.TransferData(CommunicationCommand.BypassON, CommunicationID.MainBoard);
                    else
                        this.ParentForm.ParentForm.TransferData(CommunicationCommand.ByNGON, CommunicationID.MainBoard);

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Bypass, "Consecute - ON");
                }
                else
                {
                    this.buttonBypassDirection.Enabled = true;
                    this.buttonBypassOnce.Enabled = true;
                    this.ParentForm.ParentForm.IsBypassUse = false;
                    this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightBigScreen.UpdateSpotOrBypassImageVisibleStatus(false);
                    this.ParentForm.ParentForm.ChildFormMainDisplay.MainWeightSmall.UpdateSpotOrBypassImageVisibleStatus(false);

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

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Bypass, "Consecute - OFF");
                }
            }
        }

        private void buttonDryContact_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            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
    }
}
