<!--#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,chanl
userid=request("userid")
id=request("id")
ids=request("ids")
Set rs= Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM farm where usid="&myid&" and id="&id&"",connnong,1,1
set rs3=server.createobject("adodb.recordset")
rs3.open"select times from sd where id="&rs("intname"),connnong,1,1
nongztimes=rs3("times")
rs3.close
set rs3=Nothing
nongatimeas=DateAdd("h",nongztimes,rs("times"))
if rs.eof then
Response.write "不是您的土地或时间未到<br/>"
elseif nongatimeas>now() then
response.Write "时间未到<br/>"
else
rs.update
  rs.close
  set rs=Nothing

if id="" or IsNumeric(userid)=False then
  Call Error("土地ID无效！")
  end if
if ids="" 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="&myid,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

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM farm where usid="&myid&" and id="&id,connnong,1,1
if not rs.eof Then
chanlnong=rs("chanl")-rs("chanll")
response.write "成功收获了"&rs("chanl")&"个"
response.write nonglx(ids)
response.write "<br/>"



if Not(connnong.execute("select top 1 usid from cangku where usid="&myid&" and lx="&ids).eof) Then
connnong.execute("update cangku set shuliang=shuliang+"&chanlnong&" where usid="&myid&" and lx="&ids)
Else
                set rs2=server.CreateObject("adodb.recordset")
				sql="select * from cangku"
				rs2.open sql,connnong,1,2
				rs2.addnew()
				rs2("shuliang")=chanlnong
				rs2("usid")=myid
				rs2("lx")=ids
				rs2.update()
				Rs.close
				set rs=Nothing
End if
connnong.execute("update farm set chanl=0 where usid="&myid&" and id="&id)
connnong.execute("update farm set chanll=0 where usid="&myid&" and id="&id)
connnong.execute("update farm set chenzhang=0 where usid="&myid&" and id="&id)

if myid<>0 then
mz="[url=/bbs/nongchang/?userid="&myid&"&amp;saytk=[saytk]&amp;sid=[sid]]"&myni&"[/url]"
else
mz="游客"&Replace(time(),":","")&""
end If
usernamet=(""&unames(userid)&"")
connnong.execute("insert into nongdt(shijian,dz,fid,tid,ids) values('"&now&"','"&mz&"成功收获了"&rs("chanl")&"个','"&userid&"','"&myid&"','"&ids&"')")

else
 response.write "摘取失败<br/>"
end if
  rs.close
  set rs=Nothing

end if


Response.write "------------<br/>"
Response.write "<a href='index.asp?sid="&sid&"&amp;saytk="&saytk&"'>返回"&spbt&"</a><br/>"
connnong.close
set connnong=Nothing
%>
<!--#include file="../fanhui.asp"-->
<%Call head1()%>