<!--#include file=../conn.asp-->
<!-- #include file="inc/const.asp" -->
<%Head()
	dim admin_flag
	admin_flag=",29,"
	if not master or instr(","&session("flag")&",",admin_flag)=0 then
		Errmsg=ErrMsg + "<BR><li>本页面为管理员专用，请<a href=../"&LoginUrl&" target=_top>登录</a>后进入。<br><li>您没有管理本页面的权限。"
		Call Ms_error()
	Else
		if request("action")="userdata" then
		call userdata()
		elseif request("action")="upgroup" then
		call upgroup()
		elseif request("action")="upsetup" then
		call upsetup()
		else
		call main()
		end if
		Footer()
	End If

sub main()%>
<table width="95%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
<tr> 
<th height="23" colspan="3" class="tableHeaderText" align="left">更新系统数据</th>
</tr>
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">注意事项
</td>
<td height="25" colspan="2" class="forumrow">下面有的操作可能将非常消耗服务器资源，而且更新时间很长，请仔细确认每一步操作后执行。
</td>
</tr>
<tr> 
<th height="23" colspan="3" class="tableHeaderText" align="left">更新用户数据</th>
</tr>
<FORM METHOD=POST ACTION="?action=userdata">
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">
</td>
<td height="25" colspan="2" class="forumrow">此操作重新统计用户文章、日记、相册等数据
</td>
</tr>
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">开始的ID号
</td>
<td height="25" colspan="2" class="forumrow"><input type=text name="beginID" value="1" size=10>&nbsp;用户ID，可以填写您想从哪一个ID号开始进行修复
</td>
</tr>
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">结束的ID号
</td>
<td height="25" colspan="2" class="forumrow"><input type=text name="endID" value="100" size=10>&nbsp;将更新开始到结束ID之间的用户数据，之间的数值最好不要选择过大
</td>
</tr>
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">
</td>
<td height="25" colspan="2" class="forumrow"><input type="submit" name="Submit" value="更新用户">
</td>
</tr>
</form>

<tr> 
<th height="23" colspan="3" class="tableHeaderText" align="left">更新等级库</th>
</tr>
<FORM METHOD=POST ACTION="?action=upgroup">
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">
</td>
<td height="25" colspan="2" class="forumrow">此操作重新统计各等级的用户数
</td>
</tr>
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">
</td>
<td height="25" colspan="2" class="forumrow"><input type="submit" name="Submit" value="更新等级">
</td>
</tr>
</form>

<tr> 
<th height="23" colspan="3" class="tableHeaderText" align="left">更新系统库</th>
</tr>
<FORM METHOD=POST ACTION="?action=upsetup">
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">
</td>
<td height="25" colspan="2" class="forumrow">此操作重新统计系统库数据
</td>
</tr>
<tr>
<td height="25" colspan="1" class="forumrow" width="18%">
</td>
<td height="25" colspan="2" class="forumrow"><input type="submit" name="Submit" value="更新开始">
</td>
</tr>
</form>
<%end sub

sub userdata()
dim beginID,endID
Dim C1,Ers
beginID=trim(request("beginID"))
endID=trim(request("endID"))
if not isnumeric(beginID) then
	ErrMsg=ErrMsg+"<br>"+"<li>错误的开始参数！</li>"
	Founderr=true
End If
if not isnumeric(endID) then
	ErrMsg=ErrMsg+"<br>"+"<li>错误的结束参数！</li>"
	Founderr=true
end if
if beginID>endID then
	ErrMsg=ErrMsg+"<br>"+"<li>开始ID应该比结束ID小！</li>"
	Founderr=true
end if
if Founderr=true then Ms_error()
C1=clng(request.form("endid"))-clng(request.form("beginid"))%>
<br><table cellpadding="0" cellspacing="0" border="0" width="95%" class="tableBorder" align=center>
<tr><td colspan=2 class=forumrow>
下面开始重新统计各项数据，预计本次统计<%=C1%>个用户。
<table width="400" border="0" cellspacing="1" cellpadding="1">
<tr> 
<td bgcolor=000000>
<table width="400" border="0" cellspacing="0" cellpadding="1">
<tr> 
<td bgcolor=ffffff height=9><img src="../skins/default/bar/bar3.gif" width=0 height=16 id=img2 name=img2 align=absmiddle></td></tr></table>
</td></tr></table> <span id=txt2 name=txt2 style="font-size:9pt">0</span></td></tr>
</table>
<%dim i
Response.Flush
	sql="select username from Ms_user where Userid>="&beginID&" and Userid<="&endID
	set rs=conn.Execute(sql)
		if rs.eof and rs.bof then
			ErrMsg=ErrMsg+"<br>"+"<li>已经到记录的最尾端，请结束更新！</li>"
			exit sub
		end if
	i=0
	do while not rs.eof
	''更新文章数
		sql="select Count(id) from Ms_Article where Username='"&rs(0)&"'"
			set Ers=Conn.Execute(sql)	
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_user] set UserArt="&Ers(0)&" where Username='"&rs(0)&"'")
			end if
		Ers.close
		''更新日记数
		sql="select count(Did) from Ms_diary where username='"&rs(0)&"'"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_user] set Userdiary="&Ers(0)&" where Username='"&rs(0)&"'")
			end if
		Ers.close
		''更新相册数
		sql="select count(FID) from Ms_Upphoto where username='"&rs(0)&"'"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_user] set UserPics="&Ers(0)&" where Username='"&rs(0)&"'")
			end if
		Ers.close
		''更新朋友数
		sql="select count(FID) from Ms_friend where username='"&rs(0)&"'"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_user] set Friendjoin="&Ers(0)&" where Username='"&rs(0)&"'")
			end if
		Ers.close
	i=i+1
	Response.Write "<script>img2.width=" & Fix((i/C1) * 400) & ";" & VbCrLf
	Response.Write "txt2.innerHTML=""" & FormatNumber(i/(C1+1)*100,2,-1) & "%，更新用户数据成功！"";" & VbCrLf
	Response.Write "img2.title=""已成功更新(" & i & ")用户！"";</script>" & VbCrLf
		Response.Flush
	rs.movenext
	loop
	rs.close
end sub

sub upgroup()''更新等级库
Dim C1,Ers
Set Rs=conn.Execute("Select Count(UserGroupID) From [Ms_UserGroups]")
	If Not (Rs.eof or Rs.bof) then
	C1=rs(0)
	end if
	rs.close
%>
<br><table cellpadding="0" cellspacing="0" border="0" width="95%" class="tableBorder" align=center>
<tr><td colspan=2 class=forumrow>
下面开始重新统计等级用户，预计本次统计<%=C1%>个用户。
<table width="400" border="0" cellspacing="1" cellpadding="1">
<tr> 
<td bgcolor=000000>
<table width="400" border="0" cellspacing="0" cellpadding="1">
<tr> 
<td bgcolor=ffffff height=9><img src="../skins/default/bar/bar3.gif" width=0 height=16 id=img2 name=img2 align=absmiddle></td></tr></table>
</td></tr></table> <span id=txt2 name=txt2 style="font-size:9pt">0</span></td></tr>
</table>
<%
dim i
Response.Flush
	sql="select UserGroupID from Ms_UserGroups"
	set rs=conn.Execute(sql)
		if rs.eof and rs.bof then
			ErrMsg=ErrMsg+"<br>"+"<li>已经到记录的最尾端，请结束更新！</li>"
			exit sub
		end if
		do while not rs.eof
			sql="select Count(Userid) from Ms_user where UserGroupID="&rs(0)&""
			set Ers=Conn.Execute(sql)	
				if not (Ers.eof and Ers.bof) then
				conn.Execute("update [Ms_UserGroups] set Useradd="&Ers(0)&" where UserGroupID="&rs(0)&"")
				end if
			Ers.close
		i=i+1
			Response.Write "<script>img2.width=" & Fix((i/C1) * 400) & ";" & VbCrLf
			Response.Write "txt2.innerHTML=""" & FormatNumber(i/C1*100,2,-1) & "%，更新等级数据成功！"";" & VbCrLf
			Response.Write "img2.title=""已成功更新(" & i & ")个等级！"";</script>" & VbCrLf
			Response.Flush
		rs.movenext
		loop
		rs.close
end sub

sub upsetup()''更新系统总数据
Dim C1,Ers
C1=7
%>
<br><table cellpadding="0" cellspacing="0" border="0" width="95%" class="tableBorder" align=center>
<tr><td colspan=2 class=forumrow>
下面开始重新统计系统表，预计本次统计<%=C1%>个表。
<table width="400" border="0" cellspacing="1" cellpadding="1">
<tr> 
<td bgcolor=000000>
<table width="400" border="0" cellspacing="0" cellpadding="1">
<tr> 
<td bgcolor=ffffff height=9><img src="../skins/default/bar/bar3.gif" width=0 height=16 id=img2 name=img2 align=absmiddle></td></tr></table>
</td></tr></table> <span id=txt2 name=txt2 style="font-size:9pt">0</span></td></tr>
</table>
<%dim i
Response.Flush
	''统计文章数
		sql="select Count(id) from Ms_Article"
			set Ers=Conn.Execute(sql)	
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set UserArt="&Ers(0)&" where Cid=1")
			end if
		Ers.close
		''统计日记数
		sql="select count(Did) from Ms_diary"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set Userdiary="&Ers(0)&" where Cid=1")
			end if
		Ers.close
		''统计相册数
		sql="select count(FID) from Ms_Upphoto"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set Uploadph="&Ers(0)&" where Cid=1")
			end if
		Ers.close
		''统计用户
		sql="select count(UserID) from Ms_user"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set UserNum="&Ers(0)&" where Cid=1")
			end if
		Ers.close
				''统计征婚数
		sql="select count(MID) from Ms_Marry"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set Marrynum="&Ers(0)&" where Cid=1")
			end if
		Ers.close
				''统计约会数
		sql="select count(PID) from Ms_party"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set Partynum="&Ers(0)&" where Cid=1")
			end if
		Ers.close
				''统计VIP数
		sql="select count(Userid) from Ms_User where UserVip>1"
			set Ers=Conn.Execute(sql)
			if not (Ers.eof and Ers.bof) then
			conn.Execute("update [Ms_setup] set UserVip="&Ers(0)&" where Cid=1")
			end if
		Ers.close
	Response.Write "<script>img2.width=400;" & VbCrLf
	Response.Write "txt2.innerHTML=""100%，更新数据成功！"";" & VbCrLf
	Response.Write "img2.title=""已成功更新统计表！"";</script>" & VbCrLf
		Response.Flush
end sub
%>