<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!-- #include file="tc_dv.asp" -->
<!-- #include file="tc_conn.asp" -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%'
'
'
'
	Response.Buffer=True 
Dvbbs.stats="<a href=plus_tc.asp>社区体彩</a>"
Dvbbs.Nav()
Dvbbs.Head_var 2,0,"",""
if dvbbs.Membername="" then
  Dvbbs.AddErrCode(6)
  Dvbbs.Showerr()
else
response.write "<table cellpadding=3 cellspacing=1 align=center class=tableborder1><tr><th valign=middle colspan=2 align=center height=25><b>社区体彩</b></td></tr><tr><td valign=middle class=tablebody1 height=100><CENTER>"
 sql="select userwealth,UserPower,usertitle,userpost from dv_user where username='"&dvbbs.Membername&"' "
   set rs=conn.execute(sql)
%><body>
<font color="#FF0000"><%=Dvbbs.MyUserInfo(5)%> 怀着 <%=rs("userwealth")%> 来到 </font><span style="color: #0000FF; font-weight: bold;">流淌的岁月影视论坛</span><font color="#FF0000"> 社区体彩.</font> 
<% 
    rs.close
	set rs=nothing
    dim userarticle,strhm,rs0,intqs,intzs,intdzje,strtime,intxse,zjyf,zjyf1,zjyf2,zjyf3,intzj0,intzj1,intzj2,intzj3,t,strxz,kk,j,strkj,intzj,strsqhm,rszj,intje,gengxin,strzj
			  'Set rs0=Server.CreateObject("ADODB.RecordSet")'当前期数的设置
			  set rs0=tc_conn.execute("select * from cp_sz order by qs desc")
			  if rs0.eof then'第一次,注册首期，时间为相隔两天后开奖。
			  '首期开奖号码 
			  strhm=cstr(zj_rnd())'预置开奖号码
			  tc_conn.execute("insert into cp_sz(qs,kjhm,kjsj) values (1,'"&strhm&"','"&dateadd("d",2,cstr(now()))&"')")
			  response.redirect("plus_tc.asp")
			  else
			  intqs=rs0("qs")
			  intdzje=rs0("dzje")
			  strtime=rs0("kjsj")
			  rs0.close
			  set rs0=nothing
			  end if
			  intzs=tc_conn.execute("select count(id) from cp_gmxx where qs="&intqs&"")(0)'至今总投注数
			  session("qs")=intqs'保存现在期数
			  
			  if dateadd("n",1,cstr(now()))>=strtime then'开奖前十分钟不能下注。。做开奖前的准备,或者超过本期的开奖时间，才有人来此，则结算上一次开奖的信息！
					intxse=intzs*intdzje
					strsqhm=tc_conn.execute("select kjhm from cp_sz where qs="&intqs&"")(0)'取本期的中奖号码进行处理
					tc_conn.execute("insert into cp_kjxx(qs,hm,xse) values ("&intqs&",'"&strsqhm&"',"&intxse&")")'把本期的开奖情况了决。为下一期做准备
					'%%%%%统计中奖人数对中奖用户进行奖金的冲值。
					zjyf=tc_conn.execute("select count(id) from cp_gmxx where qs="&intqs&" and zj=5")(0)'特等奖。
					zjyf1=tc_conn.execute("select count(id) from cp_gmxx where qs="&intqs&" and zj=4")(0)'一等奖。
					zjyf2=tc_conn.execute("select count(id) from cp_gmxx where qs="&intqs&" and zj=3")(0)'二等奖。
					zjyf3=tc_conn.execute("select count(id) from cp_gmxx where qs="&intqs&" and zj=2")(0)'三等奖。
					
					intzj0=intxse*0.1+500'销售额的10%+底金500
					intzj1=100'一等奖,100为一等奖的金额,可改.下同
					intzj2=50
					intzj3=20
					strzj="特等奖:奖金"&intzj0&"&nbsp;"&zjyf&"&nbsp;人中&nbsp;一等奖:"&zjyf1&"人中&nbsp;二等奖:"&zjyf2&"人中&nbsp;三等奖:"&zjyf3&"人中"
					tc_conn.execute("update cp_kjxx set zjyf='"&strzj&"',tdjje="&intzj0&" where qs="&intqs&"")
                    set rszj=tc_conn.execute("select gmz,zj from cp_gmxx where qs="&intqs&"")
					do while not rszj.eof
					          intje=0
							  gengxin=0
					   select case rszj("zj")
					          case 5
							  intje=intzj0
							  gengxin=1
							  case 4
							  intje=intzj1
							  gengxin=1
							  case 3
							  intje=intzj2
							  gengxin=1
							  case 2
							  intje=intzj3
							  gengxin=1
					   end select
				   if gengxin=1 then'用户有中奖的，金钱增加
					conn.execute("update dv_user set userwealth=userwealth+"&intje&" where username='"&rszj("gmz")&"'")
					'   tc_conn.execute("update suser set smoney=smoney+"&intje&" where susername='"&rszj("gmz")&"'")
				   end if

					rszj.movenext
					loop
					rszj.close
					set rszj=nothing
					strhm=cstr(zj_rnd())'预置开奖号码
					tc_conn.execute("insert into cp_sz(qs,kjhm,kjsj) values ("&intqs+1&",'"&strhm&"','"&dateadd("d",2,cstr(now()))&"')")'下一期的开奖情况为:期数加1,号码为随机数,时间为隔两天
					
					'对中奖用户进行奖金的冲值完成
					 response.redirect("plus_tc.asp")
end if
			 

			dim strkjxx
			strkjxx=tc_conn.execute("select zjyf from cp_kjxx where qs="&session("qs")-1&"")("zjyf")%>
			<marquee scrolldelay="120" width="100%">
          上一期开奖情况:<%=strkjxx%>
        </marquee>
		截止目前,本期购买注数为:<%=intzs%>&nbsp;&nbsp;销售额为:<%=intzs*intdzje%>
  <%
 response.write "</CENTER></td></tr></table>"
%>
  <table class=tableborder1 cellspacing=1 cellpadding=4 width="97%" border=0 align="center">
    <tbody>
      
      <tr>
        <th Class=tablebody1  align=middle colspan=3 height=9><b>欢迎光临虚拟体育彩票中心---22选5第<%=intqs%>期</b></th>
      </tr>
      <tr>
        <td height=10 colspan=3  align=middle Class=tablebody1><div align="center">奖金计算：特等奖为销售额×10%+500，一等奖为100，二等奖为50，三等奖为20（单位:皇家币币）</div></td>
      </tr>      
      <tr>
        <td Class=tablebody2  valign=center align=left width="40%" 
            height=20 nowrap>玩法：</td>
        <td valign=top align=left width="27%" height=20 Class=tablebody2 >近期您下注的情况：<br>
        </td>
        <td valign=top align=left width="33%" height=20 nowrap Class=tablebody2 > 近二十期开奖情况 </td>
      </tr>
      <tr>
        <td Class=tablebody2  valign=top align=left width="40%" 
            height=1 nowrap>
			<form name="form1" method="post" action="plus_tc.asp?do=save">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
              <td Class=tablebody2 >
                <p>22选5：从01-22上数字中选出5个数组成一组，做为一注进行下注。每注金额<font color="#FF0000"><%=intdzje%></font>皇家币！不能选择相同的号码！<br>
              本期的开奖时间为：<font size="" color="#CC0033"><%=strtime%></font></p>              </td>
            </tr>
            <tr>
              <td height="8" Class=tablebody2 > <br>
                  <select name="xz">
                    <option value=01>01</option>
                    <option value=02>02</option>
                    <option value=03>03</option>
                    <option value=04>04</option>
                    <option value=05>05</option>
                    <option value=06>06</option>
                    <option value=07>07</option>
                    <option value=08>08</option>
                    <option value=09>09</option>
                    <%for i=10 to 22
                            response.write("<option value="&i&">"&i&"</option>")
							next
							%>
                  </select>
                  <select name="xz">
                    <option value=01>01</option>
                    <option value=02>02</option>
                    <option value=03>03</option>
                    <option value=04>04</option>
                    <option value=05>05</option>
                    <option value=06>06</option>
                    <option value=07>07</option>
                    <option value=08>08</option>
                    <option value=09>09</option>
                    <%for i=10 to 22
                            response.write("<option value="&i&">"&i&"</option>")
							next
							%>
                  </select>
                  <select name="xz">
                    <option value=01>01</option>
                    <option value=02>02</option>
                    <option value=03>03</option>
                    <option value=04>04</option>
                    <option value=05>05</option>
                    <option value=06>06</option>
                    <option value=07>07</option>
                    <option value=08>08</option>
                    <option value=09>09</option>
                    <%for i=10 to 22
                            response.write("<option value="&i&">"&i&"</option>")
							next
							%>
                  </select>
                  <select name="xz">
                    <option value=01>01</option>
                    <option value=02>02</option>
                    <option value=03>03</option>
                    <option value=04>04</option>
                    <option value=05>05</option>
                    <option value=06>06</option>
                    <option value=07>07</option>
                    <option value=08>08</option>
                    <option value=09>09</option>
                    <%for i=10 to 22
                            response.write("<option value="&i&">"&i&"</option>")
							next
							%>
                  </select>
                  <select name="xz">
                    <option value=01>01</option>
                    <option value=02>02</option>
                    <option value=03>03</option>
                    <option value=04>04</option>
                    <option value=05>05</option>
                    <option value=06>06</option>
                    <option value=07>07</option>
                    <option value=08>08</option>
                    <option value=09>09</option>
                    <%for i=10 to 22
                            response.write("<option value="&i&">"&i&"</option>")
							next
							%>
                  </select>
                  <input type="submit" name="Submit2" value="我买了">
              </td>
            </tr>
        </table>
		</form>
		</td>
        <td Class=tablebody2  valign=top align=left width="27%" height=1>           <%
			sql="select top 15 * from  (select *from cp_gmxx where gmz='"&dvbbs.Membername&"' order by qs desc)"
	      set rs=tc_conn.execute(sql)
		  do while not rs.eof
		  response.write("第"&rs("qs")&"期："&rs("gmhm")&"<br>")
		  rs.movenext
		  loop
		  rs.close
			  set rs=nothing
			  response.write("<A HREF=plus_tc_show.asp?show=user>查看您所有的投注情况！》》</A>")
			  %> </td>
        <td width="33%" height=1 align=left valign="top" nowrap Class=tablebody2  cvalign=top> <%
				set rs=tc_conn.execute("select top 10 qs,hm from cp_kjxx order by qs desc")
		  do while not rs.eof
		  response.write("第"&rs("qs")&"期开奖情况：<br>中奖号码为："&rs("hm")&"<A HREF=plus_tc_show.asp?show=zj&qs="&rs("qs")&">查看中奖名单》》</A><br>")
		  rs.movenext
		  loop
		  rs.close
			  set rs=nothing%> </td>
      </tr>
	  <%if dvbbs.usergroupid=1 then '是管理员可以查看记录%>
      <tr>
        <td 
            height=0 colspan="3" align=left  valign=center nowrap Class=tablebody2><table width="100%" border=0 align=center cellpadding=3 cellspacing=1 class=tableborder1>
          <tr>
            <th>管理选项</th>
          </tr>
          <tr>
            <td Class=tablebody2 valign="middle" align=center nowrap><Font Color="#0066FF"><b>=**</b><a href="plus_tc_admin.asp">进入管理</a><b>**=</b></Font></td>
          </tr>
        </table></td>
      </tr>
  <% end if%>
      <tr align="center">
        <th 
            height=0 colspan="3"  valign=center nowrap Class=tablebody2>&nbsp;</th>
      </tr>
    </tbody>
  </table>
  


</body>
<%
if request("do")="save" then
strxz=request.form("xz")
'xzqk=split(strxz,",")


'判断是数组内是否有相同的值，相同则出错。
kk=split(strxz,",")
t=1
for i=LBound(kk) To UBound(kk)-1
   for j=i+1 To UBound(kk)
   if kk(i)=kk(j) then'存在相同的注码
   t=0
   %><script language="vbscript">
      alert ("您输入的注码存在相同！请重选！")
      history.back()
      </script>
   <%
   end if
   next
next
if t=1 then
   intzj=0'开始时，有中奖情况为0
   strkj=tc_conn.execute("select kjhm from cp_sz where qs="&intqs&"")(0)'取得开奖号码
   for i=LBound(kk) To UBound(kk)
   if instr(strkj,trim(cstr(kk(i)))) then
   intzj=intzj+1
   end if
   next
   '判断是几等奖。
   tc_conn.execute("insert into cp_gmxx(qs,gmz,gmhm,zj) values("&intqs&",'"&dvbbs.Membername&"','"&strxz&"',"&intzj&")")'用户购买情况登记
   
   '用户买，金钱减。
   conn.execute("update dv_user set userwealth=userwealth-"&intdzje&" where username='"&dvbbs.Membername&"'")
   'response.write(intdzje)
   response.redirect("plus_tc.asp")
end if
end if
function zj_rnd()
  randomize
  dim a(4),mm
  i=0

  do while i<5
  
  do'保证随机数不会为0
  kk=rnd()
  kk=kk*100 mod 23
  if kk<>0 then
  exit do
  end if
  loop
 
  if kk<10 then'小于0的在前面加“0”
     kk="0"&kk
  end if
  kk=cstr(kk)
  if i<>0 then'判断是否重复了
     if instr(mm,trim(kk)) then
	 else
	 a(i)=kk
	 i=i+1     
	 mm=join(a,",")
	 end if
  else
     a(i)=kk
     i=i+1
     mm=join(a,",")
  end if
  zj_rnd=mm
  loop
end function
end if
call Dvbbs.footer()  
%> 