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 ITC81DB_2.Forms;
using ITC81DB_2_ImageDll;

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

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

            this.ParentForm = parent;

            this.InitializeDesign();
        }
        #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 == Define.E_LanguageID.English)
            {
                this.buttonOver1.DownImage = this.buttonOver2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engLightOverDown));
                this.buttonOver1.UpImage = this.buttonOver2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engLightOverUp));
                this.buttonPass1.DownImage = this.buttonPass2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engLightPassDown));
                this.buttonPass1.UpImage = this.buttonPass2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engLightPassUp));
                this.buttonUnder1.DownImage = this.buttonUnder2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engLightUnderDown));
                this.buttonUnder1.UpImage = this.buttonUnder2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engLightUnderUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
                this.buttonOver1.DownImage = this.buttonOver2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnLightOverDown));
                this.buttonOver1.UpImage = this.buttonOver2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnLightOverUp));
                this.buttonPass1.DownImage = this.buttonPass2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnLightPassDown));
                this.buttonPass1.UpImage = this.buttonPass2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnLightPassUp));
                this.buttonUnder1.DownImage = this.buttonUnder2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnLightUnderDown));
                this.buttonUnder1.UpImage = this.buttonUnder2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnLightUnderUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
                this.buttonOver1.DownImage = this.buttonOver2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnLightOverDown));
                this.buttonOver1.UpImage = this.buttonOver2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnLightOverUp));
                this.buttonPass1.DownImage = this.buttonPass2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnLightPassDown));
                this.buttonPass1.UpImage = this.buttonPass2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnLightPassUp));
                this.buttonUnder1.DownImage = this.buttonUnder2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnLightUnderDown));
                this.buttonUnder1.UpImage = this.buttonUnder2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.spnLightUnderUp));
            }
            else
            {
                this.buttonOver1.DownImage = this.buttonOver2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korLightOverDown));
                this.buttonOver1.UpImage = this.buttonOver2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korLightOverUp));
                this.buttonPass1.DownImage = this.buttonPass2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korLightPassDown));
                this.buttonPass1.UpImage = this.buttonPass2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korLightPassUp));
                this.buttonUnder1.DownImage = this.buttonUnder2.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.korLightUnderDown));
                this.buttonUnder1.UpImage = this.buttonUnder2.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.korLightUnderUp));
            }
        }

        public void UpdateDisplay()
        {

        }
        public void UpdateEquipmentStatusDisplay(Define.E_EquipmentStatus status)
        {
            if (status == Define.E_EquipmentStatus.Start)
            {
                this.labelWeight1.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelWeight2.Text = Helper.StringToDecimalPlaces("0", this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            }
            else
            {
                this.pictureBoxIconGap1.Visible = false;
                this.pictureBoxIconGap2.Visible = false;
                this.pictureBoxIconMetal1.Visible = false;
                this.pictureBoxIconMetal2.Visible = false;

                this.buttonUnder1.ButtonUp();
                this.buttonUnder2.ButtonUp();
                this.buttonPass1.ButtonUp();
                this.buttonPass2.ButtonUp();
                this.buttonOver1.ButtonUp();
                this.buttonOver2.ButtonUp();
            }
        }
        public void UpdateStopWeightDisplay(Define.E_EquipmentStatus status, WeightData data1, WeightData data2)
        {
            this.UpdateDisplayStopWeight1(status, data1);
            this.UpdateDisplayStopWeight2(status, data2);
        }
        private void UpdateDisplayStopWeight1(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            // 영점 아이콘표시
            if (data.Status == Define.E_WeightStatus.WeightZero)
                this.pictureBoxIconZero1.Visible = true;
            else
                this.pictureBoxIconZero1.Visible = false;

            if (status == Define.E_EquipmentStatus.Stop)
            {
                // 중량
                value = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeight1.Text != value)
                    this.labelWeight1.Text = value;
            }
        }
        private void UpdateDisplayStopWeight2(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            // 영점 아이콘표시
            if (data.Status == Define.E_WeightStatus.WeightZero)
                this.pictureBoxIconZero2.Visible = true;
            else
                this.pictureBoxIconZero2.Visible = false;

            if (status == Define.E_EquipmentStatus.Stop)
            {
                // 중량
                value = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                if (this.labelWeight2.Text != value)
                    this.labelWeight2.Text = value;
            }
        }
        private void UpdateDisplayJudgmentIcon1(Define.E_JudgmentStatus status)
        {
            if (status == Define.E_JudgmentStatus.Under)
            {
                this.buttonUnder1.ButtonDown();
                this.buttonPass1.ButtonUp();
                this.buttonOver1.ButtonUp();
            }
            else if (status == Define.E_JudgmentStatus.Pass)
            {
                this.buttonUnder1.ButtonUp();
                this.buttonPass1.ButtonDown();
                this.buttonOver1.ButtonUp();
            }
            else if (status == Define.E_JudgmentStatus.Over)
            {
                this.buttonUnder1.ButtonUp();
                this.buttonPass1.ButtonUp();
                this.buttonOver1.ButtonDown();
            }
            else
            {
                this.buttonUnder1.ButtonUp();
                this.buttonPass1.ButtonUp();
                this.buttonOver1.ButtonUp();
            }
        }
        private void UpdateDisplayJudgmentIcon2(Define.E_JudgmentStatus status)
        {
            if (status == Define.E_JudgmentStatus.Under)
            {
                this.buttonUnder2.ButtonDown();
                this.buttonPass2.ButtonUp();
                this.buttonOver2.ButtonUp();
            }
            else if (status == Define.E_JudgmentStatus.Pass)
            {
                this.buttonUnder2.ButtonUp();
                this.buttonPass2.ButtonDown();
                this.buttonOver2.ButtonUp();
            }
            else if (status == Define.E_JudgmentStatus.Over)
            {
                this.buttonUnder2.ButtonUp();
                this.buttonPass2.ButtonUp();
                this.buttonOver2.ButtonDown();
            }
            else
            {
                this.buttonUnder2.ButtonUp();
                this.buttonPass2.ButtonUp();
                this.buttonOver2.ButtonUp();
            }
        }
        private void UpdateDisplayIconNET1(ProductItem item)
        {
            double dValue = 0.0;

            dValue = Helper.StringToWeight(item.TareRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (dValue != 0.0)
                this.labelIconNET1.Visible = true;
            else
                this.labelIconNET1.Visible = false;
        }
        private void UpdateDisplayIconNET2(ProductItem item)
        {
            double dValue = 0.0;

            dValue = Helper.StringToWeight(item.TareRange, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (dValue != 0.0)
                this.labelIconNET2.Visible = true;
            else
                this.labelIconNET2.Visible = false;
        }
        public void UpdateCurrentProductDisplay(Define.E_EquipmentStatus status, ProductItem pItem1, ProductItem pItem2, WeightData wData1, WeightData wData2)
        {
            this.UpdateDisplayIconNET1(pItem1);
            this.UpdateDisplayIconNET2(pItem2);
        }

        public void UpdateStartWeightDisplay1(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            if (data.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return;

            // 중량
            value = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight1.Text != value)
                this.labelWeight1.Text = value;

            // GAP 아이콘 표시
            if (data.JudgmentStatus == Define.E_JudgmentStatus.Double)
            {
                if (this.pictureBoxIconGap1.Visible != true)
                    this.pictureBoxIconGap1.Visible = true;
            }
            else
                this.pictureBoxIconGap1.Visible = false;

            // Metal 아이콘 표시
            if (data.JudgmentStatus == Define.E_JudgmentStatus.Metal)
            {
                if (this.pictureBoxIconMetal1.Visible != true)
                    this.pictureBoxIconMetal1.Visible = true;
            }
            else
                this.pictureBoxIconMetal1.Visible = false;

            this.UpdateDisplayJudgmentIcon1(data.JudgmentStatus);
        }
        public void UpdateStartWeightDisplay2(Define.E_EquipmentStatus status, WeightData data)
        {
            string value = "";

            if (data.JudgmentStatus == Define.E_JudgmentStatus.Empty)
                return;

            // 중량
            value = Helper.DoubleToString(data.Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
            if (this.labelWeight2.Text != value)
                this.labelWeight2.Text = value;

            // GAP 아이콘 표시
            if (data.JudgmentStatus == Define.E_JudgmentStatus.Double)
            {
                if (this.pictureBoxIconGap2.Visible != true)
                    this.pictureBoxIconGap2.Visible = true;
            }
            else
                this.pictureBoxIconGap2.Visible = false;

            // Metal 아이콘 표시
            if (data.JudgmentStatus == Define.E_JudgmentStatus.Metal)
            {
                if (this.pictureBoxIconMetal2.Visible != true)
                    this.pictureBoxIconMetal2.Visible = true;
            }
            else
                this.pictureBoxIconMetal2.Visible = false;

            this.UpdateDisplayJudgmentIcon2(data.JudgmentStatus);
        }

        public void DisplayRefresh(SystemStatus status)
        {
            // NET Icon 표시
            this.UpdateDisplayIconNET1(this.ParentForm.ParentForm.CurrentProductItem1);
            this.UpdateDisplayIconNET2(this.ParentForm.ParentForm.CurrentProductItem2);
        }
        #endregion
    }
}
