C#Devexpress,更新报告

时间:2012-03-15 08:58:51

标签: c# devexpress xtrareport

使用C sharp,winforms,visual studio 2010,.NET 4和devexpress API。

大家好,我最近尝试使用devexpress xtreport控件进行报告。   它运行良好,看起来很棒,唯一的问题是我需要它在运行时更新。

我遇到的问题是当我的控件更新时我需要他们将值传递给我的报告,到目前为止,这不起作用,也不是我的xtrachart报告,没有任何更新。

如果有这样的方法,我正在徘徊我应该更新整个报告的内容。

原因我正在使用文本框值放入报告中是因为报告的显示从未改变,而且我使用的是在winforms应用程序中处理的少量数据。

下面是一些代码:

public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
    DataTable chartTable3 = new DataTable("Table1");
    DataTable chartTable4 = new DataTable("Table2");
    DataTable chartTable5 = new DataTable("Table3");
    DataTable chartTable6 = new DataTable("Table4");
    public DevExpress.XtraReports.UI.XRChart xrChart1;

    public XtraReport1()
    {
        InitializeComponent();

    }

    public void branchname(string bname)
    {
        branch.Text = bname;
    }


    public void names(string pg1k, string pg2k, string pg3k, string pg4k)
    {
        Pg1.Text = pg1k;
        Pg2.Text = pg2k;
        Pg3.Text = pg3k;
        Pg4.Text = pg4k;
    }

    public void TotalSalesk(string totS)
    {
        Sales.Text = totS;
    }

    public void TotalQtyk(string totQ)
    {
        Qty.Text = totQ;
    }

    public void SelectedSales(string pg1S, string pg2S, string pg3S, string pg4S)
    {
        //xrLabel1.Text = label1;
        Pg1Sales.Text = pg1S;
        Pg2Sales.Text = pg2S;
        Pg3Sales.Text = pg3S;
        Pg4Sales.Text = pg4S;
    }

    public void SelectedQty(string pg1Q, string pg2Q, string pg3Q, string pg4Q)
    {
        Pg1Qty.Text = pg1Q;
        Pg2Qty.Text = pg2Q;
        Pg3Qty.Text = pg3Q;
        Pg4Qty.Text = pg4Q;
    }

    public void PgGrpPercent(string pg1P, string pg2P, string pg3P, string pg4P)
    {
        Pg1Perc.Text = pg1P;
        Pg2Perc.Text = pg2P;
        Pg3perc.Text = pg3P;
        Pg4perc.Text = pg4P;
    }

    public void PgTop50(string pg1t5, string pg2t5, string pg3t5, string pg4t5)
    {
        Pg1T50.Text = pg1t5;
        Pg2T50.Text = pg2t5;
        Pg3T50.Text = pg3t5;
        Pg4T50.Text = pg4t5;
    }

    public void PgTop100(string pg1t1, string pg2t1, string pg3t1, string pg4t1)
    {
        Pg1T100.Text = pg1t1;
        Pg2T100.Text = pg2t1;
        Pg3T100.Text = pg3t1;
        Pg4T100.Text = pg4t1;
    }

    public void PgTop200(string pg1t2, string pg2t2, string pg3t2, string pg4t2)
    {
        Pg1T200.Text = pg1t2;
        Pg2T200.Text = pg2t2;
        Pg3T200.Text = pg3t2;
        Pg4T200.Text = pg4t2;
    }

    public void PgOver(string pg1tO, string pg2tO, string pg3tO, string pg4tO)
    {
        Pg1Over.Text = pg1tO;
        Pg2over.Text = pg2tO;
        Pg3over.Text = pg3tO;
        Pg4over.Text = pg4tO;
    }

    public void CheckClear(bool checkme)
    {
        if (checkme == true)
        {
            //DevExpress.XtraReports.UI.XRChart xrChart1;
            chartTable3.Clear();
            chartTable3.Columns.Clear();
            chartTable4.Clear();
            chartTable4.Columns.Clear();
            chartTable5.Clear();
            chartTable5.Columns.Clear();
            chartTable6.Clear();
            chartTable6.Columns.Clear();
        }
    }

    public void myChartSeries1(double top, double tmid, double bmid, double bottom, string pgName, bool table)
    {
        //xrChart1.Series.Clear();


            // Add two columns to the table.
            chartTable3.Columns.Add("Names", typeof(string));
            chartTable3.Columns.Add("Value", typeof(Int32));
            chartTable3.Rows.Add("Below 50", top);
            chartTable3.Rows.Add("Between 50-100", tmid);
            chartTable3.Rows.Add("Between 100-200", bmid);
            chartTable3.Rows.Add("Greater than 200", bottom);

            Series series3 = new Series(pgName, ViewType.Bar);

            //.Series.Add(series1);
            series3.DataSource = chartTable3;

            series3.ArgumentScaleType = ScaleType.Qualitative;

            series3.ArgumentDataMember = "Names";  //error here

            series3.ValueScaleType = ScaleType.Numerical;

            series3.ValueDataMembers.AddRange(new string[] { "Value" });

            //series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;

            series3.LegendPointOptions.PointView = PointView.ArgumentAndValues;

            series3.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

            series3.LegendPointOptions.ValueNumericOptions.Precision = 0;
            xrChart1.Series.Add(series3);

            xrChart1.Legend.Visible = true;


    }

    public void myChartSeries2(double top, double tmid, double bmid, double bottom, string pgName, bool table)
    {

            // Add two columns to the table.
            chartTable4.Columns.Add("Names", typeof(string));
            chartTable4.Columns.Add("Value", typeof(Int32));
            chartTable4.Rows.Add("Below 50", top);
            chartTable4.Rows.Add("Between 50-100", tmid);
            chartTable4.Rows.Add("Between 100-200", bmid);
            chartTable4.Rows.Add("Greater than 200", bottom);

            Series series4 = new Series(pgName, ViewType.Bar);

            //.Series.Add(series1);
            series4.DataSource = chartTable4;

            series4.ArgumentScaleType = ScaleType.Qualitative;

            series4.ArgumentDataMember = "Names";

            series4.ValueScaleType = ScaleType.Numerical;

            series4.ValueDataMembers.AddRange(new string[] { "Value" });

            //series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;

            series4.LegendPointOptions.PointView = PointView.ArgumentAndValues;

            series4.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

            series4.LegendPointOptions.ValueNumericOptions.Precision = 0;
            xrChart1.Series.Add(series4);

            xrChart1.Legend.Visible = true;        
    }

    public void myChartSeries3(double top, double tmid, double bmid, double bottom, string pgName, bool table)
    {

            // Add two columns to the table.
            chartTable5.Columns.Add("Names", typeof(string));
            chartTable5.Columns.Add("Value", typeof(Int32));
            chartTable5.Rows.Add("Below 50", top);
            chartTable5.Rows.Add("Between 50-100", tmid);
            chartTable5.Rows.Add("Between 100-200", bmid);
            chartTable5.Rows.Add("Greater than 200", bottom);

            Series series5 = new Series(pgName, ViewType.Bar);

            //.Series.Add(series1);
            series5.DataSource = chartTable5;

            series5.ArgumentScaleType = ScaleType.Qualitative;

            series5.ArgumentDataMember = "Names";

            series5.ValueScaleType = ScaleType.Numerical;

            series5.ValueDataMembers.AddRange(new string[] { "Value" });

            //series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;

            series5.LegendPointOptions.PointView = PointView.ArgumentAndValues;

            series5.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

            series5.LegendPointOptions.ValueNumericOptions.Precision = 0;
            xrChart1.Series.Add(series5);

            xrChart1.Legend.Visible = true;


    }

    public void myChartSeries4(double top, double tmid, double bmid, double bottom, string pgName, bool table)
    {

            // Add two columns to the table.
            chartTable6.Columns.Add("Names", typeof(string));
            chartTable6.Columns.Add("Value", typeof(Int32));
            chartTable6.Rows.Add("Below 50", top);
            chartTable6.Rows.Add("Between 50-100", tmid);
            chartTable6.Rows.Add("Between 100-200", bmid);
            chartTable6.Rows.Add("Greater than 200", bottom);

            Series series6 = new Series(pgName, ViewType.Bar);

            //.Series.Add(series1);
            series6.DataSource = chartTable6;

            series6.ArgumentScaleType = ScaleType.Qualitative;

            series6.ArgumentDataMember = "Names";

            series6.ValueScaleType = ScaleType.Numerical;

            series6.ValueDataMembers.AddRange(new string[] { "Value" });

            //series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;

            series6.LegendPointOptions.PointView = PointView.ArgumentAndValues;

            series6.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

            series6.LegendPointOptions.ValueNumericOptions.Precision = 0;
            xrChart1.Series.Add(series6);

            xrChart1.Legend.Visible = true;


    }
}

我意识到这段代码需要大量的清理工作,因为它可以做得更整洁更短,但这是暂时的,可以测试我是否可以让报告工作。 还请原谅带有错误名称的方法和变量,这些方法和变量都映射在我的设计上供我参考,并且在完成后也会被更改,我可以想出一些好名字。

非常感谢。

我的报告副本

enter image description here

@reniuz

namespace RepSalesNetAnalysis
{
public partial class MyPrintPreviewForm : DevExpress.XtraEditors.XtraForm
{
    public MyPrintPreviewForm()
    {
        InitializeComponent();
    }

    XtraReport1 report = new XtraReport1();

    private void MyPrintPreviewForm_Load(object sender, EventArgs e)
    {
        printControl1.PrintingSystem = report.PrintingSystem;
        //creating document
        report.CreateDocument();
    }

    public void addSeries1(double top, double tmid, double bmid, double bottom, string pgName, bool table1)
    {
        //calling your method in report
        report.myChartSeries1(top, tmid, bmid, bottom, pgName, table1);
        //recreate document
        //report.CreateDocument();
    }

    public void addSeries2(double top, double tmid, double bmid, double bottom, string pgName, bool table2)
    {
        //calling your method in report
        report.myChartSeries2(top, tmid, bmid, bottom, pgName, table2);
        //recreate document
        //report.CreateDocument();
    }

    public void addSeries3(double top, double tmid, double bmid, double bottom, string pgName, bool table3)
    {
        //calling your method in report
        report.myChartSeries3(top, tmid, bmid, bottom, pgName, table3);
        //recreate document
        //report.CreateDocument();
    }

    public void addSeries4(double top, double tmid, double bmid, double bottom, string pgName, bool table4)
    {
        //calling your method in report
        report.myChartSeries4(top, tmid, bmid, bottom, pgName, table4);
        //recreate document
        //report.CreateDocument();
    }

    public void addBranchName(string BranchName)
    {
        report.branchname(BranchName);
    }

    public void addNames(string pg1k, string pg2k, string pg3k, string pg4k)
    {
        report.names(pg1k, pg2k, pg3k, pg4k);
    }

    public void addTotalSalesk(string totS)
    {
        report.TotalSalesk(totS);
    }

    public void addTotalQtyk(string totQ)
    {
        report.TotalQtyk(totQ);
    }

    public void addSelectedSales(string pg1S, string pg2S, string pg3S, string pg4S)
    {
        report.SelectedSales(pg1S, pg2S, pg3S, pg4S);
    }

    public void addSelectedQty(string pg1Q, string pg2Q, string pg3Q, string pg4Q)
    {
        report.SelectedQty(pg1Q, pg2Q, pg3Q, pg4Q);
    }

    public void addPgGrpPercent(string pg1P, string pg2P, string pg3P, string pg4P)
    {
        report.PgGrpPercent(pg1P, pg2P, pg3P, pg4P);
    }

    public void addPgTop50(string pg1t5, string pg2t5, string pg3t5, string pg4t5)
    {
        report.PgTop50(pg1t5, pg2t5, pg3t5, pg4t5);
    }

    public void addPgTop100(string pg1t1, string pg2t1, string pg3t1, string pg4t1)
    {
        report.PgTop100(pg1t1, pg2t1, pg3t1, pg4t1);
    }

    public void addpgTop200(string pg1t2, string pg2t2, string pg3t2, string pg4t2)
    {
        report.PgTop200(pg1t2, pg2t2, pg3t2, pg4t2);
    }

    public void addPgOver(string pg1tO, string pg2tO, string pg3tO, string pg4tO)
    {
        report.PgOver(pg1tO, pg2tO, pg3tO, pg4tO,);
    }

}
}

我应该把创建文档放在哪里?

1 个答案:

答案 0 :(得分:2)

更新报告的代码:

//XtraReport1 is your report
XtraReport1 report = new XtraReport1();
//Open print preview form
report.ShowPreview();

//Update your report content
report.myChartSeries2(1,2,3,4,DateTime.Now.ToShortTimeString());
//Recreate/update document in print preview 
report.CreateDocument();

有关CreateDocument()方法的更多详情和说明,请访问DevExpress documentation