<!-- #include file="conn.asp" -->
<!-- #include file="cls_main.asp" -->
<!-- #include file="cls_Mesky_showPage.asp" -->
<% dim obj
set obj = New comment_down
	obj.AspInit()
set obj = nothing

Class comment_down
	
	Private ID, arrPage, arrMainPage, sRs, Mesky
	Private Sub Class_Initialize()
		Set Mesky = New Cls_Main
	End Sub
	Private Sub Class_Terminate()
		ConnectionDatabase
		Set Mesky = Nothing
	End Sub
	Public Sub AspInit()
		If Trim(Request("ID")) = "" Then
			 Response.End
		End If
		ID = CLng(Request("ID"))
	
		Call Mesky.LoadSetting
		
		Set sRs = Mesky.Execute("select id,resName,resVer,Grade,commentNum from Mesky_Down_Resource where ID=" & ID)
		If Not (sRs.EOF And sRs.BOF) Then
			arrPage = Split(Mesky.ReadStylePage("Style_Down_Comment"), "<!--|||-->")
			arrMainPage = Split(Mesky.ReadStylePage("Style_Down_Main"), "<!--|||-->")
			Response.Write (Replace(arrMainPage(0), "{$page_title}", "发表评论"))
			Response.Write (arrMainPage(1))
			Response.Write (arrMainPage(2))
			Response.Write (Replace(Replace(Replace(arrPage(0), "{$softname}", sRs(1)), "{$softver}", sRs(2)), "{$softurl}", Replace(Mesky.Setting(77), "{$id}", ID)))
			If Trim(Request.Form("content")) <> "" Then
				Call save_comment
			Else
				Call show_comment
			End If
			Response.Write (arrMainPage(5))
		End If
		Set sRs = Nothing
	
	End Sub
	Private Sub show_comment()
		Dim Rs, showPageRs, sql, i, sColumn, currentPage, s
		sColumn = "ID,Content,UserName,Email,dateandtime,Graded,IP"
		If Trim(Request.QueryString("Page")) = "" Then
			currentPage = 1
		Else
			currentPage = Trim(Request.QueryString("Page"))
		End If
		Set showPageRs = New cls_Mesky_showPage
		With showPageRs
			'.Conn=ConnStr      '得到数据库连接对象
			If IsSqlDataBase = 1 Then
			.DbType = "MSSQL_SP"
			Else
			.DbType = "AC"
			End If
			'数据库类型,AC为access,MSSQL为sqlserver2000,MSSQL_SP为存储过程版,MYSQL为mysql,PGSQL为PostgreSql
			.RecType = 0
			'取记录总数方法(0执行count,1自写sql语句取,2固定值)
			.RecSql = 0
			'如果RecType＝1则=取记录sql语句，如果是2=数值，等于0=""
			.RecTerm = 1
			'取从记录条件是否有变化(0无变化,1有变化,2不设置cookies也就是及时统计，适用于搜索时候)
			.CookieName = "comment_down" & ID '如果RecTerm＝2,cookiesname="",否则写cookiesname
			.Order = 1              '排序(0顺序1降序),注意要和下面sql里面主键ID的排序对应
			.PageSize = Int(Mesky.Setting(83))  '每页记录条数
			.currentPage = currentPage
			.sql = sColumn & "$Mesky_Down_Comment$ResourceID=" & ID & "$ID Desc$ID" '字段,表,条件(不需要where),排序(不需要需要ORDER BY),主键ID
		End With
		
		Dim iRecCount, sqlRs, no
		iRecCount = showPageRs.RecCount '记录总数
		If iRecCount > 0 Then
			If currentPage = 1 Then
				no = iRecCount
			Else
				no = iRecCount - (currentPage - 1) * Int(Mesky.Setting(83))
			End If
			Response.Write (Replace(arrPage(1), "{$showpage}", showPageRs.showPage("?Page={$pages}&ID=" & ID)))
			If iRecCount < 1 Then
				Response.Write (arrPage(2))
			Else
				Rs = showPageRs.ResultSet   '返回ResultSet
				For i = 0 To UBound(Rs, 2)
				s = arrPage(3)
				s = Replace(s, "{$dateandtime}", Rs(4, i))
				s = Replace(s, "{$softurl}", Replace(Mesky.Setting(77), "{$id}", ID))
				s = Replace(s, "{$username}", Rs(2, i))
				s = Replace(s, "{$retopic}", sRs("resName") & " " & sRs("resVer"))
				s = Replace(s, "{$ip}", Rs(6, i))
				s = Replace(s, "{$content}", Mesky.HTMLEncode1(Rs(1, i)))
				s = Replace(s, "{$no}", "第 <font color=red><b>" & no & "</font></b> 楼 [<A " & _
					"onclick=""comment.style.display=''; comment.content.focus(); comment.content.value='回复 " & no & " 楼(" & Rs(2, i) & ")：'; return false;"" href=""javascript:""><FONT color=#3366cc>回复</FONT></A>]<a name=""commentID" & Rs(0, i) & """></a>")
				Response.Write (s)
				s = Null
				no = no - 1
				Next
				Rs = Null
			End If
		End If
			Response.Write (Replace(Replace(arrPage(4), "{$showpage}", showPageRs.showPage("?Page={$pages}&ID=" & ID)), "{$id}", ID))
		showPageRs = Null
		Set showPageRs = Nothing
		
	End Sub
	Private Sub save_comment()
		Dim isSend, Grade, commentNum, makehtml
		If Trim(Request.Form("SendMaster")) = "yes" Then
			isSend = 1
		Else
			isSend = 0
		End If
		If Trim(Request.Form("username")) <> "" And Trim(Request.Form("content")) <> "" Then
			dim tRs,topic
			tRs = Mesky.Execute("select ResName,ResVer From Mesky_Down_Resource where ID = "&Clng(Request.Form("ID")))
			topic = tRs(0) & " " & tRs(1)
			Set tRs = Nothing
			Mesky.Execute ("INSERT INTO Mesky_Down_Comment(ResourceID, ReTopic, Content, UserName, Email, IP, DateAndTime, Graded,SendMaster, Reply, ReDateAndTime, isRead)VALUES (" & Trim(Request.Form("id")) & ",'" & topic & "','" & Trim(Request.Form("content")) & "','" & Trim(Request.Form("username")) & "','" & Trim(Request.Form("email")) & "','" & Mesky.UserTrueIP & "'," & SqlNowString & "," & Trim(Request.Form("Grade")) & "," & isSend & ",''," & SqlNowString & ",0)")
			Mesky.strMsg = "发表评论操作完成！"
			commentNum = Mesky.Execute("select Count(*) from Mesky_Down_Comment where ResourceID=" & ID)(0)
			If commentNum > 0 Then
				Grade = (sRs(3) + CLng(Request.Form("Grade"))) \ 2
			Else
				Grade = CLng(Request.Form("Grade"))
			End If
			Mesky.Execute ("Update Mesky_Down_Resource set Grade=" & Grade & ",commentNum=" & commentNum & " where id=" & ID)
			
		Else
			Mesky.strMsg = "发表评论操作出现错误，请将项目填写完整！"
		End If
		Call Mesky.SystemMsg
		'Response.Wrtie "<li>" & Mesky.strMsg
	End Sub
	

End Class %>