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

using INT63DC_2C.Controls;
using INT63DC_2C.DialogForms;
using INT63DC_ImageDll;

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

        private ControlCalibration2 Calibration2;
        private ControlCalibration3 Calibration3;
        private ControlCalibration4 Calibration4;
        private ControlCalibration5 Calibration5;
        private ControlCalibration6 Calibration6;
        private ControlCalibration7 Calibration7;
        private ControlCalibration8 Calibration8;
        private ControlCalibration10 Calibration10;
        private ControlCalibration12 Calibration12;
        private ControlCalibration15 Calibration15;
        private ControlCalibration16 Calibration16;
        #endregion

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

            this.ParentForm = parent;
        }
        #endregion

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

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

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    break;
                case DataStore.E_LanguageID.English:
                    #region English
                    this.labelTitle.Text = "Calibration";

                    this.buttonStart.Text = "Start";
                    this.buttonBalance.Text = "Balance";
                    this.buttonCancel.Text = "Cancel";

                    this.groupBoxSetting.Text = "Setting";
                    this.groupBoxHelp.Text = "Help";
                    this.labelStaticBalanceWeight.Text = "Balance weight";
                    this.labelStaticMaxWeight.Text = "Max weight";
                    this.labelStaticDigit.Text = "Digit";

                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp));
                    #endregion
                    break;
                case DataStore.E_LanguageID.Chinese:
                    #region Chinese
                    this.labelTitle.Text = "校准";

                    this.buttonStart.Text = "";
                    this.buttonBalance.Text = "";
                    this.buttonCancel.Text = "";

                    this.groupBoxSetting.Text = "设定";
                    this.groupBoxHelp.Text = "帮助";
                    this.labelStaticBalanceWeight.Text = "砝码重量";
                    this.labelStaticMaxWeight.Text = "最大重量";
                    this.labelStaticDigit.Text = "数字";

                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp));

                    this.buttonStart.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationStartDisable));
                    this.buttonStart.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationStartDown));
                    this.buttonStart.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationStartUp));
                    this.buttonBalance.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationBalanceDisable));
                    this.buttonBalance.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationBalanceDown));
                    this.buttonBalance.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationBalanceUp));
                    this.buttonCancel.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationCancelDisable));
                    this.buttonCancel.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationCancelDown));
                    this.buttonCancel.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnFormCalibrationCancelUp));
                    #endregion
                    break;
                case DataStore.E_LanguageID.Czech:
                    #region Czech
                    this.labelTitle.Text = "Kalibrace";

                    this.buttonStart.Text = "Start";
                    this.buttonBalance.Text = "Váha";
                    this.buttonCancel.Text = "Zrušit";

                    this.groupBoxSetting.Text = "Seřízení";
                    this.groupBoxHelp.Text = "Pomoc";
                    this.labelStaticBalanceWeight.Text = "Vyvažovací závaží";
                    this.labelStaticMaxWeight.Text = "Max. hmotnost";
                    this.labelStaticDigit.Text = "Číslice";

                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp));
                    #endregion
                    break;
                case DataStore.E_LanguageID.German:
                    #region German
                    this.labelTitle.Text = "Kalibrierung";

                    this.buttonStart.Text = "Start";
                    this.buttonBalance.Text = "Gegengewicht";
                    this.buttonCancel.Text = "Stornieren";

                    this.groupBoxSetting.Text = "Einstellung";
                    this.groupBoxHelp.Text = "Hilfe";
                    this.labelStaticBalanceWeight.Text = "Gewicht der Waage";
                    this.labelStaticMaxWeight.Text = "Maximalgewicht";
                    this.labelStaticDigit.Text = "Nummer";

                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp));
                    #endregion
                    break;
                case DataStore.E_LanguageID.Japanese:
                    #region Japanese
                    this.labelTitle.Text = "キャリブレㅡション";

                    this.buttonStart.Text = "スタㅡト";
                    this.buttonBalance.Text = "バランス";
                    this.buttonCancel.Text = "キャンセル";

                    this.groupBoxSetting.Text = "設定";
                    this.groupBoxHelp.Text = "ヘルプ";
                    this.labelStaticBalanceWeight.Text = "バランス重量";
                    this.labelStaticMaxWeight.Text = "最大重量";
                    this.labelStaticDigit.Text = "目量";

                    this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDisable));
                    this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDown));
                    this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackUp));
                    #endregion
                    break;
                default:
                    break;
            }
        }
        private void InitializeControl()
        {
            this.labelBalanceWeight.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);
            this.labelMaxWeight.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.SystemConfig.DecimalPlaces);

            this.comboBoxDigit.Items.Clear();
            this.comboBoxDigit.Items.Add("1");
            this.comboBoxDigit.Items.Add("2");
            this.comboBoxDigit.Items.Add("5");

            this.comboBoxDigit.SelectedIndexChanged -= new EventHandler(this.comboBoxDigit_SelectedIndexChanged);
            this.comboBoxDigit.SelectedItem = "1";
            this.comboBoxDigit.SelectedIndexChanged += new EventHandler(this.comboBoxDigit_SelectedIndexChanged);

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2 = new ControlCalibration2(this);
                    this.Calibration2.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration2);
                    break;
                case 3:
                    this.Calibration3 = new ControlCalibration3(this);
                    this.Calibration3.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration3);
                    break;
                case 4:
                    this.Calibration4 = new ControlCalibration4(this);
                    this.Calibration4.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration4);
                    break;
                case 5:
                    this.Calibration5 = new ControlCalibration5(this);
                    this.Calibration5.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration5);
                    break;
                case 6:
                    this.Calibration6 = new ControlCalibration6(this);
                    this.Calibration6.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration6);
                    break;
                case 7:
                    this.Calibration7 = new ControlCalibration7(this);
                    this.Calibration7.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration7);
                    break;
                case 8:
                    this.Calibration8 = new ControlCalibration8(this);
                    this.Calibration8.Location = new Point(0, 80);
                    this.Controls.Add(this.Calibration8);
                    break;
                case 10:
                    this.Calibration10 = new ControlCalibration10(this);
                    this.Calibration10.Location = new Point(0, 70);
                    this.Controls.Add(this.Calibration10);
                    break;
                case 12:
                    this.Calibration12 = new ControlCalibration12(this);
                    this.Calibration12.Location = new Point(0, 70);
                    this.Controls.Add(this.Calibration12);
                    break;
                case 15:
                    this.Calibration15 = new ControlCalibration15(this);
                    this.Calibration15.Location = new Point(0, 70);
                    this.Controls.Add(this.Calibration15);
                    break;
                case 16:
                    this.Calibration16 = new ControlCalibration16(this);
                    this.Calibration16.Location = new Point(0, 70);
                    this.Controls.Add(this.Calibration16);
                    break;
                default:
                    break;
            }

            this.UpdateDisplayHelpInit();
        }

        public void UpdateDisplayHelpInit()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정");
                    this.listBoxHelp.Items.Add("LANE을 선택 후");
                    this.listBoxHelp.Items.Add("시작을 누르세요");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Calibration");
                    this.listBoxHelp.Items.Add("After selecting lane, ");
                    this.listBoxHelp.Items.Add("push the [Start] button.");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("校准");
                    this.listBoxHelp.Items.Add("选择线后，按[开始]按钮。");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Kalibrace");
                    this.listBoxHelp.Items.Add("Po výběru řádku, ");
                    this.listBoxHelp.Items.Add("stiskněte tlačítko [Start].");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Kalibrierung");
                    this.listBoxHelp.Items.Add("Drücken Sie nach der Auswahl der");
                    this.listBoxHelp.Items.Add("Zeile die Taste [Start].");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("キャリブレㅡション");
                    this.listBoxHelp.Items.Add("レㅡンを選択したら、");
                    this.listBoxHelp.Items.Add("［スタㅡト］ボタンを押します。");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpBalance()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("분동 계산중 입니다");
                    this.listBoxHelp.Items.Add("잠시만 기다리세요");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Caculating...");
                    this.listBoxHelp.Items.Add("Wait a minute.");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("计算...");
                    this.listBoxHelp.Items.Add("请稍等");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Kontroluji hmotnost...");
                    this.listBoxHelp.Items.Add("čekejte prosím.");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Gewichtsüberprüfung,");
                    this.listBoxHelp.Items.Add("bitte warten");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("重量をチェック。");
                    this.listBoxHelp.Items.Add("待機する");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpStart()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정을 시작합니다.");
                    this.listBoxHelp.Items.Add("잠시만 기다리세요.");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Calibration start.");
                    this.listBoxHelp.Items.Add("Wait a minute.");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("校准开始按钮");
                    this.listBoxHelp.Items.Add("请稍等");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("START kalibrace");
                    this.listBoxHelp.Items.Add("čekejte prosím.");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Kalibrierungsstart");
                    this.listBoxHelp.Items.Add("bitte warten");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("キャリブレㅡション開始");
                    this.listBoxHelp.Items.Add("待機する");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpCancel()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정을 취소합니다");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Cancel the Calibration");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("取消校准");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Zrušení Kalibrace");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Brechen Sie die ");
                    this.listBoxHelp.Items.Add("Kalibrierung ab");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("キャリブレㅡションをキャンセルする");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpCalStandby()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("분동을 올려주세요.");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Put the balance weight.");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("放平衡重");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Položit vyvážení hmotnosti.");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Gewicht auf den Förderer legen");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("バランスウェイトを置く。");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpCalFinish()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정이 완료 되었습니다.");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Finished.");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("完");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Ukončený.");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Die Kalibrierung ist abgeschlossen.");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("キャリブレㅡション終了");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpCalError()
        {
            this.listBoxHelp.Items.Clear();

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.E_LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정 에러");
                    this.listBoxHelp.Items.Add("다시 시도해 주세요");
                    break;
                case DataStore.E_LanguageID.English:
                    this.listBoxHelp.Items.Add("Calibration error.");
                    this.listBoxHelp.Items.Add("Please try again.");
                    break;
                case DataStore.E_LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("错误发生，重试");
                    break;
                case DataStore.E_LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Kalibrace chyba.");
                    this.listBoxHelp.Items.Add("Zkuste znovu.");
                    break;
                case DataStore.E_LanguageID.German:
                    this.listBoxHelp.Items.Add("Fehler!");
                    this.listBoxHelp.Items.Add("Bitte noch einmal versuchen");
                    break;
                case DataStore.E_LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("キャリブレㅡションエラㅡ");
                    this.listBoxHelp.Items.Add("もうㅡ度試してください");
                    break;
                default:
                    break;
            }
        }

        public void CalibrationButtonEnable(bool btStart, bool btBalance, bool btCcancel)
        {
            if (this.buttonStart.Enabled != btStart)
                this.buttonStart.Enabled = btStart;
            if (this.buttonBalance.Enabled != btBalance)
                this.buttonBalance.Enabled = btBalance;
            if (this.buttonCancel.Enabled != btCcancel)
                this.buttonCancel.Enabled = btCcancel;
        }

        public void UpdateCalibrationItemDisplay(DataStore.EquipmentStatus status, CalibrationItem config)
        {
            string value = "";

            value = Helper.CommunicationWeightValueToString(config.BalanceWeight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelBalanceWeight.Text != value)
                this.labelBalanceWeight.Text = value;

            value = Helper.CommunicationWeightValueToString(config.MaxWeight, this.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelMaxWeight.Text != value)
                this.labelMaxWeight.Text = value;

            value = config.Digit.Trim();
            if (this.comboBoxDigit.SelectedItem != value)
            {
                this.comboBoxDigit.SelectedIndexChanged -= new EventHandler(this.comboBoxDigit_SelectedIndexChanged);
                this.comboBoxDigit.SelectedItem = value;
                this.comboBoxDigit.SelectedIndexChanged += new EventHandler(this.comboBoxDigit_SelectedIndexChanged);
            }

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2.UpdateConfiguration(status, config);
                    break;
                case 3:
                    this.Calibration3.UpdateConfiguration(status, config);
                    break;
                case 4:
                    this.Calibration4.UpdateConfiguration(status, config);
                    break;
                case 5:
                    this.Calibration5.UpdateConfiguration(status, config);
                    break;
                case 6:
                    this.Calibration6.UpdateConfiguration(status, config);
                    break;
                case 7:
                    this.Calibration7.UpdateConfiguration(status, config);
                    break;
                case 8:
                    this.Calibration8.UpdateConfiguration(status, config);
                    break;
                case 10:
                    this.Calibration10.UpdateConfiguration(status, config);
                    break;
                case 12:
                    this.Calibration12.UpdateConfiguration(status, config);
                    break;
                case 15:
                    this.Calibration15.UpdateConfiguration(status, config);
                    break;
                case 16:
                    this.Calibration16.UpdateConfiguration(status, config);
                    break;
                default:
                    break;
            }
        }
        public void UpdateWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 3:
                    this.Calibration3.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 4:
                    this.Calibration4.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 5:
                    this.Calibration5.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 6:
                    this.Calibration6.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 7:
                    this.Calibration7.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 8:
                    this.Calibration8.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 10:
                    this.Calibration10.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 12:
                    this.Calibration12.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 15:
                    this.Calibration15.UpdateWeightDisplay(status, weightDatas);
                    break;
                case 16:
                    this.Calibration16.UpdateWeightDisplay(status, weightDatas);
                    break;
                default:
                    break;
            }
        }

        public void DisplayRefresh()
        {
            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormCalibration;
            this.ParentForm.TransferData(CommunicationCommand.ModeCalibration, CommunicationID.MainBoard);
            this.timer.Enabled = true;

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    if (this.Calibration2 != null)
                        this.Calibration2.DisplayRefresh();
                    break;
                case 3:
                    if (this.Calibration3 != null)
                        this.Calibration3.DisplayRefresh();
                    break;
                case 4:
                    if (this.Calibration4 != null)
                        this.Calibration4.DisplayRefresh();
                    break;
                case 5:
                    if (this.Calibration5 != null)
                        this.Calibration5.DisplayRefresh();
                    break;
                case 6:
                    if (this.Calibration6 != null)
                        this.Calibration6.DisplayRefresh();
                    break;
                case 7:
                    if (this.Calibration7 != null)
                        this.Calibration7.DisplayRefresh();
                    break;
                case 8:
                    if (this.Calibration8 != null)
                        this.Calibration8.DisplayRefresh();
                    break;
                case 10:
                    if (this.Calibration10 != null)
                        this.Calibration10.DisplayRefresh();
                    break;
                case 12:
                    if (this.Calibration12 != null)
                        this.Calibration12.DisplayRefresh();
                    break;
                case 15:
                    if (this.Calibration15 != null)
                        this.Calibration15.DisplayRefresh();
                    break;
                case 16:
                    if (this.Calibration16 != null)
                        this.Calibration16.DisplayRefresh();
                    break;
                default:
                    break;
            }

            this.CalibrationButtonEnable(false, false, false);
            this.UpdateDisplayHelpInit();
        }
        #endregion

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

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

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

            before = this.ParentForm.CurrentCalibrationItem.Digit;

            value = Helper.StringZeroFillDigits4(this.comboBoxDigit.SelectedItem.ToString());
            this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress._3003_Digit, value);

            after = int.Parse(value).ToString();

            // Part 11
            if (this.ParentForm.SystemConfig.IsPart11 == true)
                this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.CalDigit, "", before, after);
        }
        private void labelBalanceWeight_Click(object sender, EventArgs e)
        {
            string value = "", before = "", after = "";

            before = this.labelBalanceWeight.Text;

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

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

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

                    // Part 11
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.CalBalWeight, "", before, after);
                }
            }
        }
        private void labelMaxWeight_Click(object sender, EventArgs e)
        {
            string value = "", before = "", after = "";

            before = this.labelMaxWeight.Text;

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelMaxWeight.Text, 5, this.ParentForm.SystemConfig.DecimalPlaces, false, this.ParentForm.SystemConfig.Language);

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

                    value = Helper.StringZeroFillDigits7(this.labelMaxWeight.Text.Replace(".", ""));
                    this.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.SubBoardAll, CommunicationAddress._3001_MaxWeight, value);

                    // Part 11
                    if (this.ParentForm.SystemConfig.IsPart11 == true)
                        this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.CalMaxWeight, "", before, after);
                }
            }
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2.CalibrationStart();
                    break;
                case 3:
                    this.Calibration3.CalibrationStart();
                    break;
                case 4:
                    this.Calibration4.CalibrationStart();
                    break;
                case 5:
                    this.Calibration5.CalibrationStart();
                    break;
                case 6:
                    this.Calibration6.CalibrationStart();
                    break;
                case 7:
                    this.Calibration7.CalibrationStart();
                    break;
                case 8:
                    this.Calibration8.CalibrationStart();
                    break;
                case 10:
                    this.Calibration10.CalibrationStart();
                    break;
                case 12:
                    this.Calibration12.CalibrationStart();
                    break;
                case 15:
                    this.Calibration15.CalibrationStart();
                    break;
                case 16:
                    this.Calibration16.CalibrationStart();
                    break;
                default:
                    break;
            }
        }
        private void buttonBalance_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2.CalibrationBalance();
                    break;
                case 3:
                    this.Calibration3.CalibrationBalance();
                    break;
                case 4:
                    this.Calibration4.CalibrationBalance();
                    break;
                case 5:
                    this.Calibration5.CalibrationBalance();
                    break;
                case 6:
                    this.Calibration6.CalibrationBalance();
                    break;
                case 7:
                    this.Calibration7.CalibrationBalance();
                    break;
                case 8:
                    this.Calibration8.CalibrationBalance();
                    break;
                case 10:
                    this.Calibration10.CalibrationBalance();
                    break;
                case 12:
                    this.Calibration12.CalibrationBalance();
                    break;
                case 15:
                    this.Calibration15.CalibrationBalance();
                    break;
                case 16:
                    this.Calibration16.CalibrationBalance();
                    break;
                default:
                    break;
            }
        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2.CalibrationCancel();
                    break;
                case 3:
                    this.Calibration3.CalibrationCancel();
                    break;
                case 4:
                    this.Calibration4.CalibrationCancel();
                    break;
                case 5:
                    this.Calibration5.CalibrationCancel();
                    break;
                case 6:
                    this.Calibration6.CalibrationCancel();
                    break;
                case 7:
                    this.Calibration7.CalibrationCancel();
                    break;
                case 8:
                    this.Calibration8.CalibrationCancel();
                    break;
                case 10:
                    this.Calibration10.CalibrationCancel();
                    break;
                case 12:
                    this.Calibration12.CalibrationCancel();
                    break;
                case 15:
                    this.Calibration15.CalibrationCancel();
                    break;
                case 16:
                    this.Calibration16.CalibrationCancel();
                    break;
                default:
                    break;
            }
        }

        private void buttonBack_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 2:
                    this.Calibration2.CalibrationCancel();
                    break;
                case 3:
                    this.Calibration3.CalibrationCancel();
                    break;
                case 4:
                    this.Calibration4.CalibrationCancel();
                    break;
                case 5:
                    this.Calibration5.CalibrationCancel();
                    break;
                case 6:
                    this.Calibration6.CalibrationCancel();
                    break;
                case 7:
                    this.Calibration7.CalibrationCancel();
                    break;
                case 8:
                    this.Calibration8.CalibrationCancel();
                    break;
                case 10:
                    this.Calibration10.CalibrationCancel();
                    break;
                case 12:
                    this.Calibration12.CalibrationCancel();
                    break;
                case 15:
                    this.Calibration15.CalibrationCancel();
                    break;
                case 16:
                    this.Calibration16.CalibrationCancel();
                    break;
                default:
                    break;
            }

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

        private void timer_Tick(object sender, EventArgs e)
        {
            this.timer.Enabled = false;

            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3901_ParameterRead3901, "");
        }
        #endregion
    }
}