double[] y   = new double[50];   //备纤衰耗,作为y轴
        public BeiXianShuaiHao()
        {
            InitializeComponent();
            try
            {
                #region 得到光纤链路表
                DBlink db = new DBlink();
                if (db.DBcon())      //填充Pname 数组 删除后显示combox1.text
                {
                    db.Get_route1(); //得到光纤链路名称
                }
                db.DBclose();

                // 已有节点显示下拉列表3.Items.Clear();//清空再刷新
                route_comboBox3.Items.Clear();
                for (int i = 0; i < route.route_list.Count; i++)
                {
                    route_comboBox3.Items.Add(route.route_list[i].ToString());
                }
                //   已有节点显示下拉列表3.Items.Add(point_data.pname[i].ToString());
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "error");
            }
        }
//选择线路
        private void route_comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                date1_comboBox1.Items.Clear();
                date2_comboBox1.Items.Clear();
                DBlink db = new DBlink();
                rn = route_comboBox3.Text;

                if (db.DBcon())       //填充日期
                {
                    db.Get_date1(rn); //得到某一线路光纤衰耗日期信息
                }
                db.DBclose();
                date1_comboBox1.Items.Clear();//清空日期再刷新
                date2_comboBox1.Items.Clear();
                for (int i = 0; i < date.dateset.Count; i++)
                {
                    date1_comboBox1.Items.Add(date.dateset[i]);
                    date2_comboBox1.Items.Add(date.dateset[i]);
                }
                // 已有节点显示下拉列表3.Items.Clear();//清空再刷新
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void RbtnSelectedcheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            // 添加线路
            DBlink db = new DBlink();

            if (db.DBcon())             //填充Pname 数组
            {
                db.Get_guzhang_route(); //得到故障线路
            }
            db.DBclose();
            route_comboBox1.Items.Clear();//需要修改
            int i;

            for (i = 0; i < guzhang.rn.Count; i++)
            {
                route_comboBox1.Items.Add(guzhang.rn[i].ToString());//添加线路名
            }
        }
        private void Route_comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            rn = route_comboBox1.Text;
            //添加年份
            DBlink db1 = new DBlink();

            if (db1.DBcon())     //填充Pname 数组
            {
                db1.GetYear(rn); //得到故障线路
            }
            db1.DBclose();
            year_comboBox1.Items.Clear();//

            for (int j = 0; j < guzhang.year.Count; j++)
            {
                year_comboBox1.Items.Add(guzhang.year[j].ToString());
            }
        }
        private void Frm_Child_Load(object sender, EventArgs e)
        {
            DBlink db = new DBlink();

            if (db.DBcon())             //填充Pname 数组
            {
                db.Get_guzhang_route(); //得到故障线路
            }
            db.DBclose();
            route_comboBox1.Items.Clear();//需要修改
            int i;

            for (i = 0; i < guzhang.rn.Count; i++)
            {
                route_comboBox1.Items.Add(guzhang.rn[i].ToString());//添加线路名
            }
            this.WindowState = FormWindowState.Maximized;
        }
        private void Barchart_Click(object sender, EventArgs e) //选择全部线路
        {
            route_comboBox1.Enabled = false;                    //选择框不可选
            single_or_all           = true;                     //当选择全部线路时,single_or_all为true

            //添加年份
            DBlink db1 = new DBlink();

            if (db1.DBcon())   //填充Pname 数组
            {
                db1.GetYear(); //得到故障线路
            }
            db1.DBclose();
            year_comboBox1.Items.Clear();//

            for (int j = 0; j < guzhang.year.Count; j++)
            {
                year_comboBox1.Items.Add(guzhang.year[j].ToString());
            }
        }
        private void Btn_beixian_Click(object sender, EventArgs e)
        {
            chart1.Visible = true;
            label3.Visible = true;
            try
            {
                chart1.Series.Clear();          //每次输入之后清空
                Series ser = new Series(rn);    // 实例化序列图对象
                ser.IsValueShownAsLabel = true; //显示每个节点信息

                chart1.Series.Add(ser);         //向chart1中添加序列对象

                #region 数据库连接操作,得到日期差值和光功率数值
                DBlink db1 = new DBlink();
                if (db1.DBcon())
                {
                    db1.Get_datediff(time2, time1); //输入线路名,得到对应的光功率和日期
                }
                db1.DBclose();
                DBlink db = new DBlink();
                if (db.DBcon())
                {
                    db.Get_Beixian(rn, time1, time2);//输入线路名,起止时间得到对应的光功率和日期
                }
                db.DBclose();
                #endregion
                rqcz = date.rqcz[0] + 1;              //得到选中的日期差值 比如10月20日与10月19
                for (int i = 0; i < rqcz; i++)        //统计日期的个数
                {
                    x[i] = (DateTime)date.dateset[i]; //日期
                    y[i] = date.beixian[i];           //将光功率赋给y轴
                    sum  = sum + y[i];
                }
                //预测部分 得到预测的光功率值
                for (int i = 0; i < rqcz; i++)//rqcz=7 x[0-6] x[7] y[7]预测
                {
                    ser.Points.AddXY(x[i], y[i]);
                }//向xy轴添加元素}
                avg = sum / rqcz;



                chart1.Series[0].ChartType = SeriesChartType.Spline; //第一条样条图类型
                                                                     //设置标题
                chart1.Titles[0].Text      = string.Format("{0}备线衰耗值显示", rn);
                chart1.Titles[0].ForeColor = Color.RoyalBlue;
                chart1.Titles[0].ForeColor = Color.RoyalBlue;
                if (avg > 3)
                {
                    MessageBox.Show("备纤状态异常,可能出现拉伸、弯曲,请检查备纤!");
                }
                else
                {
                    if (avg > 10)
                    {
                        MessageBox.Show("光缆已经断了,请前去排除故障!");
                    }
                    else
                    {
                        MessageBox.Show("光缆平均备纤衰耗值:" + avg);
                    }
                }
            }
            catch (System.Exception ex)
            { }
        }
        private void RbtnPie_CheckedChanged(object sender, EventArgs e) //
        {
            if (!single_or_all)                                         //绘制单条线路上的数据
            {
                guzhang_bar_chart.Visible = false;
                guzhang_pie_chart.Visible = true;
                double s = 0; //总
                              //List<String> xData = new List<String>();//故障类型就5种
                              //List<Double> yData = new List<Double>();
                double[] sum          = new double[5];
                double[] pro          = new double[5];
                string[] guzhang_Type = new string[] { "断裂", "拉伸", "接头盒进水", "异常", "其他" };
                double[] yData        = new double[5];//故障类型的数量5中

                DBlink db = new DBlink();
                if (db.DBcon())
                {
                    db.Gettype_count(rn, year);//输入线路名得到故障类型和数目
                }
                db.DBclose();

                for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                {
                    sum[i] = double.Parse(guzhang.count[i].ToString()); //得到故障数量
                                                                        //  guzhang_Type[i] = guzhang.guzhang_type[i].ToString();//
                                                                        //textBox1.Text= guzhang.guzhang_type[i].ToString();
                                                                        //guzhang_Type[i] =guzhangtype_comboBox1.Items[i].ToString();//此处不能赋值
                }
                guzhang.guzhang_type.CopyTo(guzhang_Type);
                for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                {
                    s += sum[i];
                }
                for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                {
                    pro[i] = sum[i] * (1 / s);

                    yData[i] = double.Parse(pro[i].ToString("0.00"));
                }
                guzhang_pie_chart.Series[0].Points.DataBindXY(guzhang_Type, yData);
                guzhang_pie_chart.Series[0]["PieLabelStyle"] = "Outside"; //将文字移到外侧
                guzhang_pie_chart.Series[0]["PieLineColor"]  = "Black";   //绘制黑色的连线。
            }
            if (single_or_all)                                            //绘制全部线路
            {
                guzhang_bar_chart.Visible = false;
                guzhang_pie_chart.Visible = true;
                double s = 0; //总
                              //List<String> xData = new List<String>();//故障类型就5种
                              //List<Double> yData = new List<Double>();
                double[] sum          = new double[5];
                double[] pro          = new double[5];
                string[] guzhang_Type = new string[5];
                double[] yData        = new double[5];//故障类型的数量5中

                DBlink db = new DBlink();
                if (db.DBcon())
                {
                    db.Gettype_count(year);//输入线路名得到故障类型和数目
                }
                db.DBclose();

                for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                {
                    sum[i] = double.Parse(guzhang.count[i].ToString()); //得到故障数量
                                                                        //  guzhang_Type[i] = guzhang.guzhang_type[i].ToString();//
                                                                        //textBox1.Text= guzhang.guzhang_type[i].ToString();
                                                                        //guzhang_Type[i] =guzhangtype_comboBox1.Items[i].ToString();//此处不能赋值
                }
                guzhang.guzhang_type.CopyTo(guzhang_Type);              //将 ArrayList中guzhang.guzhang_type复制到数组guzhang_Type

                for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                {
                    s += sum[i];
                }
                for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                {
                    pro[i] = sum[i] * (1 / s);

                    yData[i] = double.Parse(pro[i].ToString("0.00"));
                }
                guzhang_pie_chart.Series[0].Points.DataBindXY(guzhang_Type, yData);
            }
        }//用饼状图实现年份故障类型分析
        private void DataAnalysis_Click(object sender, EventArgs e)
        {
            if (!single_or_all)      //如果选择某条线路
            {
                if (rbtnBar.Checked) //当选择柱状图时
                {
                    DataTable dt1 = default(DataTable);
                    dt1 = Create_DataTable(rn); //返回值给dt1//调用
                                                //设置图表数据源
                    guzhang_bar_chart.DataSource = dt1;
                    //绑定数据
                    guzhang_bar_chart.DataBind();
                }

                if (rbtnPie.Checked)
                {
                    double s = 0; //总
                                  //List<String> xData = new List<String>();//故障类型就5种
                                  //List<Double> yData = new List<Double>();
                    double[] sum          = new double[5];
                    double[] pro          = new double[5];
                    string[] guzhang_Type = new string[5];
                    double[] yData        = new double[5];//故障类型的数量5中

                    DBlink db = new DBlink();
                    if (db.DBcon())
                    {
                        db.Gettype_count(rn, year);//输入线路名得到故障类型和数目
                    }
                    db.DBclose();

                    for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                    {
                        sum[i] = double.Parse(guzhang.count[i].ToString()); //得到故障数量
                                                                            //  guzhang_Type[i] = guzhang.guzhang_type[i].ToString();//
                                                                            //textBox1.Text= guzhang.guzhang_type[i].ToString();
                                                                            //guzhang_Type[i] =guzhangtype_comboBox1.Items[i].ToString();//此处不能赋值
                    }
                    guzhang.guzhang_type.CopyTo(guzhang_Type);
                    for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                    {
                        s += sum[i];
                    }
                    for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                    {
                        pro[i]   = sum[i] * (1 / s);
                        yData[i] = double.Parse(pro[i].ToString("0.00"));
                    }
                    guzhang_pie_chart.Series[0].Points.DataBindXY(guzhang_Type, yData);
                }
            }

            if (single_or_all)       //如果选择所有线路
            {
                if (rbtnBar.Checked) //当选择柱状图时
                {
                    DataTable dt1 = default(DataTable);
                    dt1 = Create_DataTable(); //返回值给dt2//调用
                                              //设置图表数据源
                    guzhang_bar_chart.DataSource = dt1;
                    //绑定数据
                    guzhang_bar_chart.DataBind();
                }

                if (rbtnPie.Checked)
                {
                    double s = 0; //总
                                  //List<String> xData = new List<String>();//故障类型就5种
                                  //List<Double> yData = new List<Double>();
                    double[] sum          = new double[5];
                    double[] pro          = new double[5];
                    string[] guzhang_Type = new string[5];
                    double[] yData        = new double[5];//故障类型的数量5中

                    DBlink db = new DBlink();
                    if (db.DBcon())
                    {
                        db.Gettype_count(year);//输入线路名得到故障类型和数目
                    }
                    db.DBclose();

                    for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                    {
                        sum[i] = double.Parse(guzhang.count[i].ToString()); //得到故障数量
                                                                            //  guzhang_Type[i] = guzhang.guzhang_type[i].ToString();//
                                                                            //textBox1.Text= guzhang.guzhang_type[i].ToString();
                                                                            //guzhang_Type[i] =guzhangtype_comboBox1.Items[i].ToString();//此处不能赋值
                    }
                    guzhang.guzhang_type.CopyTo(guzhang_Type);              //将 ArrayList中guzhang.guzhang_type复制到数组guzhang_Type

                    for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                    {
                        s += sum[i];
                    }
                    for (int i = 0; i < guzhang.guzhang_type.Count; i++)
                    {
                        double tmp = 1 / s;
                        pro[i]   = sum[i] * tmp;
                        yData[i] = double.Parse(pro[i].ToString("0.00"));
                    }
                    guzhang_pie_chart.Series[0].Points.DataBindXY(guzhang_Type, yData);
                }
            }
        }
        private DataTable Create_DataTable()//11-9-2125选择全部线路柱状图
        {
            //创建一个dataTable chart 的数据源
            DataTable dt1 = new DataTable();

            dt1.Columns.Add("日期");//添加5列数据
            dt1.Columns.Add("断裂");
            dt1.Columns.Add("拉伸");
            dt1.Columns.Add("进水");
            dt1.Columns.Add("异常");
            dt1.Columns.Add("其他");            //添加5列
            double[] month = new double[100]; //月份
            double[] date1 = new double[100];
            string[] type  = new string[100];

            double  resultmonth = 0;
            DataRow dr;

            //添加行数据
            //连接数据库
            DBlink db = new DBlink();

            if (db.DBcon())
            {
                db.Getmonth_guzhang(year);//输入线路名得到故障日期和类型
            }
            db.DBclose();
            for (int i = 0; i < guzhang.date.Count; i++)
            {
                date1[i] = guzhang.date[i];                    //获得月份
                type[i]  = guzhang.guzhang_type[i].ToString(); //获得对应的故障类型
            }

            DBlink db1 = new DBlink();

            if (db1.DBcon())
            {
                db1.Getmonth(year);//输入线路名得到故障日期月份
            }
            db1.DBclose();
            for (int i = 0; i < guzhang.date.Count; i++)
            {
                month[i] = guzhang.date[i];//7 8 9 10 11
            }
            double[] num = new double[] { 0, 0, 0, 0, 0 };

            for (int k = 0; k < month.Length; k++)     //已有月份month[0,1,2]=8,9,10
            {
                for (int i = 0; i < date1.Length; i++) //与实际对比
                {
                    if (month[k] == date1[i])          //比如date1[0]==month[0]=8
                    {
                        resultmonth = month[k];
                        string type1 = type[i]; //type[0]=断裂
                        switch (type1)          //某一月份的故障类型统计
                        {
                        case "断裂":              //断裂
                            num[0]++;
                            break;

                        case "拉伸":
                            num[1]++;
                            break;

                        case "接头盒进水":
                            num[2]++;
                            break;

                        case "异常":
                            num[3]++;
                            break;

                        case "其他":
                            num[4]++;
                            break;
                        }
                    }
                }

                dr       = dt1.NewRow();
                dr["日期"] = month[k] + "月"; //8,9,10月}
                dr["断裂"] = num[0];
                dr["拉伸"] = num[1];
                dr["进水"] = num[2];
                dr["异常"] = num[3];
                dr["其他"] = num[4];
                dt1.Rows.Add(dr);
                for (int i = 0; i < 5; i++)
                {
                    num[i] = 0;
                }
            }

            return(dt1);
        }