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

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

        private Color NormalColor;
        private Color FinishColor;

        // 중량 조정이 완료 되었는지 확인하는 Flag
        private bool IsCalibrationFinish;
        #endregion

        #region Constructor
        public ControlCenterSystemCalibration(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 == Define.E_LanguageID.English)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundCalibration));

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationCancelUp));
                this.buttonStart.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationStartDisable));
                this.buttonStart.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationStartDown));
                this.buttonStart.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationStartUp));
                this.buttonBalance.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationCounterweightDisable));
                this.buttonBalance.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationCounterweightDown));
                this.buttonBalance.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationCounterweightUp));
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engCalibrationZeroUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundCalibration));

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationCancelUp));
                this.buttonStart.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationStartDisable));
                this.buttonStart.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationStartDown));
                this.buttonStart.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationStartUp));
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnCalibrationZeroUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundCalibration));

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationCancelUp));
                this.buttonStart.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationStartDisable));
                this.buttonStart.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationStartDown));
                this.buttonStart.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationStartUp));
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusCalibrationZeroUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundCalibration));

                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationCancelUp));
                this.buttonStart.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationStartDisable));
                this.buttonStart.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationStartDown));
                this.buttonStart.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationStartUp));
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerCalibrationZeroUp));
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundCalibration));
                
                this.buttonCancel.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationCancelDisable));
                this.buttonCancel.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationCancelDown));
                this.buttonCancel.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationCancelUp));
                this.buttonStart.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationStartDisable));
                this.buttonStart.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationStartDown));
                this.buttonStart.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationStartUp));
                this.buttonBalance.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationCounterweightDisable));
                this.buttonBalance.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationCounterweightDown));
                this.buttonBalance.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationCounterweightUp));
                this.buttonZero.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationZeroDisable));
                this.buttonZero.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationZeroDown));
                this.buttonZero.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korCalibrationZeroUp));
            }
        }
        private void DefaultSetting()
        {
            this.NormalColor = Color.White;
            this.FinishColor = Color.Lime;
        }

        private void CalibrationButtonEnable(bool btStart, bool btBalance, bool btCcancel)
        {
            this.buttonStart.Enabled = btStart;
            this.buttonBalance.Enabled = btBalance;
            this.buttonCancel.Enabled = btCcancel;
        }
        private void CalibrationPictureBoxVisible(bool step1, bool step2, bool step3)
        {
            if (step1 == true)
            {
                this.pictureBoxStep1.Visible = true;
                this.pictureBoxStep2.Visible = false;
                this.pictureBoxStep3.Visible = false;
            }
            else if (step2 == true)
            {
                this.pictureBoxStep1.Visible = false;
                this.pictureBoxStep2.Visible = true;
                this.pictureBoxStep3.Visible = false;
            }
            else if(step3 == true)
            {
                this.pictureBoxStep1.Visible = false;
                this.pictureBoxStep2.Visible = false;
                this.pictureBoxStep3.Visible = true;
            }
            else
            {
                this.pictureBoxStep1.Visible = true;
                this.pictureBoxStep2.Visible = false;
                this.pictureBoxStep3.Visible = false;
            }
        }

        private void UpdateControlsDisplay()
        {
            this.listBoxHelp.ClearAll();
            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.listBoxHelp.AddItem("Push the start button.");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.listBoxHelp.AddItem("需要重量调节,请点击开始按钮");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.listBoxHelp.AddItem("Нажмите кнопку [Старт],");
                this.listBoxHelp.AddItem("чтобы начать калибровку");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.listBoxHelp.AddItem("Drücken Sie die Taste [Start],");
                this.listBoxHelp.AddItem("um die Kalibrierung zu starten");
            }
            else
            {
                this.listBoxHelp.AddItem("중량조정을 하시려면");
                this.listBoxHelp.AddItem("시작 버튼을 누르세요");
            }

            this.CalibrationButtonEnable(true, false, false);
            this.CalibrationPictureBoxVisible(true, false, false);

            this.radioButtonDecimalPlaces1.Click -= new EventHandler(this.radioButtonDecimalPlaces_Click);
            this.radioButtonDecimalPlaces2.Click -= new EventHandler(this.radioButtonDecimalPlaces_Click);

            if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 1)
            {
                if (this.radioButtonDecimalPlaces1.Checked != true)
                    this.radioButtonDecimalPlaces1.Checked = true;
            }
            else
            {
                if (this.radioButtonDecimalPlaces2.Checked != true)
                    this.radioButtonDecimalPlaces2.Checked = true;
            }

            this.radioButtonDecimalPlaces1.Click += new EventHandler(this.radioButtonDecimalPlaces_Click);
            this.radioButtonDecimalPlaces2.Click += new EventHandler(this.radioButtonDecimalPlaces_Click);

            //if (this.labelWeightUnit.Text != this.ParentForm.ParentForm.SystemConfig1.Unit)
            //    this.labelWeightUnit.Text = this.ParentForm.ParentForm.SystemConfig1.Unit;
        }
        public void UpdateWeightDisplay(Define.E_EquipmentStatus status, WeightData data)
        {
            switch (data.Status)
            {
                case Define.E_WeightStatus.CalNomal:
                    this.labelWeight.Text = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                    this.labelWeight.ForeColor = this.NormalColor;
                    this.CalibrationButtonEnable(true, false, false);
                    this.CalibrationPictureBoxVisible(true, false, false);
                    break;
                case Define.E_WeightStatus.CalWait:
                    // 분동중량 표시
                    this.IsCalibrationFinish = false;
                    this.labelWeight.Text = string.Format("-{0}", this.labelBalanceWeight.Text);
                    this.labelWeight.ForeColor = this.NormalColor;
                    break;
                case Define.E_WeightStatus.CalStandby:
                    //// 분동중량 표시
                    //this.IsCalibrationFinish = false;
                    //if(this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 1)
                    //    this.labelWeight.Text = "-500.0";
                    //else
                    //    this.labelWeight.Text = "-500.00";
                    //this.labelWeight.ForeColor = this.NormalColor;
                    this.listBoxHelp.ClearAll();
                    if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
                    {
                        this.listBoxHelp.AddItem("Put the balance weight.");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
                    {
                        this.listBoxHelp.AddItem("请放上砝码");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
                    {
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
                    {
                        this.listBoxHelp.AddItem("Утаноите весы");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
                    {
                        this.listBoxHelp.AddItem("Gewicht auf den Förderer legen");
                    }
                    else
                    {
                        this.listBoxHelp.AddItem("분동을 올려주세요");
                    }
                    this.CalibrationButtonEnable(false, true, true);
                    this.CalibrationPictureBoxVisible(false, true, false);
                    break;
                case Define.E_WeightStatus.CalBalans:
                    // 분동중량표시
                    this.labelWeight.Text = string.Format("-{0}", this.labelBalanceWeight.Text);
                    this.CalibrationButtonEnable(false, false, true);
                    this.CalibrationPictureBoxVisible(false, false, true);
                    break;
                case Define.E_WeightStatus.CalFinish:
                    this.listBoxHelp.ClearAll();
                    if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
                    {
                        this.listBoxHelp.AddItem("Finish the calibration");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
                    {
                        this.listBoxHelp.AddItem("重量调节已完成");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
                    {
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
                    {
                        this.listBoxHelp.AddItem("Завершение калибровки");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
                    {
                        this.listBoxHelp.AddItem("Die Kalibrierung ist abgeschlossen.");
                    }
                    else
                    {
                        this.listBoxHelp.AddItem("중량조정이 완료 되었습니다");
                    }
                    this.CalibrationButtonEnable(true, false, false);
                    this.CalibrationPictureBoxVisible(true, false, false);
                    this.labelWeight.Text = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                    this.labelWeight.ForeColor = this.FinishColor;
                    if (this.IsCalibrationFinish == false)
                    {
                        this.IsCalibrationFinish = true;
                        this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.ParameterRead3901, "");
                        this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Calibration, "Calibration Success");
                    }
                    break;
                case Define.E_WeightStatus.CalError:
                    this.listBoxHelp.ClearAll();
                    if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
                    {
                        this.listBoxHelp.AddItem("Calibration error");
                        this.listBoxHelp.AddItem("Please try again.");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
                    {
                        this.listBoxHelp.AddItem("错误发生,重试");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
                    {
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
                    {
                        this.listBoxHelp.AddItem("Произошла ошибка");
                        this.listBoxHelp.AddItem("Попробуйте еще раз");
                    }
                    else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
                    {
                        this.listBoxHelp.AddItem("Fehler!");
                        this.listBoxHelp.AddItem("Bitte noch einmal versuchen");
                    }
                    else
                    {
                        this.listBoxHelp.AddItem("중량조정 에러");
                        this.listBoxHelp.AddItem("다시 시도해 주세요.");
                    }
                    this.CalibrationButtonEnable(true, false, false);
                    this.CalibrationPictureBoxVisible(true, false, false);
                    this.labelWeight.Text = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
                    this.labelWeight.ForeColor = this.NormalColor;

                    this.ParentForm.ParentForm.SetTrackingHistoryData(Define.E_TrackingOperation.Calibration, "Calibration Fail");
                    break;
                default:
                    break;
            }
        }
        public void UpdateCalibrationItemDisplay(Define.E_EquipmentStatus status, CalibrationItem item)
        {
            string value = "";

            value = Helper.StringToDecimalPlaces(item.BalanceWeight, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelBalanceWeight.Text != value)
                this.labelBalanceWeight.Text = value;
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.SystemCalibration;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Calibration);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

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

            this.Refresh();
        }
        #endregion

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

            before = this.labelBalanceWeight.Text;
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelBalanceWeight.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces,
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 700.0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.Location = new Point(167, 207);
                    myMsg.ShowDialog();
                }
                else
                {
                    after = this.labelBalanceWeight.Text = myKeyPad.StringValue;

                    value = Helper.StringZeroFillDigits7(this.labelBalanceWeight.Text.Replace(".", ""));
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.BalanceWeight, value);

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

        private void buttonZero_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferData(CommunicationCommand.Zero, CommunicationID.SubBoard1);
        }
        private void buttonStart_Click(object sender, EventArgs e)
        {
            this.listBoxHelp.ClearAll();
            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.listBoxHelp.AddItem("Calibration start");
                this.listBoxHelp.AddItem("Wait a minute.");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.listBoxHelp.AddItem("校准开始按钮");
                this.listBoxHelp.AddItem("请等待");
            }      
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.listBoxHelp.AddItem("Начало калибровки");
                this.listBoxHelp.AddItem("Подождите");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.listBoxHelp.AddItem("Kalibrierungsstart");
                this.listBoxHelp.AddItem("bitte warten");
            }
            else
            {
                this.listBoxHelp.AddItem("중량조정을 시작합니다");
                this.listBoxHelp.AddItem("잠시만 기다리세요");
            }

            this.ParentForm.ParentForm.TransferData(CommunicationCommand.CalibrationStart, CommunicationID.SubBoard1);

            this.CalibrationButtonEnable(false, false, false);
        }
        private void buttonBalance_Click(object sender, EventArgs e)
        {
            this.listBoxHelp.ClearAll();
            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.listBoxHelp.AddItem("Caculating...");
                this.listBoxHelp.AddItem("Wait a minute.");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.listBoxHelp.AddItem("测量砝码中");
                this.listBoxHelp.AddItem("请等待");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {

            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.listBoxHelp.AddItem("Имерение…");
                this.listBoxHelp.AddItem("Ожидайте");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.listBoxHelp.AddItem("Rechnen...");
                this.listBoxHelp.AddItem("bitte warten.");
            }
            else
            {
                this.listBoxHelp.AddItem("분동 계산중 입니다");
                this.listBoxHelp.AddItem("잠시만 기다리세요");
            }

            this.ParentForm.ParentForm.TransferData(CommunicationCommand.CalibrationBalance, CommunicationID.SubBoard1);
            this.CalibrationButtonEnable(false, false, true);
        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.listBoxHelp.ClearAll();
            if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English)
            {
                this.listBoxHelp.AddItem("Cancel the calibration");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese)
            {
                this.listBoxHelp.AddItem("取消重量调节");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian)
            {
                this.listBoxHelp.AddItem("Отменить калибровку");
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German)
            {
                this.listBoxHelp.AddItem("Brechen Sie die Kalibrierung ab");
            }
            else
            {
                this.listBoxHelp.AddItem("중량조정을 취소합니다");
            }

            this.ParentForm.ParentForm.TransferData(CommunicationCommand.CalibrationCancel, CommunicationID.SubBoard1);
            this.CalibrationButtonEnable(true, false, false);
        }

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

            //this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.ParameterRead3901, "");
            this.ParentForm.ParentForm.OpenSmartFileIO();

            before = this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces.ToString();

            if (this.ParentForm.ParentForm.SystemConfig2.IsUsingRandomMode == true)
            {
                int currentDecimalPlaces = this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces;
                bool radioButtonCompare = false;

                if (this.radioButtonDecimalPlaces1.Checked == true)
                {
                    if (currentDecimalPlaces != 1)
                        radioButtonCompare = true;
                }
                else if (this.radioButtonDecimalPlaces2.Checked == true)
                {
                    if (currentDecimalPlaces != 2)
                        radioButtonCompare = true;
                }

                if (radioButtonCompare == true)
                {
                    DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 24);
                    if (myDlg.ShowDialog() == DialogResult.Yes)
                    {
                        if (this.radioButtonDecimalPlaces1.Checked == true)
                        {
                            this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces = 1;
                        }
                        else if (this.radioButtonDecimalPlaces2.Checked == true)
                        {
                            this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces = 2;
                        }

                        this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
                        this.UpdateCalibrationItemDisplay(this.ParentForm.ParentForm.CurrentSystemStatus.Equipment, this.ParentForm.ParentForm.CurrentCalibrationItem);
                    }
                }
            }
            else
            {
                if (this.radioButtonDecimalPlaces1.Checked == true)
                {
                    this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces = 1;
                }
                else if (this.radioButtonDecimalPlaces2.Checked == true)
                {
                    this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces = 2;
                }

                this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
                this.UpdateCalibrationItemDisplay(this.ParentForm.ParentForm.CurrentSystemStatus.Equipment, this.ParentForm.ParentForm.CurrentCalibrationItem);
            }

            this.ParentForm.ParentForm.CloseSmartFileIO();
            value = Helper.StringZeroFillDigits4(this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces.ToString());
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress.DecimalPlaces, value);

            this.ParentForm.ParentForm.ReLoadProductFile();

            after = this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces.ToString();

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