Telerik CsvDataSource - how do I find it?

Posted by goo on 04-Feb-2015 06:54

I have played around with the Telerik.Reporting class, but because of poor knowledge within OO I find it a bit tricky. Could someone explain to me how I can find the csvDataSource I have added to my csvtest.trdx report? I have made a report in the designer, added a csvDataSource1 that has csvDataSource1:Source = "file:///C:/Users/Temp/slettme.csv".

In my class, I have: and it works swell to view the report. Now I want to be able to change the path for my report to something else than what I have added in the report. How do I find the csvdatasource in play?

THIS-OBJECT:reportViewer1 = NEW Telerik.ReportViewer.WinForms.ReportViewer().
THIS-OBJECT:SuspendLayout().
/* */
/* reportViewer1 */
/* */
THIS-OBJECT:reportViewer1:Dock = System.Windows.Forms.DockStyle:Fill.
THIS-OBJECT:reportViewer1:Location = NEW System.Drawing.Point(0, 0).
THIS-OBJECT:reportViewer1:Name = "reportViewer1".
THIS-OBJECT:reportViewer1:Size = NEW System.Drawing.Size(421, 400).
THIS-OBJECT:reportViewer1:TabIndex = 0.
THIS-OBJECT:reportViewer1:Load:Subscribe(THIS-OBJECT:reportViewer1_Load_1).
/* */
/* slettme */
/* */
THIS-OBJECT:ClientSize = NEW System.Drawing.Size(421, 400).
THIS-OBJECT:Controls:Add(THIS-OBJECT:reportViewer1).
THIS-OBJECT:Name = "slettme".
THIS-OBJECT:Text = "slettme".



METHOD PRIVATE VOID reportViewer1_Load_1( INPUT sender AS System.Object, INPUT e AS System.EventArgs )::

RDS = new Telerik.Reporting.UriReportSource().
RDS:Uri = search("reports/csvtest.trdx").
this-object:reportViewer1:ReportSource = RDS.
THIS-OBJECT:reportViewer1:refreshreport().

return.

END.


All Replies

Posted by Bill Wood on 04-Feb-2015 07:15

Interesting post.   I am going to make sure someone from the Telerik Reporting team takes a look at this.... I don't think they are currently actively monitoring this forum, even though some of them have been playing with OpenEdge.

While I am doing that, I would be interested in what problem you are trying to solve using the Telerik Reporting .NET viewer in OpenEdge GUI4.NET.    Deploying the Reporting Viewer in ABL .NET Forms is a use case that seems very appealing and you have noted one key point -- that you want to set the ReportSource programatically from the ABL (rather than using the reportSource attribute).  So good job there!

But would you mind sharing the use case, and what you are thinking about, and what you want to report on?

Thanks in advance.

Posted by goo on 04-Feb-2015 07:40

I have made my first CSV report in Telerik, and finds it very appealing to work with. It was easy to make groups and work with numbers etc. Now I have made a class that gives me a reportviewer in a ABL form. Very cool to implement into my progress world. As a start, I would like to produce a file with the correct layout, and fill it with my report data. For that reason I need to chance the file-name that was used in the Report Designer. Of course I can edit the .trdx file and change the filename in there, but it should be possible to do it in another way :-)

my .trdx file.......

<Report DataSourceName="csvDataSource1" Width="6.5in" Name="slettmeg" SnapGridSize="0.1cm" xmlns="schemas.telerik.com/.../3.7">

 <DataSources>

   <CsvDataSource RecordSeparators="&#xD;&#xA;" FieldSeparators="," Name="csvDataSource1">

     <Source>

       <Uri Path="file:///C:/Users/Temp/slettme2.csv" />

     </Source>

     <Columns>

       <DataColumn Name="Column1" Type="Integer" />

       <DataColumn Name="Column2" />

       <DataColumn Name="Column3" />

       <DataColumn Name="Column4" Type="Decimal" />

:

:

Posted by Bill Wood on 04-Feb-2015 07:51

WRT
>> I have made my first CSV report in Telerik, and finds it very appealing to work with.
 
Thanks.  That was a use case I had not considered – mostly I have thought about going to OE DB and/or using the POCO (Plain-old-C-Objects) to access AppServer logic.   I was not thinking about generalized usage for other source.
 
WRT

>> I need to change the file-name that was used in the Report Designer. Of course I can edit the .trdx file and change the filename in there, but it should be possible to do [this programmatically]

I will pass this on and get someone from Progress to answer (I was going to say “someone from Telerik”, but they are from “Progress” as well, now).

 

Posted by Bill Wood on 04-Feb-2015 08:05

(I was able to get a quick turnaround on the answer -- I am repeating it 'verbatim', and it is not ABL-ready code -- so I hope you can translate.....)

Hi goo,

You have a report definition that is in trdx format. Your requirement is to change the definition at runtime a little bit in some way. In order to do that you need to

  1. first load the report definition as a report instance – an instance of the Telerik.reporting.Report class.
  2. Then you may use the Telerik.Reporting API to to tweak the report
  3. and then pass it as an InstanceReportSource to the report viewer.

Sample 1

See the code below as an example how to deserialize the report trdx definition (note that all code samples are written in CSharp) (source: http://www.telerik.com/help/reporting/programmatic-xml-serialization.html):

System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();

settings.IgnoreWhitespace = true;
 
using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create
("Report1.xml", settings)) { Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer(); Telerik.Reporting.Report report = (Telerik.Reporting.Report) xmlSerializer.Deserialize(xmlReader); }

Sample 2

Now that you have the report instance use the reporting API to modify the data source (http://www.telerik.com/help/reporting/p_telerik_reporting_csvdatasource_source.html):

 

var csvDataSource = (CsvDataSource)report.DataSource;

csvDataSource.Source = new Uri(“C:\Users\Temp\slettme.csv”)

Sample 3

Then pass the modified report instance to the report viewer control and refresh the rendered report:

Telerik.Reporting.InstanceReportSource instanceReportSource =
    new Telerik.Reporting.InstanceReportSource();

 
// Assigning the Report object to the InstanceReportSource

instanceReportSource.ReportDocument = report;

 
this.reportViewer1.ReportSource = instanceReportSource;

this.reportViewer1.Refreshreport();



 

Hope that helps.

There is another approach which will require much easier modification of the csv path – in the definition to change the path to the csv to be an expression like

= Parameters.CsvPath

And add such report parameter to the report definition. Then in the viewer setup code you may use UriReportSource with parameter value.

See http://www.telerik.com/help/reporting/report-sources-viewers.html

Posted by goo on 04-Feb-2015 08:09

Cool ! I will check it out…
 

Posted by goo on 04-Feb-2015 08:40

I want to do the Sample 2, but struggling…
 
var csvDataSource = (CsvDataSource)report.DataSource;
 
csvDataSource.Source = new Uri(“C:\Users\Temp\slettme.csv”)
 
 
 
  DEFINE PUBLIC  VARIABLE myCsvDataSource AS Telerik.Reporting.CsvDataSource NO-UNDO.
I am not able to do this:
  DEFINE PUBLIC  VARIABLE myDataSource AS Telerik.Reporting.DataSource NO-UNDO.
It complains when I try to use DataSource… giving me some abstract problems.
 
I thought that UriReportSource is for the predefined report and not the DataSource ? It will contain references to DataSource…
    RDS = new Telerik.Reporting.UriReportSource().
    RDS:Uri = search("reports/csvtest.trdx").
    this-object:reportViewer1:ReportSource = RDS.
 
For CsvDataSource I thought Source was the parameter that contained info about the filename? Now I am defiantly confused ….
 
//Geir Otto
 
 

Posted by goo on 04-Feb-2015 10:08

I changed the .trdx file by using XML parser hDoc:load("FILE".....)...... but after hDoc:Save("FILE"....) it changed this line:

 <DataSources>

   <CsvDataSource RecordSeparators="&#xD;&#xA;" FieldSeparators="," Name="csvDataSource1">

:

:

to this:

 <DataSources>

   <CsvDataSource FieldSeparators="," Name="csvDataSource1" RecordSeparators="

">

AS you can see, some characters has been removed from RecordSeparators... how can I get around that?

Posted by Bill Wood on 05-Feb-2015 02:18

The tricky translation here is the CAST from Telerik.Reporting.Report.DataSource to Telerik.Reporting.Report.CvsDataSource.

Telerik.Reporting.Report report = (Telerik.Reporting.Report)  
xmlSerializer.Deserialize(xmlReader); var csvDataSource = (CsvDataSource)report.DataSource;


This is done with a CAST () in ABL.  (see http://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/cast-function.html)

If you are looking for a quick way to get started without learning OOABL, then you might want to consider this.

This is not the most technically elegant solution, but it occurs to me you could have the .trdx file point to "report.cvs", and you could use ABL to overwrite the report.cvs every time (or copy from an existing file) rather than trying to manipulate it.   

Posted by elkin on 05-Feb-2015 02:24

Hi goo,

No need to parse the report definition XML manually. Instead deserialize the report instance (Sample 1), modify the in-memory report definition instance (Sample 2) and pass this instance to the viewer (Sample 3). Once you have a live instance of the report, you use InstanceReportSource to feed the viewer instead of the UriReportSource.

In Sample 2 you need to CAST the reports' data source to CsvDataSource as the DataSource property of the report is of type Telerik.Reporting.DataSource so that different data sources may be used. However you know that in yuor particular report the data source is actually CsvDataSource and you need to change one particular property of that CsvDataSurce.

So the line

var csvDataSource = (CsvDataSource)report.DataSource;

should be translated into ABL to

DEFINE PUBLIC  VARIABLE csvDataSource AS Telerik.Reporting.CsvDataSource NO-UNDO.

csvDataSource = CAST(report:DataSource, CsvDataSource)

Hope this helps.

Milen

Posted by goo on 05-Feb-2015 09:55

I got it to work by doing the following under. I had to do some stuff since the SAVE() removed or destroyed it. Now I am able to change the filename and it works as I wanted…. But not that sexy J
 
//Geir Otto
 
 
Fra: Bill Wood [mailto:bounce-wood@community.progress.com]
Sendt: 5. februar 2015 09:19
Til: TU.OE.Development@community.progress.com
Emne: RE: [Technical Users - OE Development] Telerik CsvDataSource - how do I find it?
 
Reply by Bill Wood

The tricky translation here is the CAST from Telerik.Reporting.Report.DataSource to Telerik.Reporting.Report.CvsDataSource.

Telerik.Reporting.Report report = (Telerik.Reporting.Report)  xmlSerializer.Deserialize(xmlReader);
 
var csvDataSource = (CsvDataSource)report.DataSource;


This is done with a CAST () in ABL.  (see http://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/cast-function.html)

If you are looking for a quick way to get started without learning OOABL, then you might want to consider this.

This is not the most technically elegant solution, but it occurs to me you could have the .trdx file point to "report.cvs", and you could use ABL to overwrite the report.cvs every time (or copy from an existing file) rather than trying to manipulate it.   

Stop receiving emails on this subject.

Flag this post as spam/abuse.


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5646 / Virus Database: 4273/9047 - Release Date: 02/02/15

Posted by goo on 05-Feb-2015 09:57

Thanks !! I will check it out.
 
//Geir Otto
 
Fra: elkin [mailto:bounce-elkin@community.progress.com]
Sendt: 5. februar 2015 09:25
Til: TU.OE.Development@community.progress.com
Emne: RE: [Technical Users - OE Development] Telerik CsvDataSource - how do I find it?
 
Reply by elkin

Hi goo,

No need to parse the report definition XML manually. Instead deserialize the report instance (Sample 1), modify the in-memory report definition instance (Sample 2) and pass this instance to the viewer (Sample 3). Once you have a live instance of the report, you use InstanceReportSource to feed the viewer instead of the UriReportSource.

In Sample 2 you need to CAST the reports' data source to CsvDataSource as the DataSource property of the report is of type Telerik.Reporting.DataSource so that different data sources may be used. However you know that in yuor particular report the data source is actually CsvDataSource and you need to change one particular property of that CsvDataSurce.

So the line

var csvDataSource = (CsvDataSource)report.DataSource;

should be translated into ABL to

DEFINE PUBLIC  VARIABLE csvDataSource AS Telerik.Reporting.CsvDataSource NO-UNDO.

csvDataSource = CAST(report:DataSource, CsvDataSource)

Hope this helps.

Milen

Stop receiving emails on this subject.

Flag this post as spam/abuse.


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5646 / Virus Database: 4273/9047 - Release Date: 02/02/15

Posted by goo on 05-Feb-2015 15:03

Sorry, I feel like OO dummy, anyway, I find it a bit strange that you can CAST DataSource into csvDataSource?
 

DEFINE PUBLIC  VARIABLE myReport          AS Telerik.Reporting.Report NO-UNDO.

DEFINE PUBLIC  VARIABLE csvDataSource AS Telerik.Reporting.CsvDataSource NO-UNDO.

myReport = new Telerik.Reporting.Report().

csvDataSource = new Telerik.Reporting.csvDataSource().

csvDataSource = CAST(myReport:DataSource, CsvDataSource).

This will not compile…. So I probably should use the kind of strange solution that I got to work.

 

Anyway, thanks for trying to make me understand J

 

//Geir Otto

 

Posted by Bill Wood on 06-Feb-2015 00:07

Can you share the error message?   I am wondering if you have the correct "USING" statement.   The code above where you CAST (myReportDataSource, CsvDataSource) only works if the namespace for CsvDataSource can be resolved.  

The full class name is "Telerik.Reporting.CsvDataSource"

There is a section in the OpenEdge online documentation in this: C# .NET code mapped to OpenEdge GUI for .NET ABL

You want to look at the section on Casting.   Approximately, your code should look like.

USING Telerik.Reporting.*.

DEFINE PUBLIC VAR myReport AS Report NO-UNDO.
DEFINE PUBLIC VAR csvDataSource AS CsvDataSource NO-UNDO.

myReport = new Report().
csvDataSource = CsvDataSource().

csvDataSource = CAST(myReport:DataSource, CsvDataSource).


(Note: in your cut/pasted code, you also had referred to the CvsDataSource CLASS as 'Telerik.Reporting.cvsDataSource" with different capitalization.    For .NET components, the case is important. [Clarification -- I was told after the post that ABL does not require matching capitalization for .NET classes -- .NET Classes are treated as case-insensitive EXCEPT for the first reference.  The first reference does need to identify the class and package by name 'correctly' with the same Case as the .NET definition.]:    

If you could share the error, it might point to which one of the above problems you were running into.)

Posted by Bill Wood on 06-Feb-2015 02:57

FYI...  on the last post I had incorrectly talked about case-sensitivity.   For .NET Classes, the ABL is case-insensitive.  You don't need to match the case when you reference classes.

(Also, I noted a few typos in my code sample which I corrected.)

Posted by Mike Fechner on 06-Feb-2015 03:07

Hi Bill, to be precise… the first time you reference a .NET class name in an ABL compile unit (.p/.cls) you have to be case-sensitive. From there on the ABL relaxes this requirement.
 
 
Von: Bill Wood [mailto:bounce-wood@community.progress.com]
Gesendet: Freitag, 6. Februar 2015 09:59
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] Telerik CsvDataSource - how do I find it?
 
Reply by Bill Wood

FYI...  on the last post I had incorrectly talked about case-sensitivity.   For .NET Classes, the ABL is case-insensitive.  You don't need to match the case when you reference classes.

(Also, I noted a few typos in my code sample which I corrected.)

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by goo on 06-Feb-2015 06:18

  DEFINE PUBLIC  VARIABLE myDataSource AS Telerik.Reporting.CsvDataSource NO-UNDO.
  DEFINE PUBLIC  VARIABLE report AS Telerik.Reporting.Report NO-UNDO.
:
:
    report = new Telerik.Reporting.Report().
    myDataSource = new Telerik.Reporting.CsvDataSource().
    myDataSource = CAST(report:DataSource, myDataSource).
    myDataSource:Source = new Uri("c:\Users\Temp\slettme2.csv").
 
This is how I understood what you said. This will not work. It says:
 
 

Posted by Mike Fechner on 06-Feb-2015 06:22

The cast is wrong:
 
    myDataSource = CAST(report:DataSource, myDataSource).
 
Try:
 
    myDataSource = CAST(report:DataSource, Telerik.Reporting.CsvDataSource).
 
The second argument of the CAST needs to be a class name.
 
 
Von: goo [mailto:bounce-goo@community.progress.com]
Gesendet: Freitag, 6. Februar 2015 13:19
An: TU.OE.Development@community.progress.com
Betreff: [Technical Users - OE Development] SV: Telerik CsvDataSource - how do I find it?
 
Reply by goo
  DEFINE PUBLIC  VARIABLE myDataSource AS Telerik.Reporting.CsvDataSource NO-UNDO.
  DEFINE PUBLIC  VARIABLE report AS Telerik.Reporting.Report NO-UNDO.
:
:
    report = new Telerik.Reporting.Report().
    myDataSource = new Telerik.Reporting.CsvDataSource().
    myDataSource = CAST(report:DataSource, myDataSource).
    myDataSource:Source = new Uri("c:\Users\Temp\slettme2.csv").
 
This is how I understood what you said. This will not work. It says:
 
Fra: Bill Wood [mailto:bounce-wood@community.progress.com]
Sendt: 6. februar 2015 07:09
Til: TU.OE.Development@community.progress.com
Emne: RE: [Technical Users - OE Development] Telerik CsvDataSource - how do I find it?
 
Reply by Bill Wood

Can you share the error message?   I am wondering if you have the correct "USING" statement.   The code above where you CAST (myReportDataSource, CsvDataSource) only works if the namespace for CsvDataSource can be resolved.  

The full class name is "Telerik.Reporting.CsvDataSource"

There is a section in the OpenEdge online documentation in this: C# .NET code mapped to OpenEdge GUI for .NET ABL

You want to look at the section on Casting.   Approximately, your code should look like.

USING Telerik.Reporting.
 
DEFINE PUBLIC VAR myReport Report NO-UNDO.
DEFINE PUBLIC VAR csvDataSource AS CsvDataSource NO-UNDO.
 
myReport = new Report().
csvDataSource = CsvDataSource().
 
csvDataSource = CAST(myReport:DataSource, CsvDataSource).


(Note: in your cut/pasted code, you also had referred to the CvsDataSource CLASS as 'Telerik.Reporting.cvsDataSource" with different capitalization.    For .NET components, the case is important.  If you could share the error, it might point to which one of the above problems you were running into.)

Stop receiving emails on this subject.

Flag this post as spam/abuse.


No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5646 / Virus Database: 4273/9047 - Release Date: 02/02/15
Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by Bill Wood on 06-Feb-2015 06:25

Thanks for the error message.

The issue is that you are trying to use CAST (object, class) with two objects.  The second paramter is not the 'instance', but the class reference.   Thjis is definitely not 'obvious' if you are not used to OOABL programming and .NET.

You had:

myDataSource = CAST(report:DataSource, myDataSource).    

You want:

myDataSource = CAST(report:DataSource, Telerik.Reporting.CvsDataSource).

The code sample in the forum post earlier shows a more complete sample (Look at in in a browser, The content was edited after the post so the email content is out of date)

Posted by elkin on 06-Feb-2015 08:09

Hi,

I am catching up with the ABL syntax, so here is a runnable tested ABL version of the originally provided code (Sample 1, 2, 3)

Note that you need to replace the actual paths to your report definition and runtime csv data.


        /* Deserialize the report instance from the report definition trdx */        
        DEFINE VARIABLE xmlSettings AS System.Xml.XmlReaderSettings.
        xmlSettings = NEW System.Xml.XmlReaderSettings().
        xmlSettings:IgnoreWhitespace = TRUE.
        DEFINE VARIABLE xmlReader AS System.Xml.XmlReader.
        xmlReader = System.Xml.XmlReader:Create("C:\Work\Research\trdx\CsvReport.trdx", xmlSettings).
        DEFINE VARIABLE xmlSerializer AS Telerik.Reporting.XmlSerialization.ReportXmlSerializer.
        xmlSerializer = NEW Telerik.Reporting.XmlSerialization.ReportXmlSerializer().
        DEFINE VARIABLE reportInstance AS Telerik.Reporting.Report.
        reportInstance = CAST(xmlSerializer:Deserialize(xmlReader), Telerik.Reporting.Report).
        xmlReader:Dispose().

        /* Modify the report instance as needed */
        
        DEFINE VARIABLE csvDataSource AS Telerik.Reporting.CsvDataSource.
        csvDataSource = CAST(reportInstance:DataSource, Telerik.Reporting.CsvDataSource).
        csvDataSource:Source = NEW System.Uri("C:\Work\Research\trdx\ds.txt").
        
        
        /* Use the modified in-memory report definition in my app */
        DEFINE VARIABLE instanceReportSource AS Telerik.Reporting.InstanceReportSource.
        instanceReportSource = NEW Telerik.Reporting.InstanceReportSource().
        instanceReportSource:ReportDocument = reportInstance.
        THIS-OBJECT:reportViewer1:ReportSource = instanceReportSource.
        THIS-OBJECT:reportViewer1:RefreshReport().


Hope this helps.

Milen

This thread is closed