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

📄 addtocart.asp

📁 能实现用户注册
💻 ASP
字号:
<%@ LANGUAGE="VBSCRIPT" %>
<!-- #INCLUDE FILE="odbc_connection.inc" -->
<%
'on error resume next
'====================
'Add to Shopping Cart
'====================
intSessionID=Session.SessionID
HowManyAdded=0
session("EmptyCart")=0
session("PurchaseStage")=2

'test=0
'for each item in Request.Form
'	test=test+1
'next
'if test=0 then Response.Redirect "inventory.asp"
if Request.Form.Count=0 then
	'they didn't select anything
	Response.Redirect "inventory.asp"
end if

for each item in request.form
	intQuantity=request.form(item)
	if intQuantity>0 then
		s_Item_No=item
		'find category id from s_Item_No
		sSQL="SELECT"
		sSQL=sSQL & " tbl_Categories.ID"
		sSQL=sSQL & " FROM tbl_Categories"
		sSQL=sSQL & " INNER JOIN tbl_Inventory ON tbl_Categories.s_Category = tbl_Inventory.s_Category"
		sSQL=sSQL & " WHERE (tbl_Inventory.s_Item_No='" & s_Item_No & "')"
		Set RS = Server.CreateObject("ADODB.Recordset")
		RS.Open sSQL, conn, 3, 3 'read
		CategoryID=RS("ID")
		RS.close
		set RS=nothing
		
		if CategoryID=1 then
			'SYSTEM
			sSQL="SELECT"
			sSQL=sSQL & " tbl_Inventory_System_Components_Session.intSessionID"
			sSQL=sSQL & ",tbl_Inventory_System_Components_Session.s_System_Item_No"
			sSQL=sSQL & ",Sum(tbl_Inventory.price) AS SumOfcurSalesPrice"
			sSQL=sSQL & ",Sum(tbl_Inventory.cost) AS SumOfCost"
			sSQL=sSQL & " FROM tbl_Inventory_System_Components_Session"
			sSQL=sSQL & " INNER JOIN tbl_Inventory ON"
			sSQL=sSQL & " tbl_Inventory_System_Components_Session.s_Component_Item_No = tbl_Inventory.s_Item_No"
			sSQL=sSQL & " GROUP BY tbl_Inventory_System_Components_Session.intSessionID"
			sSQL=sSQL & ",tbl_Inventory_System_Components_Session.s_System_Item_No"
			sSQL=sSQL & " HAVING tbl_Inventory_System_Components_Session.intSessionID=" & intSessionID & " AND tbl_Inventory_System_Components_Session.s_System_Item_No='" & s_Item_No & "'"
			Set Rprice = Server.CreateObject("ADODB.Recordset")
			Rprice.Open sSQL, conn, 3, 3 'read
			Price=Rprice("SumOfcurSalesPrice")
			if session("Wholesaler")="True" then Price=Rprice("SumOfCost")+(Rprice("SumOfCost")*0.1)
		else
			sSQL="SELECT "
			sSQL=sSQL & "price, cost "
			sSQL=sSQL & "FROM tbl_Inventory "
			sSQL=sSQL & "WHERE s_Item_No='" & s_Item_No & "'"
			Set Rprice = Server.CreateObject("ADODB.Recordset")
			Rprice.Open sSQL, conn, 3, 3 'read
			Price=Rprice("price")
			if session("Wholesaler")="True" then Price=Rprice("cost")+(Rprice("cost")*0.1)
		end if
		Rprice.close
		set Rprice=nothing

		sSQL="SELECT s_Item_No, intSessionID, d_Date, intQuantity "
		sSQL=sSQL & "FROM tbl_ShoppingCart "
		sSQL=sSQL & "WHERE (s_Item_No='" & s_Item_No & "' AND intSessionID=" & intSessionID & ")"
		Set RS = Server.CreateObject("ADODB.Recordset")
		RS.Open sSQL, conn , 3, 3 'read
		if (RS.BOF and RS.EOF) then
			'this product ID does not exist in our shopping cart
			sSQL="INSERT INTO tbl_ShoppingCart "
			sSQL=sSQL & "(s_Item_No, intSessionID, intQuantity, Price, d_Date, UserID) "
			sSQL=sSQL & "Values ('" & s_Item_No & "', "
			sSQL=sSQL & intSessionID
			sSQL=sSQL & "," & intQuantity
			sSQL=sSQL & "," & Price
			sSQL=sSQL & ",#" & date & "#"
			sSQL=sSQL & "," & session("UserID")
			'sSQL=sSQL & "," & b_Quote
			sSQL=sSQL & ")"
		else
			'this Product ID already exists in our cart... increase qty
			sSQL="UPDATE tbl_ShoppingCart"
			sSQL=sSQL & " SET intQuantity=[intQuantity]+" & intQuantity
			sSQL=sSQL & " WHERE (s_Item_No='" & s_Item_No & "' AND intSessionID=" & intSessionID & ")"
		end if
		RS.close
		set RS=conn.execute(sSQL)
		HowManyAdded=HowManyAdded+1
		if err.number<>0 then
			'response.write "error: " & err.description & "<BR>"
		end if
	end if
next

if HowManyAdded>0 then
	'====================
	'move to ShowCart.asp
	'====================
	response.redirect "ShowCart.asp"
else
	'================================================
	'they selected nothing...go back to inventory.asp
	'================================================
	response.redirect "inventory.asp"
end if
%>

⌨️ 快捷键说明

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