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

Report Table Help

6 Answers 280 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Fabio
Top achievements
Rank 1
Fabio asked on 25 May 2020, 12:39 AM

Hi everyone!

I'm trying to design a report in the Visual Studio integrated designer but I don't quite understand how to use the table object...

I have a query in a DAO object in my program that is doing a very complicated transaction to fetch the necessary data to plug into the table...

how can I either add row by row the data with a variable number of rows or bind something like a datatable object to the table in the report?

the wizard asks me to input sql connection strings and stuff but I don't want to do that. I have a class that is taking care of the interactions with the various databases and tables needed to build the full report...

I used JasperReports before and I could just pass to the report builder a hashmap (something like a dictionary in C#) with the object as key and the value bound to that key and it worked flawlessly can I do something like that here too?

Otherwise I may just have to ditch this reporting mechanism and make a jar to launch on the side... I really would love to avoid that because until now the whole telerik suite has been a breeze to work with...

 

thanks for any help!

 

Fabio

6 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 27 May 2020, 03:49 PM

Hello Fabio,

From the description of the issue, I assume that you use a SqlDataSource component for your Table. It requests a connection string while setting it up with the wizard.

You may use an ObjectDataSource component instead. It supports IEnumerable, DataTable, custom business objects, etc. Generally, you may prepare your custom class that will return the data and set the name of the class as DataSource for the ObjectDataSource component, and the method that will return the data as DataMember of the component. The Reporting engine will use System.Reflection to invoke the logic run-time to fetch the data. Note that you may pass parameters to the DataMember - Using Parameters with the ObjectDataSource Component.

Regards,
Todor
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Fabio
Top achievements
Rank 1
answered on 28 May 2020, 03:57 PM

Hi thanks for your answer :)

I honestly cannot understand... it's not your fault it's probably me...

I have a query that used to output a hashmap... it now outputs a dictionary because I moved my code from Java to C#.

Essentially my table needs to be variable in length up to 25 rows and when exceeding needs to go to new page...

My dictionary is generated programmatically and contains a big number of data considering that the production cycle contains upwards of 50 pieces each with a set of parameters and the common treatment parameters on the side...

I need to be able to say to my report something like:

report.setDataSource(LocalDAO.getInstance().prepareReportData());

and have this blackbox of a method parse over the data from the dictionary to the report table.

In the table each row is a piece and in my dictionary every piece has his descriptions each having for key the name of the parameter ending with the piece number ranging from 1 to 25. It's a Dictionary<string, string>.

 

Do you possibly have a code snippet or something where I can understand how to programmatically add rows to the table and possibly format the content? I don't want a class containing what essentially would be 25*8 text fields.... seems a little excessive...

 

Thanks for your help...

 

Fabio

0
Todor
Telerik team
answered on 02 Jun 2020, 10:40 AM

Hi Fabio,

We provide plenty of sample code for the ObjectDataSource component. Here are some relevant links:

Generally, the table will be rendered with as many rows as there are data records in the table DataSource. You may group the data by a specific Expression. For example, if you introduce an Index in the data fields, you will be able to group by '=Fields.Index / 25', which will split the data into groups of 25 rows.

If you prefer to create a report programmatically, you may use our Visual Studio Report Designer to create a report, and then to check its code that is in the InitializeComponent method of the ReportName.designer.cs file.

Regards,
Todor
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Fabio
Top achievements
Rank 1
answered on 19 Jun 2020, 02:29 PM
ObjectDataSource objectDataSource = new ObjectDataSource();
objectDataSource.DataSource = LocalDAO.getInstance().getActualCharge();
 
AgingReport report = new AgingReport();
 
(report.Items.Find("piecesTable", true)[0] as Table).DataSource = objectDataSource;
 
InstanceReportSource reportSource = new InstanceReportSource();
reportSource.ReportDocument = report;
 
using (SaveFileDialog dlg = new SaveFileDialog())
{
       if (dlg.ShowDialog() == DialogResult.OK)
       {
              Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
                    Telerik.Reporting.Processing.RenderingResult renderingResult = reportProcessor.RenderReport("PDF", reportSource, null);
 
                    FileStream fs = new FileStream(dlg.FileName, FileMode.Create);
                    fs.Write(renderingResult.DocumentBytes, 0, renderingResult.DocumentBytes.Length);
                    fs.Close();
        }
}

 

Hi sorry for being so late but had a lot of meat on the fire XD

So I tried to follow the examples and I kinda understand how it should be done.

The snippet I included is the method I use to save the report to PDF.

I know that inside the datasource there is data...  a lot of it... like 20 rows or something...

But PDF is as white as it can be...

What can it be?

0
Fabio
Top achievements
Rank 1
answered on 21 Jun 2020, 08:46 PM

btw I am using the integrated designer in Visual Studio. it's the main reason I wanted to use telerik because I was tired of using an external tool I wanted my project to be fully enclosed let's say.

Anyway still having problem I did a few more tests but no solutions... :(

0
Fabio
Top achievements
Rank 1
answered on 22 Jun 2020, 10:35 AM
I managed to do it quite nicely :) if anyone needs the code I'll post it here just ask :)
Tags
General Discussions
Asked by
Fabio
Top achievements
Rank 1
Answers by
Todor
Telerik team
Fabio
Top achievements
Rank 1
Share this question
or