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

namespace INT69DC_7C.Controls
{
    public partial class ControlMainDisplayEachBarGraph8 : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;

        private Collection<PictureBox> CollectionPictureBoxZero;
        private Collection<SmartLabel> CollectionLabelWeightValue;
        private Collection<SmartProgressBar> CollectionProgressBar;
        private Collection<PictureBox> CollectionPictureBoxBypass;
        #endregion

        #region Constructor
        public ControlMainDisplayEachBarGraph8(FormMainDisplay parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

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

        #region Method
        private void CreateCollection()
        {
            // PictureBoxZero
            this.CollectionPictureBoxZero = new Collection<PictureBox>();
            this.CollectionPictureBoxZero.Clear();
            this.CollectionPictureBoxZero.Add(this.pictureBox1);
            this.CollectionPictureBoxZero.Add(this.pictureBox2);
            this.CollectionPictureBoxZero.Add(this.pictureBox3);
            this.CollectionPictureBoxZero.Add(this.pictureBox4);
            this.CollectionPictureBoxZero.Add(this.pictureBox5);
            this.CollectionPictureBoxZero.Add(this.pictureBox6);
            this.CollectionPictureBoxZero.Add(this.pictureBox7);
            this.CollectionPictureBoxZero.Add(this.pictureBox8);

            // LabelWeightValue
            this.CollectionLabelWeightValue = new Collection<SmartLabel>();
            this.CollectionLabelWeightValue.Clear();
            this.CollectionLabelWeightValue.Add(this.labelWeightValue1);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue2);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue3);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue4);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue5);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue6);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue7);
            this.CollectionLabelWeightValue.Add(this.labelWeightValue8);

            // ProgressBar
            this.CollectionProgressBar = new Collection<SmartProgressBar>();
            this.CollectionProgressBar.Clear();
            this.CollectionProgressBar.Add(this.progressBar1);
            this.CollectionProgressBar.Add(this.progressBar2);
            this.CollectionProgressBar.Add(this.progressBar3);
            this.CollectionProgressBar.Add(this.progressBar4);
            this.CollectionProgressBar.Add(this.progressBar5);
            this.CollectionProgressBar.Add(this.progressBar6);
            this.CollectionProgressBar.Add(this.progressBar7);
            this.CollectionProgressBar.Add(this.progressBar8);

            // PictureBoxBypass
            this.CollectionPictureBoxBypass = new Collection<PictureBox>();
            this.CollectionPictureBoxBypass.Clear();
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass1);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass2);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass3);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass4);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass5);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass6);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass7);
            this.CollectionPictureBoxBypass.Add(this.pictureBoxBypass8);
        }
        private void InitializeControl()
        {
            foreach (PictureBox picture in this.CollectionPictureBoxZero)
                picture.Visible = false;

            foreach (SmartLabel label in this.CollectionLabelWeightValue)
                label.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);

            foreach (SmartProgressBar bar in this.CollectionProgressBar)
                bar.Value = bar.Minimum;

            foreach (PictureBox picture in this.CollectionPictureBoxBypass)
                picture.Visible = false;

            this.SetCount(this.ParentForm.ParentForm.CollectionWeightData);
        }
        private void SetCount(Collection<WeightData> weightdatas)
        {
            string value = "";

            #region Line 1
            value = weightdatas[0].TotalNGCount.ToString();
            if (this.labelNGCount1.Text != value)
                this.labelNGCount1.Text = value;

            value = weightdatas[0].PassCount.ToString();
            if (this.labelPassCount1.Text != value)
                this.labelPassCount1.Text = value;
            #endregion

            #region Line 2
            value = weightdatas[1].TotalNGCount.ToString();
            if (this.labelNGCount2.Text != value)
                this.labelNGCount2.Text = value;

            value = weightdatas[1].PassCount.ToString();
            if (this.labelPassCount2.Text != value)
                this.labelPassCount2.Text = value;
            #endregion

            #region Line 3
            value = weightdatas[2].TotalNGCount.ToString();
            if (this.labelNGCount3.Text != value)
                this.labelNGCount3.Text = value;

            value = weightdatas[2].PassCount.ToString();
            if (this.labelPassCount3.Text != value)
                this.labelPassCount3.Text = value;
            #endregion

            #region Line 4
            value = weightdatas[3].TotalNGCount.ToString();
            if (this.labelNGCount4.Text != value)
                this.labelNGCount4.Text = value;

            value = weightdatas[3].PassCount.ToString();
            if (this.labelPassCount4.Text != value)
                this.labelPassCount4.Text = value;
            #endregion

            #region Line 5
            value = weightdatas[4].TotalNGCount.ToString();
            if (this.labelNGCount5.Text != value)
                this.labelNGCount5.Text = value;

            value = weightdatas[4].PassCount.ToString();
            if (this.labelPassCount5.Text != value)
                this.labelPassCount5.Text = value;
            #endregion

            #region Line 6
            value = weightdatas[5].TotalNGCount.ToString();
            if (this.labelNGCount6.Text != value)
                this.labelNGCount6.Text = value;

            value = weightdatas[5].PassCount.ToString();
            if (this.labelPassCount6.Text != value)
                this.labelPassCount6.Text = value;
            #endregion

            #region Line 7
            value = weightdatas[6].TotalNGCount.ToString();
            if (this.labelNGCount7.Text != value)
                this.labelNGCount7.Text = value;

            value = weightdatas[6].PassCount.ToString();
            if (this.labelPassCount7.Text != value)
                this.labelPassCount7.Text = value;
            #endregion

            #region Line 8
            value = weightdatas[7].TotalNGCount.ToString();
            if (this.labelNGCount8.Text != value)
                this.labelNGCount8.Text = value;

            value = weightdatas[7].PassCount.ToString();
            if (this.labelPassCount8.Text != value)
                this.labelPassCount8.Text = value;
            #endregion

            this.ParentForm.SetTotalCount();
        }

        public void RescaleControl()
        {
            foreach (SmartProgressBar bar in this.CollectionProgressBar)
            {
                Helper.RescaleProgressBar(bar, this.ParentForm.ParentForm.CurrentProductItem.ProgressBarMaximum, this.ParentForm.ParentForm.CurrentProductItem.ProgressBarMinimum);
                bar.Value = bar.Minimum;
            }
        }
        public void Clear()
        {
            foreach (SmartX.SmartLabel label in this.CollectionLabelWeightValue)
                label.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);

            foreach (SmartX.SmartProgressBar bar in this.CollectionProgressBar)
                bar.Value = bar.Minimum;

            foreach (WeightData data in this.ParentForm.ParentForm.CollectionWeightData)
                data.ClearCount();

            this.SetCount(this.ParentForm.ParentForm.CollectionWeightData);

            this.ParentForm.ParentForm.SaveCounterFile(this.ParentForm.ParentForm.CollectionWeightData, this.ParentForm.ParentForm.SystemConfig.ProductNumber - 1);
        }

        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {
            string temp = "";

            foreach (SmartX.SmartLabel label in this.CollectionLabelWeightValue)
            {
                temp = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (label.Text != temp)
                    label.Text = temp;
            }

            foreach (SmartProgressBar bar in this.CollectionProgressBar)
                bar.Value = bar.Minimum;
        }
        public void UpdateCurrentProductDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            foreach (SmartProgressBar bar in this.CollectionProgressBar)
                bar.Value = bar.Minimum;

            this.SetCount(this.ParentForm.ParentForm.CollectionWeightData);
        }
        public void UpdateBypassDisplay(Collection<WeightData> weightData)
        {
            for (int i = 0; i < this.CollectionPictureBoxBypass.Count; i++)
            {
                if (weightData[i].IsBypassMode == true)
                    this.CollectionPictureBoxBypass[i].Visible = true;
                else
                    this.CollectionPictureBoxBypass[i].Visible = false;
            }
        }
        public void UpdateStopWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            string value = "";

            if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns > weightDatas.Count)
                return;

            if (status == DataStore.EquipmentStatus.Stop)
            {
                for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EquipmentColumns; i++)
                {
                    // 중량
                    value = Helper.DoubleToString(weightDatas[i].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    if (this.CollectionLabelWeightValue[i].Text != value)
                        this.CollectionLabelWeightValue[i].Text = value;

                    // 영점표시
                    if (weightDatas[i].Status == DataStore.WeightStatus.WeightZero)
                        this.CollectionPictureBoxZero[i].Visible = true;
                    else
                        this.CollectionPictureBoxZero[i].Visible = false;
                }
            }
            else
            {
                for (int i = 0; i < this.ParentForm.ParentForm.SystemConfig.EquipmentColumns; i++)
                {
                    // 영점표시
                    if (weightDatas[i].Status == DataStore.WeightStatus.WeightZero)
                        this.CollectionPictureBoxZero[i].Visible = true;
                    else
                        this.CollectionPictureBoxZero[i].Visible = false;
                }
            }
        }
        public void UpdateStartWeightDisplay(DataStore.EquipmentStatus status, Collection<WeightData> weightDatas)
        {
            this.UpdateStartWeightDisplay1(status, weightDatas[0]);
            this.UpdateStartWeightDisplay2(status, weightDatas[1]);
            this.UpdateStartWeightDisplay3(status, weightDatas[2]);
            this.UpdateStartWeightDisplay4(status, weightDatas[3]);
            this.UpdateStartWeightDisplay5(status, weightDatas[4]);
            this.UpdateStartWeightDisplay6(status, weightDatas[5]);
            this.UpdateStartWeightDisplay7(status, weightDatas[6]);
            this.UpdateStartWeightDisplay8(status, weightDatas[7]);
        }
        public void UpdateStartWeightDisplay1(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue1.Text != value)
                this.labelWeightValue1.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount1.Text != value)
                this.labelPassCount1.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount1.Text != value)
                this.labelNGCount1.Text = value;

            Helper.SetProgressBarValue(this.progressBar1, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay2(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue2.Text != value)
                this.labelWeightValue2.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount2.Text != value)
                this.labelPassCount2.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount2.Text != value)
                this.labelNGCount2.Text = value;

            Helper.SetProgressBarValue(this.progressBar2, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay3(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue3.Text != value)
                this.labelWeightValue3.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount3.Text != value)
                this.labelPassCount3.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount3.Text != value)
                this.labelNGCount3.Text = value;

            Helper.SetProgressBarValue(this.progressBar3, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay4(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue4.Text != value)
                this.labelWeightValue4.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount4.Text != value)
                this.labelPassCount4.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount4.Text != value)
                this.labelNGCount4.Text = value;

            Helper.SetProgressBarValue(this.progressBar4, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay5(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue5.Text != value)
                this.labelWeightValue5.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount5.Text != value)
                this.labelPassCount5.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount5.Text != value)
                this.labelNGCount5.Text = value;

            Helper.SetProgressBarValue(this.progressBar5, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay6(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue6.Text != value)
                this.labelWeightValue6.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount6.Text != value)
                this.labelPassCount6.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount6.Text != value)
                this.labelNGCount6.Text = value;

            Helper.SetProgressBarValue(this.progressBar6, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay7(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue7.Text != value)
                this.labelWeightValue7.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount7.Text != value)
                this.labelPassCount7.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount7.Text != value)
                this.labelNGCount7.Text = value;

            Helper.SetProgressBarValue(this.progressBar7, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        public void UpdateStartWeightDisplay8(DataStore.EquipmentStatus status, WeightData weightData)
        {
            string value = "";

            if (weightData.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return;

            value = Helper.DoubleToString(weightData.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeightValue8.Text != value)
                this.labelWeightValue8.Text = value;

            value = weightData.PassCount.ToString();
            if (this.labelPassCount8.Text != value)
                this.labelPassCount8.Text = value;

            value = weightData.TotalNGCount.ToString();
            if (this.labelNGCount8.Text != value)
                this.labelNGCount8.Text = value;

            Helper.SetProgressBarValue(this.progressBar8, weightData.Weight, weightData.JudgmentStatus, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
        }
        #endregion
    }
}
