FAQ/ProcessDataSet.md
... ...
@@ -83,4 +83,63 @@ When we run our post-processor code we will get the expected result:
83 83
![After Post-Processing](http://www.izenda.com/Site/KB/Uploads/Images/PostProcess_after.png)
84 84
85 85
As you can see, "CA" was replaced by "California" in the grid but the chart still displays "CA".
86
-Using this approach, you can change data retrieved from the database in many ways.
... ...
\ No newline at end of file
0
+Using this approach, you can change data retrieved from the database in many ways.
1
+---
2
+##Example: Dynamically changing time zones
3
+
4
+This code sample show how to change TimeZone dynamically from the code. This allows you to show relevant Date values according to the current user local time.
5
+
6
+C♯:
7
+
8
+```csharp
9
+public override void ProcessDataSet(DataSet ds, string reportPart)
10
+{
11
+ if (ds.Tables.Count == 0)
12
+ return;
13
+ // Iterate through ALL DateTime values and change values according to the local TimeZone
14
+ // Note: you could also change some fields only
15
+ foreach (DataColumn column in ds.Tables[0].Columns)
16
+ if (column.DataType == typeof(DateTime))
17
+ foreach (DataRow row in ds.Tables[0].Rows)
18
+ row[column] = GetLocalTime((DateTime)row[column]);
19
+}
20
+
21
+private static DateTime GetLocalTime(DateTime utcTime)
22
+{
23
+ // The only way to get user local time is to get in on the client-side (using javascript)
24
+ // Izenda already have this functionality, so you could use IZR_TimeZone session variable
25
+ // OR you may want to detect user TimeZone using your own methods
26
+ if (HttpContext.Current.Session["IZR_TimeZone"] == null)
27
+ return utcTime;
28
+ return utcTime.AddMinutes((int)HttpContext.Current.Session["IZR_TimeZone"]);
29
+}
30
+```
31
+
32
+###VB.NET:
33
+
34
+```visualbasic
35
+Public Overrides Sub ProcessDataSet(ds As Data.DataSet, reportPart As String)
36
+ If (ds.Tables.Count = 0) Then
37
+ Return
38
+ End If
39
+ ' Iterate through ALL DateTime values and change values according to the local TimeZone
40
+ ' Note: you could also change some fields only
41
+ For Each column As System.Data.DataColumn In ds.Tables(0).Columns
42
+ If (column.DataType Is GetType(DateTime)) Then
43
+ For Each row As System.Data.DataRow In ds.Tables(0).Rows
44
+ row(column) = GetLocalTime(CType(row(column), DateTime))
45
+ Next
46
+ End If
47
+ Next
48
+End Sub
49
+
50
+Private Function GetLocalTime(utcTime As DateTime) As DateTime
51
+ ' The only way to get user local time is to get in on the client-side (using javascript)
52
+ ' Izenda already have this functionality, so you could use IZR_TimeZone session variable
53
+ ' OR you may want to detect user TimeZone using your own methods
54
+ If (HttpContext.Current.Session("IZR_TimeZone") Is Nothing) Then
55
+ Return utcTime
56
+ End If
57
+ Return utcTime.AddMinutes(DirectCast(HttpContext.Current.Session("IZR_TimeZone"), Integer))
58
+End Function
59
+```
... ...
\ No newline at end of file