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 INT99DC_7C.Forms;
using INT99DC_7C.Int_Modbus;

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

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

            this.ParentForm = parent;
           
            this.Initialize();
            this.DefaultSetting();
        }
        #endregion

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

        #region Method
        private void Initialize()
        {
            this.labelValue13_1.Text = "0";
            this.labelValue13_2.Text = "0";
            this.labelValue13_3.Text = "0";
            this.labelValue13_4.Text = "0";
            this.labelValue13_5.Text = "0";
            this.labelValue13_6.Text = "0";
            this.labelValue13_7.Text = "0";
            this.labelValue13_8.Text = "0";
            this.labelValue13_9.Text = "0";

            this.labelValue14_1.Text = "0";
            this.labelValue14_2.Text = "0";
            this.labelValue14_3.Text = "0";
            this.labelValue14_4.Text = "0";
            this.labelValue14_5.Text = "0";
            this.labelValue14_6.Text = "0";
            this.labelValue14_7.Text = "0";
            this.labelValue14_8.Text = "0";
            this.labelValue14_9.Text = "0";

            this.labelValue15_1.Text = "0";
            this.labelValue15_2.Text = "0";
            this.labelValue15_3.Text = "0";
            this.labelValue15_4.Text = "0";
            this.labelValue15_5.Text = "0";
            this.labelValue15_6.Text = "0";
            this.labelValue15_7.Text = "0";
            this.labelValue15_8.Text = "0";
            this.labelValue15_9.Text = "0";
        }
        private void DefaultSetting()
        {
        }

        public void UpdateData(Modbus_30000_Data data)
        {
            if (this.ParentForm.FlagModbusDec == true)
            {
                #region DEC
                this.labelValue13_1.Text = data.ModbusLaneData[12].Update.ToString();
                this.labelValue13_2.Text = data.ModbusLaneData[12].Grade.ToString();
                this.labelValue13_3.Text = Helper.DoubleToString(data.ModbusLaneData[12].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue13_4.Text = data.ModbusLaneData[12].UnderCount.ToString();
                this.labelValue13_5.Text = data.ModbusLaneData[12].PassCount.ToString();
                this.labelValue13_6.Text = data.ModbusLaneData[12].OverCount.ToString();
                this.labelValue13_7.Text = data.ModbusLaneData[12].NGCount.ToString();
                this.labelValue13_8.Text = data.ModbusLaneData[12].ExNGCount.ToString();
                this.labelValue13_9.Text = data.ModbusLaneData[12].TotalCount.ToString();

                this.labelValue14_1.Text = data.ModbusLaneData[13].Update.ToString();
                this.labelValue14_2.Text = data.ModbusLaneData[13].Grade.ToString();
                this.labelValue14_3.Text = Helper.DoubleToString(data.ModbusLaneData[13].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue14_4.Text = data.ModbusLaneData[13].UnderCount.ToString();
                this.labelValue14_5.Text = data.ModbusLaneData[13].PassCount.ToString();
                this.labelValue14_6.Text = data.ModbusLaneData[13].OverCount.ToString();
                this.labelValue14_7.Text = data.ModbusLaneData[13].NGCount.ToString();
                this.labelValue14_8.Text = data.ModbusLaneData[13].ExNGCount.ToString();
                this.labelValue14_9.Text = data.ModbusLaneData[13].TotalCount.ToString();

                this.labelValue15_1.Text = data.ModbusLaneData[14].Update.ToString();
                this.labelValue15_2.Text = data.ModbusLaneData[14].Grade.ToString();
                this.labelValue15_3.Text = Helper.DoubleToString(data.ModbusLaneData[14].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue15_4.Text = data.ModbusLaneData[14].UnderCount.ToString();
                this.labelValue15_5.Text = data.ModbusLaneData[14].PassCount.ToString();
                this.labelValue15_6.Text = data.ModbusLaneData[14].OverCount.ToString();
                this.labelValue15_7.Text = data.ModbusLaneData[14].NGCount.ToString();
                this.labelValue15_8.Text = data.ModbusLaneData[14].ExNGCount.ToString();
                this.labelValue15_9.Text = data.ModbusLaneData[14].TotalCount.ToString();
                #endregion
            }
            else
            {
                #region HEX
                this.labelValue13_1.Text = data.ModbusLaneData[12].HexStringUpdate;
                this.labelValue13_2.Text = data.ModbusLaneData[12].HexStringGrade;
                this.labelValue13_3.Text = data.ModbusLaneData[12].HexStringWeight;
                this.labelValue13_4.Text = data.ModbusLaneData[12].HexStringUnderCount;
                this.labelValue13_5.Text = data.ModbusLaneData[12].HexStringPassCount;
                this.labelValue13_6.Text = data.ModbusLaneData[12].HexStringOverCount;
                this.labelValue13_7.Text = data.ModbusLaneData[12].HexStringNGCount;
                this.labelValue13_8.Text = data.ModbusLaneData[12].HexStringExNGCount;
                this.labelValue13_9.Text = data.ModbusLaneData[12].HexStringTotalCount;

                this.labelValue14_1.Text = data.ModbusLaneData[13].HexStringUpdate;
                this.labelValue14_2.Text = data.ModbusLaneData[13].HexStringGrade;
                this.labelValue14_3.Text = data.ModbusLaneData[13].HexStringWeight;
                this.labelValue14_4.Text = data.ModbusLaneData[13].HexStringUnderCount;
                this.labelValue14_5.Text = data.ModbusLaneData[13].HexStringPassCount;
                this.labelValue14_6.Text = data.ModbusLaneData[13].HexStringOverCount;
                this.labelValue14_7.Text = data.ModbusLaneData[13].HexStringNGCount;
                this.labelValue14_8.Text = data.ModbusLaneData[13].HexStringExNGCount;
                this.labelValue14_9.Text = data.ModbusLaneData[13].HexStringTotalCount;

                this.labelValue15_1.Text = data.ModbusLaneData[14].HexStringUpdate;
                this.labelValue15_2.Text = data.ModbusLaneData[14].HexStringGrade;
                this.labelValue15_3.Text = data.ModbusLaneData[14].HexStringWeight;
                this.labelValue15_4.Text = data.ModbusLaneData[14].HexStringUnderCount;
                this.labelValue15_5.Text = data.ModbusLaneData[14].HexStringPassCount;
                this.labelValue15_6.Text = data.ModbusLaneData[14].HexStringOverCount;
                this.labelValue15_7.Text = data.ModbusLaneData[14].HexStringNGCount;
                this.labelValue15_8.Text = data.ModbusLaneData[14].HexStringExNGCount;
                this.labelValue15_9.Text = data.ModbusLaneData[14].HexStringTotalCount;
                #endregion
            }
        }

        public void DisplayRefresh()
        {
            this.UpdateData(this.ParentForm.ParentForm.Current30000ModbusData);
        }
        #endregion

        #region Event Handler
        private void buttonCommon_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            this.ParentForm.UpdateModbusDisplay(DataStore.E_ModbusDisplay.Common);
        }
        private void button1to6_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            this.ParentForm.UpdateModbusDisplay(DataStore.E_ModbusDisplay.Display1);
        }
        private void button7to12_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();
        }
        #endregion
    }
}
