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 ITC81DB.DialogForms;
using ITC81DB.Forms;
using SmartX;
using System.Collections.ObjectModel;
using ITC81DB_ImageDll;

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

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

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

            this.ParentForm = parent;

            //this.InitializeDesign();
            this.DefaultSetting();
        }
        #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 == DataStore.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 == DataStore.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 == DataStore.LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.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 == DataStore.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 == DataStore.LanguageID.Spanish)
            {
                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
            {
                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.ControlInitializeAsEquipmentType();
            this.ControlInitialize();
        }

        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.labelConveyorLength.Text = this.ParentForm.ParentForm.SystemConfig2.ConveyorLength.ToString();
            this.labelSortingPointLength.Text = this.ParentForm.ParentForm.SystemConfig2.SortingPointLength.ToString();

            this.labelProductLength.Text = " -";
            this.labelDoubleDelayTime.Text = " -";
            this.labelJudgmentDelayTime.Text = " -";
            this.labelFilter.Text = " -";
            this.smartDraw.PutDataAllClear();
        }

        public void DisplayHiddenMenu(bool bValue)
        {
            if (bValue == true)
            {
                this.labelConveyorLength.ForeColor = Color.White;
                this.labelConveyorLength.Enabled = true;
                this.labelSortingPointLength.ForeColor = Color.White;
                this.labelSortingPointLength.Enabled = true;
            }
            else
            {
                this.labelConveyorLength.ForeColor = Color.DimGray;
                this.labelConveyorLength.Enabled = false;
                this.labelSortingPointLength.ForeColor = Color.DimGray;
                this.labelSortingPointLength.Enabled = false;
            }
        }
        public void ChangeScreen()
        {
            Class1 images = new Class1();

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

            // 0 : 컨베어, 4 : 업다운, 6 : 정지계량
            if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.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 == DataStore.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 == DataStore.LanguageID.Czech)
            {

            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.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 == DataStore.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 == DataStore.LanguageID.Spanish)
            {
                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
            {
                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));

            //if (this.ParentForm.ParentForm.SystemConfig1.IsAutoJudgmentUsing == true)
            //    this.labelProductLength.Visible = true;
            //else
            //    this.labelProductLength.Visible = false;
        }
        private void IsAutoMode(bool value)
        {
            if (value == true)
            {
                this.labelJudgmentDelayTime.ForeColor = Color.Gray;
                this.labelDoubleDelayTime.ForeColor = Color.Gray;
                this.labelFeedSpeedUnitHz.ForeColor = Color.Gray;
                this.labelJudgmentDelayTime.Enabled = false;
                this.labelDoubleDelayTime.Enabled = false;
                this.labelFeedSpeedUnitHz.Enabled = false;

                this.labelProductLength.ForeColor = Color.White;
                this.labelProductLength.Enabled = true;

                this.labelWeightJudgment.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                this.smartDraw.PutDataAllClear();
            }
            else
            {
                this.labelJudgmentDelayTime.ForeColor = Color.White;
                this.labelDoubleDelayTime.ForeColor = Color.White;
                this.labelFeedSpeedUnitHz.ForeColor = Color.White;
                this.labelJudgmentDelayTime.Enabled = true;
                this.labelDoubleDelayTime.Enabled = true;
                this.labelFeedSpeedUnitHz.Enabled = true;

                this.labelProductLength.ForeColor = Color.DimGray;
                this.labelProductLength.Enabled = false;
            }
        }

        // 모드별 배경화면 및 Label Visible/위치 변경
        private void LabelLocation(int equipmentType)
        {
            switch (equipmentType)
            {
                case 4:
                    this.labelDescendDelayTime.Visible = true;
                    this.labelAscendDelayTime.Visible = true;

                    this.labelDescendDelayTime.Location = new Point(109, 152);
                    this.labelJudgmentDelayTime.Location = new Point(109, 196);
                    this.labelDoubleDelayTime.Location = new Point(109, 240);
                    this.labelAscendDelayTime.Location = new Point(109, 284);
                    this.labelJudgmentCount.Location = new Point(109, 328);
                    this.labelFeedSpeedUnitHz.Location = new Point(109, 372);
                    this.labelDynamicCorrection.Location = new Point(109, 416);
                    break;
                default:
                    this.labelDescendDelayTime.Visible = false;
                    this.labelAscendDelayTime.Visible = false;

                    this.labelJudgmentDelayTime.Location = new Point(109, 152);
                    this.labelDoubleDelayTime.Location = new Point(109, 196);
                    this.labelJudgmentCount.Location = new Point(109, 240);
                    this.labelFeedSpeedUnitHz.Location = new Point(109, 284);
                    this.labelDynamicCorrection.Location = new Point(109, 328);
                    break;
            }
        }

        public 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;

            this.smartDraw.SetChartCfg(25, 250, 300, 240, 1, 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);

            // 가로선
            //this.smartDraw.BackDraw.SetPenStyle(Color.Gray, 1);
            //this.smartDraw.BackDraw.Line(25, 110, 325, 110);
            //this.smartDraw.BackDraw.Line(25, 150, 325, 150);

            // 가로 중심선
            this.smartDraw.BackDraw.SetPenStyle(Color.Blue, 1);
            this.smartDraw.BackDraw.Line(25, 130, 325, 130);

            // 세로선 
            this.smartDraw.BackDraw.SetPenStyle(Color.Blue, 3);
            this.smartDraw.BackDraw.Line(25, 10, 25, 250);
            this.smartDraw.BackDraw.Line(325, 10, 325, 250);

            // 세로 중심선
            this.smartDraw.BackDraw.SetPenStyle(Color.Red, 1);
            this.smartDraw.BackDraw.Line(175, 50, 175, 210);

            // 판정개수 표시선
            temp = int.Parse(this.labelJudgmentCount.Text);
            xPoint = 175 - temp;
            this.smartDraw.BackDraw.SetPenStyle(Color.Red, 1);
            this.smartDraw.BackDraw.Line(xPoint, 50, xPoint, 210);
        }
        public void CaculateJudgmentData(int time1)
        {
            this.labelSensingTime.Text = time1.ToString();

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

                // 이송속도2 = 제품길이 / 시간1
                speed = Convert.ToDouble(this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength) / Convert.ToDouble(time1);
                //speed2 = Math.Round(speed + 0.0005, 3) * 1000;
                //this.labelFeedSpeed2.Text = speed2.ToString();
                this.labelFeedSpeedUnitmmin.Text = Math.Round(speed * 60, 2).ToString();

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

                // 이중지연 = time1 + 150
                this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime = time1 + 150;
                this.labelDoubleDelayTime.Text = this.ParentForm.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime.ToString();

                // 선별기 지연시간 = (선별점거리 - 제품길이) + 제품길이 X 1/3 / 속도
                time3 = Convert.ToDouble(this.ParentForm.ParentForm.SystemConfig2.SortingPointLength
                    - (this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength * 2/3)) / speed;
                if (time3 < 0)
                    time3 = 0.0;
                else
                    time3 = Math.Floor(time3);
                this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime = Convert.ToInt32(time3);
                this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2DelayTime = Convert.ToInt32(time3);

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

                //this.ParentForm.ParentForm.DataBackup2ForAutoJudgment(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.buttonWeightReference.Text, this.labelFeedSpeed2.Text, this.IsAutoJudgment, this.labelProductSensingTime.Text);

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

        private void UpdateSystemParameterDisplay(JudgmentSetItem item)
        {
            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;

            value = item.FeedSpeed1.ToString();
            if (this.labelFeedSpeedUnitHz.Text != value)
                this.labelFeedSpeedUnitHz.Text = value;

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

            value = item.ProductLength.ToString();
            if (this.labelProductLength.Text != value)
                this.labelProductLength.Text = value;

            this.labelConveyorLength.Text = this.ParentForm.ParentForm.SystemConfig2.ConveyorLength.ToString();
            this.labelSortingPointLength.Text = this.ParentForm.ParentForm.SystemConfig2.SortingPointLength.ToString();

            this.GraphBackRedraw();
        }
        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            if (status == DataStore.EquipmentStatus.Start)
            {
                this.smartDraw.PutDataAllClear();
                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(DataStore.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);
        }
        public void UpdateGraphDataDisplay(DataStore.EquipmentStatus status, WeightData weightData, Collection<int> values)
        {
            int iValue = 0, temp = 0, inputValue = 0;
            string sValue = "";

            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.ReadSensingTime, "");

            if (this.buttonUsingAutoMode.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                return;

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

            this.smartDraw.PutDataAllClear();

            iValue = int.Parse(this.RefrenceADC);
            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 UpdateStopWeightDisplay(DataStore.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;

            value = data.ADCValue;
            if (this.labelADCValue.Text != value)
                this.labelADCValue.Text = value;
        }
        public void UpdateConstantDisplay(DataStore.EquipmentStatus status, CalibrationItem item)
        {
            string value = "";

            value = Helper.StringToDecimalPlaces(item.Constant.Trim(), 6);
            if (this.labelConstant.Text != value)
                this.labelConstant.Text = value;
        }
        public void UpdateChecksumDisplay(string value1, string value2)
        {
            this.label1.Text = value1;
            this.label2.Text = value2;
        }

        public void DisplayRefresh(SystemStatus status)
        {
            //this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.SystemJudgmentSetting2;
            this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.SystemSetting);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.CaptureJudgmentSetItem = new JudgmentSetItem();

            this.ControlInitialize();
            this.UpdateSystemParameterDisplay(this.ParentForm.ParentForm.CurrentJudgmentSetItem);

            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.DisplayHiddenMenu(false);

            // 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 message = "";

            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
                {
                    this.labelProductNo.Text = myKeyPad.StringValue;

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

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

            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
                {
                    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);
                }
            }
        }
        private void labelJudgmentDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            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
                {
                    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);

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);
                }
            }
        }
        private void labelDoubleDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            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
                {
                    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);
                }
            }
        }
        private void labelJudgmentCount_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            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
                {
                    this.labelJudgmentCount.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.JudgmentCount = myKeyPad.IntValue;

                    this.GraphBackRedraw();

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

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);
                }
            }
        }
        private void labelFeedSpeed_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 120)
                {
                    // 입력범위를 확인하세요
                    message = "1~120";
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelFeedSpeedUnitHz.Text = myKeyPad.StringValue;
                    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);
                }
            }
        }
        private void labelDynamicCorrection_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            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
                {
                    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);
                }
            }
        }

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

            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
                {
                    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);
                }
            }
        }
        private void labelAscendDelayTime_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

            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
                {
                    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);
                }
            }
        }

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

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue < 1 || myKeyPad.IntValue > int.Parse(this.labelConveyorLength.Text))
                {
                    // 입력범위를 확인하세요
                    message = "1~" + this.labelConveyorLength.Text;
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelProductLength.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.CurrentJudgmentSetItem.ProductLength = myKeyPad.IntValue;

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);
                }
            }
        }
        private void labelConveyorLength_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue < 1 || myKeyPad.IntValue > 2000)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelConveyorLength.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.SystemConfig2.ConveyorLength = myKeyPad.IntValue;

                    // 필터 - ~300미만 : 3, 300이상~700미만 : 8, 700이상~ : 16
                    if (this.ParentForm.ParentForm.SystemConfig2.ConveyorLength >= 700) // SWH
                    {
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Filter = 16;
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = 1000;
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = 1000;
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig2.ConveyorLength < 300) // SWL210
                    {
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Filter = 3;
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = 200;
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = 200;
                    }
                    else
                    {
                        this.ParentForm.ParentForm.CurrentJudgmentSetItem.Filter = 8;

                        if (this.ParentForm.ParentForm.SystemConfig2.ConveyorLength <= 350) // SWL615
                        {
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = 250;
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = 250;
                        }
                        else if (this.ParentForm.ParentForm.SystemConfig2.ConveyorLength <= 450) // SWL1222, SWL1225
                        {
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = 300;
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = 300;
                        }
                        else if (this.ParentForm.ParentForm.SystemConfig2.ConveyorLength <= 550) // SWM330
                        {
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = 500;
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = 500;
                        }
                        else // SWM635
                        {
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime = 600;
                            this.ParentForm.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime = 600;
                        }
                    }
                    this.labelFilter.Text = this.ParentForm.ParentForm.CurrentJudgmentSetItem.Filter.ToString();

                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);
                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.ParentForm.CurrentJudgmentSetItem, this.ParentForm.ParentForm.SystemConfig1.ProductNumber - 1);
                }
            }
        }
        private void labelSortingPointLength_Click(object sender, EventArgs e)
        {
            string value = "", message = "";

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

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.IntValue < 1)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelSortingPointLength.Text = myKeyPad.StringValue;
                    this.ParentForm.ParentForm.SystemConfig2.SortingPointLength = myKeyPad.IntValue;

                    this.ParentForm.ParentForm.SaveSystemConfigurationFile2(this.ParentForm.ParentForm.SystemConfig2);
                }
            }
        }
        private void buttonUsingAutoMode_Click(object sender, EventArgs e)
        {
            if (this.buttonUsingAutoMode.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.IsAutoMode(true);
            }
            else
            {
                this.IsAutoMode(false);
            }
        }

        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.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;
        }
        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.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);
        }
        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.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 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();
        }

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