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

Class admin_News

	Private isEdit, y, Mesky
	Private Sub Class_Initialize()
		Set Mesky = New Cls_Main
	End Sub
	Private Sub Class_Terminate()
		Set Mesky = Nothing
	End Sub
	Public Sub AspInit()
		Response.Write "<HTML>" & vbCrLf
		Response.Write "<HEAD>" & vbCrLf
		Response.Write "<TITLE>公告管理</TITLE>" & vbCrLf
		Response.Write "<META http-equiv=Content-Type content=""text/html; charset=gb2312"">" & vbCrLf
		Response.Write "<LINK href=""admin.css"" type=text/css rel=stylesheet>" & vbCrLf
		Response.Write "</HEAD>" & vbCrLf
		Response.Write "<BODY leftmargin=""1"" topmargin=""1"">" & vbCrLf
		isEdit = False
			If Mesky.adminName = "" Then
				Mesky.strMsg = "<li>非法操作：登录超时或你没有以管理员身份登录系统，<a href=""../admin_login.asp"" target=_top>点此进入管理员登录界面</a>。"
				Call Mesky.SystemMsg
			Else
				Call Main
			End If
		Response.Write "</BODY>" & vbCrLf
		Response.Write "</HTML>" & vbCrLf
	
	End Sub

	Private Sub Main()
		Response.Write "<table width=""100%""  border=""0"" align=""center"" cellpadding=""3"" cellspacing=""1"">" & vbCrLf
		Response.Write "<tr>" & vbCrLf
		Response.Write "  <td class=""tdbg2""><STRONG>管理快捷方式：</STRONG> <a href=""?action=add"">添加公告</a> | <a href=""?action=index"">公告管理</a></td>" & vbCrLf
		Response.Write "</tr>" & vbCrLf
		Response.Write "</table>" & vbCrLf
	
		Select Case Request("action")
		Case "saveadd"
			Call SaveAdd
		Case "modify"
			Call SaveModify
		Case "edit"
			isEdit = True
			Call myform
		Case "add"
			isEdit = False
			Call myform
		Case "del"
			Call del
		Case Else
			Call showList
		End Select
	End Sub
	Private Sub SaveAdd()
		if Trim(Request.Form("Title"))="" then Exit Sub
		Dim sContent, i, Rs, sql
		If Not IsObject(Conn) Then ConnectionDatabase
		Set Rs = Server.CreateObject("adodb.recordset")
		sql = "select * from Mesky_News where (ID is null)"
		Rs.open sql, Conn, 1, 3
		Rs.AddNew
		Rs("Title") = Trim(Request.Form("Title"))
		For i = 1 To Request("content1").Count
			sContent = sContent & Request("content1")(i)
		Next
		Rs("Content") = sContent
		Rs("Hits") = 0
		Rs("UserName") = Mesky.adminName
		Rs("DateAndTime") = Now()
		Rs("isType") = Request.Form("isType")
		Rs.Update
		Rs.Close
		Set Rs = Nothing
		Mesky.strMsg = "<li>添加网站公告操作成功！<li><a href=?action=add>继续添加网站公告</a></li>"
		Call Mesky.SystemMsg
	End Sub
	Private Sub SaveModify()
		if Trim(Request.Form("Title"))="" then Exit Sub
		Dim sContent, i, Rs, sql
		If Not IsObject(Conn) Then ConnectionDatabase
		Set Rs = Server.CreateObject("adodb.recordset")
		sql = "select * from Mesky_News where ID=" & CLng(Request.Form("ID"))
		Rs.open sql, Conn, 1, 3
		Rs("Title") = Trim(Request.Form("Title"))
		For i = 1 To Request("content1").Count
			sContent = sContent & Request("content1")(i)
		Next
		Rs("Content") = sContent
		Rs("isType") = Request.Form("isType")
		Rs.Update
		Rs.Close
		Set Rs = Nothing
		Mesky.strMsg = "<li>修改网站公告操作成功！<li><a href=?action=add>继续添加网站公告</a></li>"
		Call Mesky.SystemMsg
	End Sub
	Private Sub del()
		Dim ID
		ID = Trim(Request("ID"))
		If ID <> "" Then
			Mesky.Execute ("delete from Mesky_News where ID = " & ID)
		End If
		Mesky.strMsg = "<li>删除网站公告操作成功！></li>"
		Call Mesky.SystemMsg
	End Sub
	Private Sub showList()
		Dim sColumn, showPageRs, strSQL, Rs, i, currentPage
		If Trim(Request.QueryString("Page")) = "" Then
			currentPage = 1
		Else
			currentPage = CLng(Request.QueryString("Page"))
		End If
		sColumn = "ID,Title,Hits,DateAndTime,UserName,isType"
	
		Set showPageRs = New cls_Mesky_showPage '创建对象
			If IsSqlDataBase = 1 Then
				showPageRs.DbType = "MSSQL_SP"
			Else
				showPageRs.DbType = "AC"
			End If
			'数据库类型,AC为access,MSSQL为sqlserver2000,MSSQL_SP为存储过程版,MYSQL为mysql,PGSQL为PostgreSql
			showPageRs.RecType = 0
			'取记录总数方法(0执行count,1自写sql语句取,2固定值)
			showPageRs.RecSql = 0
			'如果RecType＝1则=取记录sql语句，如果是2=数值，等于0=""
			showPageRs.RecTerm = 2
			'取从记录条件是否有变化(0无变化,1有变化,2不设置cookies也就是及时统计，适用于搜索时候)
			showPageRs.CookieName = "admin_News" '如果RecTerm＝2,cookiesname="",否则写cookiesname
			showPageRs.Order = 0              '排序(0顺序1降序),注意要和下面sql里面主键ID的排序对应
			showPageRs.PageSize = 30          '每页记录条数
			showPageRs.currentPage = currentPage
			showPageRs.sql = sColumn & "$Mesky_News$$ID$ID" '字段,表,条件(不需要where),排序(不需要需要ORDER BY),主键ID
		Dim iRecCount, sqlRs
		iRecCount = showPageRs.RecCount() '记录总数
		
		If iRecCount < 1 Then
			Response.Write "Sorry！没有找到任何记录。"
		Else
				'Response.Write "Test!"
				'Exit Sub
			'Set sqlRs = showPageRs.ResultSet()  '返回ResultSet
			Rs = showPageRs.ResultSet()
				Response.Write "<table width=""100%"" border=""0"" cellpadding=""3"" cellspacing=""1"">" & vbCrlf
				Response.Write "  <tr align=""center"" class=""tdbg2"">" & vbCrlf
				Response.Write "    <td width=""40"">ID</td>" & vbCrlf
				Response.Write "    <td>标题</td>" & vbCrlf
				Response.Write "    <td>人气</td>" & vbCrlf
				Response.Write "    <td>时间</td>" & vbCrlf
				Response.Write "    <td>管理员</td>" & vbCrlf
				Response.Write "    <td>类型</td>" & vbCrlf
				Response.Write "    <td>操作</td>" & vbCrlf
				Response.Write "  </tr>" & vbCrlf
			For i = 0 To UBound(Rs, 2)
				Response.Write "  <tr class=""tdbg3"">" & vbCrlf
				Response.Write "    <td width=""40"" align=""center"">" & Rs(0, i) & "</td>" & vbCrlf
				Response.Write "    <td>" & Rs(1, i) & "</td>" & vbCrlf
				Response.Write "    <td>" & Rs(2, i) & "</td>" & vbCrlf
				Response.Write "    <td align=""center"">" & Rs(3, i) & "</td>" & vbCrlf
				Response.Write "    <td align=""center"">" & Rs(4, i) & "</td>" & vbCrlf
				Response.Write "    <td align=""center"">"
				If Rs(5, i) = 1 then
					Response.Write "下载公告"
				Else
					Response.Write "文章站公告"
				End IF				
				Response.Write "</td>" & vbCrlf
				Response.Write "    <td align=""center""><a href=""?action=edit&id=" & Rs(0, i) & """>修改</a>　<a href=""?action=del&id=" & Rs(0, i) & """ onclick=""{if(confirm('执行此删除操作后该资源不能恢复，确定删除吗？')){return true;}return false;}"">删除</a></td>" & vbCrlf
				Response.Write "  </tr>" & vbCrlf
			Next
				Response.Write "</table>" & vbCrlf
			Rs = Null
			'Set sqlRs = Nothing
		End If
		If iRecCount > 0 Then
			Response.Write showPageRs.showPage("?Page={$pages}" & q)
		End If
	
		Set showPageRs = Nothing
		
	End Sub
	Sub myform()
		Response.Write "<table width=""100%""  border=""0"" cellspacing=""1"" cellpadding=""3"">" & vbCrLf
		Response.Write "<form name=""myform"" method=""post"" action=""admin_News.asp"">" & vbCrLf
		
		Response.Write "  <tr>" & vbCrLf
		Response.Write "    <td height=""19"" colspan=""2"" background=""../images/menubg.gif"" align=""center"">"
		If isEdit Then
			Set Rs = Mesky.Execute("select * from Mesky_News where ID=" & CLng(Request.QueryString("ID")))
			Response.Write ("修改网站公告")
			Response.Write ("<input type=""Hidden"" name=""action"" value=""modify"">")
			Response.Write ("<input type=""Hidden"" name=""ID"" value=""" & Trim(Request.QueryString("ID")) & """>")
		Else
			Response.Write ("添加网站公告")
			Response.Write ("<input type=""Hidden"" name=""action"" value=""saveadd"">")
		End If
		Response.Write "</td>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "  <tr class=""tdbg2"">" & vbCrLf
		Response.Write "    <td align=""right"">公告标题</td>" & vbCrLf
		Response.Write "    <td><input name=""Title"" type=""text"" id=""Title"" size=""40"" maxlength=""100"" value="""
		If isEdit Then Response.Write Rs("Title")
		Response.Write """></td>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "  <tr class=""tdbg3""> " & vbCrLf
		Response.Write "    <td align=""right"" valign=""top"">专题描述</td>" & vbCrLf
		Response.Write "    <td>"
		If isEdit Then
			Response.Write "<textarea name=""content1"" id=""content1"" style=""display:none"">" & Rs("Content") & "</textarea>" & vbCrLf
		Else
			Response.Write " <INPUT type=""hidden"" name=""content1"" value=""""> " & vbCrLf
		End If
		Response.Write "        <IFRAME ID=""eWebEditor1"" src=""../ewebeditor/ewebeditor.asp?id=content1&style=s_meskycn"" frameborder=""0"" scrolling=""no"" width=""600"" height=""350""></IFRAME> </td>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "  <tr class=""tdbg2"">" & vbCrLf
		Response.Write "    <td align=""right"">公告类型</td>" & vbCrLf
		Response.Write "    <td><input name=""isType"" type=""radio"" value=""1"" "
		If isEdit Then
			If Rs("isType") = 1 Then Response.Write ("checked")
		Else
			Response.Write ("checked")
		End If
		Response.Write ">" & vbCrLf
		Response.Write "下载公告" & vbCrLf
		Response.Write "      <input type=""radio"" name=""isType"" value=""2"""
		If isEdit Then
			If Rs("isType") = 2 Then Response.Write ("checked")
		End If
		Response.Write ">" & vbCrLf
		Response.Write "文章站公告</td>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "  <tr class=""tdbg2"">" & vbCrLf
		Response.Write "    <td>&nbsp;</td>" & vbCrLf
		Response.Write "    <td><input type=""submit"" name=""Submit"" value=""提交"">" & vbCrLf
		Response.Write "      <input type=""reset"" name=""Submit"" value=""重置""></td>" & vbCrLf
		Response.Write "  </tr>" & vbCrLf
		Response.Write "</form>" & vbCrLf
		Response.Write "</table>" & vbCrLf
	
		If isEdit Then Set Rs = Nothing
	End Sub
	
	Public Sub OnEndPage()
		Response.Write Mesky.CopyRight
	End Sub ' OnEndPage

End Class %>