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

using SmartX;
using INT89DB_26_ImageDll;
using INT89DB_26.DialogForms;

namespace INT89DB_26.Forms
{
    public partial class FormSystemSetting : Form
    {
        #region Field
        private FormMain m_ParentForm;

        private bool IsHanyoung;
        private int SelectedProductNo;
        private ProductItem SelectedProductItem;
        private JudgmentSetItem SelectedJudgmentSetItem;
        private JudgmentSetItem CaptureJudgmentSetItem;
        private Collection<SmartButton> CollectionButtonLine;
        #endregion

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

            this.ParentForm = parent;
        } 
        #endregion

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

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

            this.smartKeyboard.SetHangulFont(false);

            if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Korean)
            {
                this.smartKeyboard.SetHangulFont(true);
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.English)
            {
                this.labelTitle.Text = "System setting";
                this.tabProduct.Text = "Product";
                this.tabJudgment.Text = "Judgment";
                this.tabSorter.Text = "Sorter";
                this.groupBoxWeightSetting.Text = "Weight setting";

                this.labelStaticFilter.Text = "Filter";
                this.labelStaticJudgmentDelayTime.Text = "J.Delay";
                this.labelStaticDoubleDelayTime.Text = "Overlap";
                this.labelStaticJudgmentCount.Text = "J.Count";
                this.labelStaticDynamic.Text = "Dynamic";
                this.labelStaticSorterDelayTime.Text = "Delay time";
                this.labelStaticSorterRunTime.Text = "Run time";

                this.buttonWeightReference.Text = "Reference";
                this.smartLabel31.Text = "Judgment";

                this.labelStaticConveyorSpeed1.Text = "CV Speed 1";
                this.labelStaticConveyorSpeed2.Text = "CV Speed 2";
                this.labelStaticConveyorSpeed3.Text = "CV Speed 3";
                this.labelStaticConveyorSpeed4.Text = "CV Speed 4";

                this.buttonSave.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engSaveUp));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engBackUp));

                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingNoUp));

                this.buttonCopy.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCopyDown));
                this.buttonCopy.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCopyUp));
                this.buttonPaste.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPasteDown));
                this.buttonPaste.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPasteUp));
                this.buttonPasteAll.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPasteAllDown));
                this.buttonPasteAll.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engPasteAllUp));

                this.buttonOver.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingOverDown));
                this.buttonOver.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingOverUp));
                this.buttonPass.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingPassDown));
                this.buttonPass.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingPassUp));
                this.buttonTare.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingTareDown));
                this.buttonTare.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingTareUp));
                this.buttonUnder.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingUnderDown));
                this.buttonUnder.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engFormSystemSettingUnderUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Chinese)
            {
                this.labelTitle.Text = "系统设定";
                this.tabProduct.Text = "项目设置";
                this.tabJudgment.Text = "判断设置";
                this.tabSorter.Text = "筛选设定";
                this.groupBoxWeightSetting.Text = "重量";

                this.labelTitleNo.Text = "编号";
                this.labelTitleName.Text = "名称";
                this.labelTitleLOT.Text = "批号";
                this.buttonNameEdit.Text = this.buttonLotEdit.Text = "编辑";

                this.labelStaticFilter.Text = "滤波器";
                this.labelStaticJudgmentDelayTime.Text = "判断延迟";
                this.labelStaticDoubleDelayTime.Text = "重复";
                this.labelStaticJudgmentCount.Text = "重复延迟";
                this.labelStaticDynamic.Text = "动态校正";
                this.labelStaticSorterDelayTime.Text = "延迟时间";
                this.labelStaticSorterRunTime.Text = "运行时间";

                this.buttonWeightReference.Text = "参考价值";
                this.smartLabel31.Text = "结果";
                this.smartLabel33.Text = "重量";

                this.labelStaticConveyorSpeed1.Text = "速度 1";
                this.labelStaticConveyorSpeed2.Text = "速度 2";
                this.labelStaticConveyorSpeed3.Text = "速度 3";
                this.labelStaticConveyorSpeed4.Text = "速度 4";

                this.buttonSave.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnSaveDown));
                this.buttonSave.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnSaveUp));
                this.buttonBack.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackDown));
                this.buttonBack.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackUp));

                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingNoUp));

                this.buttonCopy.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCopyDown));
                this.buttonCopy.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCopyUp));
                this.buttonPaste.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnPasteDown));
                this.buttonPaste.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnPasteUp));
                this.buttonPasteAll.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnPasteAllDown));
                this.buttonPasteAll.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnPasteAllUp));

                this.buttonOver.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingOverDown));
                this.buttonOver.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingOverUp));
                this.buttonPass.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingPassDown));
                this.buttonPass.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingPassUp));
                this.buttonTare.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingTareDown));
                this.buttonTare.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingTareUp));
                this.buttonUnder.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingUnderDown));
                this.buttonUnder.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormSystemSettingUnderUp));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.E_LanguageID.Czech)
            {

            }
            else
            {

            }
        }
        private void InitializeControl()
        {
            switch (this.ParentForm.SystemConfig.InverterQTY)
            {
                case 1:
                    this.labelStaticConveyorSpeed2.Visible = false;
                    this.labelStaticConveyorSpeed3.Visible = false;
                    this.labelStaticConveyorSpeed4.Visible = false;
                    this.labelConveyorSpeed2.Visible = false;
                    this.labelConveyorSpeed3.Visible = false;
                    this.labelConveyorSpeed4.Visible = false;
                    break;
                case 2:
                    this.labelStaticConveyorSpeed3.Visible = false;
                    this.labelStaticConveyorSpeed4.Visible = false;
                    this.labelConveyorSpeed3.Visible = false;
                    this.labelConveyorSpeed4.Visible = false;
                    break;
                case 3:
                    this.labelStaticConveyorSpeed4.Visible = false;
                    this.labelConveyorSpeed4.Visible = false;
                    break;
                case 4:
                    break;
                default:
                    break;
            }

        }
        private void DefaultSetting()
        {
            this.IsHanyoung = false;

            this.CollectionButtonLine = new Collection<SmartButton>();
            this.CollectionButtonLine.Clear();

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.CollectionButtonLine.Add(this.buttonLine1);
                    this.CollectionButtonLine.Add(this.buttonLine2);

                    this.buttonLine3.Visible = false;
                    this.buttonLine4.Visible = false;
                    this.buttonLine5.Visible = false;
                    this.buttonLine6.Visible = false;
                    break;
                case 3:
                    this.CollectionButtonLine.Add(this.buttonLine1);
                    this.CollectionButtonLine.Add(this.buttonLine2);
                    this.CollectionButtonLine.Add(this.buttonLine3);

                    this.buttonLine4.Visible = false;
                    this.buttonLine5.Visible = false;
                    this.buttonLine6.Visible = false;
                    break;
                case 4:
                    this.CollectionButtonLine.Add(this.buttonLine1);
                    this.CollectionButtonLine.Add(this.buttonLine2);
                    this.CollectionButtonLine.Add(this.buttonLine3);
                    this.CollectionButtonLine.Add(this.buttonLine4);

                    this.buttonLine5.Visible = false;
                    this.buttonLine6.Visible = false;
                    break;
                case 5:
                    this.CollectionButtonLine.Add(this.buttonLine1);
                    this.CollectionButtonLine.Add(this.buttonLine2);
                    this.CollectionButtonLine.Add(this.buttonLine3);
                    this.CollectionButtonLine.Add(this.buttonLine4);
                    this.CollectionButtonLine.Add(this.buttonLine5);

                    this.buttonLine6.Visible = false;
                    break;
                case 6:
                    this.CollectionButtonLine.Add(this.buttonLine1);
                    this.CollectionButtonLine.Add(this.buttonLine2);
                    this.CollectionButtonLine.Add(this.buttonLine3);
                    this.CollectionButtonLine.Add(this.buttonLine4);
                    this.CollectionButtonLine.Add(this.buttonLine5);
                    this.CollectionButtonLine.Add(this.buttonLine6);
                    break;
                default:
                    break;
            }

            this.labelFilter.Text = "-";
            this.labelJudgmentDelayTime.Text = "-";
            this.labelDoubleDelayTime.Text = "-";
            this.labelJudgmentCount.Text = "-";
            this.labelDynamicCorrection.Text = "-";
            this.labelConveyorSpeed1.Text = "-";
            this.labelConveyorSpeed2.Text = "-";
            this.labelConveyorSpeed3.Text = "-";
            this.labelConveyorSpeed4.Text = "-";
            this.labelSorterDelayTime.Text = "-";
            this.labelSorterRunTime.Text = "-";
            this.labelWeightReference.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);
            this.labelWeightJudgment.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);
            this.labelADCValue.Text = "-";
            this.labelWeightValue.Text = "-";

            this.buttonLine1.ButtonDown();
            for (int i = 1; i < this.CollectionButtonLine.Count; i++)
                this.CollectionButtonLine[i].ButtonUp();
            this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard1);

            this.SelectedProductItem = new ProductItem();
            this.SelectedJudgmentSetItem = new JudgmentSetItem();
            this.CaptureJudgmentSetItem = new JudgmentSetItem();

            this.textBoxProductName.MaxLength = 20;
            this.textBoxLotNo.MaxLength = 10;

            this.labelItemNo.Text = this.ParentForm.SystemConfig.ProductNumber.ToString();
            this.SelectedProductNo = this.ParentForm.SystemConfig.ProductNumber;

            this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
            this.AddProductList();
            this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);
            this.listBoxProductList.SelectedIndex = this.SelectedProductNo - 1;

            this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);
            this.DisplayControls(this.SelectedProductItem);

            this.ParentForm.LoadJudgmentSetFile(ref this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
            this.DisplayControls(this.SelectedJudgmentSetItem);
        }

        public void DisplayRefresh()
        {
            this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard1);
            this.ParentForm.SystemConfig.CurrentForm = DataStore.E_FormStore.FormSystemSetting;

            if (this.CollectionButtonLine == null || this.CollectionButtonLine.Count == 0)
                return;

            this.smartDraw.PutDataAllClear();

            this.labelWeightReference.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);
            this.labelWeightJudgment.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);

            this.buttonLine1.ButtonDown();
            for (int i = 1; i < this.CollectionButtonLine.Count; i++)
                this.CollectionButtonLine[i].ButtonUp();

            this.labelItemNo.Text = this.ParentForm.SystemConfig.ProductNumber.ToString();
            this.SelectedProductNo = this.ParentForm.SystemConfig.ProductNumber;

            this.listBoxProductList.SelectedIndex = this.SelectedProductNo - 1;

            this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);
            this.DisplayControls(this.SelectedProductItem);

            this.ParentForm.LoadJudgmentSetFile(ref this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
            this.DisplayControls(this.SelectedJudgmentSetItem);

            this.tabControl.SelectedIndex = 0;

            this.buttonCopy.Text = "00";
            this.CaptureJudgmentSetItem = new JudgmentSetItem();
        }

        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            if (status == DataStore.EquipmentStatus.Start)
            {
                this.pictureBoxStart.Visible = true;
                this.pictureBoxStop.Visible = false;
                this.buttonBack.Enabled = false;
                this.buttonItemNo.Enabled = false;
                foreach (SmartButton button in this.CollectionButtonLine)
                    button.Enabled = false;
            }
            else
            {
                this.smartDraw.PutDataAllClear();
                this.pictureBoxStart.Visible = false;
                this.pictureBoxStop.Visible = true;
                this.buttonBack.Enabled = true;
                this.buttonItemNo.Enabled = true;
                foreach (SmartButton button in this.CollectionButtonLine)
                    button.Enabled = true;
            }
        }
        public void UpdateStopWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            string value = "";

            if (this.buttonLine1.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                value = Helper.DoubleToString(weightDatas[0].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeightValue.Text != value)
                    this.labelWeightValue.Text = value;

                value = weightDatas[0].ADCValue;
                if (this.labelADCValue.Text != value)
                    this.labelADCValue.Text = value;
            }
            else if (this.buttonLine2.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                value = Helper.DoubleToString(weightDatas[1].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeightValue.Text != value)
                    this.labelWeightValue.Text = value;

                value = weightDatas[1].ADCValue;
                if (this.labelADCValue.Text != value)
                    this.labelADCValue.Text = value;
            }
            else if (this.buttonLine3.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                value = Helper.DoubleToString(weightDatas[2].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeightValue.Text != value)
                    this.labelWeightValue.Text = value;

                value = weightDatas[2].ADCValue;
                if (this.labelADCValue.Text != value)
                    this.labelADCValue.Text = value;
            }
            else if (this.buttonLine4.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                value = Helper.DoubleToString(weightDatas[3].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeightValue.Text != value)
                    this.labelWeightValue.Text = value;

                value = weightDatas[3].ADCValue;
                if (this.labelADCValue.Text != value)
                    this.labelADCValue.Text = value;
            }
            else if (this.buttonLine5.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                value = Helper.DoubleToString(weightDatas[4].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeightValue.Text != value)
                    this.labelWeightValue.Text = value;

                value = weightDatas[4].ADCValue;
                if (this.labelADCValue.Text != value)
                    this.labelADCValue.Text = value;
            }
            else if (this.buttonLine6.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                value = Helper.DoubleToString(weightDatas[5].Weight, this.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeightValue.Text != value)
                    this.labelWeightValue.Text = value;

                value = weightDatas[5].ADCValue;
                if (this.labelADCValue.Text != value)
                    this.labelADCValue.Text = value;
            }
        }
        public void UpdateGraphDataDisplay(DataStore.EquipmentStatus status, WeightData weightData, Collection<int> values)
        {
            int iValue = 0, temp = 0, inputValue = 0;
            string sValue = "";

            sValue = Helper.DoubleToString(weightData.Weight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightJudgment.Text != sValue)
                this.labelWeightJudgment.Text = sValue;

            this.smartDraw.PutDataAllClear();

            sValue = this.labelWeightReference.Text.Replace(".", "");
            iValue = int.Parse(sValue);
            temp = 120 - iValue;

            for (int i = 0; i < values.Count; i++)
            {
                inputValue = values[i] + temp;

                if (inputValue > 240)
                    inputValue = 240;
                else if (inputValue < 0)
                    inputValue = 1;

                this.smartDraw.PutData(inputValue);
            }
        }
        public void UpdateItemNoDisplay(DataStore.EquipmentStatus status,ProductItem pItem, JudgmentSetItem jItem)
        {
            if (this.SelectedJudgmentSetItem == null && this.SelectedJudgmentSetItem == null)
                return;

            #region Judgment Item
            this.SelectedJudgmentSetItem.Filter = jItem.Filter;
            this.SelectedJudgmentSetItem.JudgmentDelayTime = jItem.JudgmentDelayTime;
            this.SelectedJudgmentSetItem.DoubleDelayTime = jItem.DoubleDelayTime;
            this.SelectedJudgmentSetItem.JudgmentCount = jItem.JudgmentCount;
            this.SelectedJudgmentSetItem.DynamicCorrection = jItem.DynamicCorrection;
            this.SelectedJudgmentSetItem.ConveyorSpeed1 = jItem.ConveyorSpeed1;
            this.SelectedJudgmentSetItem.ConveyorSpeed2 = jItem.ConveyorSpeed2;
            this.SelectedJudgmentSetItem.ConveyorSpeed3 = jItem.ConveyorSpeed3;
            this.SelectedJudgmentSetItem.ConveyorSpeed4 = jItem.ConveyorSpeed4;

            this.SelectedJudgmentSetItem.Sorter1Mode = jItem.Sorter1Mode;
            this.SelectedJudgmentSetItem.Sorter1DelayTime = jItem.Sorter1DelayTime;
            this.SelectedJudgmentSetItem.Sorter1RunTime = jItem.Sorter1RunTime;
            #endregion

            #region Product Item
            this.SelectedProductItem.LotNo = pItem.LotNo;
            this.SelectedProductItem.Name = pItem.Name;
            this.SelectedProductItem.Number = pItem.Number;
            this.SelectedProductItem.OverRange = pItem.OverRange;
            this.SelectedProductItem.PassRange = pItem.PassRange;
            this.SelectedProductItem.UnderRange = pItem.UnderRange;
            this.SelectedProductItem.TareRange = pItem.TareRange;
            #endregion

            this.DisplayControls(this.SelectedJudgmentSetItem);
            this.DisplayControls(this.SelectedProductItem);
        }

        #region 품목설정
        private void AddProductList()
        {
            this.listBoxProductList.Items.Clear();

            for (int i = 0; i < this.ParentForm.CollectionProductName.Count; i++)
                this.listBoxProductList.Items.Add(this.ParentForm.CollectionProductName[i]);
        }
        private void DisplayControls(ProductItem item)
        {
            if (this.SelectedProductItem == null && item == null)
                return;

            this.buttonItemNo.Text = item.Number.ToString();
            this.textBoxProductName.Text = item.Name;
            this.textBoxLotNo.Text = item.LotNo;
            this.buttonOver.Text = Helper.StringToDecimalPlaces(item.OverRange, this.ParentForm.SystemConfig.DecimalPlaces);
            this.buttonPass.Text = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.SystemConfig.DecimalPlaces);
            this.buttonUnder.Text = Helper.StringToDecimalPlaces(item.UnderRange, this.ParentForm.SystemConfig.DecimalPlaces);
            this.buttonTare.Text = Helper.StringToDecimalPlaces(item.TareRange, this.ParentForm.SystemConfig.DecimalPlaces);
        }
        #endregion

        #region 판정설정
        public void DrawInitialize()
        {
            SmartX.SmartDraw.CHARTREFRESH charRefreshType = SmartX.SmartDraw.CHARTREFRESH.NORMAL;
            SmartX.SmartDraw.CHARTPENSTYLE[] charPenStyle;
            charPenStyle = new SmartX.SmartDraw.CHARTPENSTYLE[1];
            charPenStyle[0].m_chColor = Color.Yellow;
            charPenStyle[0].m_iPenWidth = 2;

            this.smartDraw.SetChartCfg(33, 260, 400, 240, 4, charRefreshType, 1);
            this.smartDraw.ChartChannelPenStyle = charPenStyle;
            this.smartDraw.ChartDrawStep = 1;
        }
        public void GraphBackRedraw()
        {
            int xx, yy;

            this.smartDraw.PutDataAllClear();

            this.DrawInitialize();

            this.smartDraw.BackDraw.BackErase(Color.Black);

            // 가로선
            this.smartDraw.BackDraw.SetPenStyle(Color.Gray, 1);
            this.smartDraw.BackDraw.Line(30, 100, 427, 100);
            this.smartDraw.BackDraw.Line(30, 180, 427, 180);

            // 세로선 
            this.smartDraw.BackDraw.SetPenStyle(Color.Blue, 3);
            this.smartDraw.BackDraw.Line(30, 20, 30, 260);
            this.smartDraw.BackDraw.Line(427, 20, 427, 260);

            // 가로중심선
            this.smartDraw.BackDraw.SetPenStyle(Color.Blue, 1);
            this.smartDraw.BackDraw.Line(30, 140, 427, 140);

            // 판정개수 표시선
            xx = int.Parse(this.labelJudgmentCount.Text);
            yy = 430 - (xx * 4);
            this.smartDraw.BackDraw.SetPenStyle(Color.Red, 1);
            this.smartDraw.BackDraw.Line(yy, 40, yy, 240);
        }

        private void DisplayControls(JudgmentSetItem item)
        {
            string sValue = "";

            if (item == null)
                return;

            sValue = item.Filter.ToString();
            if (this.labelFilter.Text != sValue)
                this.labelFilter.Text = sValue;

            sValue = item.JudgmentDelayTime.ToString();
            if (this.labelJudgmentDelayTime.Text != sValue)
                this.labelJudgmentDelayTime.Text = sValue;

            sValue = item.DoubleDelayTime.ToString();
            if (this.labelDoubleDelayTime.Text != sValue)
                this.labelDoubleDelayTime.Text = sValue;

            sValue = item.JudgmentCount.ToString();
            if (this.labelJudgmentCount.Text != sValue)
                this.labelJudgmentCount.Text = sValue;

            sValue = string.Format("{0:f6}", item.DynamicCorrection);
            if (this.labelDynamicCorrection.Text != sValue)
                this.labelDynamicCorrection.Text = sValue;

            sValue = item.Sorter1DelayTime.ToString();
            if (this.labelSorterDelayTime.Text != sValue)
                this.labelSorterDelayTime.Text = sValue;

            sValue = item.Sorter1RunTime.ToString();
            if (this.labelSorterRunTime.Text != sValue)
                this.labelSorterRunTime.Text = sValue;

            sValue = item.ConveyorSpeed1.ToString();
            if (this.labelConveyorSpeed1.Text != sValue)
                this.labelConveyorSpeed1.Text = sValue;

            sValue = item.ConveyorSpeed2.ToString();
            if (this.labelConveyorSpeed2.Text != sValue)
                this.labelConveyorSpeed2.Text = sValue;

            sValue = item.ConveyorSpeed3.ToString();
            if (this.labelConveyorSpeed3.Text != sValue)
                this.labelConveyorSpeed3.Text = sValue;

            sValue = item.ConveyorSpeed4.ToString();
            if (this.labelConveyorSpeed4.Text != sValue)
                this.labelConveyorSpeed4.Text = sValue;

            this.GraphBackRedraw();
        }
        #endregion
        #endregion

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

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

        #region Event Handler
        private void buttonBack_Click(object sender, EventArgs e)
        {
            foreach (SmartX.SmartButton bt in this.CollectionButtonLine)
                bt.ButtonUp();

            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.E_FormStore.FormMenu);
        }

        private void buttonItemNo_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonItemNo.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(280, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 1000)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonItemNo.Text = this.labelItemNo.Text = myKeyPad.StringValue;
                    this.SelectedProductNo = myKeyPad.IntValue;

                    this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
                    this.listBoxProductList.SelectedIndex = this.SelectedProductNo - 1;
                    this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);

                    this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);

                    this.ParentForm.LoadJudgmentSetFile(ref this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);

                    this.buttonItemNo.Text = "**";
                    this.ParentForm.TransferProductParameter(this.SelectedProductNo);
                }
            }
        }

        private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl.SelectedIndex == 0)
            {
                this.buttonCopy.Visible = false;
                this.buttonPaste.Visible = false;
                this.buttonPasteAll.Visible = false;
            }
            else
            {
                this.buttonCopy.Visible = true;
                this.buttonPaste.Visible = true;
                this.buttonPasteAll.Visible = true;
            }
        }

        #region 품목설정
        private void listBoxProductList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listBoxProductList.SelectedItem == null)
                return;

            this.SelectedProductNo = this.listBoxProductList.SelectedIndex + 1;
            this.labelItemNo.Text = this.SelectedProductNo.ToString();

            this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.listBoxProductList.SelectedIndex);

            this.ParentForm.LoadJudgmentSetFile(ref this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);

            this.buttonItemNo.Text = "**";
            this.ParentForm.TransferProductParameter(this.SelectedProductNo);
        }

        private void textBoxProductName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.SelectedProductItem.Name = this.textBoxProductName.Text;
                this.ParentForm.CollectionProductName[this.SelectedProductItem.Number - 1] = this.textBoxProductName.Text;

                this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
                this.listBoxProductList.Items.Insert(this.SelectedProductItem.Number - 1, this.textBoxProductName.Text);
                this.listBoxProductList.Items.RemoveAt(this.SelectedProductItem.Number);
                this.listBoxProductList.SelectedIndex = this.SelectedProductItem.Number - 1;
                this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);

                e.Handled = true;
                this.smartKeyboard.Hide();

                this.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductItem.Number - 1);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxLotNo.Enabled = true;
                this.buttonItemNo.Enabled = true;
                this.listBoxProductList.Enabled = true;

                if (this.IsHanyoung == true)
                {
                    this.smartKeyboard.HanYoungKeyToggle();
                    this.IsHanyoung = false;
                }
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;
                this.smartKeyboard.Hide();
                this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.listBoxProductList.SelectedIndex);
                this.DisplayControls(this.SelectedProductItem);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxLotNo.Enabled = true;
                this.buttonItemNo.Enabled = true;
                this.listBoxProductList.Enabled = true;
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }

        private void textBoxLotNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.SelectedProductItem.LotNo = this.textBoxLotNo.Text;

                e.Handled = true;
                this.smartKeyboard.Hide();

                this.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductItem.Number - 1);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxProductName.Enabled = true;
                this.buttonItemNo.Enabled = true;
                this.listBoxProductList.Enabled = true;

                if (this.IsHanyoung == true)
                {
                    this.smartKeyboard.HanYoungKeyToggle();
                    this.IsHanyoung = false;
                }
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;
                this.smartKeyboard.Hide();
                this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.listBoxProductList.SelectedIndex);
                this.DisplayControls(this.SelectedProductItem);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxProductName.Enabled = true;
                this.buttonItemNo.Enabled = true;
                this.listBoxProductList.Enabled = true;
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }

        private void buttonNameEdit_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(0, 290);
            this.smartKeyboard.Size = new Size(800, 310);
            this.smartKeyboard.Hide();

            this.smartKeyboard.TargetInputObject = this.textBoxProductName;
            this.smartKeyboard.Show();

            this.textBoxProductName.Select(this.textBoxProductName.Text.Length, 0);

            this.buttonNameEdit.Enabled = false;
            this.buttonLotEdit.Enabled = false;
            this.textBoxLotNo.Enabled = false;
            this.buttonItemNo.Enabled = false;
            this.listBoxProductList.Enabled = false;
        }

        private void buttonLotEdit_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(0, 290);
            this.smartKeyboard.Size = new Size(800, 310);
            this.smartKeyboard.Hide();

            this.smartKeyboard.TargetInputObject = this.textBoxLotNo;
            this.smartKeyboard.Show();

            this.textBoxLotNo.Select(this.textBoxLotNo.Text.Length, 0);

            this.buttonNameEdit.Enabled = false;
            this.buttonLotEdit.Enabled = false;
            this.textBoxProductName.Enabled = false;
            this.buttonItemNo.Enabled = false;
            this.listBoxProductList.Enabled = false;
        }

        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            this.smartKeyboard.Hide();
            this.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.listBoxProductList.SelectedIndex);
            this.DisplayControls(this.SelectedProductItem);
            this.buttonNameEdit.Enabled = true;
            this.buttonLotEdit.Enabled = true;
            this.textBoxProductName.Enabled = true;
            this.textBoxLotNo.Enabled = true;
            this.buttonItemNo.Enabled = true;
            this.listBoxProductList.Enabled = true;
        }

        private void buttonUnder_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonUnder.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(100, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(this.SelectedProductItem.PassRange.ToString(), this.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonUnder.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.UnderRange = myKeyPad.StringValue.Replace(".", "");

                    this.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductItem.Number - 1);
                }
            }
        }
        private void buttonPass_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonPass.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(100, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if ((myKeyPad.doubleValue > Helper.StringToWeight(this.SelectedProductItem.OverRange, this.ParentForm.SystemConfig.DecimalPlaces)) ||
                    (myKeyPad.doubleValue < Helper.StringToWeight(this.SelectedProductItem.UnderRange, this.ParentForm.SystemConfig.DecimalPlaces)))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonPass.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.PassRange = myKeyPad.StringValue.Replace(".", "");

                    this.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductItem.Number - 1);
                }
            }
        }
        private void buttonOver_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonOver.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(100, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(this.SelectedProductItem.PassRange.ToString(), this.ParentForm.SystemConfig.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonOver.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.OverRange = myKeyPad.StringValue.Replace(".", "");

                    this.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductItem.Number - 1);
                }
            }
        }
        private void buttonTare_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonTare.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(100, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 99999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonTare.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.TareRange = myKeyPad.StringValue.Replace(".", "");

                    this.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductItem.Number - 1);
                }
            }
        } 
        #endregion

        #region 판정설정
        private void labelFilter_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelFilter.Text, 2, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 16)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelFilter.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.Filter = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelFilter.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.Filter, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelJudgmentDelayTime_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelJudgmentDelayTime.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

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


                    value = Helper.StringZeroFillDigits4(this.labelJudgmentDelayTime.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.JudgmentDelayTime, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelDoubleDelayTime_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDoubleDelayTime.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

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

                    value = Helper.StringZeroFillDigits4(this.labelDoubleDelayTime.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.DoubleDelayTime, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelJudgmentCount_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelJudgmentCount.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 20)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelJudgmentCount.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.JudgmentCount = myKeyPad.IntValue;

                    this.GraphBackRedraw();

                    value = Helper.StringZeroFillDigits4(this.labelJudgmentCount.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.JudgmentCount, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelDynamicCorrection_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDynamicCorrection.Text, 7, 6, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0.500000 || myKeyPad.doubleValue > 2.000000)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelDynamicCorrection.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.DynamicCorrection = myKeyPad.doubleValue;

                    value = string.Format("{0:f6}", this.labelDynamicCorrection.Text);
                    value = value.Remove(1, 1);
                    value = Helper.StringZeroFillDigits7(value);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.DynamicCorrection, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelConveyorSpeed1_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelConveyorSpeed1.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 120)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelConveyorSpeed1.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.ConveyorSpeed1 = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelConveyorSpeed1.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.InverterSpeed1, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelConveyorSpeed2_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelConveyorSpeed2.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 120)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelConveyorSpeed2.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.ConveyorSpeed2 = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelConveyorSpeed2.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.InverterSpeed2, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelConveyorSpeed3_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelConveyorSpeed3.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 120)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelConveyorSpeed3.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.ConveyorSpeed3 = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelConveyorSpeed3.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.InverterSpeed3, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelConveyorSpeed4_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelConveyorSpeed4.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 120)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, "");
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelConveyorSpeed4.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.ConveyorSpeed4 = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelConveyorSpeed4.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.InverterSpeed4, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }

        private void buttonWeightReference_Click(object sender, EventArgs e)
        {
            if (this.labelWeightReference.Text != this.labelWeightValue.Text)
                this.labelWeightReference.Text = this.labelWeightValue.Text;
        }
        private void buttonLine_Click(object sender, EventArgs e)
        {
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            if (button == this.buttonLine1)
                this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard1);
            else if (button == this.buttonLine2)
                this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard2);
            else if (button == this.buttonLine3)
                this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard3);
            else if (button == this.buttonLine4)
                this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard4);
            else if (button == this.buttonLine5)
                this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard5);
            else
                this.ParentForm.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.SubBoard6);
        }
        private void buttonCopy_Click(object sender, EventArgs e)
        {
            this.buttonCopy.Text = this.buttonItemNo.Text;

            this.CaptureJudgmentSetItem.Filter = this.SelectedJudgmentSetItem.Filter;
            this.CaptureJudgmentSetItem.JudgmentDelayTime = this.SelectedJudgmentSetItem.JudgmentDelayTime;
            this.CaptureJudgmentSetItem.DoubleDelayTime = this.SelectedJudgmentSetItem.DoubleDelayTime;
            this.CaptureJudgmentSetItem.JudgmentCount = this.SelectedJudgmentSetItem.JudgmentCount;
            this.CaptureJudgmentSetItem.DynamicCorrection = this.SelectedJudgmentSetItem.DynamicCorrection;
            this.CaptureJudgmentSetItem.ConveyorSpeed1 = this.SelectedJudgmentSetItem.ConveyorSpeed1;
            this.CaptureJudgmentSetItem.ConveyorSpeed2 = this.SelectedJudgmentSetItem.ConveyorSpeed2;
            this.CaptureJudgmentSetItem.ConveyorSpeed3 = this.SelectedJudgmentSetItem.ConveyorSpeed3;
            this.CaptureJudgmentSetItem.ConveyorSpeed4 = this.SelectedJudgmentSetItem.ConveyorSpeed4;

            this.CaptureJudgmentSetItem.Sorter1Mode = this.SelectedJudgmentSetItem.Sorter1Mode;
            this.CaptureJudgmentSetItem.Sorter1DelayTime = this.SelectedJudgmentSetItem.Sorter1DelayTime;
            this.CaptureJudgmentSetItem.Sorter1RunTime = this.SelectedJudgmentSetItem.Sorter1RunTime;
        }
        private void buttonPaste_Click(object sender, EventArgs e)
        {
            if (this.buttonCopy.Text == "00")
                return;

            this.SelectedJudgmentSetItem.Filter = this.CaptureJudgmentSetItem.Filter;
            this.SelectedJudgmentSetItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
            this.SelectedJudgmentSetItem.DoubleDelayTime = this.CaptureJudgmentSetItem.DoubleDelayTime;
            this.SelectedJudgmentSetItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
            this.SelectedJudgmentSetItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;
            this.SelectedJudgmentSetItem.ConveyorSpeed1 = this.CaptureJudgmentSetItem.ConveyorSpeed1;
            this.SelectedJudgmentSetItem.ConveyorSpeed2 = this.CaptureJudgmentSetItem.ConveyorSpeed2;
            this.SelectedJudgmentSetItem.ConveyorSpeed3 = this.CaptureJudgmentSetItem.ConveyorSpeed3;
            this.SelectedJudgmentSetItem.ConveyorSpeed4 = this.CaptureJudgmentSetItem.ConveyorSpeed4;

            this.SelectedJudgmentSetItem.Sorter1Mode = this.CaptureJudgmentSetItem.Sorter1Mode;
            this.SelectedJudgmentSetItem.Sorter1DelayTime = this.CaptureJudgmentSetItem.Sorter1DelayTime;
            this.SelectedJudgmentSetItem.Sorter1RunTime = this.CaptureJudgmentSetItem.Sorter1RunTime;

            this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);

            this.buttonItemNo.Text = "**";
            this.ParentForm.TransferProductParameter(this.SelectedProductNo);
        }
        private void buttonPasteAll_Click(object sender, EventArgs e)
        {
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            if (this.buttonCopy.Text == "00")
                return;

            SmartSplash splash = new SmartSplash();
            splash.CenterPosition = true;
            splash.AnimationInterval = 200;
            splash.LoadingImagePathname = "SmartLoading4";
            splash.Start();

            this.buttonBack.Enabled = false;
            this.buttonCopy.Enabled = false;
            this.buttonPaste.Enabled = false;
            this.buttonPasteAll.Enabled = false;

            this.SelectedJudgmentSetItem.Filter = this.CaptureJudgmentSetItem.Filter;
            this.SelectedJudgmentSetItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
            this.SelectedJudgmentSetItem.DoubleDelayTime = this.CaptureJudgmentSetItem.DoubleDelayTime;
            this.SelectedJudgmentSetItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
            this.SelectedJudgmentSetItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;
            this.SelectedJudgmentSetItem.ConveyorSpeed1 = this.CaptureJudgmentSetItem.ConveyorSpeed1;
            this.SelectedJudgmentSetItem.ConveyorSpeed2 = this.CaptureJudgmentSetItem.ConveyorSpeed2;
            this.SelectedJudgmentSetItem.ConveyorSpeed3 = this.CaptureJudgmentSetItem.ConveyorSpeed3;
            this.SelectedJudgmentSetItem.ConveyorSpeed4 = this.CaptureJudgmentSetItem.ConveyorSpeed4;

            this.SelectedJudgmentSetItem.Sorter1Mode = this.CaptureJudgmentSetItem.Sorter1Mode;
            this.SelectedJudgmentSetItem.Sorter1DelayTime = this.CaptureJudgmentSetItem.Sorter1DelayTime;
            this.SelectedJudgmentSetItem.Sorter1RunTime = this.CaptureJudgmentSetItem.Sorter1RunTime;

            fullFilePath = this.ParentForm.PathSystemFileFolder2 + "JudgmentSetItem.int";
            this.ParentForm.smartFileIO.FilePathName = fullFilePath;

            this.ParentForm.smartFileIO.Open(this.ParentForm.BufferSmartUart);

            for (int i = 0; i < 1000; i++)
            {
                structItem.Filter = this.CaptureJudgmentSetItem.Filter;
                structItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
                structItem.DoubleDelayTime = this.CaptureJudgmentSetItem.DoubleDelayTime;
                structItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
                structItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;

                structItem.ConveyorSpeed1 = this.CaptureJudgmentSetItem.ConveyorSpeed1;
                structItem.ConveyorSpeed2 = this.CaptureJudgmentSetItem.ConveyorSpeed2;
                structItem.ConveyorSpeed3 = this.CaptureJudgmentSetItem.ConveyorSpeed3;
                structItem.ConveyorSpeed4 = this.CaptureJudgmentSetItem.ConveyorSpeed4;

                structItem.Sorter1Mode = this.CaptureJudgmentSetItem.Sorter1Mode;
                structItem.Sorter1DelayTime = this.CaptureJudgmentSetItem.Sorter1DelayTime;
                structItem.Sorter1OperatingTime = this.CaptureJudgmentSetItem.Sorter1RunTime;

                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyInt4 = 0;
                structItem.DummyInt5 = 0;
                structItem.DummyInt6 = 0;
                structItem.DummyInt7 = 0;
                structItem.DummyInt8 = 0;
                structItem.DummyInt9 = 0;
                structItem.DummyInt10 = 0;
                structItem.DummyInt11 = 0;
                structItem.DummyInt12 = 0;
                structItem.DummyInt13 = 0;
                structItem.DummyInt14 = 0;
                structItem.DummyInt15 = 0;
             
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";
                structItem.DummyString5 = "";

                this.ParentForm.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.ParentForm.smartFileIO.WriteStructure_End();
            this.ParentForm.smartFileIO.Close();

            this.buttonItemNo.Text = "**";
            this.ParentForm.TransferProductParameter(this.SelectedProductNo);

            this.buttonBack.Enabled = true;
            this.buttonCopy.Enabled = true;
            this.buttonPaste.Enabled = true;
            this.buttonPasteAll.Enabled = true;

            splash.Finish();
        }
        #endregion

        #region 선별기설정
        private void labelSorterDelayTime_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSorterDelayTime.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

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

                    value = Helper.StringZeroFillDigits4(this.labelSorterDelayTime.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.Sorter1DelayTime, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void labelSorterRunTime_Click(object sender, EventArgs e)
        {
            string value = "";

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSorterRunTime.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
            myKeyPad.Location = new Point(300, 90);

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

                    value = Helper.StringZeroFillDigits4(this.labelSorterRunTime.Text);
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress.Sorter1RunTime, value);

                    this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 1);
                }
            }
        } 
        #endregion

        #region TestButton
        private void buttonClear_Click(object sender, EventArgs e)
        {
            this.smartDraw.PutDataAllClear();
        }
        private void buttonMax_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
                this.smartDraw.PutData(240);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
                this.smartDraw.PutData(120);
        }
        private void buttonMin_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
                this.smartDraw.PutData(0);
        } 
        #endregion

        private void buttonUp_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorUp, CommunicationID.MainBoard);
        }

        private void buttonDown_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorDown, CommunicationID.MainBoard);
        }

        private void smartKeyboard_OnHanYoungKeyChange(object sender, EventArgs e)
        {
            if (this.IsHanyoung == false)
                this.IsHanyoung = true;
            else
                this.IsHanyoung = false;
        }
        #endregion
    }
}