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

using SmartX;
using INT69DB_2A.Forms;
using INT69DB_2A_ImageDll;

namespace INT69DB_2A.Controls
{
    public partial class ControlConfiguration : UserControl
    {
        #region Field
        private FormConfiguration m_ParentForm;

        private Collection<SmartLabel> CollectionZeroParameterRangeLabel;
        private Collection<SmartLabel> CollectionZeroParameterTimeLabel;
        private Collection<SmartLabel> CollectionZeroParameterVariateLabel;
        private Collection<SmartLabel> CollectionMaxWeightLabel;
        private Collection<SmartLabel> CollectionBalanceWeightLabel;
        private Collection<SmartLabel> CollectionDigitLabel;
        private Collection<SmartLabel> CollectionFilterLabel;
        #endregion

        #region Constructor
        public ControlConfiguration(FormConfiguration parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.InitializeControl();
            this.DefaultSetting();

        } 
        #endregion

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

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

            if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
            {
                this.tabPage1.Text = "자동영점";
                this.buttonZeroRange.Text = "범위";
                this.buttonZeroTime.Text = "시간";
                this.buttonZeroVariate.Text = "변량";

                this.tabPage2.Text = "중량조정";
                this.buttonBalanceWeight.Text = "분동중량";
                this.buttonMaxWeight.Text = "최대중량";
                this.buttonDigit.Text = "한눈의값";

                this.tabPage3.Text = "판정설정";
                this.buttonFilter.Text = "필터";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
                this.tabPage1.Text = "AutoZero";
                this.buttonZeroRange.Text = "Time";
                this.buttonZeroTime.Text = "Range";
                this.buttonZeroVariate.Text = "Variable";

                this.tabPage2.Text = "Calibration";
                this.buttonBalanceWeight.Text = "Balance";
                this.buttonMaxWeight.Text = "Max";
                this.buttonDigit.Text = "Digit";

                this.tabPage3.Text = "Judgment";
                this.buttonFilter.Text = "Filter";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.tabPage1.Text = "自动零点跟踪";
                this.buttonZeroRange.Text = "时间";
                this.buttonZeroTime.Text = "范围";
                this.buttonZeroVariate.Text = "变化";

                this.tabPage2.Text = "校准";
                this.buttonBalanceWeight.Text = "砝码重量";
                this.buttonMaxWeight.Text = "最大重量";
                this.buttonDigit.Text = "数字";

                this.tabPage3.Text = "判断设置";
                this.buttonFilter.Text = "Filter";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.tabPage1.Text = "自動ゼロ";
                this.buttonZeroRange.Text = "時間";
                this.buttonZeroTime.Text = "範囲";
                this.buttonZeroVariate.Text = "変化";

                this.tabPage2.Text = "キャリブレㅡション";
                this.buttonBalanceWeight.Text = "分銅";
                this.buttonMaxWeight.Text = "最大";
                this.buttonDigit.Text = "目量";

                this.tabPage3.Text = "判定";
                this.buttonFilter.Text = "フィルタㅡ";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
            }
            else
            {

            }
        }
        private void InitializeControl()
        {
        }
        private void DefaultSetting()
        {
            this.CollectionZeroParameterRangeLabel = new Collection<SmartLabel>();
            this.CollectionZeroParameterTimeLabel = new Collection<SmartLabel>();
            this.CollectionZeroParameterVariateLabel = new Collection<SmartLabel>();
            this.CollectionMaxWeightLabel = new Collection<SmartLabel>();
            this.CollectionBalanceWeightLabel = new Collection<SmartLabel>();
            this.CollectionDigitLabel = new Collection<SmartLabel>();
            this.CollectionFilterLabel = new Collection<SmartLabel>();

            this.CollectionZeroParameterRangeLabel.Clear();
            this.CollectionZeroParameterTimeLabel.Clear();
            this.CollectionZeroParameterVariateLabel.Clear();
            this.CollectionMaxWeightLabel.Clear();
            this.CollectionBalanceWeightLabel.Clear();
            this.CollectionDigitLabel.Clear();
            this.CollectionFilterLabel.Clear();

            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange1);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange2);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange3);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange4);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange5);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange6);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange7);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange8);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange9);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange10);

            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime1);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime2);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime3);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime4);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime5);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime6);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime7);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime8);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime9);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime10);

            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate1);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate2);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate3);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate4);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate5);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate6);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate7);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate8);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate9);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate10);

            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight1);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight2);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight3);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight4);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight5);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight6);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight7);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight8);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight9);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight10);

            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight1);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight2);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight3);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight4);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight5);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight6);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight7);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight8);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight9);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight10);

            this.CollectionDigitLabel.Add(this.labelDigit1);
            this.CollectionDigitLabel.Add(this.labelDigit2);
            this.CollectionDigitLabel.Add(this.labelDigit3);
            this.CollectionDigitLabel.Add(this.labelDigit4);
            this.CollectionDigitLabel.Add(this.labelDigit5);
            this.CollectionDigitLabel.Add(this.labelDigit6);
            this.CollectionDigitLabel.Add(this.labelDigit7);
            this.CollectionDigitLabel.Add(this.labelDigit8);
            this.CollectionDigitLabel.Add(this.labelDigit9);
            this.CollectionDigitLabel.Add(this.labelDigit10);

            this.CollectionFilterLabel.Add(this.labelFilter1);
            this.CollectionFilterLabel.Add(this.labelFilter2);
            this.CollectionFilterLabel.Add(this.labelFilter3);
            this.CollectionFilterLabel.Add(this.labelFilter4);
            this.CollectionFilterLabel.Add(this.labelFilter5);
            this.CollectionFilterLabel.Add(this.labelFilter6);
            this.CollectionFilterLabel.Add(this.labelFilter7);
            this.CollectionFilterLabel.Add(this.labelFilter8);
            this.CollectionFilterLabel.Add(this.labelFilter9);
            this.CollectionFilterLabel.Add(this.labelFilter10);

            for (int i = 0; i < 10; i++)
            {
                this.CollectionZeroParameterRangeLabel[i].Text = "";
                this.CollectionZeroParameterTimeLabel[i].Text = "";
                this.CollectionZeroParameterVariateLabel[i].Text = "";
                this.CollectionMaxWeightLabel[i].Text = "";
                this.CollectionBalanceWeightLabel[i].Text = "";
                this.CollectionDigitLabel[i].Text = "";
                this.CollectionFilterLabel[i].Text = "";
            }
        }

        public void UpdateZeroParameterRangeDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
                this.CollectionZeroParameterRangeLabel[i].Text = values[i];
        }
        public void UpdateZeroParameterTimeDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
                this.CollectionZeroParameterTimeLabel[i].Text = values[i];
        }
        public void UpdateZeroParameterVariateDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
            {
                if (values[i].Trim() == "0")
                    this.CollectionZeroParameterVariateLabel[i].Text = "0.05";
                else if (values[i].Trim() == "1")
                    this.CollectionZeroParameterVariateLabel[i].Text = "0.1";
                else if (values[i].Trim() == "2")
                    this.CollectionZeroParameterVariateLabel[i].Text = "0.2";
                else if (values[i].Trim() == "3")
                    this.CollectionZeroParameterVariateLabel[i].Text = "0.5";
                else if (values[i].Trim() == "4")
                    this.CollectionZeroParameterVariateLabel[i].Text = "1";
            }
        }
        public void UpdateBalanceWeightDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
                this.CollectionBalanceWeightLabel[i].Text = values[i];
        }
        public void UpdateMaxWeightDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
                this.CollectionMaxWeightLabel[i].Text = values[i];
        }
        public void UpdateDigitDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
                this.CollectionDigitLabel[i].Text = values[i];
        }
        public void UpdateFilterDisplay(DataStore.EquipmentStatus status, Collection<string> values)
        {
            if (values == null || values.Count == 0)
                return;

            for (int i = 0; i < values.Count; i++)
                this.CollectionFilterLabel[i].Text = values[i];
        }
        #endregion

        #region Event Handler
        private void buttonZeroRange_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._4002_ZeroRange, "");
        }
        private void buttonZeroVariate_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._4003_ZeroVariate, "");
        }
        private void buttonZeroTime_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._4001_ZeroTime, "");
        }
        private void buttonDigit_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3003_Digit, "");
        }
        private void buttonMaxWeight_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3001_MaxWeight, "");
        }
        private void buttonBalanceWeight_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3002_BalanceWeight, "");
        }
        private void buttonFilter_Click(object sender, EventArgs e)
        {
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._5001_Filter, "");
        }
        #endregion
    }
}
