Monday, August 1, 2011

USE CRL To Display Subreports

DataDynamics Reports expects that the RDLX for a Main Report and a SubReport exist in the same physical location on the File System. But many a times, we may need to pull up the SubReport from a different location or probably from a database \ memory. The ResourceLocator Class within the DataDynamics.Reports.Extensibility namespace can be used to implement the same. We would need to :-

1)    Create a new Class inheriting the ResourceLocator class.
2)    Use code to check the ResourceName (the subreport) being looked for and return the valid subreport object through a MemoryStream or something similar.
C#:-

Using DataDynamics.Reports.Extensibility;

Using (var _stream = GetType ().Assembly.GetManifestResourceStream (GetType (), "MainReport.rdlx"))
            {
                using (var _reader = new StreamReader (_stream))
                {
                    var _report = new ReportDefinition (_reader);
                    _report. ResourceLocator = new SubReportResourceLocator();
                    this.reportViewer.OpenReport (_report, "Test");
                   
                }
            }
Class SubReportResourceLocator: ResourceLocator
    {

        Public override Resource GetResource (ResourceInfo resourceInfo)
        {
            Resource _resource;
            if (resourceInfo.Name.Equals("SubReport.rdlx"))
            {
                byte[] _buffer = System.Text.UTF8Encoding.UTF8.GetBytes (File.ReadAllText("../../SubReport.txt"));
              
                MemoryStream _ms = new MemoryStream (_buffer);
               
               
                if (_ms != null)
                {
                    _resource = new Resource (_ms, new Uri ("C :\\"));
                }
            }

            return _resource;
        }


VB.NET:-
Using _stream = [GetType]().Assembly.GetManifestResourceStream([GetType](), "MainReport.rdlx")
            Using _reader = New StreamReader (_stream)
                Dim _report = New ReportDefinition (_reader)
                _report. ResourceLocator = New SubReportResourceLocator ()    Me.ReportViewer.OpenReport (_report, "Test")
            End Using
        End Using

Public Class SubReportResourceLocator
    Inherits ResourceLocator
 Public Overrides Function GetResource (ByVal resourceInfo As DataDynamics.Reports.Extensibility. ResourceInfo) As DataDynamics.Reports.Extensibility. Resource
        Dim _resource As Resource
        If resourceInfo.Name.Equals ("SubReport.rdlx") Then
            Dim _buffer As Byte () = System.Text.UTF8Encoding.UTF8.GetBytes (File.ReadAllText ("../../SubReport.txt"))
         Dim _ms As New MemoryStream (_buffer)
         If _ms IsNot Nothing Then
                _resource = New Resource(_ms, New Uri("C:\"))
            End If
        End If

        Return _resource
    End Function
End Class

Thursday, May 26, 2011

How to Draw a Pie Chart out of your Data using DataDynamics Reports

One of the different charting types provided in the DataDynamics Report is the Pie chart. Essentially,a pie chart would be used to display a summary of your
data in a pie . For instance, you have a Table with Country, Sales1, Sales2, Sales3 as columns of data. Now you might want to draw a pie chart out of the Sum of Sales1, Sum of Sales2,Sum of Sales3. You may follow the below mentioned steps to implement the same.

1) Drop in a Chart reportitem to the body of the report.
2) Chage the ChartType by right click on the chart->ChartType->pie->
3) For each column that you want to add to the pie chart,right click on the section(at the top)that says Drop Data Fields here and click on add.
4) Now you will need to assign values to this Data Fields that you have added.Set the value of the data field(->right click on the data field->edit->value)
to something as =Sum(Field!Sales1.Value),=Sum(Field!Sales3.Value),=Sum(Field!Sales3.Value)

Now if you preview the RDLX you would see the pie chart drawn.But it will lack the data values being displayed in the chart. In order to show them as well you will need to use the series labels. For this once again:-

1) Right click on the data fields added->edit->Series Values Labels->check the cross mark that says Show point labels
2) For the Data Label that has become editable now use expression as =Sum([Sales1] for the first data field. Repeat this for all the data fields added to the chart.
3) You will also find a Format Code property just below the Data label one. You can use this to change the format of the data displayed within the regions of the pie chart.

At times you may want to display percentage values within the pie chart as how much of total does one section of the pie represent.In order to do this, you will need to use step 1 as in the previous case. But steps 2 and 3 would be a little different.

2) Set the Data Label for the Series Values-Labels as something like  =Sum([Sales1]/(Sum([Sales1]+Sum([Sales2]+Sum([Sales3]) for the Series that represents Sales1 and similar with the other 2
3) Change the Format Code to percent.

You may also change the position property in the same window to change where exactly you want the Series Value Label to be placed. Please find a very simple RDLX at this link demonstrating the same.

Wednesday, May 25, 2011

DataDynamics Reports

DataDynamics Reports is another cool reporting tool developed by Grapecity Powertools.It includes the basic report designing capabilities as in
ActiveReports as well as numerous advanced features.The design itself is based on RDL 2005 specs and includes reportitems as Matrix and Tables.As in ActiveReports,DataDynamics Reports also has a winform viewer , webviewer and has the capability to export the reports to different format(more than ActiveReports) viz Word,Xml etc. Over the last couple of months I had this great opportunity to work with this product as well as sme very smart people on the earth who work on the code as well as managing the product. I take this opportunity to bring forth some very good features of the product as well as some how tos that I have learnt.