<%@ LANGUAGE=VBScript%>
<% 
Response.Expires=0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "Pragma","No-Cache"
Response.AddHeader "Cache-Control","Private"
Response.CacheControl = "No-Cache"
if Session("zhbg_name")="" or Session("zhbg_id")="" then response.end
my=Session("zhbg_name")
grade=Session("zhbg_grade")
myid=session("zhbg_id")
id=request("id")
	
%>
<!--#include file="dadata.asp"-->
<%
sql="SELECT 物品名,银两,类型,说明,功能,美味度 FROM 菜场 where ID=" & id 
	Set Rs=connt.Execute(sql)
        wu=rs("物品名")
	yin=rs("银两")
	lx=rs("类型")
       sm=rs("说明")
       gn=rs("功能")  
        mw=rs("美味度")

Set conn=Server.CreateObject("ADODB.CONNECTION")
Set rs=Server.CreateObject("ADODB.RecordSet")
conn.open Application("zhbg_usermdb")
sql="select 银两 from 用户 where ID=" & myid
set rs=conn.execute(sql)
		if yin<=rs("银两") then
			sql="update 用户 set 银两=银两- " & yin & "  where ID=" & myid
			rs=conn.execute(sql)
			sql="select 物品名 from 物品 where 物品名='" & wu & "' and 拥有者='" & my & "'"
			set rs=connt.execute(sql)
			if rs.eof or rs.bof then
			sql="insert into 物品(物品名,拥有者,类型,说明,功能,美味度,银两) values ('"& wu &"','"& my &"','"& lx &"','" & sm &"','"& gn &"',"& mw &","& yin &")"
			rs=connt.execute(sql)
                  
			connt.close
                     set connt=nothing
                    conn.close
                    set conn=nothing
                     set rs=nothing
			Response.Redirect "caichang.asp"
			else
            Response.Write "<script Language=Javascript>alert('你已经购买了这个物品，不能够再购买了!');window.close();</script>"
           response.end
			connt.close
                     set connt=nothing
                    conn.close
                    set conn=nothing
                 
                     set rs=nothing
				
			end if
		else
Response.Write "<script Language=Javascript>alert('不能购买，原因银两不够!');window.close();</script>"
response.end
			connt.close
                     set connt=nothing
                    conn.close
                    set conn=nothing
                     set rs=nothing
		
		end if%>
