?? shoppingcart.aspx.vb
字號:
Public Class ShoppingCart
Inherits System.Web.UI.Page
Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
Protected WithEvents drpBasket As System.Web.UI.WebControls.Repeater
Protected WithEvents lblSubTotal As System.Web.UI.WebControls.Label
Protected WithEvents btnRecalculate As System.Web.UI.WebControls.Button
Protected WithEvents btnCheckout As System.Web.UI.WebControls.Button
Protected WithEvents pnlBasketSection As System.Web.UI.WebControls.Panel
Protected Header1 As Store.header
#Region " Web 窗體設計器生成的代碼 "
'該調用是 Web 窗體設計器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法調用是 Web 窗體設計器所必需的
'不要使用代碼編輯器修改它。
InitializeComponent()
End Sub
#End Region
Private myCart As New StoreCommon.Services.ShoppingCart()
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'在此處放置初始化頁的用戶代碼
If Not IsPostBack Then
'更新購物車
PopulateShoppingCart()
End If
End Sub
Private Sub btnRecalculate_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnRecalculate.Click
'更新購物車
UpdateShoppingCart()
'重新設置購物車
PopulateShoppingCart()
End Sub
Private Sub btnCheckout_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles btnCheckout.Click
'更新購物車
UpdateShoppingCart()
'獲取購物車的當前用戶
Dim strCartID As String = myCart.GetCartID
'查詢該客戶的消費總金額
myCart.SubTotal(strCartID)
'導航到訂單確認頁面
Response.Redirect("CheckOut.aspx")
End Sub
Public Sub PopulateShoppingCart()
'獲取購物車的當前用戶
Dim myCartID As String = myCart.GetCartID
If myCart.ItemsCount(myCartID) > 0 Then
'獲取商品詳細信息,并綁定到Repeater控件中
drpBasket.DataSource = myCart.GetItemsList(myCartID)
drpBasket.DataBind()
'顯示消費總金額
lblSubTotal.Text = myCart.SubTotal(myCartID).ToString
End If
End Sub
Public Sub UpdateShoppingCart()
Dim intListItemsCounter As Integer
Dim objRepeaterItem As RepeaterItem
'獲取購物車的當前用戶
Dim strCartID As String = myCart.GetCartID
For Each objRepeaterItem In drpBasket.Items
'定義并獲取數量的文本框控件和是否移除的CheckBox控件以及被掩藏的商品ID號
Dim txtQuantity As System.Web.UI.WebControls.TextBox = _
CType(objRepeaterItem.FindControl("txtQuantity"), TextBox)
Dim chkRemove As System.Web.UI.WebControls.CheckBox = _
CType(objRepeaterItem.FindControl("chkRemove"), CheckBox)
Dim hdnItemID As System.Web.UI.HtmlControls.HtmlInputHidden = _
CType(objRepeaterItem.FindControl("hdnItemID"), HtmlInputHidden)
If (txtQuantity Is Nothing = False) And (chkRemove Is Nothing = False) _
And (hdnItemID Is Nothing = False) Then
'將文本轉換成整數
Dim intQuantity As Integer = Int32.Parse(txtQuantity.Text)
If (chkRemove.Checked = True Or intQuantity = 0) Then
'確定移除數量已經被設置為0的商品
myCart.RemoveItem(strCartID, hdnItemID.Value)
Else
myCart.UpdateItem(strCartID, hdnItemID.Value, intQuantity)
End If
End If
Next
'顯示已經選擇的商品數量
lblStatus.Text = "您已經選擇了如下: " & myCart.ItemsCount(strCartID) & " 商品了:"
'顯示消費總金額
lblSubTotal.Text = myCart.SubTotal(strCartID).ToString
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -