﻿
Partial Class order_centre_customer_contact_info
    Inherits System.Web.UI.Page

    Private _webAdapter As New WebWS()
    Private _goPrint2Adapter As New com.racadtech.services.GoPrint2Client()
    Private _customerDetails As New com.racadtech.services.CustomerDetails()

    Public ReadOnly Property WebAdapter() As WebWS
        Get
            Return _webAdapter
        End Get
    End Property
    Public ReadOnly Property GoPrint2Adapter() As com.racadtech.services.GoPrint2Client
        Get
            Return _goPrint2Adapter
        End Get
    End Property
    Public Property CustomerInformation() As com.racadtech.services.CustomerDetails
        Get
            Return _customerDetails
        End Get
        Set(ByVal value As com.racadtech.services.CustomerDetails)
            _customerDetails = value
        End Set
    End Property
    Public ReadOnly Property MasterKey() As String
        Get
            Return "877k31hg333-d03423332wq-312dkazlfs-433398j543"
        End Get
    End Property
    Public ReadOnly Property CurrentUser() As String
        Get
            Return System.Web.HttpContext.Current.User.Identity.Name.ToString()
        End Get
    End Property
    Public ReadOnly Property CurrentUserId() As String
        Get
            Return Membership.GetUser(CurrentUser).ProviderUserKey.ToString()
        End Get
    End Property
    Public ReadOnly Property CurrentCustomerId() As String
        Get
            Return WebAdapter.GetCustomerIdByUserId(CurrentUserId)
        End Get
    End Property
    Public ReadOnly Property CurrentActivationId() As String
        Get
            Return WebAdapter.GetActivationIdByStoreId(Session("StoreId")).ToString()
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Dim _customerId As String = WebAdapter.GetCustomerIdByUserId(CurrentUserId)
        'Dim _customId As String = "27fa33e4-7a8d-4e63-9873-1d8e580240f9"
        If Not Page.IsPostBack Then
            If (Not System.Web.HttpContext.Current.User.Identity.IsAuthenticated()) Then
                Response.Redirect("~/order_centre/login.aspx")
            End If

            If (Not CurrentCustomerId Is Nothing) Then
                CustomerInformation = GoPrint2Adapter.GetCustomerDetails(MasterKey, CurrentCustomerId)
                FirstnameTextBox.Text = CustomerInformation.Firstname
                LastNameTextBox.Text = CustomerInformation.Lastname
                CompanyNameTextBox.Text = CustomerInformation.CompanyName
                AddressTextBox1.Text = CustomerInformation.Address1
                AddressTextBox2.Text = CustomerInformation.Address2
                CityTextBox.Text = CustomerInformation.City
                ZipTextBox.Text = CustomerInformation.PostalCode
                StateTextBox.Text = CustomerInformation.Province
                If ((Not CustomerInformation.Country Is Nothing) And (CustomerInformation.Country <> "")) Then
                    If (Not CountryDropDownList.Items.FindByText(CustomerInformation.Country) Is Nothing) Then
                        CountryDropDownList.SelectedValue = CustomerInformation.Country
                    End If
                End If
                EmailTextBox.Text = CustomerInformation.Email
                PhoneTextBox.Text = CustomerInformation.Phone
                FaxTextBox.Text = CustomerInformation.Fax
                Response.Write(CustomerInformation.Country)
            End If
        End If
        'Response.Write(Session("StoreId"))
    End Sub

    'Protected Sub NextImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles NextImageButton.Click
    '    Dim _customerId As String = ""
    '    Dim _storeId As String = Session("StoreId")
    '    If (Not CurrentCustomerId Is Nothing) Then
    '        _customerId = CurrentCustomerId
    '    End If
    '    GoPrint2Adapter.UpdateCustomerDetailsWithUserId(_customerId, CurrentUserId, CurrentActivationId, _
    '                                                    FirstnameTextBox.Text, LastNameTextBox.Text, _
    '                                                    AddressTextBox1.Text, AddressTextBox2.Text, _
    '                                                    CityTextBox.Text, StateTextBox.Text, ZipTextBox.Text, _
    '                                                    CountryDropDownList.SelectedValue, PhoneTextBox.Text, _
    '                                                    FaxTextBox.Text, EmailTextBox.Text, MasterKey)

    '    Response.Redirect("job_options.aspx")
    'End Sub
    ' 
    ' 
    ' 

    Protected Sub NextButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NextButton.Click
        Dim _customerId As String = ""
        Dim _storeId As String = Session("StoreId")
        If (Not CurrentCustomerId Is Nothing) Then
            _customerId = CurrentCustomerId
        End If
        GoPrint2Adapter.UpdateCustomerDetailsWithUserId(_customerId, CurrentUserId, CurrentActivationId, _
                                                        FirstnameTextBox.Text, LastNameTextBox.Text, CompanyNameTextBox.Text, _
                                                        AddressTextBox1.Text, AddressTextBox2.Text, _
                                                        CityTextBox.Text, StateTextBox.Text, ZipTextBox.Text, _
                                                        CountryDropDownList.SelectedValue, PhoneTextBox.Text, _
                                                        FaxTextBox.Text, EmailTextBox.Text, MasterKey)

        Response.Redirect("job_options.aspx")
    End Sub
End Class
