c2b92fc0d0ccb4f0392842eef63d8e46e29691a3
FAQ/ProcessDataRow.md
| ... | ... | @@ -0,0 +1,169 @@ |
| 1 | +#ProcessDataRow() |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##Usage |
|
| 6 | + |
|
| 7 | +The ``ProcessDataRow`` method is useful when you want to use post-processing in your application. This method should be overridden in your global.asax file. |
|
| 8 | + |
|
| 9 | +```csharp |
|
| 10 | +public class CustomAdHocConfig : DatabaseAdHocConfig |
|
| 11 | +{ |
|
| 12 | + public override void ProcessDataRow(DataRow row, Report report, bool isTotals) |
|
| 13 | + { |
|
| 14 | + // Put your code here |
|
| 15 | + } |
|
| 16 | +} |
|
| 17 | +``` |
|
| 18 | + |
|
| 19 | +```visualbasic |
|
| 20 | +<Serializable()> |
|
| 21 | +Public Class CustomAdHocConfig |
|
| 22 | + Inherits FileSystemAdHocConfig |
|
| 23 | + |
|
| 24 | + Public Overrides Sub ProcessDataRow(row As DataRow, report As Report, isTotals As Boolean) |
|
| 25 | + ' put your code here |
|
| 26 | + End Sub |
|
| 27 | +End Class |
|
| 28 | +``` |
|
| 29 | + |
|
| 30 | +###Example: Using post-processing |
|
| 31 | + |
|
| 32 | +C♯: |
|
| 33 | + |
|
| 34 | +```csharp |
|
| 35 | +public override void ProcessDataRow(DataRow row, Report report, bool isTotals) |
|
| 36 | +{ |
|
| 37 | + // We want to alter only "Detail" part of the report set |
|
| 38 | + if (report.Name == "Detail") |
|
| 39 | + { |
|
| 40 | + if (row != null) |
|
| 41 | + { |
|
| 42 | + // Iterate through columns to find column with name "Ship Region" |
|
| 43 | + foreach (DataColumn col in row.Table.Columns) |
|
| 44 | + { |
|
| 45 | + if (col.ColumnName == "Ship Region") |
|
| 46 | + { |
|
| 47 | + // Iterate through rows to find the field with a value of "CA" |
|
| 48 | + if (row[col].ToString() == "CA") |
|
| 49 | + row[col] = "California"; |
|
| 50 | + // There can be only one column with a specific name, |
|
| 51 | + // so we can leave the cycle as soon as we find it |
|
| 52 | + break; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | +} |
|
| 58 | +``` |
|
| 59 | + |
|
| 60 | +VB.NET |
|
| 61 | + |
|
| 62 | +```visualbasic |
|
| 63 | +Public Overrides Sub ProcessDataRow(row As DataRow, report As Report, isTotals As Boolean) |
|
| 64 | + 'We want to alter only "Detail" part of the report set |
|
| 65 | + If report.Name = "Detail" Then |
|
| 66 | + If row IsNot Nothing Then |
|
| 67 | + 'Iterate through columns to find column with name "Ship Region" |
|
| 68 | + For Each col As DataColumn In row.Table.Columns |
|
| 69 | + If col.ColumnName = "Ship Region" Then |
|
| 70 | + If row(col).ToString() = "CA" Then row(col) = "California" |
|
| 71 | + 'There can be only one column with a specific name, |
|
| 72 | + 'so we can leave the cycle as soon as we find it |
|
| 73 | + Exit For |
|
| 74 | + End If |
|
| 75 | + Next |
|
| 76 | + End If |
|
| 77 | + End If |
|
| 78 | +End Sub |
|
| 79 | + |
|
| 80 | +``` |
|
| 81 | + |
|
| 82 | +###Example: Dynamically changing time zones |
|
| 83 | + |
|
| 84 | +C♯: |
|
| 85 | + |
|
| 86 | +```csharp |
|
| 87 | +public override void ProcessDataRow(DataRow row, Report report, bool isTotals) |
|
| 88 | +{ |
|
| 89 | + if (row.Table.Columns.Count == 0) |
|
| 90 | + return; |
|
| 91 | + // Iterate through ALL DateTime values and change values according to the local TimeZone |
|
| 92 | + // Note: you could also change some fields only |
|
| 93 | + foreach (DataColumn column in row.Table.Columns) |
|
| 94 | + if (column.DataType == typeof(DateTime)) |
|
| 95 | + row[column] = GetLocalTime((DateTime)row[column]); |
|
| 96 | +} |
|
| 97 | + |
|
| 98 | +private static DateTime GetLocalTime(DateTime utcTime) |
|
| 99 | +{ |
|
| 100 | + // The only way to get user local time is to get in on the client-side (using javascript) |
|
| 101 | + // Izenda already have this functionality, so you could use IZR_TimeZone session variable |
|
| 102 | + // OR you may want to detect user TimeZone using your own methods |
|
| 103 | + if (HttpContext.Current.Session["IZR_TimeZone"] == null) |
|
| 104 | + return utcTime; |
|
| 105 | + return utcTime.AddMinutes((int)HttpContext.Current.Session["IZR_TimeZone"]); |
|
| 106 | +} |
|
| 107 | +``` |
|
| 108 | + |
|
| 109 | +VB.NET |
|
| 110 | + |
|
| 111 | +```visualbasic |
|
| 112 | +Public Overrides Sub ProcessDataRow(row As DataRow, report As Report, isTotals As Boolean) |
|
| 113 | + If (row Is Nothing) Then |
|
| 114 | + Return |
|
| 115 | + End If |
|
| 116 | + ' Iterate through ALL DateTime values and change values according to the local TimeZone |
|
| 117 | + ' Note: you could also change some fields only |
|
| 118 | + For Each column As System.Data.DataColumn In row.Table.Columns |
|
| 119 | + If (column.DataType Is GetType(DateTime)) Then |
|
| 120 | + row(column) = GetLocalTime(CType(row(column), DateTime)) |
|
| 121 | + End If |
|
| 122 | + Next |
|
| 123 | +End Sub |
|
| 124 | + |
|
| 125 | +Private Function GetLocalTime(utcTime As DateTime) As DateTime |
|
| 126 | + ' The only way to get user local time is to get in on the client-side (using javascript) |
|
| 127 | + ' Izenda already have this functionality, so you could use IZR_TimeZone session variable |
|
| 128 | + ' OR you may want to detect user TimeZone using your own methods |
|
| 129 | + If (HttpContext.Current.Session("IZR_TimeZone") Is Nothing) Then |
|
| 130 | + Return utcTime |
|
| 131 | + End If |
|
| 132 | + Return utcTime.AddMinutes(DirectCast(HttpContext.Current.Session("IZR_TimeZone"), Integer)) |
|
| 133 | +End Function |
|
| 134 | +``` |
|
| 135 | + |
|
| 136 | +###Example: Fetching a Column Used in a Report |
|
| 137 | + |
|
| 138 | +C♯: |
|
| 139 | + |
|
| 140 | +```csharp |
|
| 141 | +public override void ProcessDataRow(DataRow row, Report report, bool isTotals) |
|
| 142 | +{ |
|
| 143 | + string columnToDecrypt = "[dbo].[Orders].[CustomerID]"; |
|
| 144 | + if (report.Name == "Gauges" && row != null) |
|
| 145 | + { |
|
| 146 | + ReportSet crs = AdHocContext.CurrentReportSet; |
|
| 147 | + if (crs != null && crs.Reports.Contains("Gauges") && crs.Reports["Gauges"] != null && crs.Reports["Gauges"].Fields[0].ColumnName == columnToDecrypt) |
|
| 148 | + { |
|
| 149 | + // Decrypt ds.Tables[0].Columns[0] |
|
| 150 | + // ... |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | +} |
|
| 154 | +``` |
|
| 155 | + |
|
| 156 | +VB.NET: |
|
| 157 | + |
|
| 158 | +```visualbasic |
|
| 159 | +Public Overrides Sub ProcessDataRow(row As DataRow, report As Report, isTotals As Boolean) |
|
| 160 | + Dim columnToDecrypt As String = "[dbo].[Orders].[CustomerID]" |
|
| 161 | + If report.Name = "Gauges" AndAlso row IsNot Nothing Then |
|
| 162 | + Dim crs As ReportSet = AdHocContext.CurrentReportSet |
|
| 163 | + If (crs IsNot Nothing AndAlso crs.Reports.Contains("Gauges") AndAlso crs.Reports("Gauges") IsNot Nothing AndAlso crs.Reports("Gauges").Fields(0).ColumnName = columnToDecrypt) Then |
|
| 164 | + ' Decrypt ds.Tables[0].Columns[0] |
|
| 165 | + ' ... |
|
| 166 | + End If |
|
| 167 | + End If |
|
| 168 | +End Sub |
|
| 169 | +``` |
|
| ... | ... | \ No newline at end of file |