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 ChromTabs : Form
    {

        private ChromColumn[] chromColumn =new ChromColumn[2];
        //private ChromeTab chromTab;


        TabPage Page;

        HWConfig hwconfig;
        GCMethodConfig methodconfig;

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

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

            //chromTab = new ChromeTab(this.hwconfig, ref this.methodconfig);
            chromColumn[0] = new ChromColumn(this.hwconfig, ref this.methodconfig);
            chromColumn[1] = new ChromColumn(this.hwconfig, ref this.methodconfig);

        }
        

        public void recordCurData()
        {
            //chromTab.recordCurData();
            //chromColumn.recordCurData();
            //this.methodconfig.SetChromAllPara();

            if (this.hwconfig.hwconfiginfo.u16ChromNum >= 1)
            {
                if (this.hwconfig.hwconfiginfo.u16ChromFront == 1)
                {
                    chromColumn[0].recordCurData(0);
                    if (this.hwconfig.hwconfiginfo.u16ChromBehind == 1)
                    {
                        chromColumn[1].recordCurData(1);
                    }
                }
                else if (this.hwconfig.hwconfiginfo.u16ChromBehind == 1)
                {
                    chromColumn[0].recordCurData(1);
                }
            }
            else
            {
                chromColumn[0].recordCurData(0);
            }
        }


        private void Detadd_Dlg(int position,int type, int index)
        {
            //chromTab.TopLevel = false;
            //chromTab.Show();
            //tabControlDet.TabPages[0].Controls.Add(chromTab);
            //chromTab.reflashContent();
            switch (position)
            {
                case 0:
                    chromColumn[0].TopLevel = false;
                    chromColumn[0].Show();
                    tabControlDet.TabPages[index].Controls.Add(chromColumn[0]);
                    chromColumn[0].reflashContent(type);
                    break;
                case 1:
                    chromColumn[1].TopLevel = false;
                    chromColumn[1].Show();
                    tabControlDet.TabPages[index].Controls.Add(chromColumn[1]);
                    chromColumn[1].reflashContent(type);
                    break;
            }
        }

        public void reflashContent()
        {
            foreach (TabPage tabPage in tabControlDet.TabPages)
            {
                this.tabControlDet.TabPages.Remove(tabPage);
            }

            //for (int i = 0; i < 2; 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(600, 350);
            //    Page.TabIndex = i;

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

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

            //}

            //tabControlDet.TabPages[0].Text = "色谱柱";

            //tabControlDet.TabPages[1].Text = "色谱柱参数";
            //Detadd_Dlg();

            if (this.hwconfig.hwconfiginfo.u16ChromNum >= 1)
            {
                if (this.hwconfig.hwconfiginfo.u16ChromFront == 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(600, 350);
                    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,0, tabControlDet.TabPages.Count - 1);
                    if (this.hwconfig.hwconfiginfo.u16ChromBehind == 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(600, 350);
                        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,1, tabControlDet.TabPages.Count - 1);
                    }
                }
               else if (this.hwconfig.hwconfiginfo.u16ChromBehind == 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(600, 350);
                    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, 1, tabControlDet.TabPages.Count - 1);
                }
            }
            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(600, 350);
                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, 0, tabControlDet.TabPages.Count - 1);
            }
            tabControlDet.SelectedIndex = 0;
        }
    }
}
