<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("username")="" or RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="用户名没填或非法字符！"
ElseIf Request.Form ("Submit")<>"查询用户信息" And Request.Form ("usermoney")="" Then
	ef=True
	ec="金额没填！"
ElseIf Request.Form ("Submit")<>"查询用户信息" And Request.Form ("add")="" Then
	ef=True
	ec="必须选择款项操作分类！"
ElseIf Request.Form ("Submit")<>"查询用户信息" And not IsNumeric(Request.Form ("usermoney"))  Then
	ef=True
	ec="金额应该是数字！"
ElseIf Request.Form ("Submit")<>"查询用户信息" And Request.Form ("forwhat")="" Then
	ef=True
	ec="必须填写原因！"
end if

if not ef then
if Request.Form ("Submit")<>"查询用户信息" Then
if Request.Form ("usermoney")<0 then
	ef=True
	ec="金额不能小于零！"
end If
end if
end if

if not ef then
isagn=false
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	if Request.Form ("usertype")="用户名" then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
if ds.Eof then
		ef=True
		ec="用户不存在！"
end if
end if
end if

if not ef then
if Request.Form ("usertype")="代理名" then
		Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
	if ds.Eof then
		ef=True
		ec="代理用户不存在！"
	else
		isagn=true
	end if
end if
end if




if not ef then
if Request.Form ("usertype")="用户或代理名" then
isagn=false
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
		Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
	if ds.Eof then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
		ds.Open Sql,conn,1,3
if ds.Eof then
		ef=True
		ec="用户或代理不存在！"
end if
	else
		isagn=true
	end if
end if
end if

if not ef then
	Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent where username='"&session("agentusername")&"'"
		dsagent.Open Sql,conn,1,3
if dsagent.eof then
	ef=True
	ec="您并不是代理会员，或不存在您的代理名！"
end if
end if

if not ef then
if session("agentpassword")<>dsagent("password") then
	ef=True
	ec="密码不正确！"
end if
end if

if not ef then
if trim(Lcase(session("agentusername")))=trim(Lcase(ds("username"))) then
	ef=True
	ec="不能自己操作自己！"
end if
end If


If Not ef Then
If Request.Form ("Submit")="查询用户信息" Then
If isagn=True Then response.redirect "searchagent.asp?username="&Request.Form ("username")
If isagn=false Then response.redirect "searchuser.asp?username="&Request.Form ("username")
End if
End If

if not ef then
if Request.Form ("add")="入款" or Request.Form ("add")="退款" then
if dsagent("usermoney")<Clng(request.Form ("usermoney")) then
	ef=True
	ec="您的金额不足！"
end if
end if
end if

if not ef then
'check if this one is by this agent
if ds("agent1")<>session("agentusername") and ds("agent2")<>session("agentusername") then
	ef=True
	ec="此用户并不是您所代理的用户，不能操作！"
end if
end if

if not ef then
stmoney=ds("usermoney")
moneych=0
oriagentmoney=dsagent("usermoney")

if Request.Form ("add")="入款" or Request.Form ("add")="退款" then
isadd="y"
ds("usermoney")=ds("usermoney")+request.Form ("usermoney")
moneych=request.Form ("usermoney")
'changet agent money
dsagent("usermoney")=dsagent("usermoney")-request.Form ("usermoney")
else
isadd="n"
ds("usermoney")=ds("usermoney")-request.Form ("usermoney")
moneych=request.Form ("usermoney")
'changet agent money
dsagent("usermoney")=dsagent("usermoney")+request.Form ("usermoney")
end if

end if

if not ef then
if ds("usermoney")<0 then
	ef=True
	ec="用户的金额不能小于零！"
end if
end if

if not ef then
endmoney=ds("usermoney")


ds.Update
dsagent.Update


'if isagn then
'tyx="y"
'else
'tyx="n"
'end if
'log
'FreeHost_moneylog conn,Request.Form ("username"),session("agentusername"),moneych,Request.Form ("forwhat"),Request.Form ("whichProduct"),0,Request.Form ("corewhat"),tyx

issubagn="n"
isuser="n"
if isagn then
isagn="y"
else
isagn="n"
isuser="y"
end if
'log to user or agn
connmoney=conn
isuser=isuser
isagn=isagn
issubagn=issubagn
issup="n"
ishand="y"
isadd=isadd
isAgnHostSer=false
moneyX=moneych
if isuser="y" then
norusername=Request.Form ("username")
norStmoney=stmoney
norEndmoney=endmoney
end if
if isagn="y" then
agnusername=Request.Form ("username")
agnStmoney=stmoney
agnEndmoney=endmoney
end if
'supusername=session("agentusername")
forwhat=Request.Form ("forwhat")
if isuser="y" then
corewhat="代理手工操作名下用户"
end if
if isagn="y" then
corewhat="代理手工操作名下代理"
end if


whichProduct=Request.Form ("whichProduct")
pdid=0
attime=NOW
pingzheng=Request.Form ("pingzheng")
type1=Request.Form ("add")
bank=Request.Form ("bank")
haveget=Request.Form ("haveget")
havecheck="否"
'pdtype=pdtype
'pdsttime=pdsttime
'pdendtime=pdendtime

username=Request.Form ("username")
opusername=session("agentusername")

FreeHost_moneyNewlog conn,isuser,isagn,issup,ishand,isadd,isAgnHostSer,moneyX,username,opusername,norusername,norStmoney,norEndmoney,agnusername,agnStmoney,agnEndmoney,supusername,forwhat,corewhat,whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck





'conn.Close 
'set conn=nothing
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
　操作成功
<%=htmlwrite("html6")%>
<br>
操作成功：
<%if isagn="y" then%>
<font color=red>操作代理：</font>
<%else%>
操作用户：
<%end if%>
<%=Request.Form ("username")&" 原金额是："&stmoney&"元　现在的可用金额是："&endmoney&"元。"%>
<%if isadd="y" then%>
增加：
<%else%>
减少：
<%end if%>
<%=moneych%> 元
<br>
<br>
<br>
您的原金额是：<%=oriagentmoney%> 元 现在的金额是：<%=dsagent("usermoney")%> 元

<%
issubagn="n"
isuser="n"
isagn="y"
connmoney=conn
isuser=isuser
isagn=isagn
issubagn=issubagn
issup="n"
ishand="y"
isAgnHostSer=false
moneyX=moneych

agnusername=session("agentusername")
agnStmoney=oriagentmoney
agnEndmoney=dsagent("usermoney")

'supusername=session("agentusername")
forwhat=Request.Form ("forwhat")
if isuser="y" then
corewhat="代理手工操作名下用户"
end if
if isagn="y" then
corewhat="代理手工操作名下代理"
end if

whichProduct=Request.Form ("whichProduct")
pdid=0
attime=NOW
pingzheng=Request.Form ("pingzheng")
type1=Request.Form ("add")
bank=Request.Form ("bank")
haveget=Request.Form ("haveget")
havecheck="否"
'pdtype=pdtype
'pdsttime=pdsttime
'pdendtime=pdendtime

username=Request.Form ("username")
opusername=session("agentusername")

if isadd="y" then
isadd2="n"
else
isadd2="y"
end if
FreeHost_moneyNewlog conn,isuser,isagn,issup,ishand,isadd2,isAgnHostSer,moneyX,username,opusername,norusername,norStmoney,norEndmoney,agnusername,agnStmoney,agnEndmoney,supusername,forwhat,corewhat,whichProduct,pdid,pingzheng,type1,bank,haveget,havecheck


ds.Close
set ds=nothing

%>

<%=htmlwrite("html7")%>
<%end if

if ef then
Response.Redirect "e.asp?e="&ec
end if%>
