<!--#include file="../Inc.asp"-->
<!--#include file="../ydzq.asp"-->
<!--#include file="admin.asp"-->
<!--#include file="conn.asp"-->

<%Call head()
Call saycardd("种子购买")
dim action
dim userid,ids,TP,id,num,jiage
userid=request("userid")
id=request("id")
num=request("num")
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select jiage from sd where id="&id,connnong,1,1
jiage=rs("jiage")
  rs.close
  set rs=Nothing

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT xuan,myjb FROM users where id="&userid,conn,1,2
myjb=rs("myjb")
rs.update
  rs.close
  set rs=Nothing
if userid="" or IsNumeric(userid)=False then
  Call Error("会员ID无效！")
  end if
'检查ID是否存在
dim username
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT name FROM users where id="&userid,conn,1,1
if rs.eof then
  rs.close
  set rs=Nothing
  Call Error("会员ID不存在！")
end if
username=rs("name")
  rs.close
  set rs=Nothing
  
TP=request("TP")
action=request("action")
Select Case action
	Case "get"   
		Call xxget()
	Case "del" 
		Call xxdel()
end select 
sub xxget()
if TP<>"" then
TP=clng(TP)
if TP=1 then
tou=request("tou")

if num="" then
  Call Error("选择数量无效！")
  end if
end if

if myjb>jiage*num Then

conn.execute("update users set myjb=myjb-"&jiage*num&" where id="&myid)
connnong.execute("update sd set shuliang=shuliang-"&num&" where id="&id)

if Not(connnong.execute("select top 1 usid from beibao where usid="&myid&" and lx="&id).eof) Then
connnong.execute("update beibao set shuliang=shuliang+"&num&" where usid="&myid&" and lx="&id)
Else
                set rs=server.CreateObject("adodb.recordset")
				sql="select * from beibao"
				rs.open sql,connnong,1,2
				rs.addnew()
				rs("shuliang")=num
				rs("usid")=myid
				rs("lx")=id
				rs.update()
				Rs.close
				set rs=Nothing
End if




response.write "恭喜您购买"&num&"个"
response.write nonglx(id)
response.write "成功！扣除"&jiage*num&""&getcent&"<br/>"


else
 response.write "购买失败！您的余额不足"&jiage*num&""&getcent&"<br/>"
end if




ELSE

response.write "欢迎您"&username&"ID："&userid&"<br/>"
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select name,jiage from sd where id="&id,connnong,1,1
dim j
j=1
do while not rs.eof
Response.write ""& ubb(rs("name")) & "单价:" & ubb(rs("jiage")) &getcent& ""
j=j+1
rs.movenext
loop
rs.close
set rs=Nothing
If saytk>1 Then Response.Write "<form name=""form"" method=""post"" action=""goumai.asp?action=get&amp;id="&id&"&amp;sid="&sid&"&amp;saytk="&saytk&""">"
Response.Write "<br/>数量<br/>"
Response.Write "<input name=""num"" maxlength=""18"" value=""10""/><br/>"
If saytk>1 Then 
response.write "<input type=""hidden"" name=""userid"" value="""&userid&"""/>"
response.write "<input type=""hidden"" name=""TP"" value=""1""/>"
response.write "<input type=""submit"" name=""Submit"" value=""确定购买""></form><br/>"
Else
Response.write "<anchor>确定购买<go href='goumai.asp?action=get&amp;id="&id&"&amp;sid="&sid&"&amp;saytk="&saytk&"' method='post' accept-charset='utf-8'>"
Response.write "<postfield name='num' value='$(num)'/>"
Response.write "<postfield name='userid' value='"&userid&"'/>"
Response.write "<postfield name='TP' value='1'/>"
Response.write "</go></anchor><br/>"
End if
END IF
end sub
Response.write "------------<br/>"
Response.write "<a href='beibao.asp?sid="&sid&"&amp;saytk="&saytk&"'>返回上级</a><br/>"
Response.write "<a href='index.asp?sid="&sid&"&amp;saytk="&saytk&"'>返回我的农场</a><br/>"&chr(13)
connnong.close
set connnong=Nothing
%>
<!--#include file="../../fanhui.asp"-->
<%Call head1()%>