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 System.Collections.ObjectModel;

using ITC81DB_2H.DialogForms;
using ITC81DB_2H.Forms;
using SmartX;
using ITC81DB_2H_ImageDll;
using ITC81DB_2H.Datastore;

namespace ITC81DB_2H.Controls
{
    public partial class ControlCenterSystemJudgment : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;

        private int MovePoint;
        //private int SelectedProductNo;
        private string RefrenceADC;
        //private ProductItem SelectedProductItem;
        //private JudgmentSetItem SelectedJudgmentSetItem;
        private JudgmentSetItem CaptureJudgmentSetItem;
        private int MaxSpeed;
        #endregion

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

            this.ParentForm = parent;

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

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

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

            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.buttonWeightReference.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engJudgmentStandardDisable));
                this.buttonWeightReference.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engJudgmentStandardDown));
                this.buttonWeightReference.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engJudgmentStandardUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.buttonWeightReference.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormJudgmentStandardDisable));
                this.buttonWeightReference.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormJudgmentStandardDown));
                this.buttonWeightReference.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormJudgmentStandardUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.buttonWeightReference.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusJudgmentStandardDisable));
                this.buttonWeightReference.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusJudgmentStandardDown));
                this.buttonWeightReference.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusJudgmentStandardUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.buttonWeightReference.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerJudgmentStandardDisable));
                this.buttonWeightReference.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerJudgmentStandardDown));
                this.buttonWeightReference.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerJudgmentStandardUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {

            }
            else
            {
                this.buttonWeightReference.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korJudgmentStandardDisable));
                this.buttonWeightReference.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korJudgmentStandardDown));
                this.buttonWeightReference.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korJudgmentStandardUp));
            }

            this.ChangeScreen();
        }
        private void DefaultSetting()
        {
            this.RefrenceADC = "0";
            this.CaptureJudgmentSetItem = new JudgmentSetItem();
            this.MaxSpeed = 120;

            this.ControlInitializeAsEquipmentType();
            this.ControlInitialize();
        }

        private void DrawInitialize()
        {
            SmartX.SmartDraw.CHARTREFRESH charRefreshType = SmartX.SmartDraw.CHARTREFRESH.LEFTSCROLL;

            SmartX.SmartDraw.CHARTPENSTYLE[] charPenStyle;
            charPenStyle = new SmartX.SmartDraw.CHARTPENSTYLE[1];
            charPenStyle[0].m_chColor = Color.Yellow;
            charPenStyle[0].m_iPenWidth = 2;

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

            this.smartDraw.PutDataAllClear();

            this.DrawInitialize();

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

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

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

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

            // BackLayer 세로 중심선
            //this.smartDraw.BackDraw.SetPenStyle(Color.Red, 1);
            //this.smartDraw.BackDraw.Line(228, 40, 228, 240);

            // 판정개수 표시선
            temp = (int)(int.Parse(this.labelJudgmentCount.Text) / 2);
            xPoint = 228 - temp;
            this.smartDraw.BackDraw.SetPenStyle(Color.Red, 1);
            this.smartDraw.BackDraw.Line(xPoint, 40, xPoint, 240);
            xPoint = 228 + temp;
            this.smartDraw.BackDraw.Line(xPoint, 40, xPoint, 240);
        }

        public void DisplayHiddenMenu(bool bValue)
        {
            this.MaxSpeed = 200;
        }

        private void ControlInitializeAsEquipmentType()
        {

        }
        private void ControlInitialize()
        {
            this.labelProductNo.Text = this.ParentForm.ParentForm.SystemConfig1.ProductNumber.ToString();
            this.buttonCopy.Text = "00";
            this.labelSensingTime.Text = "";
            this.buttonWeightReference.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            this.labelWeightJudgment.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);

            this.labelDoubleDelayTime.Text = " -";
            this.labelJudgmentDelayTime.Text = " -";
        }
       
        public void ChangeScreen()
        {
            Class1 images = new Class1();

            this.buttonUp.Visible = false;
            this.buttonDown.Visible = false;

            // 0 : 컨베어, 4 : 업다운, 6 : 정지계량
            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                switch (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType))
                {
                    case 0:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundJudgment));
                        break;
                    case 4:
                        this.buttonUp.Visible = true;
                        this.buttonDown.Visible = true;
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundJudgment_Updown));
                        break;
                    case 6:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundJudgment_StopWeighing));
                        break;
                    default:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundJudgment));
                        break;
                }
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                switch (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType))
                {
                    case 0:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundJudgment));
                        break;
                    case 4:
                        this.buttonUp.Visible = true;
                        this.buttonDown.Visible = true;
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundJudgment_Updown));
                        break;
                    case 6:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundJudgment_StopWeighing));
                        break;
                    default:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundJudgment));
                        break;
                }
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                switch (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType))
                {
                    case 0:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundJudgment));
                        break;
                    case 4:
                        this.buttonUp.Visible = true;
                        this.buttonDown.Visible = true;
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundJudgment_Updown));
                        break;
                    case 6:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundJudgment_StopWeighing));
                        break;
                    default:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundJudgment));
                        break;
                }
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                switch (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType))
                {
                    case 0:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundJudgment));
                        break;
                    case 4:
                        this.buttonUp.Visible = true;
                        this.buttonDown.Visible = true;
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundJudgment_Updown));
                        break;
                    case 6:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundJudgment_StopWeighing));
                        break;
                    default:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundJudgment));
                        break;
                }
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish)
            {

            }
            else
            {
                switch (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType))
                {
                    case 0:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundJudgment));
                        break;
                    case 4:
                        this.buttonUp.Visible = true;
                        this.buttonDown.Visible = true;
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundJudgment_Updown));
                        break;
                    case 6:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundJudgment_StopWeighing));
                        break;
                    default:
                        this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundJudgment));
                        break;
                }
            }

            //this.LabelLocation(int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType));
        }
        private void IsAutoMode(bool value)
        {
            if (value == true)
            {
                this.labelJudgmentDelayTime.ForeColor = Color.Gray;
                this.labelDoubleDelayTime.ForeColor = Color.Gray;
                this.labelFeedSpeed.ForeColor = Color.Gray;
                this.labelJudgmentDelayTime.Enabled = false;
                this.labelDoubleDelayTime.Enabled = false;
                this.labelFeedSpeed.Enabled = false;
            }
            else
            {
                this.labelJudgmentDelayTime.ForeColor = Color.White;
                this.labelDoubleDelayTime.ForeColor = Color.White;
                this.labelFeedSpeed.ForeColor = Color.White;
                this.labelJudgmentDelayTime.Enabled = true;
                this.labelDoubleDelayTime.Enabled = true;
                this.labelFeedSpeed.Enabled = true;
            }
        }

        // 모드별 배경화면 및 Label Visible/위치 변경
        private void LabelLocation(int equipmentType)
        {
            switch (equipmentType)
            {
                case 4:
                     break;
                default:
                    break;
            }
        }

        public void CaculateJudgmentData(int time1)
        {
            if (this.buttonUsingAutoMode.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                double time2; // 시간2 : (컨베이어 길이 - 제품길이) / 속도
                double speed; // 이송속도 : 제품길이 / 시간1

                // 이중지연 = 시간1 = 센서 검출 시간
                this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime = time1;
                this.labelDoubleDelayTime.Text = this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime.ToString();

                // 이송속도 = 제품길이 / 시간1
                speed = Convert.ToDouble(this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength) / Convert.ToDouble(time1);
                speed = Math.Round(speed + 0.5, 2);
                this.labelFeedSpeed.Text = speed.ToString();

                time2 = Convert.ToDouble(this.ParentForm.ParentForm.SystemConfig2.ConveyorLength -
                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength) / speed;
                time2 = Math.Floor(time2);

                // 판정지연 = 시간1 + 시간2(=(컨베어 길이-제품길이) / 속도)
                this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime = time1 + Convert.ToInt32(time2);
                this.labelJudgmentDelayTime.Text = this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime.ToString();

                this.ParentForm.ParentForm.TransferProductParameter(this.ParentForm.ParentForm.SystemConfig1.ProductNumber);

                this.buttonUsingAutoMode.ButtonUp();
                this.IsAutoMode(false);
            }

            this.labelSensingTime.Text = time1.ToString();
        }

        private void UpdateSystemParameterDisplay(JudgmentSetItem item, Collection<BLDCMotorParameter> item2)
        {
            string value = "";

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

            value = item.DescendDelayTime.ToString();
            if (this.labelDescendDelayTime.Text != value)
                this.labelDescendDelayTime.Text = value;

            value = item.AscendDelayTime.ToString();
            if (this.labelAscendDelayTime.Text != value)
                this.labelAscendDelayTime.Text = value;

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

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

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

            if (this.ParentForm.ParentForm.SystemConfig1.IsBLDCON == false)
            {
                value = item.FeedSpeed1.ToString();
            }
            else
            {
                if (this.ParentForm.ParentForm.SystemConfig2.BLDCTotalMotorNum > 2)
                    value = item2[1]._6704_MotorSpeed.ToString();
                else if (this.ParentForm.ParentForm.SystemConfig2.BLDCTotalMotorNum == 1)
                    value = item2[0]._6704_MotorSpeed.ToString();
                else
                    value = "60";
            }
            if (this.labelFeedSpeed.Text != value)
                this.labelFeedSpeed.Text = value;

            value = Helper.DoubleToString(item.DynamicCorrection, 6);
            if (this.labelDynamicCorrection.Text != value)
                this.labelDynamicCorrection.Text = value;

            this.GraphBackRedraw();
        }
        public void UpdateEquipmentStatusDisplay(Define.E_EquipmentStatus status)
        {
            if (status == Define.E_EquipmentStatus.Start)
            {
                this.labelProductNo.Enabled = false;
                this.buttonWeightReference.Enabled = false;
                this.buttonCopy.Enabled = false;
                this.buttonPaste.Enabled = false;
                this.buttonPasteAll.Enabled = false;
            }
            else
            {
                this.labelProductNo.Enabled = true;
                this.buttonWeightReference.Enabled = true;
                this.buttonCopy.Enabled = true;
                this.buttonPaste.Enabled = true;
                this.buttonPasteAll.Enabled = true;
            }
        }
        public void UpdateCurrentProductDisplay(Define.E_EquipmentStatus status, ProductItem pItem)
        {
            string value = "";

            value = pItem.Number.ToString();
            if (this.labelProductNo.Text != value)
                this.labelProductNo.Text = value;

            this.UpdateSystemParameterDisplay(this.ParentForm.ParentForm.CurrentJudgmentSetItem,
                this.ParentForm.ParentForm.CollectionBLDCParameter);
        }
        public void UpdateStopWeightDisplay(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            value = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelWeightValue.Text != value)
                this.labelWeightValue.Text = value;
        }
        public void UpdateGraphDataDisplay(Define.E_EquipmentStatus status, WeightData weightData, Collection<int> values)
        {
            int iValue = 0, temp = 0, inputValue = 0;
            string sValue = "";

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

            this.smartDraw.PutDataAllClear();

            sValue = this.buttonWeightReference.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 DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.SystemJudgment;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.SystemSetting);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.CaptureJudgmentSetItem = new JudgmentSetItem();

            this.ControlInitialize();
            if (this.ParentForm != null)
                this.ParentForm.UpdateEquipmentStatusDisplay(this.ParentForm.ParentForm.CurrentSystemStatus.Equipment);
            this.UpdateSystemParameterDisplay(this.ParentForm.ParentForm.CurrentJudgmentSetItem,
                this.ParentForm.ParentForm.CollectionBLDCParameter);

            if (int.Parse(this.ParentForm.ParentForm.CurrentSystemParameter1.EquipmentType) != 0)
                this.buttonUsingAutoMode.Enabled = false;
            else
            {
                this.buttonUsingAutoMode.Enabled = true;
                this.buttonUsingAutoMode.ButtonUp();
            }
            this.IsAutoMode(false);

            this.MaxSpeed = 120;
            this.smartDraw.PutDataAllClear();

            //// Read Calibration Constant
            //this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.ReadConstant, "");
        }
        #endregion

        #region Event Handler
        private void labelProductNo_Click(object sender, EventArgs e)
        {
            string before = "", after = "";
            string message = "";

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

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

                    this.labelProductNo.Text = "**";
                    this.ParentForm.ParentForm.TransferProductParameter(myKeyPad.IntValue);

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

        private void labelFilter_Click(object sender, EventArgs e)
        {
            string before = "", after = "";
            string value = "", message = "";

            before = this.labelFilter.Text;
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelFilter.Text, 2, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.Filter, value);

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.JudgeFilter, "", before, after);
                }
            }
        }
        private void labelJudgmentDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

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

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);

                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.JudgmentDelayTime, value);

                    if (this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime < this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime)
                    {
                        this.labelDoubleDelayTime.Text = this.labelJudgmentDelayTime.Text;

                        value = Helper.StringZeroFillDigits4(this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime.ToString());
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime;
                        this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.DoubleDelayTime, value);

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

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.JudgeDelay, "", before, after);
                }
            }
        }
        private void labelDoubleDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    message = "0~9999";
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    if (myKeyPad.IntValue > this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime)
                    {
                        after = this.labelDoubleDelayTime.Text = this.labelJudgmentDelayTime.Text;
                        value = Helper.StringZeroFillDigits4(this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime.ToString());
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime;
                    }
                    else
                    {
                        after = this.labelDoubleDelayTime.Text = myKeyPad.StringValue;
                        value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime = myKeyPad.IntValue;
                    }
                    
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.DoubleDelayTime, value);
                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.JudgeDoubleDelay, "", before, after);
                }
            }
        }
        private void labelJudgmentCount_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

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

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.JudgmentCount, value);
                    this.GraphBackRedraw();

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.JudgeNumber, "", before, after);
                }
            }
        }
        private void labelFeedSpeed_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

            before = this.labelFeedSpeed.Text;
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelFeedSpeed.Text, 3, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > this.MaxSpeed)
                {
                    // 입력범위를 확인하세요
                    message = "1~" + this.MaxSpeed.ToString();
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    after = this.labelFeedSpeed.Text = myKeyPad.StringValue;

                    if (this.ParentForm.ParentForm.SystemConfig1.IsBLDCON == false)
                    {
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.FeedSpeed1 = myKeyPad.IntValue;

                        value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                        this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.FeedSpeed, value);

                        this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);
                    }
                    else
                    {
                        for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig2.BLDCTotalMotorNum; i++)
                            this.ParentForm.ParentForm.CollectionBLDCParameter[i]._6704_MotorSpeed = myKeyPad.IntValue;

                        value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                        this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter);
                        this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, "0", CommunicationAddress.BLDCMotorSpeed, value);

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

        private void labelDescendDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

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

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.DescendDelayTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.DescendDelayTime, value);

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

                    if (before != after)
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingParameter.JudgeDesDelay, "", before, after);
                }
            }
        }
        private void labelAscendDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

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

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

                    value = Helper.StringZeroFillDigits4(myKeyPad.StringValue);
                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.AscendDelayTime = myKeyPad.IntValue;
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.AscendDelayTime, value);

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

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

        private void labelDynamicCorrection_Click(object sender, EventArgs e)
        {
            string value = "", message = "";
            string before = "", after = "";

            before = this.labelDynamicCorrection.Text;
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDynamicCorrection.Text, 7, 6, false, this.ParentForm.ParentForm.SystemConfig1.Language);

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

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

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

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

        private void buttonUsingAutoMode_Click(object sender, EventArgs e)
        {
            if (this.buttonUsingAutoMode.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.IsAutoMode(true);
            }
            else
            {
                this.IsAutoMode(false);
            }
        }
        private void buttonToLeftOrRight_Click(object sender, EventArgs e)
        {
            //int iValue = 0, temp = 0, inputValue = 0, graphInitValue = 0, unit = 50;
            //int removeData = 0;

            //SmartX.SmartButton button = sender as SmartX.SmartButton;

            //if (button == null)
            //    return;

            //if (button == this.buttonToLeft)
            //{
            //    this.MovePoint -= 1;
            //    removeData = (unit * 2) / (this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime / 150);
            //    this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime += unit;
            //}
            //else
            //{
            //    this.MovePoint += 1;
            //    removeData = (unit * 2) / (this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime / 150);
            //    this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime -= unit;
            //}

            //this.labelJudgmentDelayTime.Text = this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime.ToString();
            //this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);
            //this.ParentForm.ParentForm.TransferProductParameter(this.ParentForm.ParentForm.SystemConfig1.ProductNumber);

            //this.smartDraw.PutDataAllClear();

            //iValue = int.Parse(this.RefrenceADC);
            //temp = 120 - iValue;

            //if (this.MovePoint < 0)
            //{
            //    graphInitValue = removeData * this.MovePoint * -1;

            //    for (int i = graphInitValue; i < this.CollectionGraphDataTemp.Count; i++)
            //    {
            //        inputValue = this.CollectionGraphDataTemp[i] + temp;

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

            //        this.smartDraw.PutData(inputValue);
            //    }

            //    for (int i = 0; i < graphInitValue; i++)
            //        this.smartDraw.PutData(1);
            //}
            //else
            //{
            //    graphInitValue = removeData * this.MovePoint;

            //    for (int i = 0; i < graphInitValue; i++)
            //        this.smartDraw.PutData(1);

            //    for (int i = 0; i < this.CollectionGraphDataTemp.Count - graphInitValue; i++)
            //    {
            //        inputValue = this.CollectionGraphDataTemp[i] + temp;

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

            //        this.smartDraw.PutData(inputValue);
            //    }
            //}
        }

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

        private void buttonCopy_Click(object sender, EventArgs e)
        {
            this.buttonCopy.Text = this.labelProductNo.Text;

            this.CaptureJudgmentSetItem.Filter = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Filter;
            this.CaptureJudgmentSetItem.JudgmentDelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime;
            this.CaptureJudgmentSetItem.DoubleDelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime;
            this.CaptureJudgmentSetItem.JudgmentCount = this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentCount;
            this.CaptureJudgmentSetItem.FeedSpeed1 = this.ParentForm.ParentForm.CurrentJudgmentSetItem.FeedSpeed1;
            this.CaptureJudgmentSetItem.DynamicCorrection = this.ParentForm.ParentForm.CurrentJudgmentSetItem.DynamicCorrection;
            this.CaptureJudgmentSetItem.MovingAverage = this.ParentForm.ParentForm.CurrentJudgmentSetItem.MovingAverage;

            this.CaptureJudgmentSetItem.Sorter1Mode = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1Mode;
            this.CaptureJudgmentSetItem.Sorter1DelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime;
            this.CaptureJudgmentSetItem.Sorter1RunTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime;
            this.CaptureJudgmentSetItem.Sorter2Mode = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2Mode;
            this.CaptureJudgmentSetItem.Sorter2DelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2DelayTime;
            this.CaptureJudgmentSetItem.Sorter2RunTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime;

            this.CaptureJudgmentSetItem.DescendDelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.DescendDelayTime;
            this.CaptureJudgmentSetItem.AscendDelayTime = this.ParentForm.ParentForm.CurrentJudgmentSetItem.AscendDelayTime;
            this.CaptureJudgmentSetItem.ProductLength = this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength;

            // Part11
            this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.ProductCopy, this.buttonCopy.Text);
        }
        private void buttonPaste_Click(object sender, EventArgs e)
        {
            if (this.buttonCopy.Text == "00")
                return;

            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Filter = this.CaptureJudgmentSetItem.Filter;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime = this.CaptureJudgmentSetItem.DoubleDelayTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.FeedSpeed1 = this.CaptureJudgmentSetItem.FeedSpeed1;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.MovingAverage = this.CaptureJudgmentSetItem.MovingAverage;

            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1Mode = this.CaptureJudgmentSetItem.Sorter1Mode;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime = this.CaptureJudgmentSetItem.Sorter1DelayTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = this.CaptureJudgmentSetItem.Sorter1RunTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2Mode = this.CaptureJudgmentSetItem.Sorter2Mode;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2DelayTime = this.CaptureJudgmentSetItem.Sorter2DelayTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = this.CaptureJudgmentSetItem.Sorter2RunTime;

            this.ParentForm.ParentForm.CurrentJudgmentSetItem.DescendDelayTime = this.CaptureJudgmentSetItem.DescendDelayTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.AscendDelayTime = this.CaptureJudgmentSetItem.AscendDelayTime;
            this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength = this.CaptureJudgmentSetItem.ProductLength;

            this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);

            this.labelProductNo.Text = "**";
            this.ParentForm.ParentForm.TransferProductParameter(this.ParentForm.ParentForm.SystemConfig1.ProductNumber);

            // Part11
            this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.ProductPaste, this.ParentForm.ParentForm.SystemConfig1.ProductNumber.ToString());
        }
        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.ParentForm.Enabled = false;

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

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

            for (int i = 0; i < this.ParentForm.ParentForm.ProductCount; i++)
            {
                structItem.Filter = this.CaptureJudgmentSetItem.Filter;
                structItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
                structItem.DoubleDelayTime = this.CaptureJudgmentSetItem.DoubleDelayTime;
                structItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
                structItem.FeedSpeed1 = this.CaptureJudgmentSetItem.FeedSpeed1;
                structItem.FeedSpeed2 = this.CaptureJudgmentSetItem.FeedSpeed2;
                structItem.FeedSpeed3 = this.CaptureJudgmentSetItem.FeedSpeed3;
                structItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;

                structItem.Sorter1Mode = this.CaptureJudgmentSetItem.Sorter1Mode;
                structItem.Sorter1DelayTime = this.CaptureJudgmentSetItem.Sorter1DelayTime;
                structItem.Sorter1RunTime = this.CaptureJudgmentSetItem.Sorter1RunTime;
                structItem.Sorter2Mode = this.CaptureJudgmentSetItem.Sorter2Mode;
                structItem.Sorter2DelayTime = this.CaptureJudgmentSetItem.Sorter2DelayTime;
                structItem.Sorter2RunTime = this.CaptureJudgmentSetItem.Sorter2RunTime;

                structItem.ProductLength = this.CaptureJudgmentSetItem.ProductLength;
                structItem.AutoJudgment1 = this.CaptureJudgmentSetItem.AutoJudgment1;
                structItem.AutoJudgment2 = this.CaptureJudgmentSetItem.AutoJudgment2;
                structItem.AutoJudgment3 = this.CaptureJudgmentSetItem.AutoJudgment3;

                structItem.DescendDelayTime = this.CaptureJudgmentSetItem.DescendDelayTime;
                structItem.AscendDelayTime = this.CaptureJudgmentSetItem.AscendDelayTime;
                structItem.MovingAverage = this.CaptureJudgmentSetItem.MovingAverage;
                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyString1 = "0";
                structItem.DummyString2 = "0";
                structItem.DummyString3 = "0";
                structItem.DummyString4 = "0";
                structItem.DummyString5 = "0";

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

            this.ParentForm.ParentForm.ReLoadJudgmentSetFile();

            this.labelProductNo.Text = "**";
            this.ParentForm.ParentForm.TransferProductParameter(this.ParentForm.ParentForm.SystemConfig1.ProductNumber);

            this.ParentForm.Enabled = true;

            splash.Finish();

            // Part11
            this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.ProductAllPaste, "");
        }

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

            value = this.labelWeightValue.Text;
            if (this.buttonWeightReference.Text != value)
                this.buttonWeightReference.Text = value;

            //this.RefrenceADC = this.labelADCValue.Text;
        }
        #endregion       
    }
}
