<!--#include file="setup.asp" -->
<%
Server.ScriptTimeout = 9999999
NC_Admin.AdminChk = "23"
NC_Admin.Check
DownsysClass.admin_header
If request("action") = "yes" Then
	NC_Admin.Succeed_Msg("操作成功，各分类的文章数已经更新！")
	DownsysClass.admin_footer
	Response.End
End If

Response.Write "<table width=""400"" border=""0"" cellspacing=""1"" cellpadding=""1"">"& vbCrLf
Response.Write "<tr>"& vbCrLf
Response.Write "<td bgcolor=000000>"& vbCrLf
Response.Write " <table width=""400"" border=""0"" cellspacing=""0"" cellpadding=""1"">"& vbCrLf
Response.Write "<tr>"& vbCrLf
Response.Write "<td bgcolor=ffffff height=9><img src=""images/bar9.gif"" width=0 height=16 id=img2 name=img2 align=absmiddle></td></tr></table>"& vbCrLf
Response.Write "</td></tr></table></td></tr><tr>"& vbCrLf
Response.Write "<td align=center bgcolor=000000> <span id=txt2 name=txt2 style=""font-size:9pt"">0</span><span style=""font-size:9pt"">%</span></td></tr>"& vbCrLf
Response.Write "</table>"& vbCrLf
Response.Flush
Dim Rsc, Rss, ArticleNum, ClassNum, totalPut, body, i, Rs1, AllClassID
Set Rs = server.CreateObject("adodb.recordset")
Set Rsc = server.CreateObject("adodb.recordset")
Set Rss = server.CreateObject("adodb.recordset")

Rs.Open "select * from NC_Class where depth=0 order by classid asc", conn, 1, 1

If Rs.bof And Rs.EOF Then
	Response.Write ""
Else
	totalPut = Rs.recordcount
	i = 1
	Do While Not Rs.EOF
		Rss.Open "select Count(id) as ArticleNum from NC_article where isLock=0 and rootid="&Rs("rootid")&"", conn, 1, 1
		ArticleNum = Rss("ArticleNum")
		Rss.Close
		conn.Execute("update NC_Class set ArticleNum="&ArticleNum&",isUpdate=1 where depth=0 and classid=" & Rs("classid"))
		Rsc.Open "select * from NC_Class where depth<>0 order by classid asc", conn, 1, 1
		If Rsc.bof And Rsc.EOF Then
			Response.Write ""
		Else
			Do While Not Rsc.EOF
				Set Rs1 = Conn.Execute("select * from NC_Class where strParent like '%"& Rsc("classid") &"%'")
				If Rs1.EOF And Rs1.bof Then
					AllClassID = Rsc("classid")
				Else
					AllClassID = Rsc("classid")
					Do While Not Rs1.EOF
						AllClassID = AllClassID & "," & Rs1("classid")
						Rs1.movenext
					Loop
				End If
				Rs1.Close
				Set Rs1 = Nothing
				Rss.Open "select Count(id) as ArticleNum from NC_article where isLock=0 and classid in ("&AllClassID&")", conn, 1, 1
				ClassNum = Rss("ArticleNum")
				Rss.Close
				conn.Execute("update NC_Class set ArticleNum="&ClassNum&",isUpdate=1 where depth<>0 and classid=" & Rsc("classid"))
				Rsc.movenext
			Loop
		End If
		Rsc.Close
		Response.Write "<script>img2.width=" & Fix((i / totalPut) * 400) & ";" & vbCrLf
		Response.Write "txt2.innerHTML=""更新完 数据，" & FormatNumber(i / totalPut * 100, 4, -1) & """;" & vbCrLf
		Response.Write "img2.title=""(" & i & ")"";</script>" & vbCrLf
		Response.Flush
		body = "<table cellpadding=0 cellspacing=0 border=0 width=95%  align=center><tr><td colspan=2 class=forumrow>更新文章数据成功，["&Rs(1)&"] 共有 "&Rs(9)&" 篇文章。</td></tr></table>"
		Response.Write body
		Response.Flush
		Rs.movenext
		i = i + 1
	Loop
End If
Rs.Close
Set Rs = Nothing
Set Rss = Nothing
Set Rsc = Nothing
Response.Write"<script>img2.width=400;txt2.innerHTML=""100"";</script>"
Response.Write"<meta HTTP-EQUIV=REFRESH CONTENT='2; URL=admin_articleupdate.asp?action=yes'>"
DownsysClass.admin_footer
NothingObject
%>
