Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.CommonEntities.Library.EntityMemberServices
'Imports CharterDotCom.CommonEntities.Library.EntityEBSServices
Imports CharterDotCom.CommonEntities.Library.EntitySupport
Imports CharterDotCom.CommonEntities.Library.EntitySearch
Imports CharterDotCom.CommonEntities.Library.EntityWebConfig
'Imports CharterDotCom.CommonEntities.Library.EntityG2BServices
Imports CharterDotCom.WebSite.Library
' Imports CharterDotCom.Common.Logging


Partial Class Account_CharterEPay
    Inherits CharterCMSPage

    Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
        Try
            SetPageTitle("Charter EPay")
            'Logger.WebLog(String.Format("\UI\Account\CharterEPay\{0}", Request.QueryString("successPage")))

            If Not IsPostBack() Then

                '#################################################################
                'MODIFICATION   ROD COPELAND    ISSUE ID 6782   AUG 13, 2009
                '#################################################################
                'SUPPORT CSG MULTI-STATEMENT LINKS NOT DIRECTING TO SPECIFIC ACCTS 
                'ON THE BILL VENDOR DOMAIN
                '#################################################################
                'Request.QueryString("AcctIndex") IS SET IN THE 
                'CONTROLS/QUICKPAY.ASCX PAGE.
                '#################################################################
                Dim url As String = ""
                Dim blnViewStatementsForSiblingAccountNumber As Boolean = False
                Dim lAccount As IAccount = Nothing
                Dim strAcctIndex As String = Request.QueryString("AcctIndex")

                If IsNumeric(strAcctIndex) Then
                    lAccount = AccountManager.Instance.GetAccount()
                    If lAccount IsNot Nothing Then
                        If lAccount.Bill IsNot Nothing Then
                            If (strAcctIndex + 1) <= lAccount.Bill.Count() Then
                                blnViewStatementsForSiblingAccountNumber = True
                            End If
                        End If
                    End If
                End If

                ' removed a ton of comments here that were pretty unnecessary surrounding this
                ' massive nested if statement.  boiled down to:  if all these succeed then use
                ' newregisteroptions, otherwise default to query string.  i think this is a
                ' 'little' more legible
                ' cortright 9/19/2011
                Dim successPage As String = Request.QueryString("successPage")
                Dim _account As IAccount = AccountManager.Instance.GetAccount()
                If Not (_account Is Nothing) Then
                    If Not (Application("USE_MYACCOUNT_EBPP_REDIRECT") Is Nothing) Then
                        If Application("USE_MYACCOUNT_EBPP_REDIRECT") = "T" Then
                            If Not _account.EBPP Is Nothing Then
                                If _account.EBPP.Trim().ToUpper() = "N" Then
                                    successPage = "newregisteroptions"
                                End If
                            End If
                        End If
                    End If
                End If

                If blnViewStatementsForSiblingAccountNumber Then
                    url = AccountManager.Instance.GetMSBillingSystemLink(lAccount.Bill(strAcctIndex).AccountNumber, successPage)
                Else
                    url = AccountManager.Instance.GetMSBillingSystemLink(Nothing, successPage)
                End If
               
                If Not String.IsNullOrEmpty(url) Then
                    url = url & appendStatementCode(Request.QueryString("sc"))
                    Response.Redirect(url)
                Else
                    Select Case True
                        Case Not AccountManager.Instance.GetLastCCOMDisplayFriendlyExceptionMessage Is Nothing
                            Response.Write(AccountManager.Instance.GetLastCCOMDisplayFriendlyExceptionMessage)
                            AccountManager.Instance.ClearCCOMDisplayFriendlyExceptionMessage()
                        Case Else
                            Response.Write("Sorry, we're unable to take your request at this time.")
                    End Select
                End If
            End If
        Catch ex As Exception
            Response.Write("Billing info is not available at this time, please try back later.")
        End Try
    End Sub

    Private Function appendStatementCode(ByVal sc As String) As String
        '##########################################################################################
        'MODIFICATION   ROD COPELAND    JUNE 23, 2008   ISSUE 4084
        '##########################################################################################
        'THE BILLING VENDOR SITE AND CUSTOMER CARE GROUP HAVE REQUESTED PEOPLE BE ABLE TO CLICK A 
        'LINK ON THE MYACCOUNT SECTION AND GET REDIRECTED OVER TO A SPECIFC LANDING PAGE RATHER 
        'THAN THE MAIN BILLING SUMMARY LANDING PAGE.  SINCE THE BILLING VENDOR USING URL MAPPING 
        'TO SEND TO SPECIFIC PAGES, WE'VE AGREED TO APPEND A NEW QUERYSTRING ATTRIBUTE TO THE URL 
        'TO INDICATE WHICH LANDING PAGE PEOPLE WANT. THE 'SC' VALUE IN THE QUERYSTRING IS FOR THE
        'STATEMENT CODE THAT IS NEEDED BY THE BILLING VENDOR. EXAMPLE 'SC' VALUES INCLUDE 003 002 001
        '##########################################################################################
        If Not (sc Is Nothing) Then
            Select Case sc.ToLower()
                Case "001"
                    Return "&sc=001"
                Case "002"
                    Return "&sc=002"
                Case "003"
                    Return "&sc=003"
                Case "004"
                    Return "&sc=004"
                Case "005"
                    Return "&sc=005"
                Case "006"
                    Return "&sc=006"
                Case "007"
                    Return "&sc=007"
                Case Else
                    '##############################
                    'TREAT AS NORMAL PAGE REQUEST
                    '##############################
                    Return ""
            End Select
        Else
            '##############################
            'TREAT AS NORMAL PAGE REQUEST
            '##############################
            Return ""
        End If
        '##########################################################################################

    End Function

End Class
