RReport will assist you in the task of creating reports for your .NET applications. RReport can access a database and retrieve the data to be printed. However this is only one of the possibilities, you can also programatically print the report and set the values yourself, or print data form an array.
The product is made of:
Note: the present document covers RReport Visual Builder which uses the RReport library. It is assumed that the reader has some background about the RReport package. Please read also RReport Documentation .
In order to distribute your application that includes reports you must distribute the following file:
You should NOT distribute:
In order to run the Builder and start designing your reports you need to execute the following commands:
The screen of the builder is very simple, it has three main parts:
The menu allows the following operations:
Futhermore the toolbar will allow you to perform this operations (buttons from left to right):
screenshot 1
The report is divided into areas. An area is a section in a report that contains objects that will always be printed together. There are several types of areas:
By clicking on the name of the Area its properties will be displayed in the properties window.
The properties window
The properties window will display the properties of the selected object, area or report. Click on refresh if you want to see the result of the modified properties.
Working with objects
Adding a new object
In order to add a new object you must select the appropiate object in the toolbar and click on the area you want to add the object. Select the first button in the tool bar (the one with the pointer) in order the deactivate the current selection.
Selecting one or more objects
Click on the objects in order to select them. Selected objects show four black squares on the corners. In order to select more than 1 object you must press the SHIFT key and click on the objects.
Deleting objects
Use the CTRL-X or DEL in order to delete selected objects
Moving objects
Move selected objects by dragging and dropping them.
Resizing objects
Move the cursor to the right or the bottom border of the objects in order to resize them. The cursor will the will change and you can drap the border of the object.
Copying objects
Copy selected object with CRTL-C and paste themin the curret area with CRTL-V. You can also use the menu items in the Objects menu or in the popup menu.
Aligning objects
Select the objects you want to align and click on the right button of the mouse. Select then the alignment type from the popup menu.
Bringing object to the front or to the back
you can determine the order in which objects are printed by bringing them to the front or the back. Select the objects you want to move and click on the right button of the mouse. Select then the action (bring to front or send to back) from the popup menu.
Description of the supported objects
Report
Select File-> Properties to set the properties of the report. The properties are:
- Background: background color.
- Date format: format of the date returned by the [Date] syste, variable.
- DB Active: when you select YES, the database will be opened. Make sure you enter the database information first (connection provider and connection string).
- DB Con(nection) assembly: file that contains the data provider (leave it empty for providers which are part of the .NET framework)
- DB Con(nection) Class: enter connection class name or select the connection provider (the class name will be automatically filled).
- DB Con(nection) Provider: Select data provider to use: ole , odbc , sql server driver , Oracle or other.
- DB Con(nection) string: connection string. The format will depend on the date provider you use. Examples:
- SQL server provider example: Data Source=(local);User ID=sa;Password=sa;Initial Catalog=mydb
- ODBC provider example: Dsn=DsnName;Uid=sa;Pwd=sa;
- ODBC provider example: DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;Uid=sa;Pwd=sa;
- ODBC provider example: DRIVER={Microsoft ODBC for Oracle};Server=Oracleserver.word;Uid=sa;Pwd=sa;
- ODBC provider example: Driver=Microsoft Access Driver (*.mdb);dbq=c:\rreport\RReport2.mdb
- OLE provider example: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\rreportRReport2.mdb;
- OLE provider example: Provider=SQLOLEDB;Data Source=(local);User ID=sa;Password=sa;Initial Catalog=mydb;
- OLE provider example: Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User ID=sa;Password=sa;
- OLE provider example: Provider=IBMDA400.DataSource.1;Data Source=MyAs400DB;User ID=sa;Password=sa;
- ORACLE provider example: Data Source=MyOracleDB;User ID=sa;Password=sa;
note: only OLE providers are able to retrieve the list of tables in the database, we therefore recommend you to use the ole data provider.
- Frame: if true, the report will have a frame around the page.
- Frame color.
- Frame Style.
- Frame Width.
- Margins: in centimeters.
- Orientation. You can set here that the report should be printed in landscape (horizontal) format.
- PDF File: file name for pdf output. Click here to learn how to install the PDF features.
- PDF ttf fonts: directory where ttf files for the iText library. The PDF library only supports the following fonts: Courier, Helvetica, Times Roman, Symbol, ZapfDingbats. If you need to use other fonts you must code the ttf files to this directory. The ttf files must be named as "<fontname>.ttf"
- Printer Dialog: shoudl the printer dialog be displayed?
- Resolution: resolution used by rreport (default is 39 pixels/cm=100 dpi)
Area
Click on the area's name to set the properties of the area:
- Background: background color.
- Columns (default is 1). Set this value to greater than 1 if you want RReport to print the area in several columns.
- Name: name of the area
- Frame: if you select AREA there will be a border for each repetition of the area, if PAGE there will be only one border for all areas in the page.
- Frame color.
- Frame Style.
- Frame Width.
- Grid: list of positions (CM) of the columns (vertical lines). This is used to draw a grid in the area. After each repetition a horizontal Line will be draw.
- Grid color.
- Grid Style.
- Grid Width.
- Group by. List of fields of the data source (normally a database) you want to group by. The fields must be separated by |. This property is only available in the detail section of the areas groups. Your data source must provide the data grouped and sorted (if you use a database you can use the GROUP BY and the ORDER BY sql statements). RReport will print the group header and footer for each new value of the "group by" field/s but it will not reorganize or sort the data in any way.
- Header Area: If the current repetition of the area cannot be printed in the current page, a new page is created. The header area will be printed in the new page before the current area.
- DB Link from: list of fields for the link (separated by "|" ) in the super area. This is used to make a link between two areas/tables in order to have a nested area. Only needed this area is nested in a superarea.
- DB Link To: list of fields for the link (separated by "|" ) in this area. This is used to make a link between two areas/tables in order to have a nested area.Only needed this area is nested in a superarea.
- DB Linked Area: super area. The current area will be printed for every repetition of the super-area. The correct registers from tha table will be read using the "link from" and "link to" fields.
- DB list Tables: list of available tables in the database. The property "DB Sel Table" will be updated automatically when you select a table from the list.
- DB sel Table: name of the table in the database used as RDatabaseCSource for the area. It can also be a SQL select statement. The SQL statement may contain parameters like for example: "select * from Table where ID=[%param1]". RReport Visual Builder will ask for the parameter when you run the report. In this case don't forget to use RDatabaseSource.setParameter() when you run the report from your application.
- Test Repetitions: (only for testing purposes) number of repetitions of the areas you want to create when printing or previewing from RReport Visual Builder.
Note: if you use parameters in the SQL statement, the "DB List Fields" in the RVObjects will not be filled. For this reason you should first enter a sql statement or table name. This will load the list of fields "DB List Fields", then you can add the parameters.
RVObject
This object corresponds to the RObject object used in RReport. Its properties are common for all the object used in report. The properties are:
- X and Y: position in the report (CM).
- widht and Height: size of the object.
- Constant: if true the object is supposed not to modify its content during report printing. For example, in the case of database access, this object would not be read from the table.
- Name: name of the object.
RVField
This object corresponds to the RField object used in RReport. It is used to print texts and its properties are:
- Align: text alignment.
- Compress: see text wrapping.
- DB List Fields: list of field in the table. When you select on the property "DB sel Field" will be updates.
- DB sel Field: you can enter here the name of the field in a database used as data source for this object.
- Expand. see text wrapping.
- Evaluate: set it to "No" if you want to disable the evaluation of expressions (Values starting with = are assumed to be expressions, for example =3+5 will print 8).
- Font: font of the text.
- Font Color: color of the font of the text.
- Format: Format string used for dates and numbers.Examples: "dd/MM/yyyy" for a date or {0:F2} for a number.
- Multiline: if true the words the text will be printed in several lines if needed.
- Value: default value.
RVCheck
This object corresponds to the RCheck object used in RReport. It is used to boolean values and its properties are:
- DB List Fields: list of field in the table. When you select on the property "DB sel Field" will be updates.
- DB sel Field: you can enter here the name of the field in a database used as data source for this object. You must select a field of type "bool".
- Value: default value.
RVCombo
This object corresponds to the RCombo object used in RReport. It is used to display values based on the value of a key, its properties are:
- Align: text alignment.
- DB List Fields: list of field in the table. When you select on the property "DB sel Field" will be updates.
- DB sel Field: you can enter here the name of the field in a database used as data source for this object.
- Font: font of the text.
- Font Color: color of the font of the text.
- Key: font of the key.
- Key Color: color of the font of the key
- Key List: list of key separated by "|" .
- Print Key: if true the key and the value will be printed.
- Format: Format string used for dates and numbers.Examples: "dd/MM/yyyy" for a date or {0:F2} for a number.
- Multiline: if true the words the text will be printed in several lines if needed.
- Value: default value.
- Values List: list of values separated by "|".
RCombo support also a list of images as values to be printed but RVCombo only support a list of strings. If you want to specify a list of images you should do it programatically when you run your report. For example:
[c#]
report.importFile(filename);
RCombo combo=(RCombo) report.getAreaByName(areaname).getItemByName(comboname);
combo.Values=listOfImages;
[vbnet]
report.importFile(filename)
Dim co as RCombo
co= report.getAreaByName(areaname).getItemByName(comboname)
co.Values=listOfImages
RVPicture
This object corresponds to the RPicture object used in RReport and is used to print images. Its properties are:
- Image: the image file (gif) must be located in the images folder.
RVLine
This object corresponds to the RLine object used in RReport. Its properties are:
- Direction: select HORIZONTAL to draw a horizontal line, VERTICAL to draw a vertical line, USER_DEFINED1 to draw a line from top left corner to the bottom right corner and USER_DEFINED2 to draw a line from bottom left corner to the top right corner.
- Line Width.
- Style.
RVPageBreak
The RPageBreak will force that a page break after the area is printed.
RVRectangle
This object corresponds to the RRectangle object used in RReport. Its properties are:
- Fill: if false the rectangle will be transparent. Make sure you send the rectangle to the background if you select fill=true.
- Fill Color.
- Style: line style for the border.
- Line width: width of the border.
RVBarcode
This object will insert a barcode in your report. Note that a separater license of RBarcode is required if you want to print barcodes. RReport includes a evaluation version of RBarcode.
The parameters of the barcode are explained in RBarcode's documentation.
RVGraph
This object will insert a chart in your report. Note that a separate license of RChart is required if you want to create charts. RReport includes a evaluation version of RChart.
This object only requires 1 parameter, the "Data File" that contains the chart parameters. This file is created using RChart Visual Builder.
Evaluation of expressions
RReport can also evaluate expressions you enter in the "value" property of the RVField objects. Any value starting with "=" is assumed to be an expression to be evaluated unless you set the "evaluate" property of the RVField to "No".
Examples of expressions are:
- =5+1+1 will be printed as 7
- =((5+1)*2) will be printed as 12
- =[areaname.fieldname] * 2 will print the value of the referenced field of the referenced area multiplied by 2.
- =[fieldname] * 2 will print the value of the referenced field (of the current area) multiplied by 2.
- =sum("total") will sum the values of the "total" field in a group. Note that this function and other (avg, min, max) can only be applied to groups and therefore can only be used in the group footer.
- =(trim(" hell ") & "o") will print "hello".
Supported operators are: + , - , / , \ (integer division), ^ (power), *, % (modulo) and & (concatenation of strings).
Supported functions are:
- round(double): round decimal value.
- trunc(double): truncate decimal value.
- mid(string,init,length). Extract substring.
- left(string,len): Extract substring starting at possition 0.
- right(string,len): Extract substring starting from the end of the string.
- trim(string): remove leading and trailing blanks.
- rtrim(string): remove trailing blanks.
- ltrim(string): remove leading blanks.
Supported functions for group footers are:
- sum("fieldname")
- avg("fieldname")
- min("fieldname")
- max("fieldname")
You can implement your own functions using the IUserFunctions interface and setting the Evaluator.userFunctions property. For example, the following code would implement the "charAt" function that extracts a given character froma string.
[c#]
class myFunctions : IUserFunctions {public object executeFunction(string functionName,object[] parameters) {
// implement charAt function which have 2 parameters: String and position of the char to return
if (functionName.CompareTo("charAt")==0)
if (parameters.GetLength(0)==2) {string s=parameters[0].ToString();
string positionStr=parameters[1].ToString();
int32 position=Int32.Parse(positionStr);if (s.Length>position) return ""+s[position];
}return "";
}
}
Note that user defined functions are only executed within your .NET application. When testing the report inside RReport Visual Builder, user defined functions will be ignored.
Using a database
In order to retrieve data from a database you must:
- Enter the connection data in the Report's Properties
- DB Con Provider: select the provider you want to use (ole is recommended)
- DB Con String: enter the connection string
- Activate the database connection. Select YES in the DB Active combo box.
- Enter the table name or the SQL query in the Area's Properties (see DB Sel Table property). Each area will retrieve data from a table in the database. You can also have nested areas. In this case you must select a "linked Area" (super area) and enter the "link from" (fields in the supertable) and "link to" (fields on the subtable) information in the nested area (subarea). The "link from" and "link to" are list of fields separated by "|" that build the foreign key relationship between tables/areas.
- Enter the field name in the Object's properties. The following object support database access: RField, RCheck and RCombo.
Running the report
The following code will run the report examples/databaseSource/DBorder.rep:
[c#]
using J4L.RReport;
using System;
using System.Drawing;
using System.Windows.Forms;public class exampleDBOrder:RAreaListener
{
int total=0;
// entry point
public static void Main(string[] args)
{
exampleDBOrder f=new exampleDBOrder();
f.init();
}
public void init() {
// load report from file
Report report=new Report();
if (!report.importReport("examples\\DatabaseSource\\DBorder.rep")) {
Console.WriteLine("Error, exiting");
Application.Exit();
}
// set listener to calculate amounts on the fly
report.getAreaByName("Detail").setListener(this);
report.getReportFooter().setListener(this);
// create preview window
RReportWindow Win= new RReportWindow(report);// this will print the Header Area and all dependent areas
Console.WriteLine("Preparing report");
report.prepare();
Console.WriteLine("End report");
report.endReport();
Console.WriteLine("Show preview window");
Win.ShowNow();
Application.Exit();
}
public void beforePrintingArea(RArea area) {
// calculate the amount of each line
if (area.getName().CompareTo("Detail")==0) {
double price=((Double) area.getItemByName("Price").getruntimeValue());
int quantity=((Int32) area.getItemByName("Quantity").getruntimeValue());
total=(int) (total+(quantity*price));
area.getItemByName("Amount").setruntimeValue((Int32) quantity*price);
}
// set total amount
if (area.getName().CompareTo("Footer")==0) {
area.getItemByName("Total").setruntimeValue(( (Int32) total));
total=0;
}
}
}
[vbnet]
Imports J4L.RReport
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.FormsModule MyModule
Public Class exampleDBOrder : implements RAreaListener
private total as integer
Overridable sub beforePrintingArea(area As RArea) Implements RAreaListener.beforePrintingArea
Dim price as Double
Dim quantity as Integer
' calculate the amount of each line
if (area.getName()="Detail") then
price= area.getItemByName("Price").getruntimeValue()
quantity=area.getItemByName("Quantity").getruntimeValue()
total= (total+(quantity*price))
area.getItemByName("Amount").setruntimeValue( quantity*price)
end if
' set total amount
if (area.getName()="Footer") then
area.getItemByName("Total").setruntimeValue( total)
total=0
end if
end sub
public sub init()
' load report from file
Dim report as Report
Dim dbconnection as OleDbConnection
Dim dbcommand as OleDbCommandreport=new Report()
if (not report.importReport("examples\DatabaseSource\DBorder.rep")) then
Console.WriteLine("Error, exiting")
end
end if
' set the images for the combo box. This can only be done programatically
Dim comboImages(3) as Image
comboImages(0)=new RImageFile("images/ball1.gif").getImage()
comboImages(1)=new RImageFile("images/ball2.gif").getImage()
comboImages(2)=new RImageFile("images/ball3.gif").getImage()
Dim co as RCombo
co= report.getAreaByName("Detail").getItemByName("Priority")
co.Values=comboImages
' set listener to calculate amounts on the fly
report.getAreaByName("Detail").setListener(me)
report.getReportFooter().setListener(me)
' create preview window
Dim Win as RReportWindow
Win= new RReportWindow(report)' this will print the Header Area and all dependent areas
report.prepare()
report.endReport()
Win.ShowNow()
End
end sub
end class
end module
The process is:
- The report is created by calling the constructor new Report().
- load the report using importReport(file). This will also open the database (this example uses a Ole data source that opens the database RReport2.mdb). Here you will find other examples that do not use database.
- sets the area listeners. This will be triggered for each repetition of detail and page footer.
- create a preview window if you need it.
- call prepare(). This will print the report header. The detail area will also be printed since it is a subarea of report header.
- call endReport().
Accesing loaded fields and methods:
In order to change the properties of object or area after loading a report from a file you must use the methods:
[c# / vbnet]
rreport.getAreaByName() and rarea.geItemByName().
for example. In order to change the image of a RPicture object you must call:
[c# / vbnet]
report.getAreaByName("areaname").getItemByName("RPicturename").setruntimeValue(Image)
note that if your want to access the headers, background or footers area you must use the rreport.getPageHeader(), rreport.getReportHeadert()...
Using your own database connection and statement for database access:
If your report uses a database, it will open the database connection when you execute the importReport() method. If you already have a database connection you can use your own IDBConnection object in this way:
[c#]
dbconnection=new OleDbConnection();
dbconnection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=RReport2bis.mdb";
dbconnection.Open() ;
report.setDBCon(dbConnection);
report.importReport("filename");[vbnet]
Dim dbconnection as OleDbConnection
dbconnection=new OleDbConnection()
dbconnection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=RReport2bis.mdb"
dbconnection.Open()
report.setDbCon(dbconnection)
report.importReport("filename")
The importReport() method will also create all necesary RAreas and RDatabaseSource objects. The RDatabase Source's constructor needs a ICommand object as parameter.
If you want to change the sql statement at runtime:
[c#]
((RDatabaseSource) report.getAreaByName(name).getDataSource()).setSQL("Select * from Employees");
[vbnet]Dim ds as RDatabaseSource
ds=report.getAreaByName(name).getDataSource()
ds.setSQL("select * from PurchaseOrderBis")
Programatically printing
If you do not use any RSource you must print the imported report programatically ba setting the values of the object in the area one by one and printing every single repetition with rreport.printArea(). Like this:
[c#]
report.importReport(name);
myArea=report.getAreaByName(areaname);while (datatoprint) {
// set values for fields
myArea.getItemByName(fieldname1).setruntimeValue(value1);
myArea.getItemByName(fieldname2).setruntimeValue(value2);
.....// print repetition
report.printArea(myArea);
}[vbnet
while dataToPrint
'set values for fields
myArea.getItemByName(fieldname1).setruntimeValue(value1)
myArea.getItemByName(fieldname2).setruntimeValue(value2)
.....
' print repetition
report.printArea(myArea)
while endUsing other RSources
In other to use other RSources (for example, printing an array) ,different from RDatabaseSource, you must import the report and set the new RSource:
[c#]
report.importReport(name);
report.getAreaByName(areaname).setDataSource(yourRSource);
Combining RSources and programatically printing
If you use a RSource object to print all repetitions of an area automatically but you still need to set a field value programatically your must use a RareaListener.