<!--#include file="../conn.asp"-->
<!--#include file="../conn_BBS.asp"-->
<!--#include file="../inc/function.asp"-->
<%
if CheckUserLogined()=False then
	response.Redirect "User_Login.asp"
end if

'这里设置转换比率
CONST PerWealth=10

dim strMsg
dim rsBBS,sqlBBS,rs,sql
dim UserWealth
dim TransferType
Action=trim(request("Action"))
UserWealth=trim(Request("UserWealth"))
TransferType=trim(request("TransferType"))
if TransferType="" then
	TransferType=1
else
	TransferType=Clng(TransferType)
end if
if Action="Modify" then
	UserName=trim(request("UserName"))
else
	username=Request.Cookies(Site_Sn)("UserName")
end if
if UserName="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数不足！</li>"
else
	UserName=ReplaceBadChar(UserName)
end if
if FoundErr=true then
	call WriteErrMsg()
else
Set rs=Server.CreateObject("Adodb.RecordSet")
	sql="select username,userpoint from PE_User where username='" & UserName & "'"
	rs.Open sql,Conn,1,3

	Set rsBBS=Server.CreateObject("Adodb.RecordSet")
	sqlBBS="select * from Dv_User where username='" & UserName & "'"
	rsBBS.Open sqlBBS,Conn_BBS,1,3
	if rsBBS.bof and rsBBS.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>论坛中找不到指定用户！</li>"
		call writeErrMsg()
	else
		if Action="Modify" then
			if UserWealth="" or not isNumeric(UserWealth) then
				founderr=true
				if TransferType=1 then
					errmsg=errmsg & "<br><li>请输入要转换的论坛货币数量</li>"
				else
					errmsg=errmsg & "<br><li>请输入要转换的动易点数</li>"
				end if
				call WriteErrMsg()
				response.end
			else
				UserWealth=Clng(UserWealth)
			end if
			if UserWealth<0 then
				FoundErr=True
				if TransferType=1 then
					ErrMsg=ErrMsg & "<br><li>论坛货币必须是正数！</li>"
				else
					ErrMsg=ErrMsg & "<br><li>动易点数必须是正数！</li>"
				end if
			end if
			if FoundErr<>true then
				if TransferType=1 then
					if UserWealth>rsBBS("UserWealth") then
						UserWealth=(rsBBS("UserWealth")\PerWealth)*PerWealth
					else
						UserWealth=(UserWealth\PerWealth)*PerWealth
					end if
					rsBBS("UserWealth")=rsBBS("UserWealth")-UserWealth
					rs("UserPoint")=rs("UserPoint")+(UserWealth\PerWealth)
					rsBBS.update
					rs.update
					strMsg="成功将 " & UserWealth & " 个论坛货币转换为 " & UserWealth\PerWealth & " 点动易点数！<br>"
				else
					if UserWealth>rs("UserPoint") then
						UserWealth=rs("UserPoint")*PerWealth
					else
						UserWealth=UserWealth*PerWealth
					end if
					rsBBS("UserWealth")=rsBBS("UserWealth")+UserWealth
					rs("UserPoint")=rs("UserPoint")-(UserWealth\PerWealth)
					rsBBS.update
					rs.update
					strMsg="成功将 " & UserWealth\PerWealth & " 点动易点数转换为 " & UserWealth & " 个论坛货币！<br>"
				end if
				strMsg=strMsg & "转换后，你的论坛货币数量为：<font color=red>" & rsBBS("UserWealth") & "</font>；动易点数为：<font color=red>" & rs("UserPoint") & "</font> 。"
				call WriteSuccessMsg(strMsg,"")
			else
				call WriteErrMsg()
			end if
		else
%>
<html>
<head>
<title><%
if TransferType=1 then
	response.write "论坛货币转换为动易点数"
else
	response.write "动易点数转换为论坛货币"
end if%>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="/Admin/Admin_Style.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<FORM name="Form1" action="User_Money2Point.asp" method="post">
  <p></p><p> </p> 
  <br>
  <br>
  <br>
  <br>
  <br>
  <br>
  <table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>
    <tr align='center' class='title'>
      <td height='22'><strong>用户点数转换管理</strong></td>
    </tr>
    <tr class='tdbg'>
      <td height='100' valign='top'><table cellpadding=0 cellspacing=0 border=0 width=400  align=center>
        <tr>
          <td><table cellpadding="2" cellspacing="0" border="0" width="400"align=center>
              <tr>
                <td width="100" class="tdbg" height=23><strong>管理快捷方式：</strong></td>
                <td><a href="User_Money2Point.asp">论坛货币转换为动易点数</a> | <a href="User_Money2Point.asp?transfertype=0">动易点数转换为论坛货币</a></td>
              </tr>
            </table>
              <table width=400 border=0 align="center" cellpadding=0 cellspacing=0 >
                <TR align=center class='title'>
                  <TD height=22 colSpan=2><font class=en><b>
                    <%
if TransferType=1 then
	response.write "论坛货币转换为动易点数"
else
	response.write "动易点数转换为论坛货币"
end if%>
                  </b></font></TD>
                </TR>
                <TR class="tdbg" >
                  <TD width="150" align="right"><b>用 户 名：</b></TD>
                  <TD><%=Request.Cookies(Site_Sn)("UserName")%>
                      <input name="UserName" type="hidden" value="<%=Trim(Request.Cookies(Site_Sn)("UserName"))%>"></TD>
                </TR>
                <TR class="tdbg" >
                  <TD width="150" align="right"><strong>目前可用的论坛货币：</strong></TD>
                  <TD><font color='green'><%=rsBBS("UserWealth")%></font> 个</TD>
                </TR>
                <TR class="tdbg" >
                  <TD width="150" align="right"><strong>目前可用的动易点数：</strong></TD>
                  <TD><font color='green'><%=rs("UserPoint")%></font> 点</TD>
                </TR>
                <TR class="tdbg" >
                  <TD width="150" align="right"><strong>
                    <%if TransferType=1 then
		response.write "欲转换论坛货币数量："
	  else
		response.write "欲转换的动易点数："
	  end if%>
                    <br>
                  </strong></TD>
                  <TD><%if TransferType=1 then%>
                      <INPUT name=UserWealth id="UserWealth" value="<%=rsBBS("userWealth")%>" size=10   maxLength=10>
                    个
                    <%else%>
                    <INPUT name=UserWealth id="UserWealth" value="<%=rs("UserPoint")%>" size=10   maxLength=10>
                    点
                    <%end if%></TD>
                </TR>
                <TR class="tdbg" >
                  <TD width="150" align="right"><strong>提示：</strong></TD>
                  <TD><%if TransferType=1 then
		response.write "每 <font color=red>" & PerWealth & "</font> 个论坛货币可转换为 1 点动易点数。"
	  else
		response.write "每点动易点数可转换为 <font color=red>" & PerWealth & "</font> 个论坛货币"
	  end if
	  %></TD>
                </TR>
                <TR align="center" class="tdbg" >
                  <TD height="40" colspan="2"><input name="Action" type="hidden" id="Action" value="Modify">
                      <input name="TransferType" type="hidden" id="TransferType" value="<%=TransferType%>">
                      <input name=Submit   type=submit id="Submit" value="我要转换">
                  </TD>
                </TR>
            </TABLE></td>
        </tr>
      </table></td>
    </tr>
    <tr align='center' class='tdbg'>
      <td></td>
    </tr>
  </table>
</form>
</body>
</html>
<%
		end if
	end if

	rsBBS.close
	set rsBBS=nothing
    rs.close
	set rs=nothing
end if

call CloseConn_BBS()
call CloseConn()
%>