How to Post Process Data in Izenda

By October 20, 2011Tips

There’s a difference between the best way to store certain values in a database and the best way to report those values out to the people in your company. With Izenda you can perform post-processing of data objects for encryption, logging, localization or whatever you want. For example, replace “CA” with “California” or replace encrypted data values with decrypted information.

To use the post-processor you should override only one method in CustomAdHocConfig class which is normally found in the Global.asax file.

[csharp] public class CustomAdHocConfig : DatabaseAdHocConfig { public override void ProcessDataSet(DataSet ds, string reportPart) { // Put your code here } } [/csharp]

The “ds” parameter in this method is data retrieved from the database represented by standard System.Data.DataSet class; reportPart is a name of a report in the report set (for example, the name for the grid-represented report is “Detail” and name for the chart report is “Chart”). Now you can manipulate data and all your changes will effect the final results.

For example, we want to rename “CA” state code to “California” but only in the results grid. Without any post-processing we have the following report:

Pie chart and graph after postprocess code

Now let’s add some extra code to the CustomAdHocConfig class:

csharp] public override void ProcessDataSet(DataSet ds, string reportPart) { // We want to alter only "Detail" part of the report set if (reportPart == "Detail") { if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { // Iterate through columns to find column with name "Ship Region" for (int index = 0; index < ds.Tables[0].Columns.Count; index ) if (ds.Tables[0].Columns[index].ColumnName == "Ship Region") { foreach (DataRow row in ds.Tables[0].Rows) if (row[index].ToString() == "CA") row[index] = "California"; // There can be only one column with specific name, // so we can leave the cycle as soon as we find it break; } } } } [/csharp]

And after implementing post-processing the result will be:

pie chart and graph after postprocess code has been executed

As you can see “CA” was replaced by “California” in the grid but it is still “CA” in the chart. Using this approach, you can change significantly improve your reports.