<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="checklogin.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>积分兑换</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
ul{margin:0px; padding:0px;}
li{margin:2px; padding:0px;}
.style1 {color: #FF0000}
-->
</style>
<script type="text/javascript">
function check(obj){
	with(obj){
		if(SetScore.value==""){
			alert("请输入要对的的积分数!");
			SetScore.focus();
			SetScore.select();
			return false;
		}
		
		return true;
	}
}
function checkint(elem)
{
  var checkOK = ".0123456789";
  var checkStr = elem.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
		ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
      	if (ch == checkOK.charAt(j))
        break;
    	if (j == checkOK.length)
    	{
      		allValid = false;
      		break;
    	}
  }
  if (!allValid)
  {
    	alert("只能输入数字。");
    	elem.focus();
    	return (false);
  }
  return (true);
}
</script>
</head>

<body>
<!--#include file="top.asp"-->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr>
    <td valign="top">
<%
dim act,rs,user_score,SetScore
set rs=server.CreateObject("adodb.recordset")
rs.open "select Score from t_member where userid='"&checkusername&"'",conn,3,1
if not rs.eof then
	user_score=rs(0)
end if
rs.close
set rs=nothing
act=request.querystring("act")
if(act="do") then
	SetScore=Cint(request.form("SetScore"))
	if(SetScore>user_score) then
		call alertstr("积分不足!",1)
	else
		if(SetScore>0) then
			dim addm
			addm=csng(SetScore/ScoreToMoney)
			set rs=server.CreateObject("adodb.recordset")
			conn.execute("update t_member set Score=Score-"&SetScore&",GoldMoney=GoldMoney+"&addm&" where UserId='"&checkusername&"'")
			'消费记录
			dim ranNum,pay_billno
			randomize
			ranNum=int(900*rnd)+100
			pay_billno=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
			set rs=server.CreateObject("adodb.recordset")
			rs.open "select * from t_payhis where 1=0",conn,3,3
			rs.addnew
			rs("PayType")="积分兑换"
			rs("PayMoney")=addm
			rs("PayFrom")="会员控制面板"
			rs("PayTo")=checkusername
			rs("PayDate")=now()
			rs("PayNo")=pay_billno
			rs("PayTitle")="积分兑换(会员控制面板)"
			rs("PayDesc")="积分兑换(消费积分："&SetScore&"，获得金币："&addm&")"
			rs.update
			rs.close
			set rs=nothing
			response.Write("<p align=""center"">成功兑换积分!获取金币："&addm&"</p>")
		else
			call alertstr("兑换积分不用为0!",1)
		end if
	end if	
else
%>

	  <form id="form1" name="form1" method="post" action="?act=do" onsubmit="return check(this)">
	    <table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" class="border">
          <tr>
            <td height="28" colspan="2" class="th_title">积分兑换</td>
          </tr>
          <tr>
            <td colspan="2" class="td_row"><div align="center">积分兑换比例：<span class="style1"><%=ScoreToMoney%>[积分]:1[金币]</span> ；当前您的积分为：<span class="style1"><%=user_score%></span></div></td>
          </tr>
          <tr>
            <td width="34%" class="td_row"><div align="right">兑换积分：</div></td>
            <td width="66%" class="td_row"><input name="SetScore" type="text" id="SetScore" value="100" size="20" onblur="checkint(this)" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /></td>
          </tr>
          <tr>
            <td><div align="center"></div></td>
            <td><input type="submit" name="Submit" value="确定" />
              &nbsp;&nbsp;
              <input type="reset" name="Submit2" value="取消" /></td>
          </tr>
        </table>
      </form>    
<%end if%></td>
  </tr>
</table>
</body>
</html>
<%
call connclose()
%>