<!--#include file="setup.asp"-->
<!--#include file="hunconn.asp"-->
<%
if Request.Cookies("username")=empty then error2("请登录后再进行操作！")
top
membername=request.cookies("username")
user=request.form("txt_sMateNick") 
if user="" then error2("你要向谁求婚啊？")
message=request.form("txt_sOath") 
if message="" then error2("你的求婚宣言是什么呢？")
id=request.form("sCheckSel")
if id="" then error2("没有礼物怎么求婚啦？")
if membername=user then error2("你脑子进水了，怎么能自己和自己结婚呢？")

set rs=server.createobject("adodb.recordset")
rs.open"select * from qiuhun where UserName='"&membername&"'",connj,1,1
if not rs.eof then error2("你已经求过婚了，恋爱不能三心二意！")
rs.close

rs.open"select * from qiuhun where (tousername='"&user&"' or username= '"&user&"') and dlg ",connj,1,1
if not rs.eof then 
	if rs("jiehun") then  
		error("<li>他(她)已经结婚了，你没有机会了")
	else
		error("<li>他(她)已经订婚了，你没有机会了")
	end if
end if
rs.close

rs.open"select * from [user] where username='"&user&"'",conn,3,1
if rs.bof then
	rs.close
	error2("你在想什么呢，社区里没有这个人！") 
else
	sex1=rs("sex")
	if sex1="" then error2("对方的性别没有设置(无法确定男女)，无法进行求婚！")
	rs.close
end if
rs.open"select * from liwu where id="&id&"",connj,1,1
if rs.bof then
	rs.close
	error2("没这个礼品呀！")
else
	giftname=rs("name")
	price=rs("price")
	imageurl=rs("images")
	rs.close
end if
rs.open"select * from [user] where username='"&membername&"'",conn,1,1
splosh=rs("savemoney")
sex2=rs("sex")
if sex2="" then error2("抱歉，你的性别都没有设置还要求婚，到控制面板菜单的基本资料修改里面设置一下吧。")
rs.close
if sex1=sex2 then error2("社区只支持异性之间结婚，同性之间不能结婚")
nowmoney=price
if nowmoney>splosh then
	error2("很抱歉，您银行里没有这么多钱买这个礼品，等你撰够了钱再来吧！")
else
	set rs1 = Server.CreateObject("ADODB.recordset")
	rs1.open "Select * From [message]",conn,3,3
	rs1.addnew
	rs1("author")=membername
	rs1("incept")=user
	rs1("content")="求婚:"&message&",送你价值"&nowmoney&"的大礼<br>请到结婚殿堂的“月下老人”去看看吧"
	rs1("time")=now()
	rs1.update
	rs1.close
	rs1.Open "select * from [user] where username='"&user&"'",Conn,1,3
	rs1("newmessage")=rs1("newmessage")+1
	rs1.update
	rs1.close
	set rs3 = Server.CreateObject("ADODB.recordset")
	rs3.open"Select * From [qiuhun]",connj,3,3
	rs3.addnew
	rs3("username")=membername
	rs3("tousername")=user
	rs3("addtime")=now()
	rs3("message")=message
	rs3("lw")=giftname
	rs3("liwu")=imageurl
	rs3("dlg")=false
	rs3.update
	conn.execute"update [user] set savemoney=savemoney-"&nowmoney&" where username='"&membername&"'" 
	
	message="<li>恭喜！求婚成功，我们会帮你转告"&user&"的！祝你好运"
	succeed(message&"<meta http-equiv=refresh content=3;url='hunindex.asp'")
	
end if
set rs=nothing
set rs1=nothing
set rs3=nothing

%>

