<!--#include file="CommonCode.asp"-->
<!--#include file="../Conn_BBS.asp"-->
<%
'这里设置转换比率
CONST PerWealth=5

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>请输入要转换的" & PointName & "数量</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>" & PointName & "数量必须是正数！</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 & PointUnit & "！<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 & PointUnit & "转换为 " & UserWealth & " 个论坛金钱！<br>"
				end if
				strMsg=strMsg & "转换后，你的论坛金钱数量为：<font color=red>" & rsBBS("UserWealth") & "</font>；" & PointName & "数量为：<font color=red>" & rs("UserPoint") & "</font> 。"
'				call WriteSuccessMsg(strMsg)
	response.write "转换成功，请返回前页刷新查看"
			else
				call WriteErrMsg()
			end if
		else
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><%=SiteName & " >> 会员中心 >> 充值管理"%></title>
<link href="User_Skin/DefaultSkin.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<!--#include file="top.asp"-->
<table width="756" border="0" align="center" cellpadding="0" cellspacing="0" class="user_border">
  <tr>
    <td valign="top">
      <table width="100%" border="0" cellpadding="5" cellspacing="0" class="user_box">
        <tr>
          <td class="user_righttitle"><img src="Images/point2.gif" align="absmiddle"><%="您现在的位置：<a href='../'>" & SiteName & "</a> >> <a href='Index.asp'>会员中心</a> >> 充值管理"%></td>
        </tr>
        <tr>
          <td class="tdbg">
            <font color="#0066FF"> ●</font> <font color=red> 请选择转换方式：</font> <a href="User_Money2Point.asp">论坛金钱转换为<%=PointName%></a> | <a href="User_Money2Point.asp?transfertype=0"><%=PointName%>转换为论坛金钱</a>
          </td>
        </tr>
        <tr>
          <td height="200" valign='top' align='center'>
<FORM name="Form1" action="User_Money2Point.asp" method="post">
  <table width="99% border=0 align="center" cellpadding=2 cellspacing=1 class='border'>
    <TR align=center class='title'> 
      <TD height=22 colSpan=2><font class=en><b><%
if TransferType=1 then
	response.write "论坛金钱转换为" & PointName
else
	response.write PointName & "转换为论坛金钱"
end if%></b></font></TD>
    </TR>
    <TR class="tdbg" > 
      <TD width="120" align="right" bgcolor="#E0EEF5">用户名：</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="120" align="right" bgcolor="#E0EEF5">可用论坛金钱：</TD>
      <TD><%=rsBBS("UserWealth")%> 个</TD>
    </TR>
    <TR class="tdbg" >
      <TD width="120" align="right" bgcolor="#E0EEF5">可用<%=PointName%>数：</TD>
      <TD><%=rs("UserPoint")%>&nbsp;<%=PointUnit%></TD>
    </TR>
    <TR class="tdbg" >
      <TD width="120" align="right" bgcolor="#E0EEF5"><%if TransferType=1 then
		response.write "兑换" & PointName & "："
	  else
		response.write "兑换论坛金钱："
	  end if%><br>
      </TD>
      <TD><%if TransferType=1 then%>将论坛金钱 <INPUT name=UserWealth id="UserWealth" value="<%=rsBBS("userWealth")%>" size=10   maxLength=10> 个兑换成<%=PointName%><%else%>将 <INPUT name=UserWealth id="UserWealth" value="<%=rs("UserPoint")%>" size=10   maxLength=10> <%=PointUnit%>兑换成论坛金钱<%end if%>&nbsp;&nbsp;&nbsp;&nbsp;兑换比例：1<%=PointUnit%>:<%=PerWealth%>个论坛金钱</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>
</form>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!--#include file="bottom.asp"-->
</body>
</html>
<%
		end if
	end if

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

call CloseConn_BBS()
call CloseConn()
%>