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 INT69DC_7C.Forms;

namespace INT69DC_7C.Controls
{
    public partial class ControlConfiguration1 : UserControl
    {
        #region Field
        private FormMain 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 ControlConfiguration1(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

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

        #region Method
        private void InitializeDesign()
        {
            if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
            {

            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
            }
            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.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange11);
            this.CollectionZeroParameterRangeLabel.Add(this.labelZeroRange12);

            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.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime11);
            this.CollectionZeroParameterTimeLabel.Add(this.labelZeroTime12);

            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.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate11);
            this.CollectionZeroParameterVariateLabel.Add(this.labelZeroVariate12);

            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.CollectionMaxWeightLabel.Add(this.labelMaxWeight11);
            this.CollectionMaxWeightLabel.Add(this.labelMaxWeight12);

            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.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight11);
            this.CollectionBalanceWeightLabel.Add(this.labelBalanceWeight12);

            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.CollectionDigitLabel.Add(this.labelDigit11);
            this.CollectionDigitLabel.Add(this.labelDigit12);

            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);
            this.CollectionFilterLabel.Add(this.labelFilter11);
            this.CollectionFilterLabel.Add(this.labelFilter12);

            for (int i = 0; i < 12; 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 = "";
            }

            for (int i = this.ParentForm.SystemConfig.EquipmentColumns; i < 12; i++)
            {
                this.CollectionZeroParameterRangeLabel[i].Visible = false;
                this.CollectionZeroParameterTimeLabel[i].Visible = false;
                this.CollectionZeroParameterVariateLabel[i].Visible = false;
                this.CollectionMaxWeightLabel[i].Visible = false;
                this.CollectionBalanceWeightLabel[i].Visible = false;
                this.CollectionDigitLabel[i].Visible = false;
                this.CollectionFilterLabel[i].Visible = false;
            }
        }

        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.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._4002_ZeroRange, "");
        }
        private void buttonZeroVariate_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._4003_ZeroVariate, "");
        }
        private void buttonZeroTime_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._4001_ZeroTime, "");
        }
        private void buttonDigit_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3003_Digit, "");
        }
        private void buttonMaxWeight_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3001_MaxWeight, "");
        }
        private void buttonBalanceWeight_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._3002_BalanceWeight, "");
        }
        private void buttonFilter_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.SubBoardAll, CommunicationAddress._5001_Filter, "");
        }
        #endregion
    }
}
