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 Controls_EnterInformation
    Inherits System.Web.UI.UserControl

    Public blnEBureauFlagEnabled As Boolean = False
    Private _isexistinguser As Boolean = False


    Public Property IsExistingUser() As Boolean
        Get
            Return _isexistinguser
        End Get
        Set(ByVal value As Boolean)
            _isexistinguser = value
        End Set
    End Property
    Dim _account As IAccount            'added
    Public Property Account() As IAccount           'added
        Get
            Return _account
        End Get
        Set(ByVal value As IAccount)
            _account = value
        End Set
    End Property

    '#######################################################################
    '9/18/2007 - Brad Miller
    'Shipping Address panel and corresponding logic added for G2B 4.1
    '#######################################################################
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Dim account As IAccount					'commntd
        Dim _email As IAccount.IMember.IEmail

        If Not IsPostBack Then
            vldBillingAddress1Required.ValidationGroup = Me.ID
            vldBillingCityRequired.ValidationGroup = Me.ID
            vldBillingStateRequired.ValidationGroup = Me.ID
            vldBillingZipCodeRegEx.ValidationGroup = Me.ID
            vldBillingZipCodeRequired.ValidationGroup = Me.ID

            vldShippingAddress1Required.ValidationGroup = Me.ID
            vldShippingCityRequired.ValidationGroup = Me.ID
            vldShippingStateRequired.ValidationGroup = Me.ID
            vldShippingZipCodeRegEx.ValidationGroup = Me.ID
            vldShippingZipCodeRequired.ValidationGroup = Me.ID

            vldEmailRegEx.ValidationGroup = Me.ID
            ' vldEmailRequired.ValidationGroup = Me.ID
            vldFirstNameRequired.ValidationGroup = Me.ID
            vldLastNameRequired.ValidationGroup = Me.ID
            vldPhoneRegEx.ValidationGroup = Me.ID
            vldPhoneRequired.ValidationGroup = Me.ID
            vldSummaryEnterInformation.ValidationGroup = Me.ID

            vldMovingToAddress1.ValidationGroup = Me.ID
            vldMovingToCity.ValidationGroup = Me.ID
            vldMovingToState.ValidationGroup = Me.ID
            vldMovingToZipCode.ValidationGroup = Me.ID


            btnNext.ValidationGroup = Me.ID

            ddlBillingState.DataSource = CType(Application(ApplicationKey.StateList), System.Data.DataTable)
            ddlBillingState.DataTextField = "Name"
            ddlBillingState.DataValueField = "Abbv"
            ddlBillingState.DataBind()
            ddlBillingState.Items.Insert(0, New ListItem(String.Empty, String.Empty))

            ddlShippingState.DataSource = CType(Application(ApplicationKey.StateList), System.Data.DataTable)
            ddlShippingState.DataTextField = "Name"
            ddlShippingState.DataValueField = "Abbv"
            ddlShippingState.DataBind()
            ddlShippingState.Items.Insert(0, New ListItem(String.Empty, String.Empty))

            'account = AccountManager.Instance.GetAccount()				'commntd

            lblAddress1.Text = _account.Address.Street1
            lblAddress2.Text = _account.Address.Street2
            lblCity.Text = _account.Address.City

            lblState.Text = _account.Address.State
            lblZipCode.Text = _account.Address.Zip

            If Not (_account.Person Is Nothing) Then
                txtLastName.Text = _account.Person.LastName
                txtFirstName.Text = _account.Person.FirstName

                txtPhone.Text = _account.Phone

                If Not (_account.Person.Email Is Nothing) Then
                    For Each _email In _account.Person.Email
                        If _email.IsPrimary Then
                            txtEmail.Text = _email.MailID
                            Exit For
                        End If
                    Next
                End If

            End If

            If Not (_account.BillingAddress Is Nothing) Then
                txtBillingAddress1.Text = _account.BillingAddress.Street1
                txtBillingAddress2.Text = _account.BillingAddress.Street2
                txtBillingCity.Text = _account.BillingAddress.City
                ddlBillingState.SelectedValue = _account.BillingAddress.State
                txtBillingZipCode.Text = _account.BillingAddress.Zip

                chkBillingInfo.Checked = True
                pnlBillingInfo.Visible = True
            Else
                chkBillingInfo.Checked = False
                pnlBillingInfo.Visible = False
            End If

            If Not (_account.ShippingAddress Is Nothing) Then
                txtShippingAddress1.Text = _account.ShippingAddress.Street1
                txtShippingAddress2.Text = _account.ShippingAddress.Street2
                txtShippingCity.Text = _account.ShippingAddress.City
                ddlShippingState.SelectedValue = _account.ShippingAddress.State
                txtShippingZipCode.Text = _account.ShippingAddress.Zip

                chkShippingInfo.Checked = True
                pnlShippingInfo.Visible = True
            Else
                chkShippingInfo.Checked = False
                pnlShippingInfo.Visible = False
            End If

            'If Request.IsAuthenticated Then
            '    btnBack.Visible = False
            'Else
            '    btnBack.Visible = True
            'End If

            'Disable Entry fields but for E-Mail, for Existing Users
            If IsExistingUser Then
                txtFirstName.Enabled = False
                txtLastName.Enabled = False
                txtPhone.Enabled = False
            Else
                txtFirstName.Enabled = True
                txtLastName.Enabled = True
                txtPhone.Enabled = True
            End If

            '10/15/2007 Brad Miller - Shipping Address only visible for self-installation
            Dim catalog As ICatalog
            Dim cart As ICart
            Const HSIKey5 As String = "25700"
            Const HSIKey10 As String = "25800"
            'Const CableModemKey As String = "42956"
            Const ShipOptionsKey As String = "411297"
            Const ShipStandardKey As String = "4995258"
            Const ShipOvernightKey As String = "4995260"

            'retrieve catalog and cart
            catalog = CatalogManager.Instance.GetCatalog()
            If catalog Is Nothing Then
                Throw New MissingCatalogException()
            End If

            'check if self-installation is checked
            pnlChkShipping.Visible = False
            cart = catalog.Cart
            If Not cart Is Nothing Then
                If Not cart.CartItems Is Nothing Then
                    If IsExistingUser Then
                        If cart.CartItems.ContainsKey(HSIKey5) Then
                            If cart.CartItems(HSIKey5).Children.ContainsKey(ShipOptionsKey) Then
                                If (Not cart.CartItems(HSIKey5).Children Is Nothing) AndAlso (cart.CartItems(HSIKey5).Children.Count > 0) Then
                                    If cart.CartItems(HSIKey5).Children.ContainsKey(ShipOptionsKey) Then
                                        If (Not cart.CartItems(HSIKey5).Children(ShipOptionsKey).Children Is Nothing) AndAlso (cart.CartItems(HSIKey5).Children(ShipOptionsKey).Children.Count > 0) Then
                                            If cart.CartItems(HSIKey5).Children(ShipOptionsKey).IsSelected Then
                                                If (Not cart.CartItems(HSIKey5).Children(ShipOptionsKey).Children Is Nothing) AndAlso (cart.CartItems(HSIKey5).Children(ShipOptionsKey).Children.Count > 0) Then
                                                    If (cart.CartItems(HSIKey5).Children(ShipOptionsKey).Children(ShipStandardKey).IsSelected Or _
                                                        cart.CartItems(HSIKey5).Children(ShipOptionsKey).Children(ShipOvernightKey).IsSelected) Then
                                                        pnlChkShipping.Visible = True
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        ElseIf cart.CartItems.ContainsKey(HSIKey10) Then
                            If cart.CartItems(HSIKey10).Children.ContainsKey(ShipOptionsKey) Then
                                If (Not cart.CartItems(HSIKey10).Children Is Nothing) AndAlso (cart.CartItems(HSIKey10).Children.Count > 0) Then
                                    If cart.CartItems(HSIKey10).Children.ContainsKey(ShipOptionsKey) Then
                                        If (Not cart.CartItems(HSIKey10).Children(ShipOptionsKey).Children Is Nothing) AndAlso (cart.CartItems(HSIKey10).Children(ShipOptionsKey).Children.Count > 0) Then
                                            If cart.CartItems(HSIKey10).Children(ShipOptionsKey).IsSelected Then
                                                If (Not cart.CartItems(HSIKey10).Children(ShipOptionsKey).Children Is Nothing) AndAlso (cart.CartItems(HSIKey10).Children(ShipOptionsKey).Children.Count > 0) Then
                                                    If (cart.CartItems(HSIKey10).Children(ShipOptionsKey).Children(ShipStandardKey).IsSelected Or _
                                                        cart.CartItems(HSIKey10).Children(ShipOptionsKey).Children(ShipOvernightKey).IsSelected) Then
                                                        pnlChkShipping.Visible = True
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If





        If Not (Application("eBureau_ENABLED") Is Nothing) Then
            If Application("eBureau_ENABLED").ToString.Trim().ToLower() = "t" Then
                blnEBureauFlagEnabled = True
            Else
                blnEBureauFlagEnabled = False
            End If
        Else
            blnEBureauFlagEnabled = False
        End If




    End Sub

    Protected Sub chkBillingInfo_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBillingInfo.CheckedChanged
        If chkBillingInfo.Checked Then
            pnlBillingInfo.Visible = True
        Else
            txtBillingAddress1.Text = String.Empty
            txtBillingAddress2.Text = String.Empty
            txtBillingCity.Text = String.Empty
            ddlBillingState.SelectedValue = String.Empty
            txtBillingZipCode.Text = String.Empty

            pnlBillingInfo.Visible = False
        End If
    End Sub

    Protected Sub chkShippingInfo_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkShippingInfo.CheckedChanged
        If chkShippingInfo.Checked Then
            pnlShippingInfo.Visible = True
        Else
            txtShippingAddress1.Text = String.Empty
            txtShippingAddress2.Text = String.Empty
            txtShippingCity.Text = String.Empty
            ddlShippingState.SelectedValue = String.Empty
            txtShippingZipCode.Text = String.Empty

            pnlShippingInfo.Visible = False
        End If
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnBack.Click
        Response.Redirect("ChooseOptions.aspx")
    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnNext.Click
        If Page.IsValid Then
            Dim rgPattern As String = "[^0-9]" '"[\\\/:\*\?""'<>|]"
            Dim regX As New Regex(rgPattern)
            Dim phone As String = regX.Replace(txtPhone.Text, "")


            If Not (Application("eBureau_ENABLED") Is Nothing) Then
                If Application("eBureau_ENABLED").ToString.Trim().ToLower() = "t" Then
                    '##############################################################################################
                    'ISSUE ID 6402      ROD COPELAND    6/9/2009
                    '##############################################################################################
                    'JOE KESSLER REQUESTED A CHANGE THAT DOES NOT PASS THE 401 ADDRESS TWO AUTHINPUTFIELD 
                    'TO THE G2B AUTHENTICATE WS METHOD WHEN THE USER DOES NOT ENTER ONE.  TO AVOID PASSING 
                    'AN EMPTY STRING AS A PLACEHOLDER.  MADE CHANGES TO THIS ATTRIBUTE ALONG WITH THE OTHER 
                    'AUTHINPUTFIELD VALUES ASSOCIATED TO THE SECONDARY ADDRESS.
                    '##############################################################################################
                    If rblDisplayMovingToAddress.SelectedIndex = 0 Then 'if MovingTo address selected, add MovingTo address to account object
                        Dim lAccount As IAccount = AccountManager.Instance.GetAccount()
                        If Not (lAccount Is Nothing) Then
                            If Not (lAccount.AuthQuestion Is Nothing) Then
                                If lAccount.AuthQuestion.ContainsKey("400") Then
                                    If txtMovingToAddress1.Text.Trim() <> "" Then
                                        lAccount.AuthQuestion("400").UserResponded = True
                                        lAccount.AuthQuestion("400").AnswerFromUser = txtMovingToAddress1.Text.Trim()
                                    End If
                                End If

                                If lAccount.AuthQuestion.ContainsKey("401") Then
                                    If txtMovingToAddress2.Text.Trim() <> "" Then
                                        lAccount.AuthQuestion("401").UserResponded = True
                                        lAccount.AuthQuestion("401").AnswerFromUser = txtMovingToAddress2.Text.Trim()
                                    End If
                                End If

                                If lAccount.AuthQuestion.ContainsKey("402") Then
                                    If txtMovingToCity.Text.Trim() <> "" Then
                                        lAccount.AuthQuestion("402").UserResponded = True
                                        lAccount.AuthQuestion("402").AnswerFromUser = txtMovingToCity.Text.Trim()
                                    End If
                                End If

                                If lAccount.AuthQuestion.ContainsKey("403") Then
                                    If txtMovingToState.Text.Trim() <> "" Then
                                        lAccount.AuthQuestion("403").UserResponded = True
                                        lAccount.AuthQuestion("403").AnswerFromUser = txtMovingToState.Text.Trim()
                                    End If
                                End If

                                If lAccount.AuthQuestion.ContainsKey("404") Then
                                    If txtMovingToZipCode.Text.Trim() <> "" Then
                                        lAccount.AuthQuestion("404").UserResponded = True
                                        lAccount.AuthQuestion("404").AnswerFromUser = txtMovingToZipCode.Text.Trim()
                                    End If
                                End If
                            End If
                        End If
                    End If

                End If
            End If


            If chkBillingInfo.Checked Or chkShippingInfo.Checked Then
                If chkBillingInfo.Checked Then
                    AccountManager.Instance.UpdateMemberInformation(txtLastName.Text, txtFirstName.Text, phone, txtEmail.Text, _
                    txtBillingAddress1.Text, txtBillingAddress2.Text, txtBillingCity.Text, ddlBillingState.Text, txtBillingZipCode.Text)
                End If
                If chkShippingInfo.Checked Then
                    AccountManager.Instance.UpdateMemberInformation(txtLastName.Text, txtFirstName.Text, phone, txtEmail.Text, _
                    txtShippingAddress1.Text, txtShippingAddress2.Text, txtShippingCity.Text, ddlShippingState.Text, txtShippingZipCode.Text, True)
                End If
            Else
                AccountManager.Instance.UpdateMemberInformation(txtLastName.Text, txtFirstName.Text, phone, txtEmail.Text)
            End If

            Response.Redirect("SubmitOrder.aspx")
        End If
    End Sub

    Protected Sub rblDisplayMovingToAddress_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rblDisplayMovingToAddress.SelectedIndexChanged
        Select Case rblDisplayMovingToAddress.SelectedIndex
            Case 1 'If No
                pnlMovingToAddress.Visible = False
            Case 0 'If Yes
                pnlMovingToAddress.Visible = True
        End Select
    End Sub
End Class
