Imports EarthSoft.Common.Reports Imports System.Text.RegularExpressions Namespace EarthSoft.Reports.Library._184911 ''' ''' This class shows an example of coding a customized transformation of ARII, which implements IGridReportTransform and adds a thousands separator to REPORT_RESULT_TEXT defined in dt_action_level_lookup.lookup_code. ''' To make ARII to load/use this transformation, the below must be done: ''' 1. Copy this EarthSoft.Reports.Library.184911.dll into EQuIS Professional folder ''' 2. Populate dt_action_level_lookup with a record of lookup_method = Thousands Separator (which is used to associate this record to a record in st_module) and lookup_code = REPORT_RESULT_TEXT (which define the column of ARII results to be modified), and the optional items which are required by dt_action_level_lookup: lookup_source=UsedInARII or NONE, param_code=NONE, comparison_operator=NONE ''' 3. Populate st_module with a record of name = Thousands Separator (which is used to associate this record to a record in dt_action_level_lookup), module_type = ARII Transformation, object_name = EarthSoft.Reports.Library.184911,EarthSoft.Reports.Library._184911.AddThousandsSeparatorToREPORT_RESULT_TEXT, and version_number = 7.20.2.20129 (in which, 20.2 means the 2nd quarter of 2020 and 20129 means the 129th of Year 2020) ''' Public Class AddThousandsSeparatorToREPORT_RESULT_TEXT Inherits IGridReportTransform Protected Shared _RegEx As New Regex(EarthSoft.Common.Utilities.String.LocalNumberFormat) Protected Shared _DecimalSeparator As String = EarthSoft.Common.Resources.CurrentCulture.NumberFormat.NumberDecimalSeparator ''' ''' Adds a thousands separator to REPORT_RESULT_TEXT of ARII results. ''' ''' The GridReport whose DataTable will be transformed. ''' The selected ListParameter row. Public Overrides Sub Transform(gridReport As IGridReport, paramSelectedRow As System.Data.DataRow) 'No need to do anything if the below conditions happen If gridReport Is Nothing Then Return If gridReport.DataTable Is Nothing Then Return If gridReport.DataTable.Rows Is Nothing Then Return If gridReport.DataTable.Rows.Count = 0 Then Return 'Define which column of ARII results to be modified: dt_action_level_lookup.lookup_code=REPORT_RESULT_TEXT 'Note 1. As we can see, if dt_action_level_lookup.lookup_code=RESULT_TEXT, RESULT_TEXT will be added with thousands separator - it's flexible to users. 'Note 2. Because paramSelectedRow is passed in as datarow, its members of lookup_code, lookup_method and param_code can also be used if needed. 'Note 3. If the below line is changed to Dim columnName As String = "REPORT_RESULT_TEXT", it removes the flexibility from users but can guarantee nothing goes wrong. Dim columnName As String = paramSelectedRow.Item("lookup_code").ToString If Not gridReport.DataTable.Columns.Contains(columnName) Then Return 'Modify REPORT_RESULT_TEXT or the values of the colunm defined by lookup_code. Dim columnOrdinal As Integer = gridReport.DataTable.Columns(columnName).Ordinal For Each dr As DataRow In gridReport.DataTable.Rows 'Modify REPORT_RESULT_TEXT of the current dr datarow dr.Item(columnOrdinal) = GetValue(dr.Item(columnOrdinal).ToString()) Next End Sub Friend Shared Function GetValue(value As String) As String If String.IsNullOrEmpty(value) Then Return value Dim match = _RegEx.Match(value) If match Is Nothing Then Return value Dim dbl As Double = 0.0 If Double.TryParse(match.Value, dbl) Then 'fb.179722 'X = dbl 'If X < 1, Then Do Not change the value; 'If 1 <= X < 10, And X Is a whole number, Then there should always be a Single trailing zero after the Decimal point (e.g. 9 should be reported As 9.0 And 1.35 should remain 1.35) – add a Single trailing zero (With Decimal point) If none exists. 'If 1 <= X < 10, And X Is NOT a whole number and there are trailing zeros, remove the trailing zeros (e.g. 1.10 => 1.1, 1.100 => 1.1, 1.2350 => 1.235). 'If 10 <= X And X Is a whole number, Then there should never be a trailing zero (e.g. 19.0 should be reported As 19 And 19.4 should remain 19.4) – remove the trailing zero (And Decimal point) If it Is there 'Also, If 1000 <= x, then add the thousands separator to the whole number (the code already does this) Dim val = match.Value Dim d As Integer = val.IndexOf(_DecimalSeparator) Dim decimalStr As String = If(d < 0, "-1", val.Substring(d + 1)) If d <= 0 Then d = val.Length Dim wholeStr = val.Substring(0, d) Dim whole As Integer = 0 If dbl < 1 Then 'Do Not change the value Else Dim isWholeNumber As Boolean = False Dim decimal0 As Integer = 0 If decimalStr.Length = 0 OrElse decimalStr = -1 Then isWholeNumber = True ElseIf Integer.TryParse(decimalStr, decimal0) Then If decimal0 = 0 Then isWholeNumber = True End If If dbl < 10 Then decimalStr = If(isWholeNumber, "0", decimalStr.TrimEnd("0"c)) ' i.e. if whole number use "0" something else remove trailing "0"'s val = wholeStr & _DecimalSeparator & decimalStr Else 'remove trailing zero of a whole regardless If isWholeNumber Then val = wholeStr End If End If If Integer.TryParse(wholeStr, whole) AndAlso wholeStr.Length > 3 Then val = whole.ToString("##,#") & val.Substring(d) End If value = value.Replace(match.Value, val) End If Return value End Function End Class End Namespace