using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Windows.Forms.DataVisualization.Charting;

namespace 气象色谱算法
{
    public partial class chart_FW : UserControl
    {
        public chart_FW()
        {
            InitializeComponent();
        }

        #region 声名委托
        delegate void SetTextCallback(string text, bool connect_t);
        delegate void webTextCallback(string text, double[] value);
        int refresh = 0;      
        DataTable data_line = null;
        private void data_show_delegate_Text(string text, double[] value)
        {
            lock (this)
            {
                try
                {
                    if (text == "port_A"&&algorithm_W.algorithm.work_OK)
                    {                       
                        refresh++;
                        if (refresh > 2)
                        {
                            refresh = 0;
                            //////chart_show.Columns.Add("count");
                            //////chart_show.Columns.Add("minute");
                            //////chart_show.Columns.Add("value");
                            //////chart_show.Columns.Add("value1");
                            //////chart_show.Columns.Add("base_value");
                            //////chart_show.Columns.Add("is_peak");
                            //////chart_show.Columns.Add("is_peak1");
                            ////chart1.Series[0].Points.DataBind(data_line.AsEnumerable(), "minute", "value1,base_value", "");
                            ////chart1.Series[0].XValueType = ChartValueType.Double; //设置X轴类型为时间
                            ////chart1.Series[1].Points.DataBind(data_line.AsEnumerable(), "minute", "value1", "");
                            ////chart1.Series[1].XValueType = ChartValueType.Double; //设置X轴类型为时间
                            ////chart1.Series[2].Points.DataBind(data_line.AsEnumerable(), "minute", "base_value", "");
                            ////chart1.Series[2].XValueType = ChartValueType.Double; //设置X轴类型为时间

                            chart1.Series[1].XValueMember = "minute";
                            chart1.Series[1].YValueMembers = "value1";
                            chart1.Series[2].XValueMember = "minute";
                            chart1.Series[2].YValueMembers = "base_value";
                            chart1.Series[0].XValueMember = "minute";
                            chart1.Series[0].YValueMembers = "value1,base_value";
                            chart1.DataSource = data_line;
                            chart1.DataBind();

                            result_dataGridView.DataSource = algorithm_W.algorithm.calculate_tab;
                            ////chart1.Series[0].Points.Clear();
                            ////chart1.Series[1].Points.Clear();                            
                            for (int k = 0; k < data_line.Rows.Count; k++)
                            {
                                ////chart1.Series[0].Points.AddXY(diandao_out_time0[RowIndex].ToString("0.0000"), diandao_value_1[RowIndex].ToString("0.0000"));
                                ////chart1.Series[1].Points.AddXY(diandao_out_time0[RowIndex].ToString("0.0000"), diandao_out_base[RowIndex].ToString("0.0000"));
                                //// = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                                //////chart_data.Rows[RowIndex][0] = diandao_out_time0[RowIndex].ToString("0.0000");
                                //////chart_data.Rows[RowIndex][1] = diandao_value_1[RowIndex].ToString("0.00");
                                //////chart_data.Rows[RowIndex][2] = diandao_out_base[RowIndex].ToString("0.00");

                                #region 标峰和谷
                                if (data_line.Rows[k][6].ToString() == "9" && top_show_cB.Checked)
                                {                                    
                                    chart1.Series[0].Points[k].MarkerBorderWidth = 4;
                                    chart1.Series[0].Points[k].MarkerColor = Color.Red;
                                    chart1.Series[0].Points[k].MarkerSize = 4;
                                    ////chart1.Series[0].Points[place - 2].
                                    ////chart1.Series[0].Points[place - 2].BorderDashStyle = ChartDashStyle.Dash;
                                    chart1.Series[0].Points[k].IsValueShownAsLabel = true;
                                }
                                else if (data_line.Rows[k][6].ToString() == "2" && bottom_show_cB.Checked)
                                {
                                    chart1.Series[0].Points[k].MarkerBorderWidth = 4;
                                    chart1.Series[0].Points[k].MarkerColor = Color.Blue;
                                    chart1.Series[0].Points[k].MarkerSize = 4;
                                    ////chart1.Series[0].Points[place - 2].
                                    ////chart1.Series[0].Points[place - 2].BorderDashStyle = ChartDashStyle.Dash;
                                    chart1.Series[0].Points[k].IsValueShownAsLabel = true;
                                }
                                else
                                {
                                    //chart1.Series[0].Points[RowIndex].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None;
                                    chart1.Series[0].Points[k].MarkerBorderWidth = 1;
                                    chart1.Series[0].Points[k].MarkerColor = Color.Gray;
                                    chart1.Series[0].Points[k].MarkerSize = 1;
                                    chart1.Series[0].Points[k].IsValueShownAsLabel = false;
                                }
                                #endregion
                            }
                            int index0 = -1;
                            int index1 = -1;
                            int index2 = -1;
                            Color area_color ;
                            ////if (algorithm_W.algorithm.calculate_tab.Columns.Count == 22)
                            ////{
                            ////    algorithm_W.algorithm.calculate_tab.Columns.Remove("颜色");
                            ////    algorithm_W.algorithm.calculate_tab.Columns.Add("颜色");
                            ////}

                            for (int k = 0; k < algorithm_W.algorithm.calculate_tab.Rows.Count; k++)
                            {
                                index0 = Convert.ToInt16(algorithm_W.algorithm.calculate_tab.Rows[k][12]);
                                index1 = Convert.ToInt16(algorithm_W.algorithm.calculate_tab.Rows[k][10]);
                                index2 = Convert.ToInt16(algorithm_W.algorithm.calculate_tab.Rows[k][11]);
                                if (!algorithm_W.algorithm.calculate_tab.Rows[k][21].Equals(DBNull.Value))
                                {
                                    area_color = Color.FromArgb(Convert.ToInt32(algorithm_W.algorithm.calculate_tab.Rows[k][21]));
                                    result_dataGridView.Rows[k].Cells[9].Style.BackColor = area_color;
                                    ////area_color = 
                                    for (int i = index1; i < index2 && i < chart1.Series[0].Points.Count; i++)
                                    {
                                        chart1.Series[0].Points[i].Color = area_color;
                                    }
                                }
                            }
                            if (chroma_show_cB.Checked)
                            {
                                 index0 =-1;
                                 index1 = -1;
                                 index2 = -1;
                                ////int index3 = -1;
                                
                                for (int k = 0; k < algorithm_W.algorithm.calculate_tab.Rows.Count; k++)
                                {
                                    index0 = Convert.ToInt16(algorithm_W.algorithm.calculate_tab.Rows[k][12]);
                                    index1 = Convert.ToInt16(algorithm_W.algorithm.calculate_tab.Rows[k][10]);
                                    index2 = Convert.ToInt16(algorithm_W.algorithm.calculate_tab.Rows[k][11]);
                                    if (index0 >= 0 && index0 < data_line.Rows.Count && index1 < data_line.Rows.Count && index2 < data_line.Rows.Count)
                                    {
                                        ////////                 0     1      2        3       4      5      6      7        8           9            10        11          12      13          14       15       16       17                              
                                        ////////calculate_tab  编号；名称；起点间；结束时间；峰高；峰半宽；峰面积；浓度；切峰方式；叠峰分离方式；对应开始点；对应结束点；峰高点；峰绝对高； 校准方式；峰高开；峰半宽开；峰面积开；
                                        chart1.Series[0].Points[index0].Label = "名称:" + algorithm_W.algorithm.calculate_tab.Rows[k][1].ToString()
                                            + Environment.NewLine + "出峰时间:" + data_line.Rows[index0][1].ToString() + "Min"
                                            + Environment.NewLine + "保持时间:" + (Convert.ToDouble(data_line.Rows[index1][1]) +" - "+ Convert.ToDouble(data_line.Rows[index2][1])).ToString() +"Min"
                                            + Environment.NewLine + "浓度:" + algorithm_W.algorithm.calculate_tab.Rows[k][7].ToString()
                                            + Environment.NewLine + "归一值:" + algorithm_W.algorithm.calculate_tab.Rows[k][18].ToString();
                                    }
                                    ////for (int i = index1; i < index2; i++)
                                    ////{
                                    ////    chart1.Series[0].Points[i].Color = Color.Red;
                                    ////}

                                }
                            }
                        }
                    }
                    else if (text == "timer")
                    {
                        if (algorithm_W.fresh_set)
                        {
                            fresh_tip_lb.Visible = !fresh_tip_lb.Visible;
                            if (tabControl1.SelectedIndex !=1) 
                            {
                                tabControl1.SelectTab(1);
                            }
                        }
                        else
                        {
                            if (fresh_tip_lb.Visible)
                            {
                                fresh_tip_lb.Hide();
                            }
                        }
                    }
                }
                catch (Exception)
                {

                }
            }
        }
        public DataTable GetDgvToTable(DataGridView dgv)
        {
            DataTable dt = new DataTable();

            for (int count = 0; count < dgv.Columns.Count; count++)
            {
                DataColumn dc = new DataColumn(dgv.Columns[count].DataPropertyName.ToString());
                dt.Columns.Add(dc);
            }

            for (int count = 0; count < dgv.Rows.Count; count++)
            {
                DataRow dr = dt.NewRow();
                for (int countsub = 0; countsub < dgv.Columns.Count; countsub++)
                {
                    dr[countsub] = Convert.ToString(dgv.Rows[count].Cells[countsub].Value);
                }
                dt.Rows.Add(dr);
            }
            return dt;
        }
        private void SetText(string text, bool connect_t)
        {

            try
            {
                if (connect_t == true)
                {


                }
                else
                {

                }
            }
            catch (Exception ex)
            {

            }

        }
        bool new_sample = true;
        string state_tip_lp_show = "■ 停止";
        int state_tip_lp_show_count = 0;
        Color show_state_fore_color = Color.Green;
        private string PadLeftEx(string str, int totalByteCount)
        {
            //Encoding coding = Encoding.GetEncoding("gb2312");
            int dcount = totalByteCount - str.Length * 2;
            //foreach (char ch in str.ToCharArray())
            //{
            //    if (coding.GetByteCount(ch.ToString()) == 2)
            //        dcount++;
            //}
            if (dcount < 0)
            {
                dcount = 0;
            }
            string w = str + new string(' ', dcount);
            return w;
        }
        private void data_show_delegate_Text0(string text)
        {
            lock (this)
            {

            }
        }
        private void readyText(string text)
        {
            switch (text)
            {
                case "1":
                    break;
                case "2":
                    break;
                case "3":
                    break;
                case "传感校零0":
                    break;
                case "传感校零1":
                    break;
                case "采原灯谱0":
                    break;
                case "采原灯谱1":
                    break;
                default:
                    break;
            }

        }
        #endregion
        Thread port_A_thread;
        string[] setting_list;
        private void chart_FW_Load(object sender, EventArgs e)
        {
            port_A_thread = new Thread(port_A_thread_method);
            port_A_thread.Start();

            ////// Zoom into the X axis
            //////chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, 2048);
            ////// Enable range selection and zooming end user interface
            chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
            chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
            chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
            chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = double.NaN;
            chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 20;
            ////// Zoom into the Y axis
            //////chart1.ChartAreas[0].AxisY.ScaleView.Zoom(0, 60000);
            ////// Enable range selection and zooming end user interface
            chart1.ChartAreas[0].CursorY.IsUserEnabled = true;
            chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
            chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
            chart1.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = double.NaN;
            chart1.ChartAreas[0].AxisY.ScaleView.SmallScrollMinSize = 20;
            //////将滚动内嵌到坐标轴中
            chart1.ChartAreas[0].AxisY.ScrollBar.Enabled = false;
            chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = false;
            ////配置文件读取  
            try
            {
                setting_list = File.ReadAllLines("sys_setting.txt");
                if (setting_list.Length > 1)
                {
                    for (int i = 1; i < setting_list.Length; i++)
                    {
                        string[] VVV = setting_list[i].Split(';');
                        history_system_set_cB.Items.Add(VVV[1]);
                    }
                    history_system_set_cB.Text = setting_list[0];
                    algorithm_W.load_infor = history_system_set_cB.Text;
                    algorithm_W.algorithm.load_formatter_infor(setting_list[0]);
                }
            }
            catch (Exception) 
            {
            
            }
            result_dataGridView.AutoGenerateColumns = false;
        }

        ////DataTable data_line = null;
        ////DataTable algorithm_W.algorithm.calculate_tab = null;
        bool new_data = false;
        public void new_data_in(double time, double value) 
        {
            algorithm_W.algorithm.datavalue_in(time, value);
            new_data = true;
        }

        bool run_pause = false;
        void port_A_thread_method()
        {
            while (true)
            {
                try
                {                    
                    Thread.Sleep(1000);
                    if (new_data && !run_pause)
                    {
                        algorithm_W.algorithm.data_calculator();
                        data_line = algorithm_W.algorithm.chart_show;
                        //////algorithm_W.algorithm.calculate_tab = algorithm_W.algorithm.calculate_tab;

                        this.Invoke(new webTextCallback(data_show_delegate_Text), new object[] { "port_A", null });
                        new_data = false;
                        ////return;
                    }
                    this.Invoke(new webTextCallback(data_show_delegate_Text), new object[] { "timer", null });
                }
                catch (Exception)
                {

                }
            }
        }

        private void result_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            ////result_dataGridView.Rows[e.RowIndex].Selected = true;

            if (e.RowIndex >= 0)
            {
                for (int i = 0; i < result_dataGridView.Columns.Count - 1; i++)
                {
                    result_dataGridView.Rows[e.RowIndex].Cells[i].Selected = true;
                }
            }
            else 
            {
                result_dataGridView.ClearSelection();
            }
            ////result_dataGridView.Rows[0].Cells[0].Selected = true;
            ////result_dataGridView.Rows[0].Cells[1].Selected = true;
            ////result_dataGridView.Rows[0].Cells[2].Selected = true;
            ////result_dataGridView.Rows[0].Cells[3].Selected = true;
            ////result_dataGridView.Rows[0].Cells[4].Selected = true;
            ////result_dataGridView.Rows[0].Selected = false;
            ////result_dataGridView.Columns[9].Selected = false;
            ////result_dataGridView.ClearSelection();
            ////result_dataGridView.Rows[0].Cells[9].Selected = false;
        }
        private void result_dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            ////chart1.ChartAreas[0].AxisY.ScaleView.Zoom(Convert.ToDouble(Y_show_start_place.Text.Trim()), Convert.ToDouble(Y_show_end_place.Text.Trim()));

        }
        private void result_dataGridView_SelectionChanged(object sender, EventArgs e)
        {
            ////result_dataGridView.Rows[0].Cells[0].Selected = true;
            ////result_dataGridView.Rows[0].Cells[1].Selected = true;
            ////result_dataGridView.Rows[0].Cells[2].Selected = true;
            ////result_dataGridView.Rows[0].Cells[3].Selected = true;
            ////result_dataGridView.Rows[0].Cells[4].Selected = true;
        }

        private void chart1_MouseClick(object sender, MouseEventArgs e)
        {
            //try
            //{
           
            //if (e.Button == System.Windows.Forms.MouseButtons.Left)
            //{
            //    MessageBox.Show(chart1.Series[1].ToolTip);
            //}
            //if (e.Button == System.Windows.Forms.MouseButtons.Right)
            //{
            //    System.Windows.Forms.DataVisualization.Charting.HitTestResult Result = new System.Windows.Forms.DataVisualization.Charting.HitTestResult();
            //    Result = chart1.HitTest(e.X, e.Y);
            //    if (Result.Series != null)
            //        MessageBox.Show("'X轴:'" + Result.Series.Points[Result.PointIndex].XValue.ToString() + "'Y轴:'" + Result.Series.Points[Result.PointIndex].YValues[0].ToString());
            //}


                ////System.Windows.Forms.DataVisualization.Charting.HitTestResult Result = new System.Windows.Forms.DataVisualization.Charting.HitTestResult();
                ////Result = chart1.HitTest(e.X, e.Y);
                ////if (Result.Series != null) 
                ////{
                ////    XYdata_value.Text = "时间:" + Result.Series.Points[Result.PointIndex].XValue.ToString() + "分"
                ////       + Environment.NewLine + "信号值:" + Result.Series.Points[Result.PointIndex].YValues[0].ToString();
                ////    ////Result.Series.Points[Result.PointIndex].XValue.ToString();
                ////}  

            ////int index = Convert.ToInt16(chart1.ChartAreas[0].CursorX.Position) * 100;
            ////XYdata_value.Text = e.Axis.Crossing.ToString();
                //////if (index >= 0)
                //////{
                ////Point AAA = e.Location;
                XYdata_value.Location = new Point(e.Location.X + 4, e.Location.Y + 4); 
                //////XYdata_value.Show(MousePosition.X, MousePosition.Y);
                XYdata_value.Text = "时间:" + chart1.ChartAreas[0].CursorX.Position + "分"
                    +Environment.NewLine + "信号值:" + chart1.ChartAreas[0].CursorY.Position;
                XYdata_value.Show();
                ////+ Environment.NewLine + "信号值:" + chart1.ChartAreas[0].CursorY.Position;
                //////    //////XYdata_value.Text = "X:" + chart1.Series[0].Points[index0].XValue.ToString() + "    Y:" + chart1.Series[0].Points[index0].YValues[0].ToString();
                //////}
                //////X_value_lb.Text = "X:" + chart1.Series[0].Points[index0].XValue.ToString();
                //////Y_value_lb.Text = "Y:" + chart1.Series[0].Points[index0].YValues[0].ToString();
            //}
            //catch (Exception) 
            //{
            
            //}
        }
        private void XYdata_value_MouseEnter(object sender, EventArgs e)
        {
            XYdata_value.Hide();
        }

        private void Y_autoscroll_bt_Click(object sender, EventArgs e)
        {
            //////algorithm_W.algorithm.calculate_tab.Columns.Add("颜色", typeof(Color));
            ////////////DataGridViewButtonColumn
            ////////////DataGridViewButtonCell AAA = new DataGridViewButtonCell();
            //////////DataGridViewCell AAA = new DataGridViewCell();
            ////////////AAA.Style.ForeColor = Color.Red;
            ////////////Button AAA = new Button();
            ////////////AAA.Text = "";
            ////////////AAA.BackColor = Color.Red;
            //////Color AAA = Color.Red;
            //////algorithm_W.algorithm.calculate_tab.Rows[0][21] = AAA;


            chart1.ChartAreas[0].AxisY.Interval = double.NaN;
            chart1.ChartAreas[0].AxisY.Maximum = double.NaN;
            chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset(0);
            ////chart1.ChartAreas[0].AxisY.ScaleView.Scroll(DateTime.Now);
            ////chart1.ChartAreas[0].CursorY.AutoScroll = true;
            ////chart1.ChartAreas[0].AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;           
        }

        private void X_autoscroll_bt_Click(object sender, EventArgs e)
        {
            chart1.ChartAreas[0].AxisX.Interval = double.NaN;
            chart1.ChartAreas[0].AxisX.Maximum = double.NaN;
            chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(0);
            ////chart1.ChartAreas[0].AxisX.ScaleView.Scroll(DateTime.Now);
            ////chart1.ChartAreas[0].CursorX.AutoScroll = true;
            ////chart1.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;           

        }
        private void chart1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            lock (this)
            {
                try
                {
                    refresh = 0;
                    chart1.Series[0].Points.Clear();
                    chart1.Series[1].Points.Clear();
                    chart1.Series[2].Points.Clear();
                    chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
                    chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();

                    chart1.Series[1].XValueMember = "minute";
                    chart1.Series[1].YValueMembers = "value1";
                    chart1.Series[2].XValueMember = "minute";
                    chart1.Series[2].YValueMembers = "base_value";
                    chart1.Series[0].XValueMember = "minute";
                    chart1.Series[0].YValueMembers = "value1,base_value";
                    chart1.DataSource = data_line;
                    chart1.DataBind();                    
                    ////this.Refresh();
                }
                catch (Exception) 
                {
                }
            }
        }

        private void system_adjust_bt_Click(object sender, EventArgs e)
        {
            ////run_pause = true;
            system_set_Form aaa = new system_set_Form();
            aaa.Show();
            ////run_pause = false;
        }
        private void data_search_bt_Click(object sender, EventArgs e)
        {
            run_pause = true;
            Form3 aaa = new Form3();
            aaa.ShowDialog();
            run_pause = false;
        }
        private void auto_show_chart_cB_Click(object sender, EventArgs e)
        {
            if (auto_show_chart_cB.Checked)
            {
                chart1.ChartAreas[0].AxisX.Interval = double.NaN;
                chart1.ChartAreas[0].AxisX.Maximum = double.NaN;
                chart1.ChartAreas[0].AxisY.Interval = double.NaN;
                chart1.ChartAreas[0].AxisY.Maximum = double.NaN;
                chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset(0);
                chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(0);
            }
            else
            {

            }
        }

        private void X_autoscroll_dUD_Bt_Click(object sender, EventArgs e)
        {
            //////chart1.ChartAreas[0].AxisX.Interval = Convert.ToInt32(X_autoscroll_dUD.Text.Trim())/20;
            //////chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, Convert.ToDouble(X_autoscroll_dUD.Text.Trim()));
            //////chart1.ChartAreas[0].AxisX.Interval = Convert.ToInt32(X_interval.Text.Trim());
            //////chart1.ChartAreas[0].AxisX.ScaleView.Zoom(Convert.ToDouble(X_show_start_place.Text.Trim()), Convert.ToDouble(X_show_end_place.Text.Trim()));
            chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(X_autoscroll_dUD.Text.Trim());
            chart1.ChartAreas[0].AxisX.Minimum =0;
            auto_show_chart_cB.Checked = false;
        }
        private void Y_autoscroll_dUD_Bt_Click(object sender, EventArgs e)
        {
            //////chart1.ChartAreas[0].AxisY.Interval = Convert.ToInt32(Y_autoscroll_dUD.Text.Trim())/10;
            //////chart1.ChartAreas[0].AxisY.ScaleView.Zoom(0, Convert.ToDouble(Y_autoscroll_dUD.Text.Trim()));
            //////chart1.ChartAreas[0].AxisX.Interval = Convert.ToInt32(X_interval.Text.Trim());
            //////chart1.ChartAreas[0].AxisX.ScaleView.Zoom(Convert.ToDouble(X_show_start_place.Text.Trim()), Convert.ToDouble(X_show_end_place.Text.Trim()));
            chart1.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(Y_autoscroll_dUD.Text.Trim());
            chart1.ChartAreas[0].AxisY.Minimum = 0;
            auto_show_chart_cB.Checked = false;
        }

        private void history_system_set_cB_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string AAA = history_system_set_cB.Text;
                if (AAA != algorithm_W.algorithm.load_infor)
                {
                    algorithm_W.algorithm.load_formatter_infor(AAA);
                    algorithm_W.load_infor = AAA;
                }
            }
            catch (Exception)
            {

            }
        }

        private void set_refresh_bt_Click(object sender, EventArgs e)
        {
            try
            {
                string AAA = history_system_set_cB.Text;
                if (AAA == algorithm_W.algorithm.load_infor)
                {
                    algorithm_W.algorithm.load_formatter_infor(AAA);
                    algorithm_W.fresh_set = false;
                    fresh_tip_lb.Hide();
                }
                else 
                {
                    algorithm_W.fresh_set = false;
                    fresh_tip_lb.Hide();
                }
            }
            catch (Exception)
            {

            }
        }
       
        string load_infor = "通道A";
        string GAC_kind = "";
        int air_volume_value = 250, ring_volume_value = 25;
        double liuliang_v = 0, yali_v = 0, dianya_v = 0;
        private void save_data_to_sql() ////结果数值存入数据库
        {
            string column_name = "";
            for (int k = 0; k < result_dataGridView.Rows.Count; k++)
            {
                column_name += "v_data" + (k + 1).ToString() + " , ";
            }
            column_name += "v_ring_volume,v_air_volume,v_liuliang,v_yali,v_dianya,v_date,v_kind_t";
            string column_value = "";
            for (int k = 0; k < result_dataGridView.Rows.Count; k++)
            {
                column_value += result_dataGridView.Rows[k].Cells[7].Value.ToString() + " , ";
            }
            
            column_value += ring_volume_value.ToString() + "," + air_volume_value.ToString() + "," + liuliang_v.ToString() + "," + yali_v.ToString() + "," + dianya_v.ToString() + "," + "'" + DateTime.Now.ToString() + "'" + ",'" + GAC_kind + "'";

            string ss = "";
            if (load_infor == "通道A")
            {
                ss = "insert into save_data0(" + column_name + ") Values(" + column_value + ")";
            }
            else if (load_infor == "通道B")
            {
                ss = "insert into save_data(" + column_name + ") Values(" + column_value + ")";
            }
            sql_Dataclass.Dataclass.Insert(ss);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           
        }
    }
}
