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

namespace INT51DB.Controls
{
    public partial class ControlCenterSystemJudgmentSetting : 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 ControlCenterSystemJudgmentSetting(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.SystemConfig.Language == DataStore.LanguageID.English)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
            }
            else
            {
            }
        }
        private void DefaultSetting()
        {
            this.RefrenceADC = "0";
            this.SelectedProductNo = 1;
            this.SelectedProductItem = new ProductItem();
            this.SelectedJudgmentSetItem = new JudgmentSetItem();
            this.CaptureJudgmentSetItem = new JudgmentSetItem();

            this.ControlInitialize();
        }

        private void ControlInitialize()
        {
            this.labelUpDelayTime.Text = " -";
            this.labelJudgmentDelayTime.Text = " -";
            this.labelFilter.Text = " -";
            this.labelJudgmentDelayTime.Text = " -";
            this.smartDraw.PutDataAllClear();
        }

        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.Gray, 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);
        }

        private void UpdateSystemParameterDisplay(JudgmentSetItem item)
        {
            string value = "";

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

            value = item.DownDelayTime.ToString();
            if (this.labelDownDelayTime.Text != value)
                this.labelDownDelayTime.Text = value;

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

            value = item.UpDelayTime.ToString();
            if (this.labelUpDelayTime.Text != value)
                this.labelUpDelayTime.Text = value;

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

            value = item.FeedSpeed.ToString();
            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(DataStore.EquipmentStatus status)
        {
            if (status == DataStore.EquipmentStatus.Start)
            {
                this.smartDraw.PutDataAllClear();
                this.labelProductNo.Enabled = false;
            }
            else
            {
                this.labelProductNo.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.SelectedProductNo = pItem.Number;

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

            this.UpdateSystemParameterDisplay(this.SelectedJudgmentSetItem);
        }
        public void UpdateGraphDataDisplay(DataStore.EquipmentStatus status, WeightData weightData, Collection<int> values)
        {
            int iValue = 0, temp = 0, inputValue = 0;
            string sValue = "";

            sValue = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.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.SystemConfig.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(DataStore.UserGroup group)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.SystemJudgmentSetting;
            this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.SystemSetting);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

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

            this.ControlInitialize();

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

            this.UpdateSystemParameterDisplay(this.SelectedJudgmentSetItem);

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

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

            // 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.SystemConfig.Language);

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

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

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

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

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

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

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

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

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

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

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

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

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 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.SystemConfig.Language);

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


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

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

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

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

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


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

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 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.SystemConfig.Language);

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

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

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

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

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

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.SelectedProductNo - 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.SystemConfig.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.SystemConfig.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelDynamicCorrection.Text = myKeyPad.StringValue;
                    this.SelectedJudgmentSetItem.DynamicCorrection = myKeyPad.doubleValue;

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

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

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

            this.CaptureJudgmentSetItem.Filter = this.SelectedJudgmentSetItem.Filter;
            this.CaptureJudgmentSetItem.DownDelayTime = this.SelectedJudgmentSetItem.DownDelayTime;
            this.CaptureJudgmentSetItem.JudgmentDelayTime = this.SelectedJudgmentSetItem.JudgmentDelayTime;
            this.CaptureJudgmentSetItem.UpDelayTime = this.SelectedJudgmentSetItem.UpDelayTime;
            this.CaptureJudgmentSetItem.JudgmentCount = this.SelectedJudgmentSetItem.JudgmentCount;
            this.CaptureJudgmentSetItem.FeedSpeed = this.SelectedJudgmentSetItem.FeedSpeed;
            this.CaptureJudgmentSetItem.DynamicCorrection = this.SelectedJudgmentSetItem.DynamicCorrection;

            this.CaptureJudgmentSetItem.Sorter1Mode = this.SelectedJudgmentSetItem.Sorter1Mode;
            this.CaptureJudgmentSetItem.Sorter1DelayTime = this.SelectedJudgmentSetItem.Sorter1DelayTime;
            this.CaptureJudgmentSetItem.Sorter1RunTime = this.SelectedJudgmentSetItem.Sorter1RunTime;
            this.CaptureJudgmentSetItem.Sorter2Mode = this.SelectedJudgmentSetItem.Sorter2Mode;
            this.CaptureJudgmentSetItem.Sorter2DelayTime = this.SelectedJudgmentSetItem.Sorter2DelayTime;
            this.CaptureJudgmentSetItem.Sorter2RunTime = this.SelectedJudgmentSetItem.Sorter2RunTime;
        }

        private void buttonPaste_Click(object sender, EventArgs e)
        {
            if (this.buttonCopy.Text == "00")
                return;

            this.SelectedJudgmentSetItem.Filter = this.CaptureJudgmentSetItem.Filter;
            this.SelectedJudgmentSetItem.DownDelayTime = this.CaptureJudgmentSetItem.DownDelayTime;
            this.SelectedJudgmentSetItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
            this.SelectedJudgmentSetItem.UpDelayTime = this.CaptureJudgmentSetItem.UpDelayTime;
            this.SelectedJudgmentSetItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
            this.SelectedJudgmentSetItem.FeedSpeed = this.CaptureJudgmentSetItem.FeedSpeed;
            this.SelectedJudgmentSetItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;

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

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

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

        private void buttonPasteAll_Click(object sender, EventArgs e)
        {
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

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

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

            this.ParentForm.Enabled = false;

            this.SelectedJudgmentSetItem.Filter = this.CaptureJudgmentSetItem.Filter;
            this.SelectedJudgmentSetItem.DownDelayTime = this.CaptureJudgmentSetItem.DownDelayTime;
            this.SelectedJudgmentSetItem.JudgmentDelayTime = this.CaptureJudgmentSetItem.JudgmentDelayTime;
            this.SelectedJudgmentSetItem.UpDelayTime = this.CaptureJudgmentSetItem.UpDelayTime;
            this.SelectedJudgmentSetItem.JudgmentCount = this.CaptureJudgmentSetItem.JudgmentCount;
            this.SelectedJudgmentSetItem.FeedSpeed = this.CaptureJudgmentSetItem.FeedSpeed;
            this.SelectedJudgmentSetItem.DynamicCorrection = this.CaptureJudgmentSetItem.DynamicCorrection;

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

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

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

            for (int i = 0; i < 1000; i++)
            {
                structItem.Filter = this.SelectedJudgmentSetItem.Filter;
                structItem.DownDelayTime = this.SelectedJudgmentSetItem.DownDelayTime;
                structItem.JudgmentDelayTime = this.SelectedJudgmentSetItem.JudgmentDelayTime;
                structItem.UpDelayTime = this.SelectedJudgmentSetItem.UpDelayTime;
                structItem.JudgmentCount = this.SelectedJudgmentSetItem.JudgmentCount;
                structItem.FeedSpeed = this.SelectedJudgmentSetItem.FeedSpeed;
                structItem.DynamicCorrection = this.SelectedJudgmentSetItem.DynamicCorrection;

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

                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyInt4 = 0;
                structItem.DummyInt5 = 0;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";
                structItem.DummyString5 = "";

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

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

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

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

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