Posts

Showing posts from July, 2012

Nrapid, working with page breaks and report options

Image
So far we been working with reports and exploring a couple of options on how to group data, customize dialogs and so on, but we never talk about printing.
While there isn’t much to say about printing when it comes to standard reports, I mean, you execute the report, press print and you are pretty much set.  When it comes to complex reports, we have a couple of options.
In this post I’m going to talk about page breaks and how they behave in reports that contain grouped data. Continuing with the categories and products example, we want to print each category in her own page (a group per page) this means that we need a page break after each group of data.
By default, NRapid will not going to add page breaks after groups, because internally doesn’t knows what a group is. It just going to emit standard html based on the default style sheet or the specified raw style. The easiest way to insert page breaks, is by building the report using the “table per group” approach, and tells to NRapid ple…

Raw styling reports with NRapid

Image
Raw styling reports is s technique that allows us to override the NRapid’s default style sheet without worrying about css.  I commonly use it for quick fixes and generally work really well. But if you want to affect the global aspect of your reports, though, the way to go is modifying the nrapid-default.css file, not raw styling a report at a time. 
A common scenario where you can apply this technique is when you add a table per group in your report. For instance, when you list products by category, grouped by category, you can add a table for each category (this is quite handy when it comes to printing options, more on this in futures posts) and populate that table with the corresponding group of products.
So far, so good, but when you run the report you see something like this:


As you may notice, the columns are not aligned across the different groups and the report looks sloppy, but don’t worry, this can be fixed with a couple of lines of code


Here I just adjust the column width, but y…

NRapid cascade filtering take 2

Image
In a previous post I’ve shown how to cascade filter an autocomplete's datasource.  The code looked really ugly, so I promised to take a look at the NRapid's code and see if I can do something about it. As it turns out, I can, so now you have a neat way to work with cascade filtering.
This is how it works before: This is how it works now:
The mayor change from the client code perspective is that now you get the whole view data in the method call responsible for filtering, instead of the object id, as it was in the previous version.
And of course, you don't have to write those cryptic functions ;)

You can get the source code of NRapid from here And the sample app from here The Northwind database is available from download at http://www.microsoft.com/en-us/download/details.aspx?id=23654

NRapid, cascade filtering with autocompletes

Image
When working with large sets of hierarchical data sometimes you need to provide some sort a cascade filter mechanism. For instance, in a travel agency system, you may want to be able to select a destination, like country or a region, and based on that selection, get some data sets with travel options such as hotel deals, car rentals, and so on….
Continuing with our example (products and categories) I’ll create a dialog with two autocompletes. One will give you whole list of categories and the other a filtered set of products based on the selected category.
Doing this is not so hard but requires a bit of an explanation. *In this post I’ll be using a nice C#’s feature called partial application. If you don’t know what does this means, don’t worry; just look at it as a magical lambda ;).
When configuring an Autocomplete it’s possible to specify a function to be executed every time the selection changes, this can be done by using the NRapid’s fluent API, and we are going to use this feature…

NRapid, customizing autocompletes take 2

Image
In a previous post I‘ve shown you how to add columns to the autocomplete control. In that post, I used the NRapid's internal API which is a bit noisy from a syntactic perspective.
In this post, I’ll show you how to do the same thing we did before, but using a cleaner syntax.  Some syntactic sugars I’ve added to the report class. (Internally it works the same way that the previous example)


And as you can see, the end result is the same.
On the next post, how to work with autocompletes and cascade filters.
You can get the source code of NRapid from here And the sample app from here The Northwind database is available from download at http://www.microsoft.com/en-us/download/details.aspx?id=23654

NRapid, customizing the autocomplete control

Image
A while ago I got a question about the autocomplete control, “it’s possible to use records coming from different tables as an autocomplete data source?”
The answer is yes, It’s possible, but requires a bit of configuration.
The use case was simple, but does not fit into the NRapid default feature set. By default, autocompletes work with a data source that contains just two columns, the record id and a description field (which is used to filter records). Those two columns must come from the same table. In this case, the user wants to see additional columns coming from different tables, so the solution requires a bit of hacking.
I’ll show you how to do this, by combining two tables, products and categories. Basically I’ll add the category name (from Categories) to the products autocomplete data source (which by default just has the product id and the product name, both coming from the products table).
To make this thing work, we need to use the customization feature, the code should look so…

Working with autocompletes in NRapid

Image
One of the main goals behind relational databases design is reduce/eliminate the amount of duplicated data. In order to do that, they split the data into multiple tables and relate them by FK. While this works really well in database terms, they don’t when it comes to searching or loading data (In highly normalized database we usually need a lot of JOINs) Continuing with an example that we were working on previous posts (products by category) we can see this design lines in action.

The goal of our report is allow the users to select a category, and based on that category, fetch the corresponding list of products. The problem is, if we look at the products table, the product's category is and ID (numeric), which is hard to remember and does not make any sense on his own. In this kind of scenarios, we can use the autocomplete control. This control will allows to the user to filter by description (category name) or any field that make sense to him/her and pass to the report engine the…

Working with combos in NRapid

Image
I think that working with combos is the most complex thing that you can do with NRapid, they are hard to configure and requires a lot of plumbing code, but they are really handy when you have to work with fixed sets of options.
This time I’m going to build a report that shows some employees info. The report’s dialog will allows us to filter that info based on the employees city and get smaller result sets. Cities are a fixed set of data(at least in Northwind) so combos will be a nice choice. In order to get a combo, we need to add to properties to the nested dialog. Those properties will work together to make selection works.
The code may look something like this:
Notice that City is annotated with the ViewIgnore attribute, this is the way to tell to engine "do not create a control for this property". And Cities is annotated with the DispalyOptionsFor attribute pointing to City, this means that the selected option in the combo will be used to set the value of the City property.
N…

Working with dialogs in NRapid

Image
In this post I’ll cover the basic usage of dialogs in NRapid, how do they work and what kinds of controls do we have available.
As we already saw, to create a dialog we have to add a nested class named "Dialog" inside a report. In order to add controls, we need to define properties in that class, and based on the properties type, the report engine will create and add the controls to the dialog. This mechanism is pretty much based on conventions, but we have some attributes to annotate the properties and modify the default behavior. This post is on basic usage of dialogs, so combos and autocompletes are off the table, because they requires a bit more of configuration. And then when we run the report we get this

As you can see in the output dialog, one of the engine conventions is “first defined, first served”, but sometimes this is not the desired behavior or you maybe want to add columns or change the text on the labels or stuff like that. To do that you can use annotations:
And w…

How to add footers to NRapid reports

Image
Grouping data it's really cool feature, that help us out to provide some sort of data visualization enhancement, it makes the report easy on the eyes and allows to the users  to figure out what’s going on without going into much detail. But usually, that it’s not enough, along with grouping, we'll also need to provide some additional info, such as the day takes, month takes, etc, etc… to complement the grouping functionality and make the report really useful.

This time I going to work with products and categories, I’m going to build a report to show units in stock for each product on each category in our database and add a footer to show the units per category (this is the sum of the units per product for a given category).

In a previous post I’ve shown you how to create reports and group data, so I’ll going to skip those steps here and concentrate in the footer section.
The code you will see below must be place inside the configure report method (also covered in previous posts)

Linked reports with NRapid

Image
Being able to link reports it’s really handy feature that usually the end users of our system will love it.
For instance, you can create a report that that displays order’s headers and when the users click on the order’s id, he/she can see a child report with the order’s detail.
In this case I’m going to work with categories and products but the technique can be applied to any master-detail scenario.
First of all we need to create a report that shows the list of categories (we already did that in a previous post, so I’m not going into details here) and then somehow link this report with a report that show a list products for a specific category.
This might sound complex, but with NRapid is pretty straightforward and only will take you just a line of code inside the configure method:





*There’s also a cool feature inside NRapid reports that allows us to run arbitrary c# code when the user clicks a link but this feature deserves his own post ;)
What does this code does, well, basically it tell…

Grouping data with NRapid

Image
Grouping data is a feature you always needs when you are working with reports and relational data bases. In this post I’ll show you how to do it with NRapid.
In this case I’ll build a report to show products grouped by category, this report is going to show the whole list of products for the whole list of categories in the Northwind database, so there is no filtering options (no dialog).















If you take a look at the SQL statement, you will notice that there is no group by instruction, the grouping is done by using the NRapid fluent interface.  (I don’t like SQL very much so I usually use the fluent interface, but if you‘re a SQL guy, you can solve the grouping inside the SQL instruction, it’s also going to works)
























Now we are going to change the report options and set the Staked option on. This setting is going to change the layout and show us a most commonly seen format in this kind of reports.


























This is just a sneak peak of NRapid grouping features. I’ll cover a lot more in upcoming post. Stay…

How to show input parameters inside a report

Image
In a previous post I’ve shown you how to create a report with basic filtering capabilities. Now we are going to tweak that report a little bit to print out the input args along with the report.
There is a lot of ways to do that, but the easiest is just call the base class constructor with the right report options.
The code should look something like this:













And as we can see in the output, now the report is showing the input parameters.



























In the next post will going to explore how we can group data inside a report.


You can get the source code of NRapid from here And the sample app from here The Northwind database is available from download at http://www.microsoft.com/en-us/download/details.aspx?id=23654


Filtering data with NRapid

Image
In a previous post I’ve shown you how to create a simple report with Rapid. In this post I'll show you how to add filtering capabilities.
NRapid provides a couple of ways to do this, in this case I’m going to use the nested dialog approach. As far as I see it, it’s the easiest way to go.
The report that we are about to build, should show products in a certain price range, to do that we need to provide a dialog where the user can introduce the lowest and the highest price and use that info as input parameters to filter the result set.
As I mentioned before, we are going to use the nested dialog approach, so our report class should include a nested class like this:










The report engine will inspect the report class at runtime and if it’s sees a nested class called dialog, it will assume that this is the class that must use to create an input parameters view. The data collected in this view will passed as a parameter to the ConfigureReport method, inside that method we can get them and use …

Creating your first report with NRapid

Image
In this post, I’m going to build a very basic report with NRapid to show some records from the Categories table in the Northwind database. The goal of this post is provide a sneak peak of the reporting capabilities of NRapid.
The first thing we have to do in order to work with NRapid, is configure the database connection in the app.config file. Once this setting is done, we will be able to let NRapid to take care of the data access.


To create our first report, we just need add a class that inherits from NRapid.Core.Reporting.Report and implement two abstract members.
The first one is a method called ConfigureReport, wich will be invoked by the report engine at run time and will allow us to add tables, groups, footers, etc. to the report.
The second is a property where we have to specify the report's title.
In this case, we need to show the whole list of categories from the Northwind data base, we are not filtering any data, so we are just going to ignore viewdata parameter (it’ll be co…