Public paste
asp
By: anoniem | Date: Nov 18 2006 14:42 | Format: None | Expires: never | Size: 4.54 KB | Hits: 1485

  1. <html>
  2.   <head>
  3.     <style type="text/css">
  4.       TR {
  5.         border: 1px solid #C0C0C0; height: 20px; color: blue; font-size: 14; font-family: arial;
  6.       }
  7.       TD {
  8.         border: 1px solid #C0C0C0; width: 200px; height: 50px; color: blue; font-size: 12; font-family: arial;
  9.       }
  10.       P {
  11.         font-size: 12; font-family: arial; color: blue;
  12.       }
  13.       a:visited {color: blue}
  14.     </style>
  15.   </head>
  16.   <body>
  17.     <%
  18.       Sub AddItemToCart(iItemID, iItemCount)
  19.         If dictCart.Exists(iItemID) Then
  20.           dictCart(iItemID) = dictCart(iItemID) + iItemCount
  21.         Else
  22.           dictCart.Add iItemID, iItemCount
  23.         End If
  24.       End Sub
  25.      
  26.       Sub ShowItemsInCart()
  27.         Dim Key
  28.         Dim aParameters
  29.         Dim sTotal
  30.     %>
  31.     <TABLE Border=1 CellPadding=3 CellSpacing=1>
  32.       <TR>
  33.         <TD>Product</TD>
  34.         <TD>Beschrijving</TD>
  35.         <TD>Aantal</TD>
  36.         <TD>Prijs</TD>
  37.         <TD>Totaal</TD>
  38.       </TR>
  39.     <%
  40.       sTotal = 0
  41.       For Each Key in dictCart
  42.         aParameters = GetItemParameters(Key)
  43.     %>
  44.         <TR>
  45.           <TD ALIGN="Center"><%= Key %></TD>
  46.           <TD ALIGN="Left"><%= aParameters(1) %></TD>
  47.           <TD ALIGN="Center"><%= dictCart(Key) %></TD>
  48.           <TD ALIGN="Right">$<%= aParameters(2) %></TD>
  49.           <TD ALIGN="Right">$<%= FormatNumber(dictCart(Key) * CSng(aParameters(2)),2) %></TD>
  50.         </TR>
  51.     <%
  52.         sTotal = sTotal + (dictCart(Key) * CSng(aParameters(2)))
  53.       Next
  54.     %>
  55.       <TR><TD COLSPAN=4 ALIGN="Right"><B>Totaal:</B></TD><TD ALIGN="Right">$<%= FormatNumber(sTotal,2) %></TD></TR>
  56.     </TABLE>
  57.     <%
  58.       End Sub
  59.       Sub ShowFullCatalog()
  60.         Dim aParameters
  61.         Dim I
  62.         Dim iItemCount
  63.         iItemCount = 3
  64.     %>
  65.         <TABLE Border=1 CellPadding=3 CellSpacing=1>
  66.         <TR>
  67.           <TD>Afbeelding</TD>
  68.           <TD>Beschrijving</TD>
  69.           <TD>Prijs</TD>
  70.           <TD>&nbsp;</TD>
  71.         </TR>
  72.     <%
  73.         For I = 1 to iItemCount
  74.           aParameters = GetItemParameters(I)
  75.     %>
  76.           <TR>
  77.             <TD><IMG SRC="<%= aParameters(0) %>" width=100 height=100></TD>
  78.             <TD><%= aParameters(1) %></TD>
  79.             <TD>€<%= aParameters(2) %></TD>
  80.             <TD><A HREF="./test.asp?action=add&item=<%= I %>&count=1"><img src="winkelmandje.gif" border=0>toevoegen</A></TD>
  81.           </TR>
  82.     <%
  83.         Next
  84.     %>
  85.     </TABLE>
  86.     <%
  87.       End Sub
  88.      
  89. Function GetItemParameters(iItemID)
  90. Dim aParameters
  91.         Select Case iItemID
  92.                 Case 1
  93.                         aParameters = Array("1.jpg", "Met deze Octopus kun je masseren. Exclusief 2 AA batterijen.", "6.50")
  94.                 Case 2
  95.                         aParameters = Array("2.jpg", "Baden met deze badeend die een radio is. Het is waterdicht.", "24.50")
  96.                 Case 3
  97.                         aParameters = Array("3.jpg", "Knuffels die levensecht snurken. Inclusief batterijen.", "13.50")
  98.                 Case 4 ' Not in use because we couldn't draw a pen in a few seconds!
  99.                         aParameters = Array("./images/shop_pen.gif", "ASP 101 Pen", "5.00")
  100.         End Select
  101. ' Return array containing product info.
  102. GetItemParameters = aParameters
  103. End Function
  104.  
  105. Dim dictCart ' as dictionary
  106. Dim sAction ' as string
  107. Dim iItemID ' as integer
  108. Dim iItemCount ' as integer
  109.  
  110. ' Get a reference to the cart if it exists otherwise create it
  111. If IsObject(Session("cart")) Then
  112.         Set dictCart = Session("cart")
  113. Else
  114.         ' We use a dictionary so we can name our keys to correspond to our
  115.         ' item numbers and then use their value to hold the quantity.  An
  116.         ' array would also work, but would be a little more complex and
  117.         ' probably not as easy for readers to follow.
  118.         Set dictCart = Server.CreateObject("Scripting.Dictionary")
  119. End If
  120.  
  121. ' Get all the parameters passed to the script
  122. sAction = CStr(Request.QueryString("action"))
  123. iItemID = CInt(Request.QueryString("item"))
  124. iItemCount = CInt(Request.QueryString("count"))
  125. %>
  126. <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
  127. <TR><TD>
  128. <%
  129.   Select Case sAction
  130.     Case "add"
  131.     AddItemToCart iItemID, iItemCount
  132.     ShowItemsInCart
  133. %>
  134.     </TD></TR>
  135. </TR>
  136.         <TR><TD ALIGN="right">
  137.                 <A HREF="./test.asp?action="><IMG SRC="./images/shop_look.gif" BORDER=0 WIDTH=46 HEIGHT=46></A>
  138.                 <%
  139.         Case "viewcart"
  140.                 ShowItemsInCart
  141.                 %>
  142.                 </TD></TR>
  143.                                
  144.                 <%
  145.         Case Else
  146.                 ShowFullCatalog
  147.                 %>
  148.                 </TD></TR>
  149.                 <TR><TD ALIGN="left">
  150.                 <A HREF="./test.asp?action=viewcart">Winkelwagen<IMG SRC="winkelmandje.gif" BORDER=0></A>
  151.                 <%
  152. End Select
  153.  
  154. ' Return cart to Session for storage
  155. Set Session("cart") = dictCart
  156. %>
  157. </TD></TR>
  158. </TABLE>
  159. </body>
  160. </html>
  161.