'SummaryPage2_AccountWarnings_WarningSummary
Option Explicit On
Option Strict On

' #################################################################
' Account Warning Summary

' Version: 2.00 (31/10/2013)

' Usage: Displays warnings on the New Account and Accept/Decline
' Account and Account Application wizards.
' #################################################################

' Objects
Private mAccountWarning As finAccountWarning
Private mAccountWarnings As finAccountWarnings

Public Function Main(source As Object, eventId As String, eventArgs As ISKeyValueList, ByRef handled As Boolean, ByRef returnValues As ISKeyValueList, ByRef text As String) As Boolean

  Dim Index As Integer
  
  ' Assume Success
  Main = True

  ' Initialise
  mAccountWarnings = DirectCast(source, finAccountWarnings)
  Index = eventArgs.GetInteger("Index", -1)
  If Index <> -1 Then mAccountWarning = mAccountWarnings(Index)

  ' Handle Events
  Select Case eventId
    Case ""
      ' Main event, i.e., return main page content
      Main = CreatePage(text)
  End Select

End Function

Private Function CreatePage(ByRef html As String) As Boolean

  Dim Ok As Boolean
  Dim SummaryTable As ISSummaryTable
  Dim SummaryTables As ISSummaryTables

  ' Assume Success
  Ok = True

  ' Initialise
  SummaryTables = finBL.CreateSummaryTables()
  
  ' Create Summary Table
  SummaryTable = finBL.CreateSummaryTable()
  With SummaryTable
    .TableClass = iseSummaryTableClass.Information 
    .Columns.AddText("", 10)
    .Columns.AddText()

    If mAccountWarning IsNot Nothing Then
      With .Rows
        ' Type
        Select Case mAccountWarning.Severity 
          Case isefinAccountWarningSeverity.Alert: .AddCaptionText("Type:", "{{icon|Warning}} " & mAccountWarning.SeverityText)
          Case isefinAccountWarningSeverity.Fail: .AddCaptionText("Type:", "{{icon|Error}} " & mAccountWarning.SeverityText)
          Case isefinAccountWarningSeverity.Information: .AddCaptionText("Type:", "{{icon|Information}} " & mAccountWarning.SeverityText)
        End Select
        
        ' Client
        If mAccountWarning.ClientPk <> 0 Then
          .AddCaptionWiki("Client:", String.Format("**[[app://FormShow?form=Clients&id={0}|{0}]]**, {1}", mAccountWarning.ClientId, mAccountWarning.ClientName))
        End If
        
        ' Warning
        .AddText(mAccountWarning.Summary, iseSummaryTableCellClass.Highlight1)
        
        ' Details
        If Len(mAccountWarning.Details) <> 0 Then
          .AddText(mAccountWarning.Details, iseSummaryTableCellClass.Normal)
        End If
      End With
      
      ' Warnings
      If mAccountWarning.DetailsIsHtml AndAlso Instr(mAccountWarning.Details, "<") <> 0 Then
        .TextAfter = "{{warning|This summary does not support HTML formatted warning details.}}"
      End If
    End If
  End With
  SummaryTables.Add("Main", SummaryTable)

  ' Create HTML
  html = finBL.Utilities.GetHtmlFromSummaryTables(SummaryTables)

  Return Ok

End Function