Question

Using C sharp, winforms, visual studio 2010, .NET 4 and devexpress API.

Hi guys I've recently attempted making a report using the devexpress xtreport control. It works fine and looks great, only problem is I need it to update during runtime.

The problem I have is when my controls are updated I need them to pass the values to my report, So far this Isn't working nor is my xtrachart on the report, nothing updates.

I'm wandering what I should call to update the entire report if there is such a method.

Reason I'm using text box values to put into the report is due to the display of the report never changing and the fact I'm using small amounts of data that gets processed within my winforms application.

Heres some code:

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;


    }
}

I realise this code needs a lot of clear up work since it could be made a lot neater and shorter, but this is temporary to test out if I can get a the report to work. Also please forgive the methods and variables with bad names, these are mapped on my design for my reference and will too be changed when this is completed and I can come up with some good names.

Many thanks.

copy of my report

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,);
    }

}
}

where should i put the create document??

Was it helpful?

Solution

Code to update report:

//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();

For more details and notes about CreateDocument() method visit DevExpress documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top