<!--#include file="setup.asp"-->
<%
Dim DownloadClass
Set DownloadClass = New Create_Sorting_Cls
DownloadClass.SortingHtml
Set DownloadClass = Nothing
CloseConn

Class Create_Sorting_Cls
	Private DownloadClass_Ads,K
	Private softid, sortid, rootid, depth, SortName, ParentID, strParent, Child
	Private CurrentPage, maxperpage, totalnumber, bookmark, Pcount
	Private order_name, strOrder, ShowPageHtml, HtmlTemplate
	Private action, d
	Private TotalPageNum,WhereSQL
	Private SQL, Rs, Rs1, SQL1, CreateHtml, FSO, total, NewFolderPath, objFSO
	Private temphtml, NowStats, HtmlTitle
	Private TempTopStr, TempFootStr, Style_CSS


	Private Sub Class_Initialize()
		DownsysClass.LoadTemplates ("Sorting")
		Set DownloadClass_Ads = New Adcolumn_Cls
		maxperpage = CInt(DownsysClass.TempSet(0)) '###每页显示数
	End Sub

	Private Sub Class_Terminate()
		If IsObject(Conn) Then
			Conn.Close
			Set Conn = Nothing
		End If
		If IsObject(DownloadClass_Ads) Then
			Set DownloadClass_Ads = Nothing
		End If
	End Sub

	Public Sub SortingHtml()
		On Error Resume Next
		Server.ScriptTimeout = 99999
		Set NC_Admin = New Check
		NC_Admin.AdminChk = "31"
		NC_Admin.Check
		DownsysClass.admin_header
		If Not(DownsysClass.IsObjectFSO(DownsysClass.Script_FSO) And CInt(DownsysClass.Setting(5)) = 0 ) Then
			NC_Admin.Error_Msg ("<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)或你后台没有选择为html方式</font></b>")
			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>  <span id=txt3 name=txt3 style=""font-size:9pt"">0</span></td></tr>" & vbCrLf
		Response.Write "</table>" & vbCrLf
		Response.Flush
		Set Rs1 = Server.CreateObject("adodb.recordset")
		SQL1 = "select * from [NC_softsort]"
		Rs1.Open SQL1, Conn, 1, 1
		total = Rs1.recordcount
		Rs1.MoveFiRst
		sortid =Rs1(0)
		K = 1
		Set Rs = Server.CreateObject("adodb.recordset")
		Do While Not Rs1.EOF
			SQL = "select sortid,sortname,rootid,depth,ParentID,strParent,Child,SoftNum from [NC_softsort] where sortid = " & sortid & ""
			Rs.Open SQL, Conn, 1, 1
			If Rs.bof And Rs.EOF Then
				Response.Write "Sorry！没有找到任何软件信息。或者您选择了错误的系统参数!"
				'Response.End
			Else
				SortName = Rs("sortname")
				sortid = Rs("sortid")
				rootid = Rs("rootid")
				depth = Rs("depth")
				ParentID = Rs("ParentID")
				strParent = Rs("strParent")
				Child = Rs("Child")
				TotalNumber = Rs("SoftNum")
			End If
			Rs.Close
		'###################################################
		TotalPageNum = CInt(TotalNumber / maxperpage)  '得到总页数
		If TotalPageNum < TotalNumber / maxperpage Then TotalPageNum = TotalPageNum + 1
		CurrentPage = 1
		'#####################################################################
		order_name = "SoftTime"
		strOrder = "Indate"
		Do
		If Len(sortid) = 0 Then
			NowStats = SortName
		Else
			NowStats = NowStation(sortid, SortName, ParentID, strParent)
		End If
		HtmlTitle = SortName
		If Len(DownsysClass.temphtml(0)) < 50 Then
			TempTopStr = DownsysClass.mainhtml(0) & DownsysClass.mainhtml(1) & DownsysClass.mainhtml(2) & DownsysClass.mainhtml(3)
		Else
			TempTopStr = DownsysClass.temphtml(0)
		End If
		If Len(DownsysClass.temphtml(4)) = 0 Then
			TempFootStr = DownsysClass.mainhtml(4)
		Else
			TempFootStr = DownsysClass.temphtml(4)
		End If
		Style_CSS = Replace(Replace(DownsysClass.Style_CSS, "{$SetupDir}", DownsysClass.SetupDir), "{$PicUrl}", DownsysClass.TempDir)
		temphtml = TempTopStr & DownsysClass.temphtml(1) & DownsysClass.temphtml(2) & DownsysClass.temphtml(3) & TempFootStr
		temphtml = Replace(temphtml, "{$NavMenu}", DownsysClass.SortingMenu)
		temphtml = Replace(temphtml, "{$Width}", DownsysClass.mainset(0))
		temphtml = Replace(temphtml, "{$Style_CSS}", Style_CSS)
		temphtml = Replace(temphtml, "{$TopMeun}", DownsysClass.mainset(9))
		temphtml = Replace(temphtml, "{$FootMeun}", DownsysClass.mainset(44))
		temphtml = Replace(temphtml, "{$NowStats}", NowStats)
		temphtml = Replace(temphtml, "{$Title}", HtmlTitle)
		temphtml = Replace(temphtml, "{$SortID}", sortid)
		temphtml = Replace(temphtml, "{$Sorting}", SoftSorting(sortid, ParentID, Child))
		temphtml = Replace(temphtml, "{$SortingList}", SoftSortingList(sortid, rootid, depth, SortName, order_name, maxperpage, CurrentPage, strOrder))
		temphtml = Replace(temphtml, "{$Adcolumn(0)}", DownloadClass_Ads.RunScriptAds(2))
		temphtml = Replace(temphtml, "{$Adcolumn(1)}", DownloadClass_Ads.BannerAds(2))
		temphtml = Replace(temphtml, "{$Adcolumn(2)}", DownloadClass_Ads.AdsColumn(2, 2))
		temphtml = Replace(temphtml, "{$Adcolumn(3)}", DownloadClass_Ads.AdsColumn(2, 3))
		temphtml = Replace(temphtml, "{$Adcolumn(6)}", DownloadClass_Ads.AdsColumn(2, 7))
		temphtml = Replace(temphtml, "{$Adcolumn(7)}", DownloadClass_Ads.AdsColumn(2, 8))
		temphtml = Replace(temphtml, "{$Adcolumn(4)}", DownloadClass_Ads.ScriptFloatAds(2))
		temphtml = Replace(temphtml, "{$Adcolumn(5)}", DownloadClass_Ads.ScriptFixedAds(2))

		NewFolderPath = Server.MapPath(DownsysClass.SetupDir & "Sorting/Catalog" & sortid)
		Set objFSO = Server.CreateObject(DownsysClass.Script_FSO)
		If Not objFSO.FolderExists(NewFolderPath) Then
			objFSO.CreateFolder (NewFolderPath)
		End If
		objFSO.Close
		Set objFSO = Nothing

		If CurrentPage < 1 Then
			CreateHtml = Server.MapPath(DownsysClass.SetupDir & "Sorting/Catalog" & sortid & "/Sorting_Indate_Desc_1.html")
		Else
			CreateHtml = Server.MapPath(DownsysClass.SetupDir & "Sorting/Catalog" & sortid & "/Sorting_Indate_Desc_" & CurrentPage & ".html")
		End If
		Set FSO = Server.CreateObject("ADODB.STREAM")
		With FSO
			.Open
			.Charset = "GB2312"
			.WriteText temphtml
			.SaveToFile CreateHtml,2
			.Close
		End With
		Set FSO = Nothing
		CurrentPage = CurrentPage + 1
		Loop While CurrentPage <= TotalPageNum

		Response.Write "<script>img2.width=" & Fix((K / total) * 400) & ";" & vbCrLf
		Response.Write "txt2.innerHTML=""生成进度:" & FormatNumber(K / total * 100, 4, -1) & """;" & vbCrLf
		Response.Write "txt3.innerHTML=""共有 <B><font color=RED>" & total & "</font></B> 个 正在生成第 " & K & " 个"";" & vbCrLf
		Response.Write "img2.title=""(" & K & ")"";</script>" & vbCrLf
		Response.Flush
		Rs1.movenext
		sortid  = Rs1(0)
		K = K + 1
		Loop
		Rs1.Close
		Set Rs1 = Nothing
		Response.Write "<script>img2.width=400;txt2.innerHTML=""100"";</script>"
		NC_Admin.Succeed_Msg ("生成软件列表页完成!")
		DownsysClass.admin_footer
	End Sub
	'*************************************************************
	'函数作用：软件列表
	'*************************************************************
	Private Function SoftSortingList(sortid, rootid, depth, SortName, order_name, maxperpage, CurrentPage, strOrder)
		Dim Rs, SQL, HtmlString, i, TopImg, isCommend, SoftImg
		Dim SoftName, SoftReadme, SoftTime, SoftSize
		Set Rs = Server.CreateObject("adodb.recordset")
		If Len(sortid) = 0 Then
			WhereSQL = "where isLock=0"
		Else
			If depth = 0 Then
				WhereSQL = "where isLock=0 and rootid = " & rootid & ""
			Else
				Dim Rss, AllSortID, ParentStr
				Set Rss = DownsysClass.Execute("select * from NC_SoftSort where strParent like '%"& sortid &"%'")
				If Rss.EOF And Rss.bof Then
					AllSortID = sortid
				Else
					Do While Not Rss.EOF
						ParentStr = Split(Rss("strParent"), ",")
						For i = 0 To UBound(ParentStr)
							If CLng(ParentStr(i)) = sortid Then
								AllSortID = AllSortID & Rss("sortid") &","
								Exit For
							End If
						Next
						Rss.movenext
					Loop
					AllSortID = AllSortID & sortid
				End If
				Rss.Close
				Set Rss = Nothing
				WhereSQL = "where isLock=0 and sortid in (" & AllSortID & ")"
			End If
		End If
		TotalNumber = Conn.Execute("Select count(softid) from [NC_SoftInfo] "& WhereSQL &"")(0)
		TotalPageNum = CInt(TotalNumber / maxperpage)  '得到总页数
		If TotalPageNum < TotalNumber / maxperpage Then TotalPageNum = TotalPageNum + 1
		If CurrentPage < 1 Then CurrentPage = 1
		If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
		SQL = "select * from NC_SoftInfo "& WhereSQL &" order by isTop Desc, " & order_name & " Desc, softid Desc"
		Rs.Open SQL, Conn, 1
		HtmlString = DownsysClass.TempSet(8)
		HtmlString = Replace(HtmlString, "{$SortID}", sortid)
		If Rs.bof And Rs.EOF Then
			HtmlString = HtmlString & "<p align=center>还没有找到任何软件！</p>"
		Else
			If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
			i = 0
			Do While Not Rs.EOF And i < CInt(maxperpage)
				HtmlString = HtmlString & DownsysClass.TempSet(10)
				If CInt(Rs("isTop")) = 1 Then
					TopImg = "<img src='" & DownsysClass.SetupDir & "images/isTop.gif' align='absmiddle'>"
				Else
					TopImg = "<img src='" & DownsysClass.SetupDir & "images/arrow.gif' align='absmiddle'>"
				End If
				If CInt(Rs("isCommend")) = 0 Then
					isCommend = ""
				Else
					isCommend = "<img src='" & DownsysClass.SetupDir & "images/jing.gif' align='absmiddle'>"
				End If
				SoftName = "" & TopImg & " <A HREF='" & DownsysClass.SetupDir & "Software/Catalog" & Rs("sortid") &"/" & Rs("softid") & ".html'>" & Trim(Rs("softname")) & " " & Trim(Rs("softver")) & "</a> " & isCommend & ""
				If Rs("SoftTime") >= Date Then
					SoftTime = "<FONT color=red>" & FormatDateTime(Rs("SoftTime"), 2) & "</FONT >"
				Else
					SoftTime = FormatDateTime(Rs("SoftTime"), 2)
				End If
				If Rs("SoftSize") > 1024 Then
					SoftSize = Round(Rs("SoftSize") / 1024, 2) & " MB"
				Else
					SoftSize = Rs("SoftSize") & " KB"
				End If
				If Not IsNull(Trim(Rs("softimg"))) And Trim(Rs("softimg")) <> "" Then
				
					SoftImg = "<A HREF='" & DownsysClass.SetupDir & "Software/Catalog" & Rs("sortid") &"/" & Rs("softid") & ".html'><img src='" & Rs("softimg") & "' width='" & DownsysClass.mainset(41) & "' height='" & DownsysClass.mainset(42) & "' border='0'></a> "
				Else
					SoftImg = "<img src='" & DownsysClass.SetupDir & "images/NoPic.jpg' width='" & DownsysClass.mainset(41) & "' height='" & DownsysClass.mainset(42) & "' border=0>"
				End If
				SoftReadme = DownsysClass.CutString(Rs("content"), CInt(DownsysClass.TempSet(7)))
				HtmlString = Replace(HtmlString, "{$SoftName}", SoftName)
				HtmlString = Replace(HtmlString, "{$SoftReadme}", SoftReadme)
				HtmlString = Replace(HtmlString, "{$SoftTime}", SoftTime)
				HtmlString = Replace(HtmlString, "{$SoftSize}", SoftSize)
				HtmlString = Replace(HtmlString, "{$Hits}", Rs("Hits"))
				HtmlString = Replace(HtmlString, "{$RunSystem}", Rs("RunSystem"))
				HtmlString = Replace(HtmlString, "{$Impower}", Rs("impower"))
				HtmlString = Replace(HtmlString, "{$Grades}", Rs("Grades"))
				HtmlString = Replace(HtmlString, "{$SoftImg}", SoftImg)
				Rs.movenext
				i = i + 1
			Loop
		End If
		Rs.Close
		HtmlString = HtmlString & DownsysClass.TempSet(11)
		HtmlString = Replace(HtmlString, "{$ShowPage}", AspShowPage(SortName, maxperpage, CurrentPage, totalnumber))
		SoftSortingList = HtmlString
	End Function
	'*************************************************************
	'函数作用：Html分页
	'*************************************************************
	Private Function AspShowPage(SortName, maxperpage, CurrentPage, totalnumber)
		Dim n, HtmlString,ii
		If totalnumber Mod maxperpage = 0 Then
			n = totalnumber \ maxperpage
		Else
			n = totalnumber \ maxperpage + 1
		End If
		HtmlString = "<table cellspacing=1 width='100%' border=0><form method=Post onChange=""submit()""><tr><td align=center> " & vbCrLf
		HtmlString = HtmlString & "<font color='red'>" & SortName & "</font> "
		If CurrentPage < 2 Then
			HtmlString = HtmlString & "共有 <font COLOR=#FF0000><strong>" & totalnumber & "</strong></font> 个&nbsp;首 页&nbsp;上一页&nbsp;"
		Else
			HtmlString = HtmlString & "共有 <font COLOR=#FF0000><strong>" & totalnumber & "</strong></font> 个&nbsp;<a href=Sorting_Indate_Desc_1.html>首 页</a>&nbsp;"
			HtmlString = HtmlString & "<a href=Sorting_Indate_Desc_" & CurrentPage - 1 & ".html>上一页</a>&nbsp;"
		End If
		If n - CurrentPage < 1 Then
			HtmlString = HtmlString & "下一页&nbsp;尾 页" & vbCrLf
		Else
			HtmlString = HtmlString & "<a href=Sorting_Indate_Desc_" & (CurrentPage + 1) & ".html>下一页</a>"
			HtmlString = HtmlString & "&nbsp;<a href=Sorting_Indate_Desc_" & n & ".html>尾 页</a>" & vbCrLf
		End If
		HtmlString = HtmlString & "&nbsp;页次：<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
		HtmlString = HtmlString & "&nbsp;转到："
		HtmlString = HtmlString & "<select name='page' size='1' style=""font-size: 9pt"" onChange='javascript:window.open(this.options[this.selectedIndex].value,""_top"")'>" & vbCrLf
		For ii = 1 To n
		HtmlString = HtmlString & "&nbsp;<option value='Sorting_Indate_Desc_" & ii & ".html' "
		If CurrentPage = CInt(ii) Then
			HtmlString = HtmlString & "selected "
		End If
		HtmlString = HtmlString & ">第" & ii & "页</option>"
		Next
		HtmlString = HtmlString & "&nbsp;</select> " & vbCrLf
		HtmlString = HtmlString & "</td></tr></FORM></table>" & vbCrLf
		AspShowPage = HtmlString
	End Function
	'*************************************************************
	'函数作用：当前位置
	'*************************************************************
	Private Function NowStation(sortid, SortName, ParentID, strParent)
		Dim Rs, SQL, HtmlString
		Set Rs = Server.CreateObject("adodb.recordset")
		If ParentID <> 0 And Len(strParent) <> 0 Then
			SQL = "select sortid,sortname from [NC_SoftSort] where sortid in(" & strParent & ")"
			Rs.Open SQL, Conn, 1, 1
			If Not (Rs.EOF And Rs.bof) Then
				Do While Not Rs.EOF
					HtmlString = HtmlString & "<a href='" & DownsysClass.SetupDir & "Sorting/Catalog" & Rs(0) & "/Sorting_Indate_Desc_1.html'>" & Rs(1) & "</a>→"
					Rs.movenext
				Loop
			End If
			Rs.Close
			 Set Rs = Nothing
		End If
		HtmlString = HtmlString & "<a href='" & DownsysClass.SetupDir & "Sorting/Catalog" & sortid & "/Sorting_Indate_Desc_1.html'>" & SortName & "</a>"
		NowStation = HtmlString
	End Function
	'*************************************************************
	'函数作用：软件分类
	'*************************************************************
	Private Function SoftSorting(sortid, ParentID, Child)
		Dim Rs, SQL, HtmlString, SortName, SortingName
		Set Rs = Server.CreateObject("adodb.recordset")
		HtmlString = DownsysClass.TempSet(1)
		If sortid = "" Then
			SQL = "SELECT sortid,sortname,rootid,Child,SoftNum,Readme FROM NC_SoftSort where depth=0 order by rootid"
		Else
			If Child = 0 Then
				SQL = "SELECT sortid,sortname,rootid,Child,SoftNum,Readme FROM NC_SoftSort where Parentid=" & ParentID & " order by orders"
			Else
				SQL = "SELECT sortid,sortname,rootid,Child,SoftNum,Readme FROM NC_SoftSort where Parentid=" & sortid & " order by orders"
			End If
		End If
		Rs.Open SQL, Conn, 1, 1
		If Rs.EOF And Rs.bof Then
			HtmlString = HtmlString & "<p align=center>还没有任何分类！</p>"
		Else
			Do While Not Rs.EOF
				HtmlString = HtmlString & DownsysClass.TempSet(2)

				If CStr(Rs("sortid")) = CStr(sortid) Then
					SortingName = "<A href='" & DownsysClass.SetupDir & "Sorting/Catalog" & Rs("sortid") & "/Sorting_indate_Desc_1.html' class=ShowLink><B><FONT color=red>" & Rs("sortname") & "</font></B></a>"
					SortName = "<A href='" & DownsysClass.SetupDir & "Sorting/Catalog" & Rs("sortid") & "/Sorting_indate_Desc_1.html'' class=ShowLink><B><FONT color=red>" & Rs("sortname") & "</font></B></a>"
				Else
					SortingName = "<A href='" & DownsysClass.SetupDir & "Sorting/Catalog" & Rs("sortid") & "/Sorting_indate_Desc_1.html'  title='" & Rs("Readme") & "<BR>共有软件： " & Rs("softnum") & " 个'>" & Rs("sortname") & "</a>"
					SortName = "<A href='" & DownsysClass.SetupDir & "Sorting/Catalog" & Rs("sortid") & "/Sorting_indate_Desc_1.html'  title='" & Rs("Readme") & "<BR>共有软件： " & Rs("softnum") & " 个'>" & Rs("sortname") & "</a>"
				End If
				HtmlString = Replace(HtmlString, "{$SortName}", SortName)
				HtmlString = Replace(HtmlString, "{$SoftNum}", Rs("SoftNum"))
				Rs.movenext
			Loop
		End If
		HtmlString = HtmlString & DownsysClass.TempSet(3)
		Rs.Close
		 Set Rs = Nothing
		SoftSorting = HtmlString
	End Function

End Class
%>