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 INT51DB.Forms;
using INT51DB_ImageDll;

namespace INT51DB.Controls
{
    public partial class ControlMainDisplayStatistics : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;
        #endregion

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

            this.ParentForm = parent;

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

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

        #region Method
        public void InitializeDesign()
        {
            Class1 images = new Class1();

            if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
            }
            else
            {
            }
        }
        private void DefaultSetting()
        {

        }

        private void SetProduct(ProductItem item)
        {
            string underValue = "", passValue = "", overValue = "";

            switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentWeightInputMode)
            {
                case DataStore.WeightInputMode.Weight:
                    underValue = Helper.StringToDecimalPlaces(item.UnderRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    passValue = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    overValue = Helper.StringToDecimalPlaces(item.OverRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    break;
                case DataStore.WeightInputMode.Deviation:
                    underValue = Helper.StringToDecimalPlaces(item.UnderRangDeviation.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    passValue = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    overValue = Helper.StringToDecimalPlaces(item.OverRangeDeviation.ToString(), this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    overValue = string.Format("+{0}", overValue);
                    break;
                default:
                    break;
            }

            if (this.labelUnderRange.Text != underValue)
                this.labelUnderRange.Text = underValue;

            if (this.labelPassRange.Text != passValue)
                this.labelPassRange.Text = passValue;

            if (this.labelOverRange.Text != overValue)
                this.labelOverRange.Text = overValue;
        }
        private void SetCount(WeightData data)
        {
            string value = "";

            #region Count
            value = data.UnderCount.ToString();
            if (this.labelUnderCount.Text != value)
                this.labelUnderCount.Text = value;

            value = data.PassCount.ToString();
            if (this.labelPassCount.Text != value)
                this.labelPassCount.Text = value;

            value = data.OverCount.ToString();
            if (this.labelOverCount.Text != value)
                this.labelOverCount.Text = value;

            value = data.TotalNGCount1.ToString();
            if (this.labelNgCount.Text != value)
                this.labelNgCount.Text = value;

            value = data.ExNGCount.ToString();
            if (this.labelExNGCount.Text != value)
                this.labelExNGCount.Text = value;

            value = data.TotalCount.ToString();
            if (this.labelTotalCount.Text != value)
                this.labelTotalCount.Text = value; 
            #endregion

            #region SumWeight
            value = data.UnderSumWeightKG;
            if (this.labelUnderSumWeight.Text != value)
                this.labelUnderSumWeight.Text = value;

            value = data.PassSumWeightKG;
            if (this.labelPassSumWeight.Text != value)
                this.labelPassSumWeight.Text = value;

            value = data.OverSumWeightKG;
            if (this.labelOverSumWeight.Text != value)
                this.labelOverSumWeight.Text = value;
            #endregion

            #region Average
            value = Helper.DoubleToString(data.UnderAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelUnderAverage.Text != value)
                this.labelUnderAverage.Text = value;

            value = Helper.DoubleToString(data.PassAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelPassAverage.Text != value)
                this.labelPassAverage.Text = value;

            value = Helper.DoubleToString(data.OverAverage, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelOverAverage.Text != value)
                this.labelOverAverage.Text = value;
            #endregion
        }
        private void UpdateDisplayUser(SystemStatus status)
        {
            switch (status.CurrentUser.Group)
            {
                case DataStore.UserGroup.LogOff:
                    break;
                case DataStore.UserGroup.Level1Operator:
                    break;
                case DataStore.UserGroup.Level2Engineer:
                    break;
                case DataStore.UserGroup.Level3Manager:
                    break;
                case DataStore.UserGroup.Level4Developer:
                    break;
                default:
                    break;
            }
        }

        public void UpdateEquipmentStatusDisplay(DataStore.EquipmentStatus status)
        {

        }
        public void UpdateCurrentProductDisplay(DataStore.EquipmentStatus status, ProductItem pItem, WeightData wData)
        {
            this.SetProduct(pItem);
            this.SetCount(wData);
        }
        public void UpdateUpdateStartWeightDisplay(DataStore.EquipmentStatus status, WeightData data)
        {
            this.SetCount(this.ParentForm.ParentForm.CurrentWeightData);
        }

        public void Clear()
        {
            this.SetCount(this.ParentForm.ParentForm.CurrentWeightData);
        }
        public void DisplayRefresh(SystemStatus status)
        {
            //this.UpdateDisplayUser(status);

            this.SetProduct(this.ParentForm.ParentForm.CurrentProductItem);
            this.SetCount(this.ParentForm.ParentForm.CurrentWeightData);
        }
        #endregion
    }
}
