Esempio n. 1
0
        /// <summary>
        /// 采用分组方式配置数据源
        /// </summary>
        /// <param name="Aim">数据源</param>
        private void SetGroupData(DataTable Aim)
        {
            if (this.Apperence != null && this.Apperence.SeriesList != null && this.Apperence.SeriesList.Count > 0)
            {
                //是否绑定数据源,绑定的数据源是否存在
                if (string.IsNullOrEmpty(GroupSource.MajorBinding))
                {
                    PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error("未绑定分组-主分类字段!");
                    return;
                }
                if (string.IsNullOrEmpty(GroupSource.ValueBinding))
                {
                    PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error("未绑定分组-统计字段!");
                    return;
                }
            }
            ArrayList columnList = new ArrayList();

            if (!Aim.Columns.Contains(GroupSource.MajorBinding))
            {
                if (GroupSource.MajorBinding.EndsWith("_Year"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Year");
                }
                else if (GroupSource.MajorBinding.EndsWith("Month"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Month");
                }
                else if (GroupSource.MajorBinding.EndsWith("Day"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Day");
                }
                else if (GroupSource.MajorBinding.EndsWith("Hour"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Hour");
                }
                else if (GroupSource.MajorBinding.EndsWith("Minute"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Minute");
                }
                else if (GroupSource.MajorBinding.EndsWith("Second"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Second");
                }
                else
                {
                    return;
                }
            }

            string strValueFx;

            switch (GroupSource.ValueFx)
            {
            case Functions.Count:
                strValueFx = "count";
                break;

            case Functions.Sum:
                strValueFx = "sum";
                break;

            case Functions.Avg:
                strValueFx = "avg";
                break;

            case Functions.Max:
                strValueFx = "max";
                break;

            case Functions.Min:
                strValueFx = "min";
                break;

            default:
                strValueFx = "";
                break;
            }

            DataSetHelper ds            = new DataSetHelper();
            DataTable     tbMajorSerise = new DataTable();
            DataTable     tbMinorSerise = new DataTable();
            DataTable     tbMajor       = Aim.DefaultView.ToTable(true, GroupSource.MajorBinding);

            if (GroupSource.MajorSort == SortType.Asc)
            {
                tbMajor.DefaultView.Sort = GroupSource.MajorBinding + " Asc";
                tbMajor = tbMajor.DefaultView.ToTable();
            }
            if (GroupSource.MajorSort == SortType.Desc)
            {
                tbMajor.DefaultView.Sort = GroupSource.MajorBinding + " Desc";
                tbMajor = tbMajor.DefaultView.ToTable();
            }
            tbMajorSerise = ds.SelectGroupByInto(Aim.TableName, Aim, GroupSource.MajorBinding + "," + strValueFx + "(" + GroupSource.ValueBinding + ")", "1=1", GroupSource.MajorBinding);

            if (!string.IsNullOrEmpty(GroupSource.MinorBinding))
            {
                if (!Aim.Columns.Contains(GroupSource.MinorBinding))
                {
                    if (GroupSource.MinorBinding.EndsWith("_Year"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Year");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Month"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Month");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Day"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Day");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Hour"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Hour");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Minute"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Minute");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Second"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Second");
                    }
                    else
                    {
                        return;
                    }
                }

                DataTable tbMinor = Aim.DefaultView.ToTable(true, GroupSource.MinorBinding);
                if (GroupSource.MinorSort == SortType.Asc)
                {
                    tbMinor.DefaultView.Sort = GroupSource.MinorBinding + " Asc";
                    tbMinor = tbMinor.DefaultView.ToTable();
                }
                if (GroupSource.MinorSort == SortType.Desc)
                {
                    tbMinor.DefaultView.Sort = GroupSource.MinorBinding + " Desc";
                    tbMinor = tbMinor.DefaultView.ToTable();
                }

                foreach (DataRow row in tbMajor.Rows)
                {
                    if (row[0] != DBNull.Value)
                    {
                        tbMinorSerise.Merge(ds.SelectGroupByInto(GroupSource.MajorBinding, Aim, GroupSource.MinorBinding + "," + strValueFx + "(" + GroupSource.ValueBinding + ")", GroupSource.MajorBinding + "='" + row[0].ToString() + "'", GroupSource.MinorBinding));
                    }
                    else
                    {
                        tbMinorSerise.Merge(ds.SelectGroupByInto(GroupSource.MajorBinding, Aim, GroupSource.MinorBinding + "," + strValueFx + "(" + GroupSource.ValueBinding + ")", GroupSource.MajorBinding + " is null ", GroupSource.MinorBinding));
                    }
                }
            }

            OriginPosition = new Point(this.Location.X, this.Location.Y);
            if (this.DesignMode == true)
            {
                DrawVirtualChart();
            }
            else if (Aim == null || Aim.Rows.Count == 0)
            {
                DrawVirtualChart();
            }
            else
            {
                try
                {
                    Legend legend1 = new Legend();
                    //if (this._Apperence != null && this._Apperence.SeriesList != null && this._Apperence.SeriesList.Count > 0)
                    //{
                    //    //是否绑定数据源,绑定的数据源是否存在
                    //    this._Apperence.SeriesList[0].SetSeriesValue(series1);
                    //    if (string.IsNullOrEmpty(series1.GetCustomProperty("XBindingField")))
                    //    {
                    //        PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(Properties.Resources.ResourceManager.GetString("message0016"));
                    //        return;
                    //    }
                    //    if (!Aim.Columns.Contains(series1.GetCustomProperty("XBindingField")))
                    //    {
                    //        PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(Properties.Resources.ResourceManager.GetString("message0017"));
                    //        return;
                    //    }
                    //}

                    InitChart();
                    //绑定绘图区
                    if (this.Apperence.ChartAreaList.Count != 0)
                    {
                        ChartArea ChartArea1 = new ChartArea("ChartArea1");
                        this.Apperence.ChartAreaList[0].SetChartAreaStyle(ChartArea1);
                        ChartArea1.InnerPlotPosition.Auto = true;
                        ChartArea1.Position.Auto          = true;
                        chart1.ChartAreas.Add(ChartArea1);

                        if (!string.IsNullOrEmpty(GroupSource.MinorBinding))
                        {
                            ChartArea ChartArea2 = new ChartArea("ChartArea2");
                            this.Apperence.ChartAreaList[0].SetChartAreaStyle(ChartArea2);
                            ChartArea2.InnerPlotPosition.Auto = true;
                            ChartArea2.Position.Auto          = false;
                            //--临时给定一个坐标,绘制的时候重新赋值
                            ChartArea2.Position.Height = 0;
                            ChartArea2.Position.Width  = 0;
                            ChartArea2.Position.X      = 0;
                            ChartArea2.Position.Y      = 0;
                            //--
                            ChartArea2.BorderColor        = Color.Transparent;
                            ChartArea2.BorderDashStyle    = ChartDashStyle.NotSet;
                            ChartArea2.BorderWidth        = 0;
                            ChartArea2.BackColor          = Color.Transparent;
                            ChartArea2.BackSecondaryColor = Color.Transparent;
                            ChartArea2.BackHatchStyle     = ChartHatchStyle.None;
                            ChartArea2.BackGradientStyle  = GradientStyle.None;
                            chart1.ChartAreas.Add(ChartArea2);
                        }
                    }
                    //绑定标题
                    if (this.Apperence.TitleList.Count != 0)
                    {
                        foreach (PMSTitle item in this.Apperence.TitleList)
                        {
                            Title title1 = new Title();
                            item.SetTitle(title1);
                            chart1.Titles.Add(title1);
                        }
                    }
                    //绑定图例
                    if (this.Apperence.LegendList.Count != 0)
                    {
                        this.Apperence.LegendList[0].SetLegend(legend1);
                    }
                    //绑定数据
                    if (this.Apperence.SeriesList.Count != 0)
                    {
                        //this.Apperence.SeriesList[0].SetSeriesValue(series1);
                        //for (int i = 0; i < Aim.Rows.Count; i++)
                        //{
                        //    Xvalues.Add(Aim.Rows[i][series1.GetCustomProperty("XBindingField")].ToString());
                        //    Yvalues.Add(Convert.ToDouble(Aim.Rows[i][series1.GetCustomProperty("YBindingField")]));
                        //}

                        //if (Xvalues.Count != 0 && Yvalues.Count != 0)
                        //{
                        //    series1.Points.DataBindXY(Xvalues, Yvalues);
                        //}

                        Series series1 = new Series(tbMajorSerise.TableName);
                        this.Apperence.SeriesList[0].SetSeriseStyle(series1);
                        List <string> Xvalues1 = new List <string>();
                        List <double> Yvalues1 = new List <double>();
                        for (int i = 0; i < tbMajorSerise.Rows.Count; i++)
                        {
                            Xvalues1.Add(tbMajorSerise.Rows[i][0].ToString());
                            Yvalues1.Add(Convert.ToDouble(tbMajorSerise.Rows[i][1]));
                        }

                        if (Xvalues1.Count != 0 && Yvalues1.Count != 0)
                        {
                            series1.Points.DataBindXY(Xvalues1, Yvalues1);
                        }
                        series1.ChartType = (SeriesChartType)ChartType;
                        if (ChartType == PieChartType.Doughnut)
                        {
                            series1.SetCustomProperty("DoughnutRadius", (100.0 / 3.0 + 1.0).ToString());
                        }
                        series1.ChartArea = "ChartArea1";
                        chart1.Series.Add(series1);

                        if (!string.IsNullOrEmpty(GroupSource.MinorBinding))
                        {
                            Series series2 = new Series(tbMinorSerise.TableName);
                            this.Apperence.SeriesList[0].SetSeriseStyle(series2);
                            List <string> Xvalues2 = new List <string>();
                            List <double> Yvalues2 = new List <double>();
                            for (int i = 0; i < tbMinorSerise.Rows.Count; i++)
                            {
                                Xvalues2.Add(tbMinorSerise.Rows[i][0].ToString());
                                Yvalues2.Add(Convert.ToDouble(tbMinorSerise.Rows[i][1]));
                            }

                            if (Xvalues2.Count != 0 && Yvalues2.Count != 0)
                            {
                                series2.Points.DataBindXY(Xvalues2, Yvalues2);
                            }
                            series2.ChartType = (SeriesChartType)ChartType;
                            if (ChartType == PieChartType.Doughnut)
                            {
                                series2.SetCustomProperty("DoughnutRadius", (100.0 / 2.0).ToString());
                            }
                            series2.ChartArea = "ChartArea2";
                            chart1.Series.Add(series2);
                        }
                    }
                    chart1.Legends.Add(legend1);
                    if (this.Apperence.PMSChartAppearance != null)
                    {
                        chart1.BorderlineColor     = this.Apperence.PMSChartAppearance.BorderlineColor;
                        chart1.BorderlineDashStyle = this.Apperence.PMSChartAppearance.BorderlineDashStyle;
                        chart1.BorderlineWidth     = this.Apperence.PMSChartAppearance.BorderlineWidth;
                        chart1.BackColor           = this.Apperence.PMSChartAppearance.BackColor;
                        chart1.BackSecondaryColor  = this.Apperence.PMSChartAppearance.BackSecondaryColor;
                        chart1.BackHatchStyle      = this.Apperence.PMSChartAppearance.BackHatchStyle;
                        chart1.BackGradientStyle   = this.Apperence.PMSChartAppearance.BackGradientStyle;
                    }
                }
                catch (System.Exception ex)
                {
                    InitChart();
                    PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(ex.Message);
                }
            }
            tbMajorSerise.Dispose();
            tbMinorSerise.Dispose();
            foreach (var item in columnList)
            {
                Aim.Columns.Remove(item.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 采用分组方式配置数据源
        /// </summary>
        /// <param name="Aim">数据源</param>
        private void SetGroupData(DataTable Aim)
        {
            if (this.Apperence != null && this.Apperence.SeriesList != null && this.Apperence.SeriesList.Count > 0)
            {
                //是否绑定数据源,绑定的数据源是否存在
                if (string.IsNullOrEmpty(GroupSource.MajorBinding))
                {
                    PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error("未绑定分组-主分类字段!");
                    return;
                }
                if (string.IsNullOrEmpty(GroupSource.ValueBinding))
                {
                    PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error("未绑定分组-统计字段!");
                    return;
                }
            }
            ArrayList columnList = new ArrayList();

            if (!Aim.Columns.Contains(GroupSource.MajorBinding))
            {
                if (GroupSource.MajorBinding.EndsWith("_Year"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Year");
                }
                else if (GroupSource.MajorBinding.EndsWith("Month"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Month");
                }
                else if (GroupSource.MajorBinding.EndsWith("Day"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Day");
                }
                else if (GroupSource.MajorBinding.EndsWith("Hour"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Hour");
                }
                else if (GroupSource.MajorBinding.EndsWith("Minute"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Minute");
                }
                else if (GroupSource.MajorBinding.EndsWith("Second"))
                {
                    CreateSplitDateFiled(Aim, GroupSource.MajorBinding, columnList, "Second");
                }
                else
                {
                    return;
                }
            }

            string strValueFx;

            switch (GroupSource.ValueFx)
            {
            case Functions.Count:
                strValueFx = "count";
                break;

            case Functions.Sum:
                strValueFx = "sum";
                break;

            case Functions.Avg:
                strValueFx = "avg";
                break;

            case Functions.Max:
                strValueFx = "max";
                break;

            case Functions.Min:
                strValueFx = "min";
                break;

            default:
                strValueFx = "";
                break;
            }

            DataSetHelper    ds      = new DataSetHelper();
            List <DataTable> dtList  = new List <DataTable>();
            DataTable        tbMajor = Aim.DefaultView.ToTable(true, GroupSource.MajorBinding);

            if (GroupSource.MajorSort == SortType.Asc)
            {
                tbMajor.DefaultView.Sort = GroupSource.MajorBinding + " Asc";
                tbMajor = tbMajor.DefaultView.ToTable();
            }
            if (GroupSource.MajorSort == SortType.Desc)
            {
                tbMajor.DefaultView.Sort = GroupSource.MajorBinding + " Desc";
                tbMajor = tbMajor.DefaultView.ToTable();
            }
            if (!string.IsNullOrEmpty(GroupSource.MinorBinding))
            {
                if (!Aim.Columns.Contains(GroupSource.MinorBinding))
                {
                    if (GroupSource.MinorBinding.EndsWith("_Year"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Year");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Month"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Month");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Day"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Day");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Hour"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Hour");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Minute"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Minute");
                    }
                    else if (GroupSource.MinorBinding.EndsWith("Second"))
                    {
                        CreateSplitDateFiled(Aim, GroupSource.MinorBinding, columnList, "Second");
                    }
                    else
                    {
                        return;
                    }
                }

                DataTable tbMinor = Aim.DefaultView.ToTable(true, GroupSource.MinorBinding);
                if (GroupSource.MinorSort == SortType.Asc)
                {
                    tbMinor.DefaultView.Sort = GroupSource.MinorBinding + " Asc";
                    tbMinor = tbMinor.DefaultView.ToTable();
                }
                if (GroupSource.MinorSort == SortType.Desc)
                {
                    tbMinor.DefaultView.Sort = GroupSource.MinorBinding + " Desc";
                    tbMinor = tbMinor.DefaultView.ToTable();
                }

                foreach (DataRow row in tbMinor.Rows)
                {
                    if (row[0] != DBNull.Value)
                    {
                        dtList.Add(ds.SelectGroupByInto(row[0].ToString(), Aim, GroupSource.MajorBinding + "," + strValueFx + "(" + GroupSource.ValueBinding + ")", GroupSource.MinorBinding + "='" + row[0].ToString() + "'", GroupSource.MajorBinding));
                    }
                    else
                    {
                        dtList.Add(ds.SelectGroupByInto(row[0].ToString(), Aim, GroupSource.MajorBinding + "," + strValueFx + "(" + GroupSource.ValueBinding + ")", GroupSource.MinorBinding + " is null ", GroupSource.MajorBinding));
                    }
                }
            }
            else
            {
                dtList.Add(ds.SelectGroupByInto(Aim.TableName, Aim, GroupSource.MajorBinding + "," + strValueFx + "(" + GroupSource.ValueBinding + ")", "1=1", GroupSource.MajorBinding));
            }


            OriginPosition = new Point(this.Location.X, this.Location.Y);
            if (this.DesignMode == true)
            {
                DrawVirtualChart();
            }
            else if (Aim == null || Aim.Rows.Count == 0)
            {
                DrawVirtualChart();
            }
            else
            {
                try
                {
                    ChartArea ChartArea1 = new ChartArea("ChartArea1");
                    Legend    legend1    = new Legend();

                    InitChart();
                    //绑定绘图区
                    if (this.Apperence.ChartAreaList.Count != 0)
                    {
                        this.Apperence.ChartAreaList[0].SetChartArea(ChartArea1);
                    }
                    //绑定标题
                    if (this.Apperence.TitleList.Count != 0)
                    {
                        foreach (PMSTitle item in this.Apperence.TitleList)
                        {
                            Title title1 = new Title();
                            item.SetTitle(title1);
                            chart1.Titles.Add(title1);
                        }
                    }
                    //绑定图例
                    if (this.Apperence.LegendList.Count != 0)
                    {
                        this.Apperence.LegendList[0].SetLegend(legend1);
                    }
                    //绑定数据
                    if (this.Apperence.SeriesList.Count != 0)
                    {
                        foreach (DataTable dt in dtList)
                        {
                            Series series1 = new Series(dt.TableName);
                            this.Apperence.SeriesList[0].SetSeriseStyle(series1);
                            List <string> Xvalues = new List <string>();
                            List <double> Yvalues = new List <double>();
                            for (int i = 0; i < tbMajor.Rows.Count; i++)
                            {
                                Xvalues.Add(tbMajor.Rows[i][0].ToString());
                                Yvalues.Add(0);
                                for (int j = 0; j < dt.Rows.Count; j++)
                                {
                                    if (tbMajor.Rows[i][0].ToString() == dt.Rows[j][0].ToString())
                                    {
                                        Yvalues[i] = Convert.ToDouble(dt.Rows[j][1]);
                                    }
                                }
                            }

                            if (Xvalues.Count != 0 && Yvalues.Count != 0)
                            {
                                series1.Points.DataBindXY(Xvalues, Yvalues);
                            }
                            series1.ChartType = (SeriesChartType)ChartType;
                            chart1.Series.Add(series1);
                        }
                    }

                    chart1.ChartAreas.Add(ChartArea1);
                    chart1.Legends.Add(legend1);
                    if (this.Apperence.PMSChartAppearance != null)
                    {
                        chart1.BorderlineColor     = this.Apperence.PMSChartAppearance.BorderlineColor;
                        chart1.BorderlineDashStyle = this.Apperence.PMSChartAppearance.BorderlineDashStyle;
                        chart1.BorderlineWidth     = this.Apperence.PMSChartAppearance.BorderlineWidth;
                        chart1.BackColor           = this.Apperence.PMSChartAppearance.BackColor;
                        chart1.BackSecondaryColor  = this.Apperence.PMSChartAppearance.BackSecondaryColor;
                        chart1.BackHatchStyle      = this.Apperence.PMSChartAppearance.BackHatchStyle;
                        chart1.BackGradientStyle   = this.Apperence.PMSChartAppearance.BackGradientStyle;
                    }
                }
                catch (System.Exception ex)
                {
                    InitChart();
                    PMS.Libraries.ToolControls.PMSPublicInfo.Message.Error(ex.Message);
                }
            }
            foreach (var item in columnList)
            {
                Aim.Columns.Remove(item.ToString());
            }
        }