?? shoppingcart.aspx
字號:
<%@ Page Language="vb" %>
<%@ Register TagPrefix="Conference" TagName="Header" Src="_Header.ascx" %>
<%@ Register TagPrefix="Conference" TagName="Menu" Src="_Menu.ascx" %>
<script language="VB" runat="server">
'*******************************************************
'
' The Page_Load event on this page is used to load the
' ShoppingCart DataGrid *the first time* the page is
' accessed.
'
' Note that subsequent postbacks to the page *do not*
' reload the Datagrid. Instead, we rely on the control's
' built-in viewstate management to rebuild the control
' on the server.
'
'*******************************************************
Sub Page_Load(sender As Object, e As EventArgs)
' Populate the shopping cart the first time the page is accessed.
If Page.IsPostBack = False Then
PopulateShoppingCartList()
End If
End Sub
'*******************************************************
'
' The UpdateBtn_Click event is raised when a user clicks
' the "update" button on the client. The event handler
' updates all items in the cart back to the database,
' and then repopulates the datagrid with the current
' cart contents.
'
'*******************************************************
Sub UpdateBtn_Click(sender As Object, e As EventArgs)
' Update the Shopping Cart and then Repopulate the List
UpdateShoppingCartDatabase()
PopulateShoppingCartList()
End Sub
'*******************************************************
'
' The CheckoutBtn_Click event is raised when a user clicks
' the "checkout" button on the client. The event handler
' updates all items in the cart back to the database,
' and then redirects the user to the checkout.aspx page
'
' Other source code to examine:
' Conference.ShoppingCartDB.GetItemCount() Method
'
'*******************************************************
Sub CheckoutBtn_Click(sender As Object, e As EventArgs)
' Update Shopping Cart
UpdateShoppingCartDatabase()
' If cart is not empty, proceed on to checkout page
Dim cart As New Conference.ShoppingCartDB
' Calculate shopping cart ID
Dim cartId As String = cart.GetShoppingCartId()
' If the cart isn't empty, navigate to checkout page
If cart.GetItemCount(cartId) <> 0 Then
Page.Navigate("Checkout.aspx")
Else
MyError.Text = "You can't proceed to the Check Out page with an empty cart."
End If
End Sub
'*******************************************************
'
' The PopulateShoppingCartList helper method is used to
' dynamically populate a GridControl with the contents of
' the current user's shopping cart.
'
' Other source code to examine:
' Conference.ShoppingCartDB.GetShoppingCartID() Method
' Conference.ShoppingCartDB.GetItems() Method
' Conference.ShoppingCartDB.GetItemCount() Method
'
'*******************************************************
Sub PopulateShoppingCartList()
Dim cart As New Conference.ShoppingCartDB
' Obtain current user's shopping cart ID
Dim cartId As String = cart.GetShoppingCartId()
' If no items, hide details and display message
If cart.GetItemCount(cartId) = 0 Then
DetailsPanel.Visible = False
MyError.Text = "There are currently no items in your shopping cart."
Else
' Databind Gridcontrol with Shopping Cart Items
MyList.DataSource = cart.GetItems(cartId).Tables(0).DefaultView
MyList.DataBind()
'Update Total Price Label
lblTotal.Text = System.String.Format( "{0:c}", cart.GetTotal(cartId))
End If
End Sub
'*******************************************************
'
' The UpdateShoppingCartDatabase helper method is used to
' update a user's items within the shopping cart database
' using client input from the GridControl.
'
' Other source code to examine:
' Conference.ShoppingCartDB.GetShoppingCartID() Method
' Conference.ShoppingCartDB.GetItems() Method
' Conference.ShoppingCartDB.GetItemCount() Method
'
'*******************************************************
Sub UpdateShoppingCartDatabase()
Dim cart As New Conference.ShoppingCartDB
' Obtain current user's shopping cart ID
Dim cartId As String = cart.GetShoppingCartId()
' Iterate through all rows within shopping cart list
Dim i As Integer
Dim quantityTxt As TextBox
Dim lblProductID As Label
Dim remove As CheckBox
For i = 0 To MyList.Items.Count-1
' Obtain references to row's controls
Quantity = MyList.Items(i).FindControl("Quantity")
ProductID = MyList.Items(i).FindControl("ProductID")
Remove = MyList.Items(i).FindControl("Remove")
' Wrap in try/catch block to catch errors in the event that someone types in
' a letter instead of a number for quantity
Try
If CInt(Quantity.Text) = 0 Or Remove.Checked = True Then
cart.RemoveItem(cartId, CInt(ProductID.Text))
Else
cart.UpdateItem(cartId, CInt(ProductID.Text), CInt(Quantity.Text))
End If
Catch
MyError.Text = "There has been a problem with one or more of your inputs."
End Try
Next
End Sub
</script>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Conference.css">
</head>
<body background="images/sitebkgrd.gif" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0">
<!-- HEADER AND MENUS -->
<table width="100%" border=0>
<tr><td><Conference:Header runat="server"/></td></tr>
<tr><td>
<table width="100%" border=0>
<tr><td valign="top">
<Conference:Menu runat="server"/>
</td>
<td>
<!-- CONTENT -->
<table height="100%" valign="top" align="left" cellspacing=0 cellpadding=0 width="100%" border=0>
<tr height="100%" valign="top">
<td nowrap>
<br>
<form runat="server">
<img align=left width="32" src="images/1x1.gif">
<table cellspacing=0 cellpadding=0 width="100%" border=0>
<tr>
<td class=ContentHeader>
<img align=left height="32" width="60" src="images/1x1.gif">Shopping Cart<br>
</td>
</tr>
</table>
<img align="left" height="4" width="110" src="images/1x1.gif">
<font color="red"><asp:Label id="MyError" class="ErrorText" maintainstate="False" runat="Server"/></font>
<br>
<img align="left" height="15" width="32" src="images/1x1.gif" border="0">
<asp:panel id="DetailsPanel" runat=server>
<img align="left" height="1" width="50" src="images/1x1.gif">
<table valign=top height="100%" cellspacing=0 cellpadding=0 width="550" border=0>
<tr valign=top height="100%">
<td width="550">
<asp:DataGrid id="MyList" runat="server" BorderColor="black" GridLines="Vertical" cellpadding="4" cellspacing="0" Font-Name="Verdana" Font-Size="8pt" ShowFooter="True" HeaderStyle-CssClass="CartListHeader" FooterStyle-CssClass="CartListFooter" ItemStyle-CssClass="CartListItem" AlternatingItemStyle-CssClass="CartListItemAlt" AutoGenerateColumns="False">
<property name="Columns">
<asp:TemplateColumn HeaderText="Product ID">
<template name="ItemTemplate">
<asp:Label id=ProductID runat="server" Text='<%# Container.DataItem("ProductID") %>'/>
</template>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Product Name" DataField="ModelName"/>
<asp:BoundColumn HeaderText="Model" DataField="ModelNumber"/>
<asp:TemplateColumn HeaderText="Quantity">
<template name="ItemTemplate">
<asp:TextBox id=Quantity runat="server" Columns="4" Text='<%# Container.DataItem("Quantity") %>' width="40px" />
</template>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Price" DataField="UnitCost" DataFormatString="{0:c}" />
<asp:BoundColumn HeaderText="Subtotal" DataField="ExtendedAmount" DataFormatString="{0:c}" />
<asp:TemplateColumn HeaderText="Remove">
<template name="ItemTemplate">
<center>
<asp:CheckBox id=Remove runat="server" />
</center>
</template>
</asp:TemplateColumn>
</property>
</asp:DataGrid>
<img src="Images/1x1.gif" width="350" height="1">
<span class="TextBold"> Total: </span>
<asp:Label class="TextBold" ID="lblTotal" MaintainState="False" runat="server"/>
<br>
<br>
<asp:button id="update" OnClick="UpdateBtn_Click" Text="Update your Shopping Cart" runat="server"/>
<asp:button id="checkout" OnClick="CheckoutBtn_Click" Text="Final Check Out" runat="server"/>
<br>
</td>
</tr>
</table>
</asp:panel>
</form>
</td>
</tr>
</table>
<!-- END OF CONTENT -->
</td>
</tr>
</table>
</td></tr>
</table>
<!-- END OF HEADER AND MENU -->
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -