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.CommonEntities.Library.Common
Imports CharterDotCom.WebSite.Library


Partial Class Account_NewKeyActivated
	Inherits CharterCMSPage	'JPIRKEY 4-2010 Updating all pages to inherit from a single source.

    Public strSectionTitle As String = "New Security Key Activated"
    Public strKeyActivated As String = ""


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Me.ucSupportHelpfulLinksNew.Text = "<img src=""topbrdr_white_small.ccom"" alt="""" /><br /><div class=""content"">" & ContentManager.Instance.GetContent("home:helpfullinks", 1, OwnerType.Other) & "<div class=""clear""> </div></div><div><img src=""botbrdr_white_small.ccom"" alt="""" /></div>"
        Me.BrowseSupportNew.isNewPanel = True
        Me.BrowseSupportNew.Productategory = MenuItem.MyAccount
        Me.panelNew.Visible = True

        pnlSuccessfulKeyActivation.Visible = True

        If Not IsPostBack Then


            Dim _account As IAccount = AccountManager.Instance.GetAccount()

            If Not (_account Is Nothing) Then
                If Not (_account.Person Is Nothing) Then
                    If Not (_account.Person.MSPackageInfo Is Nothing) Then
                        If (_account.Person.MSPackageInfo.Count > 0) Then

                            Dim tempIndex As String = Request.QueryString("Index")

                            If Not tempIndex Is Nothing Then
                                If tempIndex.Trim() <> "" Then
                                    If IsNumeric(tempIndex.Trim()) Then
                                        'JUST CONTINUE, THEY SHOULD HAVE A GOOD INDEX VALUE HERE.
                                    Else
                                        tempIndex = "0"
                                    End If
                                Else
                                    tempIndex = "0"
                                End If
                            Else
                                tempIndex = "0"
                            End If



                            Dim lSecurityKeyCnt As Integer
                            If Not (_account.Person.MSPackageInfo(tempIndex).SecurityKeys Is Nothing) Then
                                lSecurityKeyCnt = _account.Person.MSPackageInfo(tempIndex).SecurityKeys.Count()
                            Else
                                '##################
                                'DEFAULTS TO ZERO
                                '##################
                                lSecurityKeyCnt = 0
                            End If



                            Dim lMaxSecurityKeysAllowed As Integer
                            If Not (_account.Person.MSPackageInfo(tempIndex).MaxSecurityKeysAllowed = 0) Then
                                lMaxSecurityKeysAllowed = _account.Person.MSPackageInfo(tempIndex).MaxSecurityKeysAllowed
                            Else
                                '##################
                                'DEFAULTS TO ZERO
                                '##################
                                lMaxSecurityKeysAllowed = 0
                            End If



                            Dim blnAddKey As Boolean = False



                            Select Case True
                                Case lSecurityKeyCnt >= lMaxSecurityKeysAllowed
                                    blnAddKey = False
                                    lblKeyMessage.Text = "You have the maximum amount of security keys available"
                                Case Else
                                    '###########################################################################
                                    'THIS COULD BE WHEN NO KEYS ARE ASSIGNED YET AND THEY HAVE AVAILABLE KEYS.
                                    '###########################################################################
                                    blnAddKey = True
                            End Select



                            If Not blnAddKey Then
                                '###########################################################
                                'DISPLAY MESSAGE ALREADY ASSIGNED TO THE lblKeyMessage.Text
                                '###########################################################
                                strSectionTitle = "New Security Key Activation Issue"
                                pnlSuccessfulKeyActivation.Visible = False
                            Else
                                Dim Result As Boolean = AccountManager.Instance.ActivateMSSecurityKey(_account.Person.MSPackageInfo(tempIndex).provisioningIdField)

                                If Result Then
                                    '##################
                                    'KEY ADD WAS GOOD.
                                    '##################


                                    '######################
                                    'SET THE COOKIE VALUE
                                    '######################

                                    If Not (_account.Person.MSPackageInfo(tempIndex).SecurityKeys Is Nothing) Then
                                        strKeyActivated = _account.Person.MSPackageInfo(tempIndex).SecurityKeys(_account.Person.MSPackageInfo(tempIndex).SecurityKeys.Count() - 1)
                                    Else
                                        '##################
                                        'DEFAULTS TO ZERO
                                        '##################
                                        lSecurityKeyCnt = 0
                                    End If
                                Else
                                    '##################################################################################
                                    '##########     E R R O R   C O D E   M A P P I N G    S O L U T I O N      #######
                                    '#################          MODIFIED BY ROD COPELAND, 5/2/2007     ################ 
                                    '##################################################################################
                                    'WRITE THE (IDEALLY) CHARTER FRIENDLY ERROR MESSAGES TO THE PAGE.  
                                    'THESE MESSAGES ARE MANAGED IN THE CHARTERDOTCOM.ADMIN.ERROR_CODE_MAPPING TABLE.
                                    'THE UNDERLYING LOGIC WILL DISPLAY THE DATASOURCE ERROR MESSAGE IF A 
                                    'CHARTERDOTCOM FRIENDLY ERROR MESSAGE IS NOT PRESENT ON THE RECORD.
                                    'THERE MAY BE MORE THAN ONE ERROR MESSAGE THAT COMES BACK, DISPLAY 
                                    'ACCORDINGLY.
                                    '##################################################################################
                                    Select Case True
                                        Case Not AccountManager.Instance.GetLastCCOMDisplayFriendlyExceptionMessage Is Nothing
                                            lblKeyMessage.Text = AccountManager.Instance.GetLastCCOMDisplayFriendlyExceptionMessage
                                            AccountManager.Instance.ClearCCOMDisplayFriendlyExceptionMessage()
                                        Case Else
                                            lblKeyMessage.Text = "Sorry, we're unable to take your request at this time."
                                    End Select
                                    '##################################################################################

                                    '####################
                                    'CONTINUE, DO NOTHING.
                                    'LEAVE PAGE AS IT WAS.
                                    '####################
                                End If
                            End If
                        Else
                            'lblKey1.Text = ""
                            'txtprovID.Text = ""
                        End If
                    Else
                        'lblKey1.Text = ""
                        'txtprovID.Text = ""
                    End If
                End If
            Else
                'lblKey1.Text = ""
                'txtprovID.Text = ""
            End If

        End If

    End Sub
End Class
