using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GcDevicePc.GCBuffer;

namespace GcDevicePc.ConfigMethod
{
    public partial class SPortTabs : Form
    {
        private injectionport.IPPIP[] m_iPPIP = new injectionport.IPPIP[2];
        private injectionport.IPSPL[] m_iPSPL = new injectionport.IPSPL[2];
        private injectionport.IPVAL[] m_iPVAL = new injectionport.IPVAL[2];


        TabPage Page;

        HWConfig hwconfig;
        GCMethodConfig methodconfig;

        public SPortTabs(HWConfig hwconfig, ref GCMethodConfig methodconfig)
        {
            InitializeComponent();

            this.hwconfig = hwconfig;
            this.methodconfig = methodconfig;


            m_iPPIP[0] = new injectionport.IPPIP(this.hwconfig, ref this.methodconfig);
            m_iPPIP[1] = new injectionport.IPPIP(this.hwconfig, ref this.methodconfig);


            m_iPSPL[0] = new injectionport.IPSPL(this.hwconfig, ref this.methodconfig);
            m_iPSPL[1] = new injectionport.IPSPL(this.hwconfig, ref this.methodconfig);


            m_iPVAL[0] = new injectionport.IPVAL(this.hwconfig, ref this.methodconfig);
            m_iPVAL[1] = new injectionport.IPVAL(this.hwconfig, ref this.methodconfig);


        }

        private void DetRec_Dlg(int position)
        {
            switch (position)
            {
                case 0:
                    if (hwconfig.hwconfiginfo.u16InjPortFront == 1)
                    {
                        if (hwconfig.hwconfiginfo.u16InjPortType_Front == 0)
                        {
                            m_iPPIP[0].recordCurData(0);

                        }
                        else if (hwconfig.hwconfiginfo.u16InjPortType_Front == 1)
                        {
                            m_iPSPL[0].recordCurData(0);

                        }


                    }
                    break;
                case 1:
                    if (hwconfig.hwconfiginfo.u16InjPortBehind == 1)
                    {
                        if (hwconfig.hwconfiginfo.u16InjPortType_Behind == 0)
                        {
                            m_iPPIP[1].recordCurData(1);

                        }
                        else if (hwconfig.hwconfiginfo.u16InjPortType_Behind == 1)
                        {
                            m_iPSPL[1].recordCurData(1);

                        }

                    }
                    break;
                //case 2:
                //    if (hwconfig.hwconfiginfo.u16InjValveVA1 == 1)
                //    {

                //        m_iPVAL[0].recordCurData(0);

                //    }
                //    break;
                //case 3:
                //    if (hwconfig.hwconfiginfo.u16InjValveVA2 == 1)
                //    {
                //        m_iPVAL[1].recordCurData(1);

                //    }
                //    break;
            }


        }

        public void recordCurData()
        {

            ushort pagenum = (ushort)this.hwconfig.hwconfiginfo.u16InjPortNum;

            //if (pagenum > 0)
            {
                if (hwconfig.hwconfiginfo.u16InjPortFront == 1)
                {
                    DetRec_Dlg(0);
                    if (hwconfig.hwconfiginfo.u16InjPortBehind == 1)
                    {
                        DetRec_Dlg(1);
                    }
                }else if (hwconfig.hwconfiginfo.u16InjPortBehind == 1)
                {
                    DetRec_Dlg(1);

                }
                //else if (hwconfig.hwconfiginfo.u16InjValveVA1 == 1)
                //{
                //    DetRec_Dlg(2);
                //}
                //else if (hwconfig.hwconfiginfo.u16InjValveVA2 == 1)
                //{
                //    DetRec_Dlg(3);
                //}
            }
        }


        private void Detadd_Dlg(int position, int index)
        {
            switch (position)
            {
                case 0:
                    if (hwconfig.hwconfiginfo.u16InjPortFront == 1)
                    {
                        if (hwconfig.hwconfiginfo.u16InjPortType_Front == 0)
                        {
                            m_iPPIP[0].TopLevel = false;
                            m_iPPIP[0].Show();
                            tabControlDet.TabPages[index].Controls.Add(m_iPPIP[0]);
                            m_iPPIP[0].reflashContent(0);
                        }
                        else if (hwconfig.hwconfiginfo.u16InjPortType_Front == 1)
                        {
                            m_iPSPL[0].TopLevel = false;
                            m_iPSPL[0].Show();
                            tabControlDet.TabPages[index].Controls.Add(m_iPSPL[0]);
                            m_iPSPL[0].reflashContent(0);
                        }
                    }
                    break;
                case 1:
                    if (hwconfig.hwconfiginfo.u16InjPortBehind == 1)
                    {
                        if (hwconfig.hwconfiginfo.u16InjPortType_Behind == 0)
                        {
                            m_iPPIP[1].TopLevel = false;
                            m_iPPIP[1].Show();
                            tabControlDet.TabPages[index].Controls.Add(m_iPPIP[1]);
                            m_iPPIP[1].reflashContent(1);
                        }
                        else if (hwconfig.hwconfiginfo.u16InjPortType_Behind == 1)
                        {
                            m_iPSPL[1].TopLevel = false;
                            m_iPSPL[1].Show();
                            tabControlDet.TabPages[index].Controls.Add(m_iPSPL[1]);
                            m_iPSPL[1].reflashContent(1);
                        }

                    }
                    break;
                //case 2:
                //    if (hwconfig.hwconfiginfo.u16InjValveVA1 == 1)
                //    {
                //        m_iPVAL[0].TopLevel = false;
                //        m_iPVAL[0].Show();
                //        tabControlDet.TabPages[index].Controls.Add(m_iPVAL[0]);
                //        m_iPVAL[0].reflashContent(0);

                //    }
  
                //    break;
                //case 3:
                //    if (hwconfig.hwconfiginfo.u16InjValveVA2 == 1)
                //    {
                //        m_iPVAL[1].TopLevel = false;
                //        m_iPVAL[1].Show();
                //        tabControlDet.TabPages[index].Controls.Add(m_iPVAL[1]);
                //        m_iPVAL[1].reflashContent(1);
                //    }
                //    break;
            }

        }

        public void reflashContent()
        {

            ushort pagenum = (ushort)hwconfig.hwconfiginfo.u16InjPortNum;
            //int i;
            foreach (TabPage tabPage in tabControlDet.TabPages)
            {
                this.tabControlDet.TabPages.Remove(tabPage);
            }
            if (pagenum > 0)
            {
                //for (i = 0; i < 4; i++)
                //{
                //    Page = new TabPage();
                //    Page.Location = new System.Drawing.Point(4, 22);
                //    Page.Padding = new System.Windows.Forms.Padding(3);

                //    Page.Size = new System.Drawing.Size(553, 288);
                //    Page.TabIndex = i;

                //    Page.Text = "";
                //    Page.Name = "tabPage" + i.ToString();

                //    Page.UseVisualStyleBackColor = true;
                //    tabControlDet.Controls.Add(Page);

                //}

                if (hwconfig.hwconfiginfo.u16InjPortFront == 1)
                {
                    Page = new TabPage();
                    Page.Location = new System.Drawing.Point(4, 22);
                    Page.Padding = new System.Windows.Forms.Padding(3);

                    Page.Size = new System.Drawing.Size(553, 288);
                    Page.TabIndex = tabControlDet.TabPages.Count;

                    Page.Text = "";
                    Page.Name = "tabPage" + tabControlDet.TabPages.Count.ToString();

                    Page.UseVisualStyleBackColor = true;
                    tabControlDet.Controls.Add(Page);
                    tabControlDet.TabPages[tabControlDet.TabPages.Count-1].Text = "前进样口";
                    Detadd_Dlg(0,tabControlDet.TabPages.Count-1);

                    if (hwconfig.hwconfiginfo.u16InjPortBehind == 1)
                    {
                        Page = new TabPage();
                        Page.Location = new System.Drawing.Point(4, 22);
                        Page.Padding = new System.Windows.Forms.Padding(3);

                        Page.Size = new System.Drawing.Size(553, 288);
                        Page.TabIndex = tabControlDet.TabPages.Count;

                        Page.Text = "";
                        Page.Name = "tabPage" + tabControlDet.TabPages.Count.ToString();

                        Page.UseVisualStyleBackColor = true;
                        tabControlDet.Controls.Add(Page);
                        tabControlDet.TabPages[tabControlDet.TabPages.Count - 1].Text = "后进样口";
                        Detadd_Dlg(1, tabControlDet.TabPages.Count - 1);

                    }

                }else if (hwconfig.hwconfiginfo.u16InjPortBehind == 1)
                {
                    Page = new TabPage();
                    Page.Location = new System.Drawing.Point(4, 22);
                    Page.Padding = new System.Windows.Forms.Padding(3);

                    Page.Size = new System.Drawing.Size(553, 288);
                    Page.TabIndex = tabControlDet.TabPages.Count;

                    Page.Text = "";
                    Page.Name = "tabPage" + tabControlDet.TabPages.Count.ToString();

                    Page.UseVisualStyleBackColor = true;
                    tabControlDet.Controls.Add(Page);
                    tabControlDet.TabPages[tabControlDet.TabPages.Count-1].Text = "后进样口";
                    Detadd_Dlg(1,tabControlDet.TabPages.Count-1);

                }
                //if (hwconfig.hwconfiginfo.u16InjValveVA1 == 1)
                //{
                //    Page = new TabPage();
                //    Page.Location = new System.Drawing.Point(4, 22);
                //    Page.Padding = new System.Windows.Forms.Padding(3);

                //    Page.Size = new System.Drawing.Size(553, 288);
                //    Page.TabIndex = tabControlDet.TabPages.Count;

                //    Page.Text = "";
                //    Page.Name = "tabPage" + tabControlDet.TabPages.Count.ToString();

                //    Page.UseVisualStyleBackColor = true;
                //    tabControlDet.Controls.Add(Page);
                //    tabControlDet.TabPages[tabControlDet.TabPages.Count-1].Text = "VA1阀";
                //    Detadd_Dlg(2,tabControlDet.TabPages.Count-1);
                //}
                //if (hwconfig.hwconfiginfo.u16InjValveVA2 == 1)
                //{
                //    Page = new TabPage();
                //    Page.Location = new System.Drawing.Point(4, 22);
                //    Page.Padding = new System.Windows.Forms.Padding(3);

                //    Page.Size = new System.Drawing.Size(553, 288);
                //    Page.TabIndex = tabControlDet.TabPages.Count;

                //    Page.Text = "";
                //    Page.Name = "tabPage" + tabControlDet.TabPages.Count.ToString();

                //    Page.UseVisualStyleBackColor = true;
                //    tabControlDet.Controls.Add(Page);
                //    tabControlDet.TabPages[tabControlDet.TabPages.Count-1].Text = "VA2阀";
                //    Detadd_Dlg(3,tabControlDet.TabPages.Count-1);
                //}
                tabControlDet.SelectedIndex = 0;
            }
            else
            {
                Page = new TabPage();
                Page.Location = new System.Drawing.Point(4, 22);
                Page.Padding = new System.Windows.Forms.Padding(3);

                Page.Size = new System.Drawing.Size(553, 288);
                Page.TabIndex = tabControlDet.TabPages.Count;

                Page.Text = "";
                Page.Name = "tabPage" + tabControlDet.TabPages.Count.ToString();

                Page.UseVisualStyleBackColor = true;
                tabControlDet.Controls.Add(Page);
                tabControlDet.TabPages[tabControlDet.TabPages.Count - 1].Text = "进样口";
                Detadd_Dlg(0, tabControlDet.TabPages.Count - 1);
            }
        }
    }
}
