Shopping Cart
<%
error=""
OpenConnection1
Set rs=Server.CreateObject("ADODB.Recordset")
If Request.QueryString("SID")<>"" then
SupplyID=cint(Request.QueryString("SID"))
If Not Logged Then
Session("page")="addtocart.asp?SID=" & SupplyID
Response.Redirect("login.asp")
End If
ElseIf Request.QueryString("S")<>"" then
SupplyID=cint(Request.QueryString("S"))
If Not Logged Then
Session("page")="addtocart.asp?S=" & SupplyID
Response.Redirect("login.asp")
End If
If Request.QueryString("Q")<>"" then
If IsNumeric(Request.QueryString("Q")) Then
Sel="SELECT txtSupply,txtItemNumber FROM Supplies WHERE SupplyID=" & SupplyID
rs.Open Sel,DB,1,3
txtSupply=rs("txtSupply")
txtItemNumber=rs("txtItemNumber")
rs.Close
Sql="SELECT * FROM SCart"
rs.Open Sql,DB,1,3
rs.AddNew
rs("nSupplyID")=SupplyID
rs("nCustomerID")=Request.Cookies("wades")("cid")
rs("datAdded")=date
rs("txtSupply")=txtSupply
rs("txtItemNumber")=txtItemNumber
rs("nQuantity")=cint(Request.QueryString("Q"))
rs.Update
rs.Close
Response.Redirect("viewcart.asp")
Else
error = "***Quantity values must be numeric***"
End If
Else
error = "***Please enter the desired Quantity below***"
End If
End If
If Request.Cookies("wades")("curopt")=1 then
curmess="All prices are in Canadian Dollars."
Else
curmess="All prices are in U.S. Dollars."
End If
Sel="SELECT txtFname,txtLname,txtCompany FROM Customers WHERE CustomerID=" & Request.Cookies("wades")("cid")
rs.Open Sel,DB,1,3
txtName=rs("txtFname") & " " & rs("txtLname")
txtCompany=""
If rs("txtCompany")<>"" then txtCompany="("&rs("txtCompany")&")"
rs.Close
Sel="SELECT * FROM SCart WHERE nCustomerID=" & Request.Cookies("wades")("cid")
rs.Open Sel,DB,1,3
%>
Shopping cart for <%=txtName & " " & txtCompany%> <%=curmess%>
<%If rs.EOF then%>
There are currently no items in your shopping cart.
<%End If
If Request.QueryString("SID")<>"" Or error<>"" then
Sel="SELECT txtSupply,txtItemNumber FROM Supplies WHERE SupplyID=" & SupplyID
rs.Open Sel,DB,1,3
txtSupply=rs("txtSupply")
txtItemNumber=rs("txtItemNumber")
txtPrice=GetPrice(SupplyID)
rs.Close
If error<>"" then%>
<%=error%>
<%Else%>
You have requested the following item be added to your Shopping Cart:
<%End If%>
Item:
<%=txtSupply%>
Item Number:
<%=txtItemNumber%>
Unit Price:
<%=txtPrice%>
Please enter the desired quantity below:
<%End If%>
<%Function GetPrice(supplyId)
Set gp=Server.CreateObject("ADODB.Recordset")
If Request.Cookies("wades")("curopt")=1 then
sql="SELECT curCanPrice FROM Supplies WHERE SupplyID=" & supplyId
gp.Open sql,DB,1,3
If gp.EOF then
GetPrice="No longer available"
Else
GetPrice=cstr(formatcurrency(gp("curCanPrice"),2,0))
End If
Else
sql="SELECT curUSPrice FROM Supplies WHERE SupplyID=" & supplyId
gp.Open sql,DB,1,3
If gp.EOF then
GetPrice="No longer available"
Else
GetPrice=cstr(formatcurrency(gp("curUSPrice"),2,0))
End If
End If
gp.Close
End Function
Function GetTotal(supplyId,quantity)
Set gt=Server.CreateObject("ADODB.Recordset")
If Request.Cookies("wades")("curopt")=1 then
sql="SELECT curCanPrice FROM Supplies WHERE SupplyID=" & supplyId
gt.Open sql,DB,1,3
If gt.EOF then
GetTotal="NA"
Else
GetTotal=cstr(formatcurrency(cint(quantity)*gt("curCanPrice"),2,0))
End If
Else
sql="SELECT curUSPrice FROM Supplies WHERE SupplyID=" & supplyId
gt.Open sql,DB,1,3
If gt.EOF then
GetTotal="NA"
Else
GetTotal=cstr(formatcurrency(cint(quantity)*gt("curUSPrice"),2,0))
End If
End If
gt.Close
End Function
%>