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

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

        #region Constructor
        public ControlModbusDisplay1to6(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.labelValue1_1.Text = "0";
            this.labelValue1_2.Text = "0";
            this.labelValue1_3.Text = "0";
            this.labelValue1_4.Text = "0";
            this.labelValue1_5.Text = "0";
            this.labelValue1_6.Text = "0";
            this.labelValue1_7.Text = "0";
            this.labelValue1_8.Text = "0";
            this.labelValue1_9.Text = "0";

            this.labelValue2_1.Text = "0";
            this.labelValue2_2.Text = "0";
            this.labelValue2_3.Text = "0";
            this.labelValue2_4.Text = "0";
            this.labelValue2_5.Text = "0";
            this.labelValue2_6.Text = "0";
            this.labelValue2_7.Text = "0";
            this.labelValue2_8.Text = "0";
            this.labelValue2_9.Text = "0";

            this.labelValue3_1.Text = "0";
            this.labelValue3_2.Text = "0";
            this.labelValue3_3.Text = "0";
            this.labelValue3_4.Text = "0";
            this.labelValue3_5.Text = "0";
            this.labelValue3_6.Text = "0";
            this.labelValue3_7.Text = "0";
            this.labelValue3_8.Text = "0";
            this.labelValue3_9.Text = "0";

            this.labelValue4_1.Text = "0";
            this.labelValue4_2.Text = "0";
            this.labelValue4_3.Text = "0";
            this.labelValue4_4.Text = "0";
            this.labelValue4_5.Text = "0";
            this.labelValue4_6.Text = "0";
            this.labelValue4_7.Text = "0";
            this.labelValue4_8.Text = "0";
            this.labelValue4_9.Text = "0";

            this.labelValue5_1.Text = "0";
            this.labelValue5_2.Text = "0";
            this.labelValue5_3.Text = "0";
            this.labelValue5_4.Text = "0";
            this.labelValue5_5.Text = "0";
            this.labelValue5_6.Text = "0";
            this.labelValue5_7.Text = "0";
            this.labelValue5_8.Text = "0";
            this.labelValue5_9.Text = "0";

            this.labelValue6_1.Text = "0";
            this.labelValue6_2.Text = "0";
            this.labelValue6_3.Text = "0";
            this.labelValue6_4.Text = "0";
            this.labelValue6_5.Text = "0";
            this.labelValue6_6.Text = "0";
            this.labelValue6_7.Text = "0";
            this.labelValue6_8.Text = "0";
            this.labelValue6_9.Text = "0";

            switch (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 7:
                    this.button7to12.Text = "7";
                    break;
                case 8:
                    this.button7to12.Text = "7 to 8";
                    break;
                case 10:
                    this.button7to12.Text = "7 to 10";
                    break;
                case 12:
                    this.button7to12.Text = "7 to 12";
                    break;
                default:
                    break;
            }
        }
        private void DefaultSetting()
        { 
        }

        public void UpdateData(Modbus_30000_Data data)
        {
            if (this.ParentForm.FlagModbusDec == true)
            {
                #region DEC
                this.labelValue1_1.Text = data.ModbusLaneData[0].Update.ToString();
                this.labelValue1_2.Text = data.ModbusLaneData[0].Grade.ToString();
                this.labelValue1_3.Text = Helper.DoubleToString(data.ModbusLaneData[0].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue1_4.Text = data.ModbusLaneData[0].UnderCount.ToString();
                this.labelValue1_5.Text = data.ModbusLaneData[0].PassCount.ToString();
                this.labelValue1_6.Text = data.ModbusLaneData[0].OverCount.ToString();
                this.labelValue1_7.Text = data.ModbusLaneData[0].NGCount.ToString();
                this.labelValue1_8.Text = data.ModbusLaneData[0].ExNGCount.ToString();
                this.labelValue1_9.Text = data.ModbusLaneData[0].TotalCount.ToString();

                this.labelValue2_1.Text = data.ModbusLaneData[1].Update.ToString();
                this.labelValue2_2.Text = data.ModbusLaneData[1].Grade.ToString();
                this.labelValue2_3.Text = Helper.DoubleToString(data.ModbusLaneData[1].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue2_4.Text = data.ModbusLaneData[1].UnderCount.ToString();
                this.labelValue2_5.Text = data.ModbusLaneData[1].PassCount.ToString();
                this.labelValue2_6.Text = data.ModbusLaneData[1].OverCount.ToString();
                this.labelValue2_7.Text = data.ModbusLaneData[1].NGCount.ToString();
                this.labelValue2_8.Text = data.ModbusLaneData[1].ExNGCount.ToString();
                this.labelValue2_9.Text = data.ModbusLaneData[1].TotalCount.ToString();

                this.labelValue3_1.Text = data.ModbusLaneData[2].Update.ToString();
                this.labelValue3_2.Text = data.ModbusLaneData[2].Grade.ToString();
                this.labelValue3_3.Text = Helper.DoubleToString(data.ModbusLaneData[2].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue3_4.Text = data.ModbusLaneData[2].UnderCount.ToString();
                this.labelValue3_5.Text = data.ModbusLaneData[2].PassCount.ToString();
                this.labelValue3_6.Text = data.ModbusLaneData[2].OverCount.ToString();
                this.labelValue3_7.Text = data.ModbusLaneData[2].NGCount.ToString();
                this.labelValue3_8.Text = data.ModbusLaneData[2].ExNGCount.ToString();
                this.labelValue3_9.Text = data.ModbusLaneData[2].TotalCount.ToString();

                this.labelValue4_1.Text = data.ModbusLaneData[3].Update.ToString();
                this.labelValue4_2.Text = data.ModbusLaneData[3].Grade.ToString();
                this.labelValue4_3.Text = Helper.DoubleToString(data.ModbusLaneData[3].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue4_4.Text = data.ModbusLaneData[3].UnderCount.ToString();
                this.labelValue4_5.Text = data.ModbusLaneData[3].PassCount.ToString();
                this.labelValue4_6.Text = data.ModbusLaneData[3].OverCount.ToString();
                this.labelValue4_7.Text = data.ModbusLaneData[3].NGCount.ToString();
                this.labelValue4_8.Text = data.ModbusLaneData[3].ExNGCount.ToString();
                this.labelValue4_9.Text = data.ModbusLaneData[3].TotalCount.ToString();

                this.labelValue5_1.Text = data.ModbusLaneData[4].Update.ToString();
                this.labelValue5_2.Text = data.ModbusLaneData[4].Grade.ToString();
                this.labelValue5_3.Text = Helper.DoubleToString(data.ModbusLaneData[4].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue5_4.Text = data.ModbusLaneData[4].UnderCount.ToString();
                this.labelValue5_5.Text = data.ModbusLaneData[4].PassCount.ToString();
                this.labelValue5_6.Text = data.ModbusLaneData[4].OverCount.ToString();
                this.labelValue5_7.Text = data.ModbusLaneData[4].NGCount.ToString();
                this.labelValue5_8.Text = data.ModbusLaneData[4].ExNGCount.ToString();
                this.labelValue5_9.Text = data.ModbusLaneData[4].TotalCount.ToString();

                this.labelValue6_1.Text = data.ModbusLaneData[5].Update.ToString();
                this.labelValue6_2.Text = data.ModbusLaneData[5].Grade.ToString();
                this.labelValue6_3.Text = Helper.DoubleToString(data.ModbusLaneData[5].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue6_4.Text = data.ModbusLaneData[5].UnderCount.ToString();
                this.labelValue6_5.Text = data.ModbusLaneData[5].PassCount.ToString();
                this.labelValue6_6.Text = data.ModbusLaneData[5].OverCount.ToString();
                this.labelValue6_7.Text = data.ModbusLaneData[5].NGCount.ToString();
                this.labelValue6_8.Text = data.ModbusLaneData[5].ExNGCount.ToString();
                this.labelValue6_9.Text = data.ModbusLaneData[5].TotalCount.ToString();
                #endregion
            }
            else
            {
                #region HEX
                this.labelValue1_1.Text = data.ModbusLaneData[0].HexStringUpdate;
                this.labelValue1_2.Text = data.ModbusLaneData[0].HexStringGrade;
                this.labelValue1_3.Text = data.ModbusLaneData[0].HexStringWeight;
                this.labelValue1_4.Text = data.ModbusLaneData[0].HexStringUnderCount;
                this.labelValue1_5.Text = data.ModbusLaneData[0].HexStringPassCount;
                this.labelValue1_6.Text = data.ModbusLaneData[0].HexStringOverCount;
                this.labelValue1_7.Text = data.ModbusLaneData[0].HexStringNGCount;
                this.labelValue1_8.Text = data.ModbusLaneData[0].HexStringExNGCount;
                this.labelValue1_9.Text = data.ModbusLaneData[0].HexStringTotalCount;

                this.labelValue2_1.Text = data.ModbusLaneData[1].HexStringUpdate;
                this.labelValue2_2.Text = data.ModbusLaneData[1].HexStringGrade;
                this.labelValue2_3.Text = data.ModbusLaneData[1].HexStringWeight;
                this.labelValue2_4.Text = data.ModbusLaneData[1].HexStringUnderCount;
                this.labelValue2_5.Text = data.ModbusLaneData[1].HexStringPassCount;
                this.labelValue2_6.Text = data.ModbusLaneData[1].HexStringOverCount;
                this.labelValue2_7.Text = data.ModbusLaneData[1].HexStringNGCount;
                this.labelValue2_8.Text = data.ModbusLaneData[1].HexStringExNGCount;
                this.labelValue2_9.Text = data.ModbusLaneData[1].HexStringTotalCount;

                this.labelValue3_1.Text = data.ModbusLaneData[2].HexStringUpdate;
                this.labelValue3_2.Text = data.ModbusLaneData[2].HexStringGrade;
                this.labelValue3_3.Text = data.ModbusLaneData[2].HexStringWeight;
                this.labelValue3_4.Text = data.ModbusLaneData[2].HexStringUnderCount;
                this.labelValue3_5.Text = data.ModbusLaneData[2].HexStringPassCount;
                this.labelValue3_6.Text = data.ModbusLaneData[2].HexStringOverCount;
                this.labelValue3_7.Text = data.ModbusLaneData[2].HexStringNGCount;
                this.labelValue3_8.Text = data.ModbusLaneData[2].HexStringExNGCount;
                this.labelValue3_9.Text = data.ModbusLaneData[2].HexStringTotalCount;

                this.labelValue4_1.Text = data.ModbusLaneData[3].HexStringUpdate;
                this.labelValue4_2.Text = data.ModbusLaneData[3].HexStringGrade;
                this.labelValue4_3.Text = data.ModbusLaneData[3].HexStringWeight;
                this.labelValue4_4.Text = data.ModbusLaneData[3].HexStringUnderCount;
                this.labelValue4_5.Text = data.ModbusLaneData[3].HexStringPassCount;
                this.labelValue4_6.Text = data.ModbusLaneData[3].HexStringOverCount;
                this.labelValue4_7.Text = data.ModbusLaneData[3].HexStringNGCount;
                this.labelValue4_8.Text = data.ModbusLaneData[3].HexStringExNGCount;
                this.labelValue4_9.Text = data.ModbusLaneData[3].HexStringTotalCount;

                this.labelValue5_1.Text = data.ModbusLaneData[4].HexStringUpdate;
                this.labelValue5_2.Text = data.ModbusLaneData[4].HexStringGrade;
                this.labelValue5_3.Text = data.ModbusLaneData[4].HexStringWeight;
                this.labelValue5_4.Text = data.ModbusLaneData[4].HexStringUnderCount;
                this.labelValue5_5.Text = data.ModbusLaneData[4].HexStringPassCount;
                this.labelValue5_6.Text = data.ModbusLaneData[4].HexStringOverCount;
                this.labelValue5_7.Text = data.ModbusLaneData[4].HexStringNGCount;
                this.labelValue5_8.Text = data.ModbusLaneData[4].HexStringExNGCount;
                this.labelValue5_9.Text = data.ModbusLaneData[4].HexStringTotalCount;

                this.labelValue6_1.Text = data.ModbusLaneData[5].HexStringUpdate;
                this.labelValue6_2.Text = data.ModbusLaneData[5].HexStringGrade;
                this.labelValue6_3.Text = data.ModbusLaneData[5].HexStringWeight;
                this.labelValue6_4.Text = data.ModbusLaneData[5].HexStringUnderCount;
                this.labelValue6_5.Text = data.ModbusLaneData[5].HexStringPassCount;
                this.labelValue6_6.Text = data.ModbusLaneData[5].HexStringOverCount;
                this.labelValue6_7.Text = data.ModbusLaneData[5].HexStringNGCount;
                this.labelValue6_8.Text = data.ModbusLaneData[5].HexStringExNGCount;
                this.labelValue6_9.Text = data.ModbusLaneData[5].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();
        }
        private void button7to12_Click(object sender, EventArgs e)
        {
            // Automatic Logout Reset
            if (this.ParentForm.ParentForm.SystemConfig.IsPart11 == true)
                this.ParentForm.Part11AutomaticLogoutReset();

            this.ParentForm.UpdateModbusDisplay(DataStore.E_ModbusDisplay.Display2);
        }
        #endregion
    }
}
