Imports BVSoftware.BVC.Core Public Class Checkout_Address_Multiple Inherits BaseStorePage #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents WelcomeDescription As System.Web.UI.WebControls.Label Protected WithEvents AddressBookList As System.Web.UI.WebControls.DropDownList Protected WithEvents ContinueButton As System.Web.UI.WebControls.ImageButton Protected WithEvents ItemsGrid As System.Web.UI.WebControls.DataGrid Protected WithEvents AddNewAddressButton As System.Web.UI.WebControls.ImageButton Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents CSSTag1 As BVSoftware.WebControls.CSSTag 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() 'SP2- Assures that SSL is used for this page if set up Me.RequiresSSL = True '-SP2 End Sub #End Region Dim thisOrder As Orders.Order Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then MetaKeywordsControl.Content = WebAppSettings.MetaKeywords MetaDescriptionControl.Content = WebAppSettings.MetaDescription CSSTag1.StyleSheetURL = PersonalizationServices.GetPersonalizedStyleSheet PageTitle = "Address" AddNewAddressButton.ImageUrl = ImageHelper.GetThemedButton("AddNewAddress.gif") ContinueButton.ImageUrl = ImageHelper.GetThemedButton("Continue.gif") End If thisOrder = BVC2004Store.GetCurrentShoppingCart If Not Page.IsPostBack Then LoadItems() End If End Sub Private Sub LoadItems() Me.ItemsGrid.DataSource = thisOrder.GetShippingItems Me.ItemsGrid.DataBind() End Sub Private Sub ItemsGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles ItemsGrid.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim editID As String = ItemsGrid.DataKeys(e.Item.ItemIndex) Dim Item As Orders.OrderItem = OrderServices.OrderItems.GetByID(editID) If Not Item Is Nothing Then Dim sDescription As String = Item.DisplayName sDescription += "
Price: " & String.Format("{0:c}", Item.SitePrice) sDescription += "
" & Item.DisplayDescription If WebAppSettings.ShowImagesInCart = True Then e.Item.Cells(0).Text = "" If e.Item.ItemType = ListItemType.Item Then e.Item.Cells(0).Text += "" Else e.Item.Cells(0).Text += "" End If e.Item.Cells(0).Text += "
" & sDescription & "" & sDescription & "
" Else e.Item.Cells(0).Text = sDescription End If 'e.Item.Cells(2).Text = String.Format("{0:c}", Item.LineTotal) End If Dim addressList As DropDownList = e.Item.Cells(2).FindControl("AddressBookList") If Not addressList Is Nothing Then addressList.Items.Clear() Dim book As Contacts.AddressCollection = BVC2004Store.GetCurrentUser.Addresses If Not book Is Nothing Then For i As Integer = 0 To book.Count - 1 Dim li As New ListItem li.Text = ContactServices.Addresses.ToSummaryString(book(i)) li.Value = i If ContactServices.Addresses.AreAddressesEqual(ShippingServices.Packages.GetPackageByID(Item.PackageID).DestinationAddress, book(i)) Then addressList.ClearSelection() li.Selected = True End If addressList.Items.Add(li) li = Nothing Next End If End If addressList = Nothing Item = Nothing End If End Sub Private Sub AddNewAddressButton_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles AddNewAddressButton.Click UpdateAddresses() Response.Redirect("MyAccount_AddressBook_New.aspx?ReturnURL=" & Server.UrlEncode("checkout_address_multiple.aspx"), True) End Sub Private Sub UpdateAddresses() Dim book As Contacts.AddressCollection = BVC2004Store.GetCurrentUser.Addresses If Not book Is Nothing Then For Each dgi As DataGridItem In Me.ItemsGrid.Items If dgi.ItemType = ListItemType.Item Or dgi.ItemType = ListItemType.AlternatingItem Then Dim itemID As Integer = Me.ItemsGrid.DataKeys(dgi.ItemIndex) Dim addressIndex As Integer = -1 Dim addressList As DropDownList addressList = dgi.Cells(2).FindControl("AddressBookList") If Not addressList Is Nothing Then addressIndex = addressList.SelectedValue End If addressList = Nothing Dim thisPak As Shipping.Package = ShippingServices.Packages.GetPackageByID(OrderServices.OrderItems.GetByID(itemID).PackageID) If Not thisPak Is Nothing Then If (addressIndex >= 0) And (addressIndex < book.Count) Then If ContactServices.Addresses.AreAddressesEqual(thisPak.DestinationAddress, book(addressIndex)) = False Then ' Item isn't set to the same address it was before If (thisPak.ForSingleItem = True) Or (thisOrder.GetItemsForPackage(thisPak.ID).Count = 1) Then ' Single item package so just update the address ContactServices.Addresses.Copy(book(addressIndex), thisPak.DestinationAddress) Else thisOrder.SplitItemFromPackage(OrderServices.OrderItems.GetByID(itemID), book(addressIndex)) End If End If End If End If thisPak = Nothing End If Next End If End Sub Private Sub ContinueButton_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ContinueButton.Click UpdateAddresses() Response.Redirect("Checkout_Confirm.aspx", True) End Sub End Class