?
Solved

HOWTO Select ActiveReport @ runtime

Posted on 2009-04-18
8
Medium Priority
?
1,217 Views
Last Modified: 2012-05-06
I want to be able to select which ActiveReport to run at runtime. How can I do that?
rpt = New rptCustomerStatement 'How can I make this selectable?
rpt.DataSource =ds
rpt.Run(False)

Open in new window

0
Comment
Question by:JEFFCECCHINI
  • 5
  • 3
8 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 24178992
We're using Reflection -- basically, we have a tree that allows us to select the report based on a friendly name. Behind the scenes, we keep track of the mapping between friendly names and actual names.

Then, we use Reflection to get the actual report. One caveat with the code below: you need to fully qualify the name of the report class. In this case, I'm just returning it as an ActiveReport. In production, we actually inherit from a different base class that inherits form ActiveReport3 -- that's just because we want to add additional functionality.



    Public Function GetReport(ByVal sReportClassName As String) As DataDynamics.ActiveReports.ActiveReport3
        Dim ctrlAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
        If ctrlAssembly Is Nothing Then Return Nothing
 
        Dim tReportType As Type = ctrlAssembly.GetType(sReportClassName)
        If tReportType Is Nothing Then Return Nothing
 
        Dim types As New System.Collections.Generic.List(Of Type)
        Dim info As System.Reflection.ConstructorInfo = tReportType.GetConstructor(types.ToArray)
        Return CType(info.Invoke(Nothing), DataDynamics.ActiveReports.ActiveReport3)
    End Function

Open in new window

0
 

Author Comment

by:JEFFCECCHINI
ID: 24179438
Hi Chaosian,

Thanks for your reply. I think I understand what the Function above is doing. However, I got confused with your caviot and how to adapt your code to make it work 'in production'.

Q1. Could you Give me a simple example of the utilization of your function taking your caviot into consideration.?

I have sucessfully used AR3 in a web environment many times. But instead of creating a new web page for each AR report, I'm now trying to re-use the same web page but with url parameters to select which AR3 report gets streamed out a pdf. In waiting for a reply, I tried the following (simplified version of my code below) and it worked, but of course it takes advantage of late binding so I don't get intellisense working for me.

Q2. Would your method give me intellisense?
Q3. What advantage does your method have over mine?

Thanks for the help, Jeff
Public Class SomeWebPage
Private rpt as Object
 
Private Sub Button1_Click
 Select Case Request.QueryString("ReportName")
  Case "rptInvoice"
   rpt = New rptInvoice
  Case "rptCustomerStatement"
   rpt = New rptCustomerStatement
  Case Else
   SendError("Report Name NOT supported")
 End Select
 
 rpt.DataSource = ds
 ' Set some report parameters
 rpt.Run(False)
End Sub
End Class

Open in new window

0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 1000 total points
ID: 24180625
1. What I meant in the caveat is that, if your report is named MyReport, you need to refer to it by MyProject.MyReport... not as MyReport. This is particularly important if you're trying to grab a report from another project/DLL in your solution.

2. You can define rpt as an ActiveReport3, rather than as Object. This will give you some intellicrack.

3. In production, we're deploying a report server (basically a Windows service that puts together reports without bogging down client machines). By using Reflection to load the report from a DLL (which is only slightly different than the code I posted earlier), we can deploy new reports to our clients without having to take the service down.

As far as additional benefits, it depends on your needs. We've created a ReportBase that inherits from ActiveReport3. All our reports inherit from this ReportBase, allowing to inject additional common functionality, such as the ability to require certain parameters, to display controls to collect those parameters, etc.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:JEFFCECCHINI
ID: 24181485
Hi Chaosian,

Thank you for your replies.

1. Ok, I understand MyProject.MyReport... not as MyReport
2. I tried to replace Private rpt As Object with Private rpt as ActiveReport3, but the build failed because a Public Property of my report that I was trying to set (before rpt.Run) was not a member of ActiveReport3.
3. I tried your code but was unable to convert it properly to VB.Net 1.1. I'm not familiar with reflection, can you help..see code snippit.

Thanks so much, Jeff
Public Function GetReport(ByVal sReportClassName As String) As DataDynamics.ActiveReports.ActiveReport3
 
Dim ctrlAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
 
If ctrlAssembly Is Nothing Then Return Nothing
 
Dim tReportType As Type = ctrlAssembly.GetType(ctrlAssembly.GetName.Name & "." & sReportClassName)
 
If tReportType Is Nothing Then Return Nothing
'Dim types As New System.Collections.Generic.List(Of Type)
 Dim types() As System.Type
 
'Dim info As System.Reflection.ConstructorInfo = tReportType.GetConstructor(types.ToArray)
 
Dim info As System.Reflection.ConstructorInfo = tReportType.GetConstructor(types)
 
Return CType(info.Invoke(Nothing), DataDynamics.ActiveReports.ActiveReport3)
End Function

Open in new window

0
 

Author Comment

by:JEFFCECCHINI
ID: 24181686
Hi Chaosian,

I figured out how to get your code to work in ASP.Net VB/Net 1.1. I removed the types generic collection and after some time I figured out that I could use System.Type.EmptyTypes instead and it worked.

I like your method because it's completely dynamic. However, I still have the problem with not being able to set a custom property on the form.

I thought about your mention of you creating a base class for your AR's. That might work for me to solve my problem so I can utilize your solution, since for this these types of reports that custom property would be the same.

However, I tried to create a base AR and an inherited one but the inherited form's designer is grey & locked. I can't add any components to it design time, like label or textbox.created a form. Here's what I did, please let me know where I am off:

A.) I added a new AR, that has the Public property that I want common in all AR's and called in ARBaseClass.

B.) I added a new AR called SomeInheritedReport. I went to the code behind and changed the inherited statement to be Inherits ARBaseClass

C.) I saved the AR, closed the inherited AR, "ReBuild" project and opened back up the inherited AR.

You help to resolve this last thing would enable me to utilize your solution.

Thanks, Jeff
Public Function GetReport(ByVal sReportClassName As String) As DataDynamics.ActiveReports.ActiveReport3
        
Dim ctrlAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
 
If ctrlAssembly Is Nothing Then Return Nothing
 
Dim tReportType As Type = ctrlAssembly.GetType(ctrlAssembly.GetName.Name & "." & sReportClassName)
 
If tReportType Is Nothing Then Return Nothing
 
Dim info As System.Reflection.ConstructorInfo = tReportType.GetConstructor(System.Type.EmptyTypes)
 
Return CType(info.Invoke(Nothing), DataDynamics.ActiveReports.ActiveReport3)
End Function

Open in new window

0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 24183870
I don't see anything immediately wrong with what you did. Mind you're we're running in VS2008.

Give me a little while to see what I can find out for you.
0
 

Author Comment

by:JEFFCECCHINI
ID: 24238587
Hi Chaosian,

I'm just chekcing back with you to see if you found anything out about utilizing inheritance?

Thanks, Jeff
0
 

Author Closing Comment

by:JEFFCECCHINI
ID: 31571904
Chaosian answers helped get me somewhat further down the road with some tweaking, for which I am greatful to him, but I was disappointed that he did not followup with the question.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question