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 System.Text.RegularExpressions;

namespace GcDevicePc
{
    public partial class CreateConfig : Form
    {

        public INIOperation createstatusfile;

        public InstrConfig fatherForm;
        public CreateConfig()
        {
            InitializeComponent();
        }
    
        private void ConfigContol_Init()
        {
            int i = 0;
            this.fsamplestart.Enabled = false;
            this.bsamplestart.Enabled = false;

            this.fsamplestart.Items.Add("进样器启动色谱仪");
            this.fsamplestart.Items.Add("色谱仪启动进样器");
            this.bsamplestart.Items.Add("进样器启动色谱仪");
            this.bsamplestart.Items.Add("色谱仪启动进样器");
           
            //阀设置
            this.valve1.Enabled = false;
            this.valve1.CheckedChanged += new EventHandler(valvenum_Changed);
            this.valve2.Enabled = false;
            this.valve2.CheckedChanged += new EventHandler(valvenum_Changed);
            this.valve3.Enabled = false;
            this.valve3.CheckedChanged += new EventHandler(valvenum_Changed);
            this.valve4.Enabled = false;
            this.valve4.CheckedChanged += new EventHandler(valvenum_Changed);
            this.valve5.Enabled = false;
            this.valve5.CheckedChanged += new EventHandler(valvenum_Changed);
            this.valve6.Enabled = false;
            this.valve6.CheckedChanged += new EventHandler(valvenum_Changed);
            for (i = 0; i < 7; i++ )
            {
                this.valvenum.Items.Add(i);
            }
            this.valvenum.SelectedIndex = 0;

            //进样口设置
            this.spmaxtemp1.Enabled = false;
            this.spmaxtemp2.Enabled = false;
            this.sampleportkind1.Enabled = false;
            this.sampleportkind1.Items.Add("PIP");
            this.sampleportkind1.Items.Add("SPL");
            this.sampleportkind1.Items.Add("PTV");
            this.sampleportkind1.Text = "";
            this.sampleportkind2.Enabled = false;
            this.sampleportkind2.Items.Add("PIP");
            this.sampleportkind2.Items.Add("SPL");
            this.sampleportkind2.Items.Add("PTV");
            this.sampleportkind2.Text = "";
            this.gaskind1.Enabled = false;
            this.gaskind1.Items.Add("N2");
            this.gaskind1.Items.Add("H2");
            this.gaskind1.Items.Add("He");
            this.gaskind1.Items.Add("Ar");
            this.gaskind1.Text = "";
            this.gaskind2.Enabled = false;
            this.gaskind2.Items.Add("N2");
            this.gaskind2.Items.Add("H2");
            this.gaskind2.Items.Add("He");
            this.gaskind2.Items.Add("Ar");
            this.gaskind2.Text = "";

            //柱箱设置
            this.Ovenkind.Enabled = false;
            this.OvenMaxTemp.Enabled = false;
            this.Ovenkind.Items.Add("标准柱箱");
            this.Ovenkind.Items.Add("小柱箱");
            this.Ovenkind.Items.Add("加热器");
            this.Ovenkind.Text = "";

            //色谱柱设置
            this.ColumnNum.Items.Add(0);
            this.ColumnNum.Items.Add(1);
            this.ColumnNum.Items.Add(2);
            this.ColumnNum.SelectedIndex = 0;

            this.Column1.Enabled = false;


            this.Column1_kind.Enabled = false;
            this.Column1_kind.Items.Add("毛细孔柱");
            this.Column1_kind.Items.Add("填充柱");
            this.Column1_kind.Text = "";

            this.Column1_len.Enabled = false;
            this.Column1_len.Text = "";
            this.Column1_len.KeyPress += new KeyPressEventHandler(alltextBox_KeyPress);
            this.Column1_caliber.Enabled = false;
            this.Column1_caliber.Text = "";
            this.Column1_caliber.KeyPress += new KeyPressEventHandler(alltextBox_KeyPress);
            this.Column1_ft.Enabled = false;
            this.Column1_ft.Text = "";
            this.Column1_ft.KeyPress += new KeyPressEventHandler(alltextBox_KeyPress);

            this.Column2.Enabled = false;
  
  
            this.Column2_kind.Enabled = false;
            this.Column2_kind.Items.Add("毛细孔柱");
            this.Column2_kind.Items.Add("填充柱");
            this.Column2_kind.Text = "";

            this.Column2_len.Enabled = false;
            this.Column2_len.Text = "";
            this.Column2_len.KeyPress += new KeyPressEventHandler(alltextBox_KeyPress);
            this.Column2_caliber.Enabled = false;
            this.Column2_caliber.Text = "";
            this.Column2_caliber.KeyPress += new KeyPressEventHandler(alltextBox_KeyPress);
            this.Column2_ft.Enabled = false;
            this.Column2_ft.Text = "";
            this.Column2_ft.KeyPress += new KeyPressEventHandler(alltextBox_KeyPress);


            //检测单元
            this.detectnum.Items.Add(0);
            this.detectnum.Items.Add(1);
            this.detectnum.Items.Add(2);
            this.detectnum.Items.Add(3);
            this.detectnum.SelectedIndex = 0;
            this.detmaxtemp1.Enabled = false;
            this.detmaxtemp2.Enabled = false;
            this.detmaxtemp3.Enabled = false;

            this.detectcheck1.Enabled = false;
            this.detectcheck2.Enabled = false;
            this.detectcheck3.Enabled = false;
            this.detecttype1.Enabled = false;
            this.detecttype1.Items.Add("TCD");
            this.detecttype1.Items.Add("FID");
            this.detecttype1.Items.Add("ECD");
            this.detecttype1.Items.Add("FPD");
            this.detecttype1.Items.Add("PID");
            this.detecttype2.Enabled = false;
            this.detecttype2.Items.Add("TCD");
            this.detecttype2.Items.Add("FID");
            this.detecttype2.Items.Add("ECD");
            this.detecttype2.Items.Add("FPD");
            this.detecttype2.Items.Add("PID");
            this.detecttype3.Enabled = false;
            this.detecttype3.Items.Add("TCD");
            this.detecttype3.Items.Add("FID");
            this.detecttype3.Items.Add("ECD");
            this.detecttype3.Items.Add("FPD");
            this.detecttype3.Items.Add("PID");

            this.detectaisle1.Enabled = false;
            this.detectaisle1.Items.Add("A");
            this.detectaisle1.Items.Add("B");
            this.detectaisle2.Enabled = false;
            this.detectaisle2.Items.Add("A");
            this.detectaisle2.Items.Add("B");
            this.detectaisle3.Enabled = false;
            this.detectaisle3.Items.Add("A");
            this.detectaisle3.Items.Add("B");
        
            this.Heaternum.Items.Add(0);
            this.Heaternum.Items.Add(1);
            this.Heaternum.Items.Add(2);
            this.Heaternum.SelectedIndex = 0;

            this.devGrade.Items.Add("请选择");
            this.devGrade.Items.Add("机械阀+压力流量");
            this.devGrade.Items.Add("机械阀");
            this.devGrade.Items.Add("EPC");
            this.devGrade.SelectedIndex = 0;


        }

        private void alltextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (e.KeyChar == '.' && ((TextBox)sender).Text.IndexOf(".") != -1)
            {
                e.Handled = true;
            }

            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }
        }


        private void CreateConfig_Load(object sender, EventArgs e)
        {
            ConfigContol_Init();
        }

        private void fsample_CheckedChanged(object sender, EventArgs e)
        {
            if(this.fsample.Checked ==true)
            {
               this.fsamplestart.Enabled =true;             
            }
            else
            {
               this.fsamplestart.Enabled = false;
               this.fsamplestart.Text = "";
            }
        }

        private void bsample_CheckedChanged(object sender, EventArgs e)
        {
            if (this.bsample.Checked == true)
            {
                this.bsamplestart.Enabled = true;
            }
            else
            {
                this.bsamplestart.Enabled = false;
                this.bsamplestart.Text = "";
            }
        }

        private void valvenum_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(this.valvenum.SelectedIndex == 0)
            {
                this.valve1.Enabled = false;
                this.valve2.Enabled = false;
                this.valve3.Enabled = false;
                this.valve4.Enabled = false;
                this.valve5.Enabled = false;
                this.valve6.Enabled = false;          
            }else
            {
                this.valve1.Enabled = true;
                this.valve2.Enabled = true;
                this.valve3.Enabled = true;
                this.valve4.Enabled = true;
                this.valve5.Enabled = true;
                this.valve6.Enabled = true;
            }
            this.valve1.Checked = false;
            this.valve2.Checked = false;
            this.valve3.Checked = false;
            this.valve4.Checked = false;
            this.valve5.Checked = false;
            this.valve6.Checked = false;
           
        }

        private int sum_checknum()
        {
            int sum = 0;
            sum += (valve1.Checked ? 1 : 0);
            sum += (valve2.Checked ? 1 : 0);
            sum += (valve3.Checked ? 1 : 0);
            sum += (valve4.Checked ? 1 : 0);
            sum += (valve5.Checked ? 1 : 0);
            sum += (valve6.Checked ? 1 : 0);
            return sum;
        }

        private void valvenum_Changed(object sender, EventArgs e)
        {
            int i = Convert.ToInt32(this.valvenum.Text);

            if( i == sum_checknum())
            {
                if (!valve1.Checked)
                    valve1.Enabled = false;
                if (!valve2.Checked)
                    valve2.Enabled = false;
                if (!valve3.Checked)
                    valve3.Enabled = false;
                if (!valve4.Checked)
                    valve4.Enabled = false;
                if (!valve5.Checked)
                    valve5.Enabled = false;
                if (!valve6.Checked)
                    valve6.Enabled = false;
            }
            else
            {
                valve1.Enabled = true;
                valve2.Enabled = true;
                valve3.Enabled = true;
                valve4.Enabled = true;
                valve5.Enabled = true;
                valve6.Enabled = true;
            }
        }

        private void sampleport1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.sampleport1.Checked)
            {
                this.sampleportkind1.Enabled = true;
                this.sampleportkind1.SelectedIndex = 0;
                this.gaskind1.Enabled = true;
                this.gaskind1.SelectedIndex = 0;
                this.spmaxtemp1.Enabled = true;
                this.spmaxtemp1.Text = "400";

            }else
            {
                this.sampleportkind1.Enabled = false;
                this.sampleportkind1.Text = "";
                this.gaskind1.Enabled = false;
                this.gaskind1.Text = "";
                this.spmaxtemp1.Enabled = false;
                this.spmaxtemp1.Text = "";
            }
        }

        private void sampleport2_CheckedChanged(object sender, EventArgs e)
        {
            if(this.sampleport2.Checked)
            {
                this.sampleportkind2.Enabled = true;
                this.sampleportkind2.SelectedIndex = 0;
                this.gaskind2.Enabled = true;
                this.gaskind2.SelectedIndex = 0;
                this.spmaxtemp2.Enabled = true;
                this.spmaxtemp2.Text = "400";
            }else
            {
                this.sampleportkind2.Enabled = false;
                this.sampleportkind2.Text = "";
                this.gaskind2.Enabled = false;
                this.gaskind2.Text = "";
                this.spmaxtemp2.Enabled = false;
                this.spmaxtemp2.Text = "";
            }

        }

        private void Ovencheck_CheckedChanged(object sender, EventArgs e)
        {
            if(this.Ovencheck.Checked)
            {
                this.Ovenkind.Enabled = true;
                this.Ovenkind.SelectedIndex = 2;
                this.OvenMaxTemp.Enabled = true;
                this.OvenMaxTemp.Text = "400";
            }
            else
            {
                this.Ovenkind.Enabled = false;
                this.Ovenkind.SelectedIndex = -1;
                this.Ovenkind.Text = "";
                this.OvenMaxTemp.Enabled = false;
                this.OvenMaxTemp.Text = "";
            }
        }

        private void ColumnNum_SelectedIndexChanged(object sender, EventArgs e)
        {        
            if(ColumnNum.SelectedIndex > 0)
            {
                this.Column1.Enabled = true;
                this.Column2.Enabled = true;
            }
            else
            {
                this.Column1.Enabled = false;
                this.Column2.Enabled = false;
          
            }
            this.Column1.Checked = false;
            this.Column2.Checked = false;
                
        }

        private void Column1_CheckedChanged(object sender, EventArgs e)
        {
            if(this.Column1.Checked)
            {
           
                this.Column1_kind.Enabled = true;
                this.Column1_kind.SelectedIndex = 0;
                this.Column1_len.Enabled = true;
                this.Column1_len.Text = "0";
                this.Column1_caliber.Enabled = true;
                this.Column1_caliber.Text = "0";
                this.Column1_ft.Enabled = true;
                this.Column1_ft.Text = "0";

                if((this.ColumnNum.SelectedIndex - 1) == 0)
                {
                    this.Column2.Enabled = false;
                }

            }else
            {

                this.Column1_kind.Enabled = false;
                this.Column1_kind.Text = "";
                this.Column1_kind.SelectedIndex = -1;
                this.Column1_len.Enabled = false;
                this.Column1_len.Text = "";
                this.Column1_caliber.Enabled = false;
                this.Column1_caliber.Text = "";
                this.Column1_ft.Enabled = false;
                this.Column1_ft.Text = "";

                if (this.ColumnNum.SelectedIndex > 0)
                {
                    this.Column2.Enabled = true;
                }
            }
        }

        private void Column2_CheckedChanged(object sender, EventArgs e)
        {
            if (this.Column2.Checked)
            {
 
                this.Column2_kind.Enabled = true;
                this.Column2_kind.SelectedIndex = 0;
                this.Column2_len.Enabled = true;
                this.Column2_len.Text = "0";
                this.Column2_caliber.Enabled = true;
                this.Column2_caliber.Text = "0";
                this.Column2_ft.Enabled = true;
                this.Column2_ft.Text = "0";

                if ((this.ColumnNum.SelectedIndex - 1) == 0)
                {
                    this.Column1.Enabled = false;
                }

            }
            else
            {

                this.Column2_kind.Enabled = false;
                this.Column2_kind.Text = "";
                this.Column2_kind.SelectedIndex = -1;
                this.Column2_len.Enabled = false;
                this.Column2_len.Text = "";
                this.Column2_caliber.Enabled = false;
                this.Column2_caliber.Text = "";
                this.Column2_ft.Enabled = false;
                this.Column2_ft.Text = "";

                if (this.ColumnNum.SelectedIndex > 0)
                {
                    this.Column1.Enabled = true;
                }
               
            }
        }

        private void detectnum_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(this.detectnum.SelectedIndex > 0)
            {
                this.detectcheck1.Enabled = true;
                this.detectcheck2.Enabled = true;
                this.detectcheck3.Enabled = true;
            }else
            {
                this.detectcheck1.Enabled = false;
                this.detectcheck2.Enabled = false;
                this.detectcheck3.Enabled = false;
            }
            this.detectcheck1.Checked = false;
            this.detectcheck2.Checked = false;
            this.detectcheck3.Checked = false;
        }

        private void detectcheck1_CheckedChanged(object sender, EventArgs e)
        {
            if(this.detectcheck1.Checked)
            {
                this.detecttype1.Enabled = true;
                this.detecttype1.SelectedIndex = 0;
                this.detectaisle1.Enabled = true;
                this.detectaisle1.SelectedIndex = 0;

                this.detmaxtemp1.Enabled = true;
                this.detmaxtemp1.Text = "400";

                if(detectnum.SelectedIndex - 1 - (detectcheck2.Checked?1:0) - (detectcheck3.Checked?1:0) == 0)
                {
                    if((detectcheck2.Checked?1:0) == 0)
                    {
                        detectcheck2.Enabled = false;
                    }

                    if ((detectcheck3.Checked ? 1 : 0) == 0)
                    {
                        detectcheck3.Enabled = false;
                    }
                }

            }else
            {
                this.detecttype1.Enabled = false;
                this.detecttype1.Text = "";
                this.detecttype1.SelectedIndex = -1;
                this.detectaisle1.Enabled = false;
                this.detectaisle1.Text = "";
                this.detectaisle1.SelectedIndex = -1;

                this.detmaxtemp1.Enabled = false;
                this.detmaxtemp1.Text = "";

                if (detectnum.SelectedIndex > 0)
                {
                    detectcheck1.Enabled = true;
                    detectcheck2.Enabled = true;
                    detectcheck3.Enabled = true;
                }
            }
        }

        private void detectcheck2_CheckedChanged(object sender, EventArgs e)
        {
            if (this.detectcheck2.Checked)
            {
                this.detecttype2.Enabled = true;
                this.detecttype2.SelectedIndex = 0;
                this.detectaisle2.Enabled = true;
                this.detectaisle2.SelectedIndex = 0;

                this.detmaxtemp2.Enabled = true;
                this.detmaxtemp2.Text = "400";

                if (detectnum.SelectedIndex - 1 - (detectcheck1.Checked ? 1 : 0) - (detectcheck3.Checked ? 1 : 0) == 0)
                {
                    if ((detectcheck1.Checked ? 1 : 0) == 0)
                    {
                        detectcheck1.Enabled = false;
                    }

                    if ((detectcheck3.Checked ? 1 : 0) == 0)
                    {
                        detectcheck3.Enabled = false;
                    }
                }
            }
            else
            {
                this.detecttype2.Enabled = false;
                this.detecttype2.Text = "";
                this.detecttype2.SelectedIndex = -1;
  
                this.detectaisle2.Enabled = false;
                this.detectaisle2.Text = "";
                this.detectaisle2.SelectedIndex = -1;

                this.detmaxtemp2.Enabled = false;
                this.detmaxtemp2.Text = "";

                if (detectnum.SelectedIndex > 0)
                {
                    detectcheck1.Enabled = true;
                    detectcheck2.Enabled = true;
                    detectcheck3.Enabled = true;
                }
            }
        }

        private void detectcheck3_CheckedChanged(object sender, EventArgs e)
        {
            if (this.detectcheck3.Checked)
            {
                this.detecttype3.Enabled = true;
                this.detecttype3.SelectedIndex = 0;
      
                this.detectaisle3.Enabled = true;
                this.detectaisle3.SelectedIndex = 0;

                this.detmaxtemp3.Enabled = true;
                this.detmaxtemp3.Text = "400";

                if (detectnum.SelectedIndex - 1 - (detectcheck1.Checked ? 1 : 0) - (detectcheck1.Checked ? 1 : 0) == 0)
                {
                    if ((detectcheck1.Checked ? 1 : 0) == 0)
                    {
                        detectcheck1.Enabled = false;
                    }

                    if ((detectcheck2.Checked ? 1 : 0) == 0)
                    {
                        detectcheck2.Enabled = false;
                    }
                }
            }
            else
            {
                this.detecttype3.Enabled = false;
                this.detecttype3.Text = "";
                this.detecttype3.SelectedIndex = -1;
    
                this.detectaisle3.Enabled = false;
                this.detectaisle3.Text = "";
                this.detectaisle3.SelectedIndex = -1;

                this.detmaxtemp3.Enabled = false;
                this.detmaxtemp3.Text = "";

                if (detectnum.SelectedIndex > 0)
                {
                    detectcheck1.Enabled = true;
                    detectcheck2.Enabled = true;
                    detectcheck3.Enabled = true;
                }
            }
        }


        private void ContolData_Init()
        {
            this.fsample.Checked = false;
            this.bsample.Checked = false;
            this.valvenum.SelectedIndex = 0;
            this.sampleport1.Checked = false;
            this.sampleport2.Checked = false;
            this.Ovencheck.Checked = false;
            this.ColumnNum.SelectedIndex = 0;
            this.detectnum.SelectedIndex = 0;
            this.Heaternum.SelectedIndex = 0;
            this.devGrade.SelectedIndex = 0;
        }

        private void resetcfg_Click(object sender, EventArgs e)
        {
            ContolData_Init();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="unitno">代表单元号，1进样器 2阀，3进样口 4色谱柱 5检测器 6加热器 </param>
        /// <returns></returns>
        private int Statistics_unit(int unitno)
        {
            int sum = 0;
            switch(unitno)
            {
                case 1:                  
                     sum += this.fsample.Checked ? 1: 0;
                     sum += this.bsample.Checked ? 1 : 0;
                     break;
                case 2:
                     sum = this.valvenum.SelectedIndex;
                    break;                    
                case 3:
                    sum += this.sampleport1.Checked ? 1 : 0;
                    sum += this.sampleport2.Checked ? 1 : 0;
                    break;                     
                case 4:
                    sum += this.ColumnNum.SelectedIndex;
                    break;                    
                case 5:
                    sum += this.detectnum.SelectedIndex;
                    break;                     
                case 6:
                    sum += this.Heaternum.SelectedIndex;
                    break;
                default:
                    sum = 0;
                    break;
            }
            return sum;
        }



        private void SaveInI(string filename)
        {

            createstatusfile = new INIOperation(filename);
            string file = filename;

            if (System.IO.File.Exists(file) == false)
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(file, false, System.Text.Encoding.Unicode);
                sw.WriteLine("[仪器编号]");
                sw.Close();     
            }

            createstatusfile.INIWriteValue(file, "仪器编号", "仪器编码", this.GCNum.Text);
            createstatusfile.INIWriteValue(file, "仪器编号", "仪器名称", this.GCName.Text);

            createstatusfile.INIEmptySection(file, "进样单元进样器");

            createstatusfile.INIWriteValue(file, "进样单元进样器", "进样器数量", Statistics_unit(1).ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样器", "前进样器", (fsample.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样器", "前进样器启动方式", fsamplestart.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样器", "后进样器", (bsample.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样器", "后进样器启动方式", bsamplestart.SelectedIndex.ToString());

            createstatusfile.INIEmptySection(file, "进样单元切换阀");

            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀数量", Statistics_unit(2).ToString());
            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀1", (valve1.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀2", (valve2.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀3", (valve3.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀4", (valve4.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀5", (valve5.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元切换阀", "阀6", (valve6.Checked ? 1 : 0).ToString());

            createstatusfile.INIEmptySection(file, "进样单元进样口");
            createstatusfile.INIWriteValue(file, "进样单元进样口", "进样口数量", Statistics_unit(3).ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "前进样口", (sampleport1.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "前进样口保护温度", spmaxtemp1.Text.ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "前进样口类型", sampleportkind1.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "前进样口载气", gaskind1.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "后进样口", (sampleport2.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "后进样口保护温度", spmaxtemp2.Text.ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "后进样口类型", sampleportkind1.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "进样单元进样口", "后进样口载气", gaskind2.SelectedIndex.ToString());


            createstatusfile.INIEmptySection(file, "柱箱单元柱箱");
            createstatusfile.INIWriteValue(file, "柱箱单元柱箱", "柱箱", (Ovencheck.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元柱箱", "柱箱类型", Ovenkind.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元柱箱", "柱箱保护温度", OvenMaxTemp.Text.ToString());

            createstatusfile.INIEmptySection(file, "柱箱单元色谱柱");
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "色谱柱数量", Statistics_unit(4).ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "前色谱柱", (Column1.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "前色谱柱类型", Column1_kind.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "前色谱柱长度", Column1_len.Text);
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "前色谱柱口径", Column1_caliber.Text);
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "前色谱柱膜厚", Column1_ft.Text);
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "后色谱柱", (Column2.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "后色谱柱类型", Column2_kind.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "后色谱柱长度", Column2_len.Text);
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "后色谱柱口径", Column2_caliber.Text);
            createstatusfile.INIWriteValue(file, "柱箱单元色谱柱", "后色谱柱膜厚", Column2_ft.Text);

            createstatusfile.INIEmptySection(file, "检测单元");
            createstatusfile.INIWriteValue(file, "检测单元", "检测器数量", Statistics_unit(5).ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "前检测器", (detectcheck1.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "前检测器保护温度", detmaxtemp1.Text.ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "前检测器类型", detecttype1.SelectedIndex.ToString());     
            createstatusfile.INIWriteValue(file, "检测单元", "前检测器通道", detectaisle1.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "中检测器", (detectcheck2.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "中检测器保护温度", detmaxtemp2.Text.ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "中检测器类型", detecttype2.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "中检测器通道", detectaisle2.SelectedIndex.ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "后检测器", (detectcheck3.Checked ? 1 : 0).ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "后检测器保护温度", detmaxtemp3.Text.ToString());
            createstatusfile.INIWriteValue(file, "检测单元", "后检测器类型", detecttype3.SelectedIndex.ToString());     
            createstatusfile.INIWriteValue(file, "检测单元", "后检测器通道", detectaisle3.SelectedIndex.ToString());

            createstatusfile.INIEmptySection(file, "辅助设置");
            createstatusfile.INIWriteValue(file, "辅助设置", "辅助加热", (Statistics_unit(6)>0?1:0).ToString());
            createstatusfile.INIWriteValue(file, "辅助设置", "辅助加热器数量", Statistics_unit(6).ToString());

            createstatusfile.INIWriteValue(file, "辅助设置", "辅助1", (((Statistics_unit(6) == 1) || (Statistics_unit(6) == 2))?1:0).ToString());
            createstatusfile.INIWriteValue(file, "辅助设置", "辅助名字1",this.Heatername1.Text);
            createstatusfile.INIWriteValue(file, "检测单元", "中检测器保护温度", (!detectcheck2.Checked && Statistics_unit(6) > 0) ? auxmaxtemp1.Text.ToString() : detmaxtemp2.Text.ToString());
            createstatusfile.INIWriteValue(file, "辅助设置", "辅助2", (((Statistics_unit(6) == 2))?1:0).ToString());
            createstatusfile.INIWriteValue(file, "辅助设置", "辅助名字2", this.Heatername2.Text);
            createstatusfile.INIWriteValue(file, "检测单元", "后检测器保护温度", (!detectcheck3.Checked && Statistics_unit(6) > 0) ? auxmaxtemp2.Text.ToString() : detmaxtemp3.Text.ToString());

            createstatusfile.INIEmptySection(file, "仪器档次");
            createstatusfile.INIWriteValue(file, "仪器档次", "仪器档次", devGrade.SelectedIndex.ToString());

            this.savecfg.Enabled = true;
            this.samplegroup.Enabled = true;
            this.Ovengroup.Enabled = true;
            this.detectgroup.Enabled = true;
            this.groupBox1.Enabled = true;
            this.groupBox8.Enabled = true;
            this.resetcfg.Enabled = true;
            this.exitcfg.Enabled = true;

            this.Close();
        }

        private void EnableFWindow()
        {
            this.savecfg.Enabled = true;
            this.samplegroup.Enabled = true;
            this.Ovengroup.Enabled = true;
            this.detectgroup.Enabled = true;
            this.groupBox1.Enabled = true;
            this.groupBox8.Enabled = true;
            this.resetcfg.Enabled = true;
            this.exitcfg.Enabled = true;
        }

        private void savecfg_Click(object sender, EventArgs e)
        {
            this.savecfg.Enabled = false;
            this.samplegroup.Enabled = false;
            this.Ovengroup.Enabled = false;
            this.detectgroup.Enabled = false;
            this.groupBox1.Enabled = false;
            this.groupBox8.Enabled = false;
            this.resetcfg.Enabled = false;
            this.exitcfg.Enabled = false;

            SaveCfg inifile = new SaveCfg();
            inifile.SaveInI += new SaveIniFile(SaveInI);
            inifile.EnableFWindow += new EnableFWin(EnableFWindow);
            inifile.Show();

           // this.Close();
        }

        private void exitcfg_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
