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 INT_LKD_2.Forms;
using INT_LKD_2.DataStore;

namespace INT_LKD_2.Controls
{
    public partial class ControlMainDisplay : UserControl
    {
        #region Field
        private FormMain m_ParentForm;

        private ControlMainDisplayDotGraph ChildControl1;
        private ControlMainDisplayDotGraph ChildControl2;
        private ControlMainDisplayDotGraph ChildControl3;
        private ControlMainDisplayDotGraph ChildControl4;
        private ControlMainDisplayDotGraph ChildControl5;
        private ControlMainDisplayDotGraph ChildControl6;
        private ControlMainDisplayDotGraph ChildControl7;
        private ControlMainDisplayDotGraph ChildControl8;
        private ControlMainDisplayDotGraph ChildControl9;
        private ControlMainDisplayDotGraph ChildControl10;

        private Collection<ControlMainDisplayDotGraph> CollectionChildControl;
        #endregion

        #region Constructor
        public ControlMainDisplay(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.Initialize();
        } 
        #endregion

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

        #region Method
        private void Initialize()
        {
            this.ChildControl1 = new ControlMainDisplayDotGraph(1, this.ParentForm);
            this.ChildControl2 = new ControlMainDisplayDotGraph(2, this.ParentForm);
            this.ChildControl3 = new ControlMainDisplayDotGraph(3, this.ParentForm);
            this.ChildControl4 = new ControlMainDisplayDotGraph(4, this.ParentForm);
            this.ChildControl5 = new ControlMainDisplayDotGraph(5, this.ParentForm);
            this.ChildControl6 = new ControlMainDisplayDotGraph(6, this.ParentForm);
            this.ChildControl7 = new ControlMainDisplayDotGraph(7, this.ParentForm);
            this.ChildControl8 = new ControlMainDisplayDotGraph(8, this.ParentForm);
            this.ChildControl9 = new ControlMainDisplayDotGraph(9, this.ParentForm);
            this.ChildControl10 = new ControlMainDisplayDotGraph(10, this.ParentForm);

            this.Controls.Add(this.ChildControl1);
            this.Controls.Add(this.ChildControl2);
            this.Controls.Add(this.ChildControl3);
            this.Controls.Add(this.ChildControl4);
            this.Controls.Add(this.ChildControl5);
            this.Controls.Add(this.ChildControl6);
            this.Controls.Add(this.ChildControl7);
            this.Controls.Add(this.ChildControl8);
            this.Controls.Add(this.ChildControl9);
            this.Controls.Add(this.ChildControl10);

            this.ChildControl1.Location = new Point(0, 0);
            this.ChildControl2.Location = new Point(0, 0);
            this.ChildControl3.Location = new Point(0, 0);
            this.ChildControl4.Location = new Point(0, 0);
            this.ChildControl5.Location = new Point(0, 0);
            this.ChildControl6.Location = new Point(0, 0);
            this.ChildControl7.Location = new Point(0, 0);
            this.ChildControl8.Location = new Point(0, 0);
            this.ChildControl9.Location = new Point(0, 0);
            this.ChildControl10.Location = new Point(0, 0);

            this.CollectionChildControl = new Collection<ControlMainDisplayDotGraph>();
            this.CollectionChildControl.Add(this.ChildControl1);
            this.CollectionChildControl.Add(this.ChildControl2);
            this.CollectionChildControl.Add(this.ChildControl3);
            this.CollectionChildControl.Add(this.ChildControl4);
            this.CollectionChildControl.Add(this.ChildControl5);
            this.CollectionChildControl.Add(this.ChildControl6);
            this.CollectionChildControl.Add(this.ChildControl7);
            this.CollectionChildControl.Add(this.ChildControl8);
            this.CollectionChildControl.Add(this.ChildControl9);
            this.CollectionChildControl.Add(this.ChildControl10);
        }

        public void UpdateNomalLeakDataDisplay(LeakData datas)
        {
            for (int i = 0; i < datas.CollDiffData.Count; i++)
            {
                this.CollectionChildControl[i].UpdateNomalLeakDataDisplay(datas.CollDiffData[i], datas.CollDispData[i]);
            }
        }
        
        // Judgment
        public void UpdateStartLeakDataDisplay(LeakData datas)
        {
            for (int i = 0; i < this.ParentForm.SystemConfig.EQUIPMENT_LANE; i++)
                this.CollectionChildControl[i].UpdateStartLeakDataDisplay(datas.CollDiffData[i], datas.CollDispData[i], datas.CollJudgment[i]);
        }
        public void UpdateStartLeakDataDisplay1(LeakData1 data)
        {
            this.CollectionChildControl[0].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);        
        }
        public void UpdateStartLeakDataDisplay2(LeakData1 data)
        {
            this.CollectionChildControl[1].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay3(LeakData1 data)
        {
            this.CollectionChildControl[2].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay4(LeakData1 data)
        {
            this.CollectionChildControl[3].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay5(LeakData1 data)
        {
            this.CollectionChildControl[4].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay6(LeakData1 data)
        {
            this.CollectionChildControl[5].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay7(LeakData1 data)
        {
            this.CollectionChildControl[6].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay8(LeakData1 data)
        {
            this.CollectionChildControl[7].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay9(LeakData1 data)
        {
            this.CollectionChildControl[8].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }
        public void UpdateStartLeakDataDisplay10(LeakData1 data)
        {
            this.CollectionChildControl[9].UpdateStartLeakDataDisplay(data.DiffData, data.DispData, data.Judgment);
        }

        public void ClearAllData()
        {
            for (int i = 0; i < this.ParentForm.SystemConfig.EQUIPMENT_LANE; i++)
                this.CollectionChildControl[i].ClearAllData();
        }

        public void DisplayRefresh(int lane)
        {
            switch (lane)
            {
                case 1:
                    this.ChildControl1.BringToFront();
                    this.button1.ButtonDown();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 2:
                    this.ChildControl2.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonDown();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 3:
                    this.ChildControl3.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonDown();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 4:
                    this.ChildControl4.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonDown();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 5:
                    this.ChildControl5.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonDown();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 6:
                    this.ChildControl6.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonDown();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 7:
                    this.ChildControl7.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonDown();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 8:
                    this.ChildControl8.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonDown();
                    this.button9.ButtonUp();
                    this.button10.ButtonUp();
                    break;
                case 9:
                    this.ChildControl9.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonDown();
                    this.button10.ButtonUp();
                    break;
                case 10:
                    this.ChildControl10.BringToFront();
                    this.button1.ButtonUp();
                    this.button2.ButtonUp();
                    this.button3.ButtonUp();
                    this.button4.ButtonUp();
                    this.button5.ButtonUp();
                    this.button6.ButtonUp();
                    this.button7.ButtonUp();
                    this.button8.ButtonUp();
                    this.button9.ButtonUp();
                    this.button10.ButtonDown();
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region Event Handler
        private void button1_Click(object sender, EventArgs e)
        {
            this.ChildControl1.BringToFront();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.ChildControl2.BringToFront();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            this.ChildControl3.BringToFront();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            this.ChildControl4.BringToFront();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            this.ChildControl5.BringToFront();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.ChildControl6.BringToFront();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.ChildControl7.BringToFront();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            this.ChildControl8.BringToFront();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.ChildControl9.BringToFront();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            this.ChildControl10.BringToFront();
        }
        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }
        #endregion
    }
}
