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_6CH.Controls;
using INT63DC_6CH.DialogForms;
using INT63DC_ImageDll;

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

        private ControlCalibration6 Calibration6;
        private ControlCalibration7 Calibration7;
        private ControlCalibration8 Calibration8;
        private ControlCalibration10 Calibration10;
        private ControlCalibration12 Calibration12;
        #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.LanguageID.Korean:
                    break;
                case DataStore.LanguageID.English:
                    #region English
                    this.labelTitle.Text = "Calibration";
                    this.buttonStart.Text = "Start";
                    this.buttonBalance.Text = "Balance";
                    this.buttonCancel.Text = "Cancel";
                    this.groupBoxHelp.Text = "Help";

                    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.LanguageID.Chinese:
                    #region Chinese
                    this.labelTitle.Text = "校准";
                    this.buttonStart.Text = "开启";
                    this.buttonBalance.Text = "分銅";
                    this.buttonCancel.Text = "取消";
                    this.groupBoxHelp.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.LanguageID.Czech:
                    #region Czech
                    this.labelTitle.Text = "Kalibrace";
                    this.buttonStart.Text = "Start";
                    this.buttonBalance.Text = "Váha";
                    this.buttonCancel.Text = "Zrušit";
                    this.groupBoxHelp.Text = "Pomoc";

                    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.LanguageID.German:
                    #region German
                    this.labelTitle.Text = "Kalibrierung";
                    this.buttonStart.Text = "Start";
                    this.buttonBalance.Text = "Gegengewicht";
                    this.buttonCancel.Text = "Stornieren";
                    this.groupBoxHelp.Text = "Hilfe";

                    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.LanguageID.Japanese:
                    #region Japanese
                    this.labelTitle.Text = "校正";
                    this.buttonStart.Text = "スタㅡト";
                    this.buttonBalance.Text = "バランス";
                    this.buttonCancel.Text = "キャンセル";
                    this.groupBoxHelp.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()
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                default:
                    break;
            }

            this.UpdateDisplayHelpInit();
        }

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

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정");
                    this.listBoxHelp.Items.Add("LANE을 선택 후");
                    this.listBoxHelp.Items.Add("시작을 누르세요");
                    break;
                case DataStore.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.LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("校准");
                    this.listBoxHelp.Items.Add("选择线后，按[开始]按钮。");
                    break;
                case DataStore.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.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.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.LanguageID.Korean:
                    this.listBoxHelp.Items.Add("분동 계산중 입니다");
                    this.listBoxHelp.Items.Add("잠시만 기다리세요");
                    break;
                case DataStore.LanguageID.English:
                    this.listBoxHelp.Items.Add("Caculating...");
                    this.listBoxHelp.Items.Add("Wait a minute.");
                    break;
                case DataStore.LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("计算...");
                    this.listBoxHelp.Items.Add("请稍等");
                    break;
                case DataStore.LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Kontroluji hmotnost...");
                    this.listBoxHelp.Items.Add("čekejte prosím.");
                    break;
                case DataStore.LanguageID.German:
                    this.listBoxHelp.Items.Add("Gewichtsüberprüfung,");
                    this.listBoxHelp.Items.Add("bitte warten");
                    break;
                case DataStore.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.LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정을 시작합니다.");
                    this.listBoxHelp.Items.Add("잠시만 기다리세요.");
                    break;
                case DataStore.LanguageID.English:
                    this.listBoxHelp.Items.Add("Calibration start.");
                    this.listBoxHelp.Items.Add("Wait a minute.");
                    break;
                case DataStore.LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("校准开始按钮");
                    this.listBoxHelp.Items.Add("请稍等");
                    break;
                case DataStore.LanguageID.Czech:
                    this.listBoxHelp.Items.Add("START kalibrace");
                    this.listBoxHelp.Items.Add("čekejte prosím.");
                    break;
                case DataStore.LanguageID.German:
                    this.listBoxHelp.Items.Add("Kalibrierungsstart");
                    this.listBoxHelp.Items.Add("bitte warten");
                    break;
                case DataStore.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.LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정을 취소합니다");
                    break;
                case DataStore.LanguageID.English:
                    this.listBoxHelp.Items.Add("Cancel the Calibration");
                    break;
                case DataStore.LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("取消校准");
                    break;
                case DataStore.LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Zrušení Kalibrace");
                    break;
                case DataStore.LanguageID.German:
                    this.listBoxHelp.Items.Add("Brechen Sie die ");
                    this.listBoxHelp.Items.Add("Kalibrierung ab");
                    break;
                case DataStore.LanguageID.Japanese:
                    this.listBoxHelp.Items.Add("校正をキャンセルする");
                    break;
                default:
                    break;
            }
        }
        public void UpdateDisplayHelpCalStandby()
        {
            this.listBoxHelp.Items.Clear();

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

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

            switch (this.ParentForm.SystemConfig.Language)
            {
                case DataStore.LanguageID.Korean:
                    this.listBoxHelp.Items.Add("중량조정 에러");
                    this.listBoxHelp.Items.Add("다시 시도해 주세요");
                    break;
                case DataStore.LanguageID.English:
                    this.listBoxHelp.Items.Add("Calibration error.");
                    this.listBoxHelp.Items.Add("Please try again.");
                    break;
                case DataStore.LanguageID.Chinese:
                    this.listBoxHelp.Items.Add("错误发生，重试");
                    break;
                case DataStore.LanguageID.Czech:
                    this.listBoxHelp.Items.Add("Kalibrace chyba.");
                    this.listBoxHelp.Items.Add("Zkuste znovu.");
                    break;
                case DataStore.LanguageID.German:
                    this.listBoxHelp.Items.Add("Fehler!");
                    this.listBoxHelp.Items.Add("Bitte noch einmal versuchen");
                    break;
                case DataStore.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 UpdateWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                default:
                    break;
            }
        }

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

            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                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 buttonStart_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                default:
                    break;
            }
        }
        private void buttonBalance_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                default:
                    break;
            }
        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                default:
                    break;
            }
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            switch (this.ParentForm.SystemConfig.EquipmentColumns)
            {
                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;
                default:
                    break;
            }

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