If rs2.Eof Then CartID=Session.SessionID Product=rs("ID_Product") Name=rs("Name") Price=rs("Price") Quantity=1 Sql2="Insert into Cart(CartID,ID_Product,Name,Price,Quantity) values("&CartID&",'"&Product&"','"&Name&"',"&Price&","&Quantity&")" Set rs2 = Conn.execute(Sql2) Session("BookSum")=Session("BookSum")+1 else if rs2("CartID")=session.sessionID then Product=rs("ID_Product") Name=rs("Name")
Price=rs("Price") Quantity=rs2("Quantity")+1 Sql="Update Cart Set ID_Product=Product,Name=Name,Price=Price,Quantity=Quantity where CartID="&Session.SessionID Set rs2 = Conn.execute(Sql) Session("BookSum")=Session("BookSum")+1 End if
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.mapPath("../E_Com.mdb") 'oledb for ado2.0 up only?
Sql="Select * From Cart where CartID=" & Session.SessionID '
Set rs2=Server.CreateObject("ADODB.Recordset")
rs2.Open Sql, Conn, , 3
ID_Product=Request.QueryString("ID_Product")
If ID_Product<>"" Then
Sql="Select * From Product where ID_Product='" & ID_Product & "'" Set rs=Server.CreateObject("ADODB.Recordset")
rs.Open Sql, Conn, 0, 3
rs2.Filter="ID_Product='" & rs("ID_Product") &"'"
If rs2.Eof Then
CartID=Session.SessionID
Product=rs("ID_Product")
Name=rs("Name")
Price=rs("Price")
Quantity=1
Sql2="Insert into Cart(CartID,ID_Product,Name,Price,Quantity) values("&CartID&",'"&Product&"','"&Name&"',"&Price&","&Quantity&")"
Set rs2 = Conn.execute(Sql2)
Session("BookSum")=Session("BookSum")+1
Else
if rs2("CartID")=Session.SessionID then
Product=rs("ID_Product")
Name=rs("Name")
Price=rs("Price")
Quantity=rs2("Quantity")+1
Sql="Update Cart Set ID_Product=Product,Name=Name,Price=Price,Quantity=Quantity where CartID="&Session.SessionID
Set rs2 = Conn.execute(Sql)
Session("BookSum")=Session("BookSum")+1
End if
End if
rs2.Filter=""
rs.close
Set rs=nothing
End If
If Request.Form("calc")<>"" and Not rs2.Eof Then
rs2.MoveFirst
Do While Not rs2.Eof
If Request.Form(rs2("ID_Product"))="on" Then
Session("BookSum")=Session("BookSum")-rs2("Quantity")
rs2.Delete Else
quantity=Request.Form("q" & rs2("ID_Product"))
If CInt(quantity)<>rs2("Quantity") Then
Session("BookSum")=Session("BookSum")+quantity-rs2("Quantity")
rs2("Quantity")=quantity ' update ฟิลด์ quantity
rs2.Update
End If
End If
rs2.MoveNext
Loop
End If
' จ่ายเงิน
If Request.Form("pay")<>"" Then
Response.Redirect "checkout.asp"
End If