About Me

My photo
Software Developer and ideas man!

Tuesday, June 7, 2011

Ever wanted to turn off the drill down capability on subreports.

Here are 2 simple ways of turning off the drilldown capability on a subreport. In the code below, I've performed the cast to expose other methods and properties of the args parameter [the cast is unnecessary though].


private void CRViewer_DrillDownSubreport(object source, CrystalDecisions.Windows.Forms.DrillSubreportEventArgs e)
        {
            (e as CrystalDecisions.Windows.Forms.ViewerEventArgs).Handled = true;
        }

Note -  this code can be useful if you wanted to enable or disable the drilldown for a particular subreport.



The drilling down in the CR viewer can also be turned off by setting "EnableDrilldown" to false in the properties of the viewer which is less flexible given it is in place for all reports.



More from this Blogger:
Localizing Crystal Reports in C# - I demonstrate one way of doing it despite the hurdles!

Look - I can't read the x-axis labels on my CR Chart!

Ever had the problem with your Crystal Report charts where the datapoints on your chart are too numerous and the x-axis labels become illegible because they all become scruntched up together.  This is primarily for charts that have greater than 100 datapoints.

Well I did and posted the Sap forums for an answer -
http://forums.sdn.sap.com/thread.jspa?threadID=1922787&tstart=0

Anyway, I was forced to come up with an alternative approach for my stacked area and line charts using the charts shipped with Crystal. 

What I did was develop 2 charts to display the same information.  One of the charts was suppressed depending on the number of datapoints to be plotted - so if the number of datapoints exceeded 20 datapoints, I suppress the chart that has the "Show Group Axis" option enabled - this appears to be the sweet spot for readability for my charts using the system default datetime formatted axis label.


With the chart that has the "Show Group Axis" unchecked, I then inserted "Summary" text boxes below the x-axis to display the Minimum and Maximum datetimes for the datapoints.  This set the start and end axes points and lined up perfectly with the start and end of the chart.  As with the duplicate chart, these were suppressed if the number of datapoints was less than 20.

I then inserted a "Data date" field in the middle of the x-axis to indicate the middle datetime for the datapoint range and inserted the following script for the "Display string".

 
So this report  


became
Let me know if you find this useful or need further info on any of the steps above.  

P.S. One further note - I am using Crystal Reports 13.0.1.220 targetted at Visual Studio 2010.

Tuesday, May 31, 2011

What do you do when you get a "Report Application Server Failed" error - scream!

I started getting this darstedly error which provided little detail or debug info.  Well fortunately, I partitioned each piece of my report into subreports so I could isolate the subreport which was causing the issue. 

this.pageViewDetails.GetActiveDocument().GetPage(3)' threw an exception of type 'CrystalDecisions.CrystalReports.Engine.InternalException'
    base {CrystalDecisions.CrystalReports.Engine.EngineException}: {"The Report Application Server failed"}



The  subreport that was causing the issue when navigating to it contained a chart with some data grouped on a key field.  The groups also contained a field which was being summed.  So, I thought lets start deleting fields and see which one maybe causing the issue.  This took little time and it turned out to be my summary field for a group which I promptly reinserted and it started working! Doh!

Anyway,  I suspect [and don't know for sure] that upgrading my Visual Studio 2010 Crystal Reports from 13.0.0.99 to Crystal Reports 13.0.1.220 may have affected fields used on the form.

It would be great to hear from other fellow sufferers and what has caused this error to occur for them!

Wednesday, January 5, 2011

Crystal Reports - How to insert a logo into the Report Header at runtime

Now how hard can it be to insert a picture into the report header of a Crystal Report at runtime - apparently this is not a straightforward exercise and I implore the folks at SAP to look at this as an area for improvement.

Anyway,  I wanted the users of our reports to be able to customize the business logo they used on the reports before they generate the report - I thought this would be easily done by passing the image as a report parameter in some way, but I thought wrong.  After much searching around and reading copious amounts of posts from other's many of which led to the backstreets of nowhere, I developed the following 8 easy steps.


1. Create a dataset,

2. Create a table in that dataset,

3. Add a column to the table that will store the image

4. Define an xml schema for that table

5. Read in the image as a byte array, to the dataset

6. Set the dataset as the datasource for the report.

7. Add in the logo->image field to the Crystal Report

8. Create the dataset connection in the Crystal Report Database Expert based on the xsd created in the code below [check out the last line] and insert logo blob field on report.


Below is the C# code developed using Visual Studio 2010 and SAP Crystal Reports for Visual Studio 2010:

private void Form1_Load(object sender, EventArgs e)
        {
            DataSet ReportDS = new DataSet();

            //Create a "Logo" Table and insert an image column
            DataTable logoTable = new DataTable("Logo");
            logoTable.Columns.Add(new DataColumn("Image", typeof(System.Byte[])));

            //Add table to the dataset to be associated with the report
            ReportDS.Tables.Add(logoTable);

            //Add a row to our new table
            DataRow logoDR = ReportDS.Tables["Logo"].NewRow();

            //Only required to generate a matching xsd for use by the Crystal Report Field Explorer!
            ReportDS.WriteXmlSchema(@"c:\temp\test.xsd");

            //Read in the image file to a filestream
            FileStream fileStream = new FileStream(@"c:\temp\test.bmp", FileMode.Open);

            BinaryReader binaryReader = new BinaryReader(fileStream);
            logoDR["Image"] = binaryReader.ReadBytes((int)binaryReader.BaseStream.Length);

            ReportDS.Tables["Logo"].Rows.Add(logoDR);

            fileStream.Close();
            binaryReader.Close();

            this.CrystalReport11.SetDataSource(ReportDS);
        }




The Test.xsd generated by the .WriteXmlschema() above should look like this - 


Now it is time to place the Logo Blob field in the Report Header.
i.) From the Field Explorer->Database Fields->Database Expert, create a new ADO.NET(xml) connection. 
 
ii). From the Database Expert-> Available Datasources, select the newly created datasource and move the table over to the "Selected Tables" listbox.


iii). Under the "Database Fields" in the "Field Explorer" should be the new table called "logo"plus a field called "image" which can be dragged into the Report Header.


...And that's it...


More from this Blogger:

Oh Ma – why is CrystalReportViewer not visible in my Visual Studio 2010 ToolBox?

I thought I knew a thing or 2 about Crystal Reports but this little problem took me back to basics.
I thought I’ll just create a new C# app. in Visual Studio 2010 using Crystal Reports targeted to this version.  Simple right.  Yeah maybe.

Anyway, I created a new Winforms app, a new blank Crystal Report and defined a dataset for it.
I was then intending to put a Crystal Report Viewer on the form, so I went to the toolbox expecting to see “Reporting->CrystalReportViewer” and nothing! Doh!  I had a Microsoft Viewer but no CrystalReportViewer.  Hmm - What to do – what to do....


OK – lets build and see if we have some unresolved references.  Yep.  Sure do.  It was coming back with  the following.  The target platform was .Net Framework 4.0!

Ok – so by retargeting my project to .Net 3.5 resolved this problem and I was happily able to continue on my development path.  There are other alternatives but this worked for me and hopefully will work for others caught out by this.

P.S. And if you really want to target to .Net 4, check out this link for further info [ I came across this during my research]
   
http://forums.sdn.sap.com/thread.jspa?threadID=1802638



More from this Blogger:
Localizing Crystal Reports in C# - I demonstrate one way of doing it despite the hurdles!