Imports System.Collections.Generic
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

Partial Class Controls_SubmitOrder
    Inherits System.Web.UI.UserControl

    Private _HBXInfo_page As String
    Private _HBXInfo_mlc As String

    Dim _cart As ICart

    Public Property Cart() As ICart
        Get
            Return _cart
        End Get
        Set(ByVal value As ICart)
            _cart = value
        End Set
    End Property

    Public Property HBXInfo_PageName() As String
        Get
            Return _HBXInfo_page
        End Get
        Set(ByVal value As String)
            _HBXInfo_page = value
        End Set
    End Property

    Public Property HBXInfo_MLC() As String
        Get
            Return _HBXInfo_mlc
        End Get
        Set(ByVal value As String)
            _HBXInfo_mlc = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            btnSubmit.ValidationGroup = "SubmitOrderGroup"
            vldSummary.ValidationGroup = "SubmitOrderGroup"



        End If

        ' assign shopping cart's cart property
        ucShoppingCart.Cart = Cart
    End Sub



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

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSubmit.Click

        '######################################################
        '10/24/2007 Brad Miller - Make G2B Authenticate call
        '######################################################
        Dim iProvider As IG2BServicesProvider = CType(Activator.GetObject(GetType(IG2BServicesProvider), CStr(HttpContext.Current.Application("RemoteURL_G2BServicesProvider"))), IG2BServicesProvider)
        Dim providerRequest As EntityG2BServices.G2BAuthenticateRequest
        providerRequest = New EntityG2BServices.G2BAuthenticateRequest()

        Dim lAccount As IAccount = AccountManager.Instance.GetAccount()
        If lAccount IsNot Nothing Then
            With providerRequest
                .FirstName = lAccount.Person.FirstName
                .LastName = lAccount.Person.LastName
                .ServiceAddressPhone = lAccount.Phone
                .ServiceAddress.AddressLine = lAccount.Address.Street1
                .ServiceAddress.Suite = lAccount.Address.Street2
                .ServiceAddress.City = lAccount.Address.City
                .ServiceAddress.State = lAccount.Address.State
                .ServiceAddress.Zip = lAccount.Address.Zip
                .SocialSecurityNumber = lAccount.SSN
                .MSOID = lAccount.MSOID
                .TrackingID = lAccount.TrackingID


                If lAccount.AuthQuestion IsNot Nothing Then
                    For Each item As BLG2BAuthQuestion In lAccount.AuthQuestion.Values
                        If Not (item Is Nothing) Then
                            Dim lProviderQuestion As New G2BAuthFieldInput
                            If item.UserResponded Then
                                lProviderQuestion.ID = item.QuestionID
                                lProviderQuestion.Value = item.AnswerFromUser
                                .AuthFieldInput.Add(lProviderQuestion)
                            End If
                        End If

                    Next
                End If

                If lAccount.IsExistingUser Then
                    .NewCustomer = False
                Else
                    .NewCustomer = True
                End If
            End With
        End If
        '##############################################################################







        '##################################################################################
        'MODIFICATION   ROD COPELAND    FEB 01 2008
        'THIS CHANGE WAS REQUESTED BY SHARON RENAUD, JOE KESSLER, LINDA LAMBERT.
        '##################################################################################
        'COUNT FLAG IS RESET IN THE CONTROLS/SHOPPINGCART.ASCX.VB AT THIS TIME.
        'IN THE EVENT THE USER ENDS UP ON THIS PAGE BY HITTING F5 WHILE ITS LOADING 
        'OR NAVIGATING DIRECTLY TO IT, THE INTENT IS TO NOT SUBMIT THE WEB SERVICE CALL 
        'TWICE BY USING THIS FLAG.
        'TO CLEAR THESE FLAGS, THE USER WILL NEED TO CHECKOUT AGAIN.
        '##################################################################################
        If Not (Session("AUTHENTICATE_CALL_FOR_SUBMIT_ORDER_COUNT") Is Nothing) Then
            '#################################################################################
            'SKIP THE AUTHENTICATE CALL SINCE IT LOOKS LIKE IT HAS BEEN MADE ALREADY
            '#################################################################################

        Else
            '#######################################################################
            'MODIFICATION   ROD COPELAND    FEB 08, 2008
            '#######################################################################
            'PER LLAMBERT, SRENAUD, JKESSLOR WE SHOULD BE CALLING THE AUTHENTICATE 
            'CALL EVERY TIME RATHER THAN CONDITIONING WITH SSN OR MS LOGIN CALLS 
            'PREVIOUSLY MADE. COMMENT OUT CONDITIONS BLOCKING AUTHENTICATE CALLS FOR ALL
            '#######################################################################

            Session("AUTHENTICATE_CALL_FOR_SUBMIT_ORDER_COUNT") = Session("AUTHENTICATE_CALL_FOR_SUBMIT_ORDER_COUNT") + 1

            'providerRequest.SourceIPAddress = CType(IIf(Request.ServerVariables("REMOTE_ADDR") Is Nothing, String.Empty, Request.ServerVariables("REMOTE_ADDR")), String)

            Dim providerResponse As EntityG2BServices.G2BAuthenticateResponse
            '#######################################################################
            'PART OF THE 4.1 PROJECT 10/30/2007
            'PER STEPHANIE BOONE, ITS OK TO JUST DO THE AUTHENTICATE CALL AND 
            'REGARDLESS OF THE RESPONSE (ERROR OR SUCCESS), WE JUST CONTINUE 
            'ON AND G2B ASSOCIATES THE TRACKING ID WITH THE ORDER AFTER THE FACT.
            '#######################################################################
            providerResponse = CType(iProvider.Authenticate(providerRequest), EntityG2BServices.G2BAuthenticateResponse)
        End If


        '#################################################################################
        'SEND TO THE LOADING PAGE AND LET IT FIGURE OUT IF A CALL SHOULD BE MADE OR NOT.
        'THE LOADING PAGE WILL SKIP OVER THE SUBMIT ORDER CALL IF IT HAS ALREADY BEEN 
        'PROCESSED, SO LETS KEEP THEM WAITING UNTIL THAT CALL COMPLETES.
        '#################################################################################
        If Page.IsValid Then
            Response.Redirect("Loading.aspx?" & QueryStringName.Destination + "=SUBMIT")
        End If



    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Me.ucShoppingCart.HBXInfo_PageName = Me.HBXInfo_PageName
        Me.ucShoppingCart.HBXInfo_MLC = Me.HBXInfo_MLC
    End Sub
End Class
