Monday, March 12, 2012

Localization Controls

Does Report Designer support Localization or Internationlization controls?
E.g. when you a run a report which has currency column the report designer
should format the column with the currency format present in the system's
control panel (Regional Settings)In short, both are supported. Localisation is easy, with the in-built
format codes, eg. 'c' for currency.
Globalisation is trickier, requiring some code. Generally the
System.Globalization namespace has most things in that you'll need.
One thing to note though is that the designer is an absolute pig with
non-US dates. Generally the reports are OK when deployed though.
--
Regards
Chris
Dan Krish wrote:
> Does Report Designer support Localization or Internationlization
> controls?
> E.g. when you a run a report which has currency column the report
> designer should format the column with the currency format present in
> the system's control panel (Regional Settings)|||Can you provide some functions that are used within the Report Designer for
localizing currencies & dates based on the regional settings? I tried using
FORMATCURRENCY in my reports, but it did not help
"Chris McGuigan" wrote:
> In short, both are supported. Localisation is easy, with the in-built
> format codes, eg. 'c' for currency.
> Globalisation is trickier, requiring some code. Generally the
> System.Globalization namespace has most things in that you'll need.
> One thing to note though is that the designer is an absolute pig with
> non-US dates. Generally the reports are OK when deployed though.
> --
> Regards
> Chris
>
> Dan Krish wrote:
> > Does Report Designer support Localization or Internationlization
> > controls?
> >
> > E.g. when you a run a report which has currency column the report
> > designer should format the column with the currency format present in
> > the system's control panel (Regional Settings)
>|||Dan,
In the "format" property of a cell, if you use "c2" for currency (with
2 decimal places) it will format the currency and number format
according to the locale of the users PC. e.g In UK, 12345.99 would be
£12,345.99 in the US $12,345.99 and in France (I'm guessing a bit
here!) I would expect something like 12.345,99â?¬. 'n' for numeric I
believe work's the same.
In RS2000 BOL a list of format codes can be found at;
ms-help://MS.RSBOL80.1033/RSCREATE/htm/rcr_creating_layout_v1_365w.htm
and try these links for further info.
ms-help://MS.RSBOL80.1033/rsadmin/htm/drp_deploying_v1_0vaa.htm
ms-help://MS.RSBOL80.1033/RSCREATE/htm/rcr_creating_building_v1_31bn.htm
As for some sample code, I wrote this some time ago in RS2000.
Essentially the report had to show group figures so I had to change
number & currency formats depending on which country I was
displaying.The Globalization namespace has lots of goodies in it and I
suggest you study the documentation on that;
Public CultureInfo As System.Globalization.CultureInfo
Public Culture As String
Public CurrencyValue As Decimal
Public CurrencyFormat As String
Public CurrencyPositivePattern(3) As String
Public CurrencyNegativePattern(15) As String
Public Function Main() As String
Dim str As String
CurrencyPositivePattern(0) = "$n"
CurrencyPositivePattern(1) = "n$"
CurrencyPositivePattern(2) = "$ n"
CurrencyPositivePattern(3) = "n $"
CurrencyNegativePattern(0) = "($n)"
CurrencyNegativePattern(1) = "-$n"
CurrencyNegativePattern(2) = "$-n"
CurrencyNegativePattern(3) = "$n-"
CurrencyNegativePattern(4) = "(n$)"
CurrencyNegativePattern(5) = "-n$"
CurrencyNegativePattern(6) = "n-$"
CurrencyNegativePattern(7) = "n$-"
CurrencyNegativePattern(8) = "-n $"
CurrencyNegativePattern(9) = "-$ n"
CurrencyNegativePattern(10) = "n $-"
CurrencyNegativePattern(11) = "$ n-"
CurrencyNegativePattern(12) = "$ -n"
CurrencyNegativePattern(13) = "n- $"
CurrencyNegativePattern(14) = "($ n)"
CurrencyNegativePattern(15) = "(n $)"
str = SetCulture("en-GB", "GBP")
Return ("")
End Function
Public Function GetCurrencyFormat(ByVal Culture As String) As String
Dim nfi As System.Globalization.NumberFormatInfo
Dim pos As String
Dim neg As String
Dim sym As String
Dim sep As String
Dim sb As System.Text.StringBuilder
Dim cpp As Integer
Dim cnp As Integer
CultureInfo = New System.Globalization.CultureInfo(Culture,
False)
nfi = CultureInfo.NumberFormat
sym = nfi.CurrencySymbol
sep = nfi.CurrencyGroupSeparator
cpp = nfi.CurrencyPositivePattern
cnp = nfi.CurrencyNegativePattern
sb = New System.Text.StringBuilder(CurrencyPositivePattern(cpp))
sb.Replace("$", sym)
sep = ","
sb.Replace("n", "###" & sep & "###" & sep & "##0")
pos = sb.ToString
sb = New System.Text.StringBuilder(CurrencyNegativePattern(cnp))
sb.Replace("$", sym)
sep = ","
sb.Replace("n", "###" & sep & "###" & sep & "##0")
neg = sb.ToString
CurrencyFormat = pos & ";" & neg
Return CurrencyFormat
End Function
Public Function SetCulture(ByVal Culture As String, ByVal Currency
As String) As String
CurrencyFormat = GetCurrencyFormat(Culture)
Return Currency
End Function
Public Function ToCur(ByVal Value As Double) As String
CurrencyValue = Value
Return Value.ToString("c0", CultureInfo)
End Function
Public Function ToCur(ByVal Value As Double, Culture As String) As
String
CultureInfo = New System.Globalization.CultureInfo(Culture,
False)
CurrencyValue = Value
Return Value.ToString("c0", CultureInfo)
End Function

No comments:

Post a Comment