This is a migrated thread and some comments may be shown as answers.

Add parameters programmatically for printing report

5 Answers 1260 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Inge
Top achievements
Rank 1
Inge asked on 07 Feb 2017, 02:48 PM

I'm trying to set my parameters trough my WPF application and after print my report. The printing works but the parameters are empty.

var report = new Badge();
 
report.ReportParameters["VisitId"].Value = code;
report.ReportParameters["VisitorName"].Value = visitorName;
report.ReportParameters["CompanyName"].Value = companyName;
report.ReportParameters["RegularVisitor"].Value = regularVisitor ? "REGULAR" : "VISITOR";
 
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrinterName = ConfigurationManager.AppSettings["PrinterNameLabel"]);
 
PrintController standardPrintController = new StandardPrintController();
ReportProcessor reportProcessor = new ReportProcessor();
reportProcessor.PrintController = standardPrintController;
TypeReportSource typeReportSource = new TypeReportSource();
 
typeReportSource.TypeName = report.GetType().AssemblyQualifiedName;
 
reportProcessor.PrintReport(typeReportSource, printerSettings);

 

As attached file my parameter settings. Any ideas? Thanks for the help

 

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 09 Feb 2017, 03:28 PM
Hello Inge,

Once the type name of the report is passed to the TypeReportSource, a new instance of the Badge report will be created internally by the reporting engine.

Thus, you need to set the report parameters via the TypeReportSource object, and not via the report instance. This way they will be passed correctly to the report:

var typeReportSource = new Telerik.Reporting.TypeReportSource();
 
// Specifying the assembly qualified name of the Report class for the TypeName of the report source
typeReportSource.TypeName = typeof(Invoice).AssemblyQualifiedName;
 
// Adding the initial parameter values
typeReportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber", "SO43659"));


Regards,
Nasko
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Inge
Top achievements
Rank 1
answered on 10 Feb 2017, 07:27 AM
Thanks for the help! This solution made it work.
0
Inge
Top achievements
Rank 1
answered on 13 Feb 2017, 09:27 AM

Is it possible to do the same for a list of objects? For example insert this list into rows for a table: 

public static void PrintVisitList(List<Visit> visits)
        {
            try
            {
                //print en report objects
                PrinterSettings printerSettings = new PrinterSettings();
                PrintController standardPrintController = new StandardPrintController();
                ReportProcessor reportProcessor = new ReportProcessor();
                TypeReportSource typeReportSource = new TypeReportSource();
 
                //set printersettings
                printerSettings.PrinterName = ConfigurationManager.AppSettings["PrinterNameLabel"];
                reportProcessor.PrintController = standardPrintController;
                // Specifying the assembly qualified name of the Report class for the TypeName of the report source
                typeReportSource.TypeName = typeof(VisitList).AssemblyQualifiedName;
 
                //Adding data
                foreach (var visit in visits)
                {
                    VisitList.tblVisitorsRow row = ds.tblVisitors.NewtblVisitorsRow();
                    row.VisitorKey = visit.VisitId;
                    row.Arrival = visit.Arrival;
                    row.FirstName = visit.FirstName;
                    row.LastName = visit.LastName;
                    row.CompanyName = visit.CompanyName;
                    row.PhoneMobile = visit.PhoneMobile;
                    row.VehicleLicensePlate = visit.VehicleLicensePlate;
                    row.AppointmentWith = visit.AppointmentWith;
 
                    ds.tblVisitors.Rows.Add(row);
                }
 
                //print command
                reportProcessor.PrintReport(typeReportSource, printerSettings);
            }
            catch (Exception ex)
            {
                LogRepository.AddLog(new Log
                {
                    Data = ex.InnerException?.Message ?? ex.Message
                });
            }
        }

 

For example the foreach loop?

0
Accepted
Stef
Telerik team
answered on 15 Feb 2017, 02:43 PM
Hi Inge,

In your code snippet you are updating data at run-time. This will require you to modify the report before processing it and to use an InstanceReportSource instead of the TypeReportSource.

For example:
//create an instance of the report that can be modified
var reportInstance = new VisitList();
reportInstance.DataSource=ds.tblVisitors;
//or if data is visualized by a nested data item like a Table/List/Crosstab
//(reportInstance.Items.Find("table1",true) as Telerik.Reporting.Table).DataSource = ds.tblVisitors;
 
//use an InstanceReportSource to wrap the modified report instance
var IRS = new InstanceReportSource { ReportDocument = reportInstance};


Report parameters' values can be updated through the report instance's ReprotParameters collection or the InstanceReportSource.Parameters collection.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Inge
Top achievements
Rank 1
answered on 17 Feb 2017, 07:18 AM

Thanks for the help but the find won't work for me. I fixed it this way:

//create an instance of the report that can be modified
                var reportInstance = new VisitList
                {
                    //add visitlist
                    table1 = {DataSource = visits}
                };
 
                //use an InstanceReportSource to wrap the modified report instance
                var instanceReportSource = new InstanceReportSource { ReportDocument = reportInstance };

 

Problem solved for me!

Tags
General Discussions
Asked by
Inge
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Inge
Top achievements
Rank 1
Stef
Telerik team
Share this question
or