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 ControlModbusDisplay7to12 : UserControl
    {
        #region Field
        private FormMainDisplay m_ParentForm;
        #endregion

        #region Constructor
        public ControlModbusDisplay7to12(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.labelValue7_1.Text = "0";
            this.labelValue7_2.Text = "0";
            this.labelValue7_3.Text = "0";
            this.labelValue7_4.Text = "0";
            this.labelValue7_5.Text = "0";
            this.labelValue7_6.Text = "0";
            this.labelValue7_7.Text = "0";
            this.labelValue7_8.Text = "0";
            this.labelValue7_9.Text = "0";

            this.labelValue8_1.Text = "0";
            this.labelValue8_2.Text = "0";
            this.labelValue8_3.Text = "0";
            this.labelValue8_4.Text = "0";
            this.labelValue8_5.Text = "0";
            this.labelValue8_6.Text = "0";
            this.labelValue8_7.Text = "0";
            this.labelValue8_8.Text = "0";
            this.labelValue8_9.Text = "0";

            this.labelValue9_1.Text = "0";
            this.labelValue9_2.Text = "0";
            this.labelValue9_3.Text = "0";
            this.labelValue9_4.Text = "0";
            this.labelValue9_5.Text = "0";
            this.labelValue9_6.Text = "0";
            this.labelValue9_7.Text = "0";
            this.labelValue9_8.Text = "0";
            this.labelValue9_9.Text = "0";

            this.labelValue10_1.Text = "0";
            this.labelValue10_2.Text = "0";
            this.labelValue10_3.Text = "0";
            this.labelValue10_4.Text = "0";
            this.labelValue10_5.Text = "0";
            this.labelValue10_6.Text = "0";
            this.labelValue10_7.Text = "0";
            this.labelValue10_8.Text = "0";
            this.labelValue10_9.Text = "0";

            this.labelValue11_1.Text = "0";
            this.labelValue11_2.Text = "0";
            this.labelValue11_3.Text = "0";
            this.labelValue11_4.Text = "0";
            this.labelValue11_5.Text = "0";
            this.labelValue11_6.Text = "0";
            this.labelValue11_7.Text = "0";
            this.labelValue11_8.Text = "0";
            this.labelValue11_9.Text = "0";

            this.labelValue12_1.Text = "0";
            this.labelValue12_2.Text = "0";
            this.labelValue12_3.Text = "0";
            this.labelValue12_4.Text = "0";
            this.labelValue12_5.Text = "0";
            this.labelValue12_6.Text = "0";
            this.labelValue12_7.Text = "0";
            this.labelValue12_8.Text = "0";
            this.labelValue12_9.Text = "0";
          
            switch (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns)
            {
                case 7:
                    this.button7to12.Text = "7";

                    this.labelTitleAddress1.Visible = false;
                    this.labelTitleAddress2.Visible = false;
                    this.labelTitleName1.Visible = false;
                    this.labelTitleName2.Visible = false;
                    this.labelTitleData1.Visible = false;
                    this.labelTitleData2.Visible = false;
                    this.smartSeparatorLine1.Visible = false;
                    this.smartSeparatorLine2.Visible = false;
                    break;
                case 8:
                    this.button7to12.Text = "7 to 8";

                    this.groupBox9.Visible = false;
                    this.groupBox10.Visible = false;
                    this.groupBox11.Visible = false;
                    this.groupBox12.Visible = false;

                    this.labelTitleAddress1.Visible = false;
                    this.labelTitleAddress2.Visible = false;
                    this.labelTitleName1.Visible = false;
                    this.labelTitleName2.Visible = false;
                    this.labelTitleData1.Visible = false;
                    this.labelTitleData2.Visible = false;
                    this.smartSeparatorLine1.Visible = false;
                    this.smartSeparatorLine2.Visible = false;
                    break;
                case 10:
                    this.button7to12.Text = "7 to 10";

                    this.groupBox11.Visible = false;
                    this.groupBox12.Visible = false;

                    this.labelTitleAddress2.Visible = false;
                    this.labelTitleName2.Visible = false;
                    this.labelTitleData2.Visible = false;
                    this.smartSeparatorLine2.Visible = false;
                    break;
                case 12:
                case 15:
                    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.labelValue7_1.Text = data.ModbusLaneData[6].Update.ToString();
                this.labelValue7_2.Text = data.ModbusLaneData[6].Grade.ToString();
                this.labelValue7_3.Text = Helper.DoubleToString(data.ModbusLaneData[6].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                this.labelValue7_4.Text = data.ModbusLaneData[6].UnderCount.ToString();
                this.labelValue7_5.Text = data.ModbusLaneData[6].PassCount.ToString();
                this.labelValue7_6.Text = data.ModbusLaneData[6].OverCount.ToString();
                this.labelValue7_7.Text = data.ModbusLaneData[6].NGCount.ToString();
                this.labelValue7_8.Text = data.ModbusLaneData[6].ExNGCount.ToString();
                this.labelValue7_9.Text = data.ModbusLaneData[6].TotalCount.ToString();

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 8)
                {
                    this.labelValue8_1.Text = data.ModbusLaneData[7].Update.ToString();
                    this.labelValue8_2.Text = data.ModbusLaneData[7].Grade.ToString();
                    this.labelValue8_3.Text = Helper.DoubleToString(data.ModbusLaneData[7].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    this.labelValue8_4.Text = data.ModbusLaneData[7].UnderCount.ToString();
                    this.labelValue8_5.Text = data.ModbusLaneData[7].PassCount.ToString();
                    this.labelValue8_6.Text = data.ModbusLaneData[7].OverCount.ToString();
                    this.labelValue8_7.Text = data.ModbusLaneData[7].NGCount.ToString();
                    this.labelValue8_8.Text = data.ModbusLaneData[7].ExNGCount.ToString();
                    this.labelValue8_9.Text = data.ModbusLaneData[7].TotalCount.ToString();
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 9)
                {
                    this.labelValue9_1.Text = data.ModbusLaneData[8].Update.ToString();
                    this.labelValue9_2.Text = data.ModbusLaneData[8].Grade.ToString();
                    this.labelValue9_3.Text = Helper.DoubleToString(data.ModbusLaneData[8].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    this.labelValue9_4.Text = data.ModbusLaneData[8].UnderCount.ToString();
                    this.labelValue9_5.Text = data.ModbusLaneData[8].PassCount.ToString();
                    this.labelValue9_6.Text = data.ModbusLaneData[8].OverCount.ToString();
                    this.labelValue9_7.Text = data.ModbusLaneData[8].NGCount.ToString();
                    this.labelValue9_8.Text = data.ModbusLaneData[8].ExNGCount.ToString();
                    this.labelValue9_9.Text = data.ModbusLaneData[8].TotalCount.ToString();
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 10)
                {
                    this.labelValue10_1.Text = data.ModbusLaneData[9].Update.ToString();
                    this.labelValue10_2.Text = data.ModbusLaneData[9].Grade.ToString();
                    this.labelValue10_3.Text = Helper.DoubleToString(data.ModbusLaneData[9].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    this.labelValue10_4.Text = data.ModbusLaneData[9].UnderCount.ToString();
                    this.labelValue10_5.Text = data.ModbusLaneData[9].PassCount.ToString();
                    this.labelValue10_6.Text = data.ModbusLaneData[9].OverCount.ToString();
                    this.labelValue10_7.Text = data.ModbusLaneData[9].NGCount.ToString();
                    this.labelValue10_8.Text = data.ModbusLaneData[9].ExNGCount.ToString();
                    this.labelValue10_9.Text = data.ModbusLaneData[9].TotalCount.ToString();
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 11)
                {
                    this.labelValue11_1.Text = data.ModbusLaneData[10].Update.ToString();
                    this.labelValue11_2.Text = data.ModbusLaneData[10].Grade.ToString();
                    this.labelValue11_3.Text = Helper.DoubleToString(data.ModbusLaneData[10].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    this.labelValue11_4.Text = data.ModbusLaneData[10].UnderCount.ToString();
                    this.labelValue11_5.Text = data.ModbusLaneData[10].PassCount.ToString();
                    this.labelValue11_6.Text = data.ModbusLaneData[10].OverCount.ToString();
                    this.labelValue11_7.Text = data.ModbusLaneData[10].NGCount.ToString();
                    this.labelValue11_8.Text = data.ModbusLaneData[10].ExNGCount.ToString();
                    this.labelValue11_9.Text = data.ModbusLaneData[10].TotalCount.ToString();
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 12)
                {
                    this.labelValue12_1.Text = data.ModbusLaneData[11].Update.ToString();
                    this.labelValue12_2.Text = data.ModbusLaneData[11].Grade.ToString();
                    this.labelValue12_3.Text = Helper.DoubleToString(data.ModbusLaneData[11].Weight, this.ParentForm.ParentForm.SystemConfig.DecimalPlaces);
                    this.labelValue12_4.Text = data.ModbusLaneData[11].UnderCount.ToString();
                    this.labelValue12_5.Text = data.ModbusLaneData[11].PassCount.ToString();
                    this.labelValue12_6.Text = data.ModbusLaneData[11].OverCount.ToString();
                    this.labelValue12_7.Text = data.ModbusLaneData[11].NGCount.ToString();
                    this.labelValue12_8.Text = data.ModbusLaneData[11].ExNGCount.ToString();
                    this.labelValue12_9.Text = data.ModbusLaneData[11].TotalCount.ToString();
                }
                #endregion
            }
            else
            {
                #region HEX
                this.labelValue7_1.Text = data.ModbusLaneData[6].HexStringUpdate;
                this.labelValue7_2.Text = data.ModbusLaneData[6].HexStringGrade;
                this.labelValue7_3.Text = data.ModbusLaneData[6].HexStringWeight;
                this.labelValue7_4.Text = data.ModbusLaneData[6].HexStringUnderCount;
                this.labelValue7_5.Text = data.ModbusLaneData[6].HexStringPassCount;
                this.labelValue7_6.Text = data.ModbusLaneData[6].HexStringOverCount;
                this.labelValue7_7.Text = data.ModbusLaneData[6].HexStringNGCount;
                this.labelValue7_8.Text = data.ModbusLaneData[6].HexStringExNGCount;
                this.labelValue7_9.Text = data.ModbusLaneData[6].HexStringTotalCount;

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 8)
                {
                    this.labelValue8_1.Text = data.ModbusLaneData[7].HexStringUpdate;
                    this.labelValue8_2.Text = data.ModbusLaneData[7].HexStringGrade;
                    this.labelValue8_3.Text = data.ModbusLaneData[7].HexStringWeight;
                    this.labelValue8_4.Text = data.ModbusLaneData[7].HexStringUnderCount;
                    this.labelValue8_5.Text = data.ModbusLaneData[7].HexStringPassCount;
                    this.labelValue8_6.Text = data.ModbusLaneData[7].HexStringOverCount;
                    this.labelValue8_7.Text = data.ModbusLaneData[7].HexStringNGCount;
                    this.labelValue8_8.Text = data.ModbusLaneData[7].HexStringExNGCount;
                    this.labelValue8_9.Text = data.ModbusLaneData[7].HexStringTotalCount;
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 9)
                {
                    this.labelValue9_1.Text = data.ModbusLaneData[8].HexStringUpdate;
                    this.labelValue9_2.Text = data.ModbusLaneData[8].HexStringGrade;
                    this.labelValue9_3.Text = data.ModbusLaneData[8].HexStringWeight;
                    this.labelValue9_4.Text = data.ModbusLaneData[8].HexStringUnderCount;
                    this.labelValue9_5.Text = data.ModbusLaneData[8].HexStringPassCount;
                    this.labelValue9_6.Text = data.ModbusLaneData[8].HexStringOverCount;
                    this.labelValue9_7.Text = data.ModbusLaneData[8].HexStringNGCount;
                    this.labelValue9_8.Text = data.ModbusLaneData[8].HexStringExNGCount;
                    this.labelValue9_9.Text = data.ModbusLaneData[8].HexStringTotalCount;
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 10)
                {
                    this.labelValue10_1.Text = data.ModbusLaneData[9].HexStringUpdate;
                    this.labelValue10_2.Text = data.ModbusLaneData[9].HexStringGrade;
                    this.labelValue10_3.Text = data.ModbusLaneData[9].HexStringWeight;
                    this.labelValue10_4.Text = data.ModbusLaneData[9].HexStringUnderCount;
                    this.labelValue10_5.Text = data.ModbusLaneData[9].HexStringPassCount;
                    this.labelValue10_6.Text = data.ModbusLaneData[9].HexStringOverCount;
                    this.labelValue10_7.Text = data.ModbusLaneData[9].HexStringNGCount;
                    this.labelValue10_8.Text = data.ModbusLaneData[9].HexStringExNGCount;
                    this.labelValue10_9.Text = data.ModbusLaneData[9].HexStringTotalCount;
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 11)
                {
                    this.labelValue11_1.Text = data.ModbusLaneData[10].HexStringUpdate;
                    this.labelValue11_2.Text = data.ModbusLaneData[10].HexStringGrade;
                    this.labelValue11_3.Text = data.ModbusLaneData[10].HexStringWeight;
                    this.labelValue11_4.Text = data.ModbusLaneData[10].HexStringUnderCount;
                    this.labelValue11_5.Text = data.ModbusLaneData[10].HexStringPassCount;
                    this.labelValue11_6.Text = data.ModbusLaneData[10].HexStringOverCount;
                    this.labelValue11_7.Text = data.ModbusLaneData[10].HexStringNGCount;
                    this.labelValue11_8.Text = data.ModbusLaneData[10].HexStringExNGCount;
                    this.labelValue11_9.Text = data.ModbusLaneData[10].HexStringTotalCount;
                }

                if (this.ParentForm.ParentForm.SystemConfig.EquipmentColumns >= 12)
                {
                    this.labelValue12_1.Text = data.ModbusLaneData[11].HexStringUpdate;
                    this.labelValue12_2.Text = data.ModbusLaneData[11].HexStringGrade;
                    this.labelValue12_3.Text = data.ModbusLaneData[11].HexStringWeight;
                    this.labelValue12_4.Text = data.ModbusLaneData[11].HexStringUnderCount;
                    this.labelValue12_5.Text = data.ModbusLaneData[11].HexStringPassCount;
                    this.labelValue12_6.Text = data.ModbusLaneData[11].HexStringOverCount;
                    this.labelValue12_7.Text = data.ModbusLaneData[11].HexStringNGCount;
                    this.labelValue12_8.Text = data.ModbusLaneData[11].HexStringExNGCount;
                    this.labelValue12_9.Text = data.ModbusLaneData[11].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();
        }

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

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