⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoppingcart.aspx

📁 This is a book about vb.you could learn this from this book
💻 ASPX
字号:
<%@ Page Language="VB" Inherits="IBuyAdventure.PageBase" src="components/stdpage.vb" clienttarget=downlevel %>
<%@ Register TagPrefix="IBA" TagName="Header" Src="UserControl\Header.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Footer" Src="UserControl\Footer.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Categories" Src="UserControl\Categories.ascx" %>
<%@ Import Namespace="System.Data" %>

<html>
  <head>
    <title>IBuyAdventure Catalog</title>
  </head>

  <script language="VB" runat="server" >
  
		' Total for shopping basket
		Dim fTotal As Double = 0

		Sub Page_Load(sender As Object, e As EventArgs)
		
			Dim cart As New IBuyAdventure.CartDB(getConnStr())
			
			' If page is not being loaded in response to postback
			If Page.IsPostBack = False Then
			
				' If a new product to add is specified, add it to the shopping cart
				If Request.Params("ProductCode") <> "" Then
					cart.AddShoppingCartItem(GetCustomerID(), Request.Params("ProductCode"))
				End If
				
				PopulateShoppingCartList()
				UpdateSelectedItemStatus()
			End If
			
		End Sub
		

		Sub UpdateSelectedItemStatus()
		
			'If MyList.Items <> "" Then
			If MyList.Items.Count <> 0 Then
				status.Text = "You have selected " & MyList.Items.Count & " items " & "so far:<br>"
			Else
				status.Text = "You have selected no items so far"
			End If
		End Sub
		

		Sub Recalculate_Click(sender As Object, e As EventArgs)
		
			' Update Shopping Cart
			UpdateShoppingCartDatabase()
			
			' Repopulate ShoppingCart List
			PopulateShoppingCartList()
			UpdateSelectedItemStatus()
		
		End Sub
		

		Sub Checkout_Click(sender As Object, e As EventArgs)
		
			' Update Shopping Cart
			UpdateShoppingCartDatabase()
			Response.Redirect("secure/Checkout.aspx")
		
		End Sub
		

		Function GetCustomerID() As String
		
			If User.Identity.Name <> "" Then
				Return Context.User.Identity.Name
			Else
				If Session("AnonUID") Is Nothing Then
					Session("AnonUID") = Guid.NewGuid()
				End If
				Return Session("AnonUID").ToString()
			End If
		
		End Function


		Sub UpdateShoppingCartDatabase()
		
			Dim inventory As New IBuyAdventure.ProductsDB(getConnStr())
			Dim cart = new IBuyAdventure.CartDB(getConnStr())
			
			' Iterate through all rows within shopping cart list
			Dim i As Integer
			For i = 0 To MyList.Items.Count - 1
			
				' Obtain references to row's controls
				Dim quantityTxt As TextBox = MyList.Items(i).FindControl("Quantity")
				Dim remove As CheckBox = MyList.Items(i).FindControl("Remove")
				Dim shoppingCartIDTxt As HtmlInputHidden = MyList.Items(i).FindControl("ShoppingCartID")
				
				' If removed checkbox selected, delete the item.  Otherwise, update its
				' quantity (todo: a product quality app should only update if value was been changed)
				' Convert quantity to a number
				Dim Quantity As Integer = Int32.Parse(quantityTxt.Text)
				
				If remove.Checked = true Or Quantity = 0 Then
					cart.DeleteShoppingCartItem(Int32.Parse(shoppingCartIDTxt.Value))
				Else
					cart.UpdateShoppingCartItem(Int32.Parse(shoppingCartIDTxt.Value), Quantity )
				End If
			Next
			
		End Sub
		

		Sub PopulateShoppingCartList()
		
			' Popoulate list with updated shopping cart data
			Dim cart As New IBuyAdventure.CartDB(getConnStr())
			Dim ds As DataSet = cart.GetShoppingCartItems(GetCustomerID())
			
			MyList.DataSource = ds
			MyList.DataBind()
			
			' Walk through table and calculate the total value
			Dim dt As DataTable = ds.Tables(0)
			Dim lIndex, Quantity As Integer
			Dim UnitPrice As Double
			
			For lIndex =0 To dt.Rows.Count - 1
				UnitPrice = dt.Rows(lIndex)("UnitPrice")
				Quantity = dt.Rows(lIndex)("Quantity")
				If Quantity > 0
					fTotal += UnitPrice * Quantity
				End If
			Next
			
		End Sub
		
  </script>

  <body background="images/back_sub.gif">
    <form runat="server">
      <font face="Verdana, Arial, Helvetica" size="2">
        <table border="0" valign="top" width="100%" style="font: 10pt verdana">
          <tr>
            <td colspan="5">
              <IBA:Header id="Header" runat="server"/>
            </td>
          </tr>
          <!--Begin Navigational Buttons-->
          <tr valign="top">
            <td width="95" align="left" valign="top">
              <IBA:Categories id="Categories" runat="server"/>
            </td>
            <td>
              &nbsp;&nbsp;
            </td>
            <td valign="top" align="left">
              <img src="images/hd_Check_out.gif">
              <br><br>
              <font size="2"><asp:label id="status" runat="server" /></font><br>
              <table colspan="8" cellpadding="5" border="0" valign="top">
                <!-- BEGIN column header row -->
                <tr valign="top">
                  <td align="center" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Remove</font>
                  </td>
                  <td align="center" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Product Code</font>
                  </td>
                  <td align="center" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Product Name</font>
                  </td>
                  <td align="center" width="250" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Description</font>
                  </td>
                  <td align="center" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Quantity</font>
                  </td>
                  <td align="center" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Unit Price</font>
                  </td>
                  <td align="center" bgcolor="#800000">
                    <font style="Verdana, Arial, Helvetica" color="#ffffff" size="2">Unit Total</font>
                  </td>
                </tr>
                <asp:repeater id="MyList" runat="server">
                  <itemtemplate>
                    <tr>
                      <td align="center" bgcolor="#f7efde">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <asp:checkbox id="Remove" runat="server"/>
                        </font>
                      </td>
                      <td align="center" bgcolor="#f7efde">
                        <input id="ShoppingCartID" type="hidden" value='<%#DataBinder.Eval(Container.DataItem, "ShoppingCartID", "{0:g}") %>' runat="server">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <%#DataBinder.Eval(Container.DataItem, "ProductCode")%>
                        </font>
                      </td>
                      <td align="center" bgcolor="#f7efde">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <%#DataBinder.Eval(Container.DataItem, "ProductName")%>
                        </font>
                      </td>
                      <td align="left" width=250 bgcolor="#f7efde">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <%#DataBinder.Eval(Container.DataItem, "Description")%>
                        </font>
                      </td>
                      <td align="center" bgcolor="#f7efde">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <asp:textbox id="Quantity" text=<%#DataBinder.Eval(Container.DataItem, "Quantity", "{0:g}")%> width=30 runat="server"/>
                        </font>
                      </td>
                      <td align="center" bgcolor="#f7efde">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <asp:label id="UnitPrice" runat="server"><%#DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}")%></asp:label>
                        </font>
                      </td>
                      <td align="center" bgcolor="#f7efde">
                        <font style="Verdana, Arial, Helvetica" color="black" size="2">
                          <%# String.Format("{0:C}", (DataBinder.Eval(Container.DataItem, "Quantity") * DataBinder.Eval(Container.DataItem, "UnitPrice"))) %>
                        </font>
                      </td>
                    </tr>
                  </itemtemplate>
                </asp:repeater>
                <tr>
                  <td colspan="5"><td colspan="3" align="right">
                    <font style="Verdana, Arial, Helvetica" color="black" size="2">
                      Total is <%=String.Format("{0:C}", fTotal ) %>
                    </font>
                  </td>
                </tr>
                <tr>
                  <td colspan="8" align="right">
                    <asp:button text="Recalculate" OnClick="Recalculate_Click" runat="server"/>
                    <asp:button text="Go To Checkout" OnClick="Checkout_Click" runat="server"/>
                  </td>
                </tr>
              </table>
             <IBA:footer runat="server"/></td> </tr>
            </td>
          </tr>
        </table>
      </font>
    </form>
  </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -