白开心

  IT博客 :: 首页 ::  :: 联系 :: 聚合  :: 管理 ::
  9 随笔 :: 76 文章 :: 28 评论 :: 0 Trackbacks

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd "
>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻发布****文件生成版本</title>
<script language="javascript">
function checkdel(id){
 
if(!confirm("确认删除此新闻内容吗?"))
 
return(false);
 myform.txtid.value
=id;
 myform.txtcmd.value
="del";
 myform.submit();
}

function checkshow(str){
 myform.txtid.value
=str;
 myform.txtcmd.value
="show";
 myform.submit();
}

function checkedit(){
 
if(myform.txtTitle.value==""){
  alert(
"新闻标题不可以空!");
  myform.txtTitle.focus();
  
return(false);
 }

 
if(myform.txtPageSize.value==""){
  alert(
"请填写每页显示字符数!");
  myform.txtPageSize.focus();
  
return(false);
 }

 
if(isNaN(myform.txtPageSize.value)){
  alert(
"每页显示字符数请一定填写数字");
  myform.txtPageSize.focus();
  
return(false);
 }

 
if(myform.txtContent.value==""){
  alert(
"新闻内容不可以空!");
  myform.txtContent.focus();
  
return(false);
 }

 myform.txtcmd.value
="edit";
 myform.submit();
}

function checkadd(){
 
if(myform.txtTitle.value==""){
  alert(
"新闻标题不可以空!");
  myform.txtTitle.focus();
  
return(false);
 }

 
if(myform.txtPageSize.value==""){
  alert(
"请填写每页显示字符数!");
  myform.txtPageSize.focus();
  
return(false);
 }

 
if(isNaN(myform.txtPageSize.value)){
  alert(
"每页显示字符数请一定填写数字");
  myform.txtPageSize.focus();
  
return(false);
 }

 
if(myform.txtContent.value==""){
  alert(
"新闻内容不可以空!");
  myform.txtContent.focus();
  
return(false);
 }

 myform.txtcmd.value
="add";
 myform.submit();
}

function checkchangepage(){
 myform.txtcmd.value
="changepage";
 myform.submit();
}

function checkgo(page){
 myform.nextPage.value
=page;
 myform.txtcmd.value
="page";
 myform.submit();
}

function checkNum(){
 
if(isNaN(myform.txtPageSize.value)){
  alert(
"每页显示多少数据请填写数字");
  myform.txtPageSize.focus();
  
return(false);
 }

}

</script>
<style type="text/css">
<!--
body 
{
 font-size
: 12px;
}

-->
</style>
</head> 

<body>
<!-- #include file="config.asp" -->
<%
on error resume next 

Dim ShowTitle,ShowContent,ShowFlag
Dim cmd,rid,iPage
rKey
=trim(request("SelKey"))
rPage
=request("SelPage")
iPage
=request("currentPage")
nextPage
=request("nextPage")
totalPage
=request("totalPage")
cmd
=trim(request("txtcmd"))
rid
=trim(request("txtid"))
rTitle
=trim(request("txtTitle"))
rTitle
=replace(rTitle,"'","''")
rPageSize
=cint(request("txtPageSize"))
rSize
=cint(request("txtSize"))
if rSize=0 then rSize=18
if rPageSize="" then rPageSize=800
rFlag
=trim(request("txtFlag"))
rContent
=trim(request("txtContent"))
rContent
=replace(rContent,vbcrlf,"|"


Select Case cmd
 
Case "add"
  
call HtmlAdd
 
Case "show"
  
call ShowData
 
Case "edit"
  
call HtmlEdit
 
Case "del"
  
call deldata
 
Case "page"
  
call Page
 
Case "changepage"
  iPage
=cint(rPage) 
 
Case else
  iPage
=1
End Select 

Sub Page
iPage
=cint(iPage)+cint(nextPage)
if iPage>cint(totalPage) then iPage=cint(totalPage)
if iPage<1 then iPage=1
End Sub 

Sub ShowData
sql
="Select * from html where flag in (select flag from html where id="&rid&")"
rs.Open sql,cn,
1,3
ShowTitle
=trim(rs("title"))
ShowFlag
=trim(rs("flag"))   'flag是多个文件对应一个标题的唯一标志,这里写出方便修改时记住哪个文件
dim fs
set fs=server.CreateObject("scripting.filesystemobject")
For i=1 to rs.RecordCount
 
 filepath
=server.MapPath("HtmlFile/"&trim(rs("src"))&"")
 
set txt=fs.OpenTextFile(filepath)       '读取内容
  Content=txt.readline
  ShowContent
=ShowContent&mid(Content,instr(Content,"<!--ContentStart-->")+19,instr(Content,"<!--ContentEnd-->")-instr(Content,"<!--ContentStart-->")-19)
 txt.close
 rs.movenext
Next
set fs=nothing
rs.close
ShowContent
=replace(ShowContent,"<br>&nbsp;&nbsp;&nbsp;&nbsp;",vbcrlf)
End Sub 

Sub deldata
rs.Open 
"Select src from html where flag in(select flag from html where id="&rid&")",cn,1,3
if rs.RecordCount>0 then
 
set fs=server.CreateObject("scripting.filesystemobject")
  
for i=1 to rs.RecordCount
   FileName
=trim(rs("src"))
   
if fs.FileExists(server.mappath("HtmlFile"&"/"&FileName)) then
   fs.DeleteFile(server.mappath(
"HtmlFile"&"/"&FileName))
   
end if
  rs.movenext
  
next
 
set fs=nothing
end if
rs.close
sql
="delete from html where flag in(select flag from html where id="&rid&")"
cn.execute sql
End Sub 

Sub HtmlEdit  '此程序主要用来删除原有数据,再调用生成新文件
rs.Open "select src from html where flag='"&rFlag&"'",cn,1,3
if rs.RecordCount>0 then
 
set fs=server.CreateObject("scripting.filesystemobject")
  
for i=1 to rs.RecordCount
   FileName
=trim(rs("src"))
   
if fs.FileExists(server.mappath("HtmlFile"&"/"&FileName)) then
   fs.DeleteFile(server.mappath(
"HtmlFile"&"/"&FileName))
   
end if
  rs.movenext
  
next
 
set fs=nothing
end if
rs.close
sql
="delete from html where flag='"&rFlag&"'"
cn.execute sql
Call HtmlAdd
End Sub 

Sub HtmlAdd
'未使用模板生成HTML页面,有时间考虑修改过来
dim fs,files,filepath,Content 

if len(rContent)<rPageSize then   '这里得到页面数,当然也可以写成函数形式
rPageCount=1
else
iNum
=len(rContent)/rPageSize
 
if instr(iNum,".")="" then
 rPageCount
=iNum
 
else
 rPageCount
=(round(iNum,0)+1)
 
end if
end if 

dim varry()
HtmlName
=year(now())&month(now())&day(now())&hour(now())&minute(now())&second(now())   '取得文件名的主要部分 

redim varry(cint(rPageCount))
For i=0 to (rPageCount-1)   '首先自动生成所有的文件名,生成文件时用此处文件名,记录文件名相同的部分,便于编辑修改
 varry(i)=HtmlName&i&".shtml"
 Sql
="insert into html(src,title,AddDate,flag) values('"&varry(i)&"','"&rTitle&"','"&date()&"','"&HtmlName&"')"
 cn.execute Sql
Next 

set fs=server.CreateObject("scripting.filesystemobject")   '生成文件对象 

For i=0 to (rPageCount-1)
Content 
= ""
Content
=Content&"<script language=vbscript src=../Counter.Asp?Page="&varry(i)&"></script>" 
Content
=Content&"<!--#include file=top.shtml-->"
Content
=Content&"<table border=0 align=center cellpadding=0 cellspacing=0 width='70%'>"
Content
=Content&"<tr><td align=center><font size=3>"&replace(rTitle,"''","'")&"</font></td></tr>"
Content
=Content&"<tr><td height=3></td></tr>"
Content
=Content&"<tr><td align=center>发表日期:"&date()&",阅读次数:<!--ReadNum-->0<!--End ReadNum--><!--该页面中阅读次数,热点新闻按点击率,最新新闻考虑使用iframe--></td>"
Content
=Content&"<tr><td height=9></td></tr>"
Content
=Content&"<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;<!--ContentStart-->"&Replace(mid(rContent,(i*rPageSize+1),rPageSize),"|","<br>&nbsp;&nbsp;&nbsp;&nbsp;")&"<!--ContentEnd--></td></tr>" 

if rPageCount>1 then  '分页操作
Content=Content&"<tr><td height=10></td></tr>"
Content
=Content&"<tr><td align=right>"
Content
=Content&"当前"&i+1&"/"&rPageCount&"页&nbsp;&nbsp;"
 
if i>0 and i<rPageCount then
  Content
=Content&"<a href="&varry(0)&">[第一页]</a>&nbsp;"
  Content
=Content&"<a href="&varry(i-1)&">[上一页]</a>&nbsp;"
 
end if
 
if rPageCount>0 and i<(rPageCount-1then
  Content
=Content&"<a href="&varry(i+1)&">[下一页]</a>"
  Content
=Content&"<a href="&varry(rPageCount-1)&">[最末页]</a>"
 
end if
Content
=Content&"</td></tr>"
end if 

Content
=Content&"<tr><td height=15></td></tr>"
Content
=Content&"<tr><td align=center><a href='javascript:window.close();'>关闭窗口</a></td></tr>"
Content
=Content&"<!-- #include file=bot.shtml -->"
 
 filepath
=server.mappath("HtmlFile")&"/"&varry(i)                   '文件名及路径
 set files=fs.createtextfile(filepath,true)                         '创建文件
 files.writeline(Content)                                           '写入信息
 files.close
Next 

set fs=nothing
End Sub 

sql
="Select * from html where id in(select min(id) from html group by flag) and title like '%"&rKey&"%' order by id desc"
%>
<form action="HtmlList.asp" method="post" name="myform">
<table border="1" style="border-collapse:collapse" width="71%" align="center">
 
<tr>
  
<td width="26%" align="right">新闻标题:&nbsp;</td>
  
<td width="74%" align="left">&nbsp;<input type="text" name="txtTitle" size="50" maxlength="90" value="<%=ShowTitle%>"></td>
 
</tr>
 
<tr>
  
<td align="right">每页显示字符数:&nbsp;</td>
  
<td align="left">&nbsp;<input type="text" size="4" maxlength="5" name="txtPageSize" value="800"></td>
 
</tr>
 
<tr>
  
<td align="right">新闻标题:&nbsp;</td>
  
<td align="left">&nbsp;
    
<textarea name="txtContent" cols="70" rows="16"><%=ShowContent%></textarea></td>
 
</tr>
 
<tr><td align="center" colspan="2">
  
<%
  
if cmd="show" then
  
%>
  
<input type="button" name="submit1" value="修改" onClick="return checkedit();">
  
<%else%><input type="button" name="submit2" value="新增" onClick="return checkadd();">
  
<%
  
end if
  
%>&nbsp;&nbsp;
  
<input type="reset" name="reset1" value="重置">
 
</tr>
</table> 

<%
rs.Open sql,cn,
1,3
rs.PageSize
=int(rSize) 


response.Write 
"<table border=1 style='border-collapse:collapse' width='70%' align=center>"
response.Write 
"<tr><td align=right colspan=3>"
response.Write 
"搜索:<input type=text name=SelKey maxlength=90 size=15 value='"&rKey&"'>&nbsp;<input type=button value='搜索' onClick='myform.submit();'>"_
&"&nbsp;当前:"&iPage&"/"&rs.PageCount&"页&nbsp;&nbsp;每页<input type=text name=txtSize value='"&rSize&"' size=3 maxlength=4 onChange='checkNum();'>条&nbsp;&nbsp;"_
&"<a href='#' onClick=checkgo(-1);>上一页</a>&nbsp;||&nbsp;<a href='#' onClick=checkgo(1);>下一页</a>"_
&"&nbsp;&nbsp;转向<select name=SelPage onChange='checkchangepage();'>"
If rs.PageCount>0 then 

for PageNum=1 to rs.PageCount
response.Write 
"<option value="&PageNum&""
if trim(iPage)=trim(PageNum) then response.Write " selected"
response.Write 
">第"&PageNum&"页</option>"
Next
Else
response.Write 
"<option value=''>无分页</option>"
End if
response.Write 
"</td></tr>"
response.Write 
"<tr>"
response.Write 
"<td align=center>ID号</td>"
response.Write 
"<td align=center>文章标题</td>"
response.Write 
"<td align=center>相关操作</td>"
response.Write 
"</tr>"
 
if rs.RecordCount>0 then
 rs.absolutepage
=iPage
 
for i=1 to rs.PageSize
 
if rs.eof then exit for
  response.Write 
"<tr><td align=center>"&trim(rs("id"))
  response.Write 
"</td><td>"
   response.Write 
"<a href='HtmlFile/"&trim(rs("src"))&"' target='_blank'>"&trim(rs("title"))&"</a>&nbsp;"&rs("AddDate")
  response.Write 
"</td>"
  response.Write 
"<td align=center><a href='#' onClick='return checkdel("&trim(rs("id"))&");'>删除</a>&nbsp;&nbsp;"
  response.Write 
"<a href='#' onClick='return checkshow("&trim(rs("id"))&")'>修改</a>"
  response.Write 
"</td></tr>" 
 rs.movenext
 
next
 
end if
response.Write 
"</table>"
%>
<input type="hidden" name="currentPage" value="<%=iPage%>">
<input type="hidden" name="nextPage" value="">
<input type="hidden" name="totalPage" value="<%=rs.PageCount%>">
<input type="hidden" name="txtid" value="<%=rid%>">
<input type="hidden" name="txtFlag" value="<%=ShowFlag%>">
<input type="hidden" name="txtcmd" value="">
</form>
<%
rs.close
Call EndConnection
%>
</body>
</html>
posted on 2005-12-11 22:17 白开心 阅读(245) 评论(0)  编辑 收藏 引用 所属分类: Asp+vbScript
只有注册用户登录后才能发表评论。