asp非常代码结构
在离开学校后不久,我就获取了Ex123.net的blog代码,在这我非常的感谢ex123.net的主人,这段代码改变了我很多,哪怕是今天,
我还不得不经常地学习它,我将它公布在我的blog上,希望易心老师不要生气,如果不妥,可以留言给我。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="Admin_Style.css">
<title>无标题文档</title>
<script language="JavaScript">
//用户自定义函数---检测表单填写
function Checkpostdata()
{
if(document.all.title.value=="")
{alert("标题不能为空");
document.all.Submit.disabled=false;
document.all.Submit2.disabled=false;
return false;
}
if(document.all.Body.value=="")
{alert("内容不能为空");
document.all.Submit.disabled=false;
document.all.Submit2.disabled=false;
return false;
}
if(document.all.classx.value=="")
{alert("你没有选择分类");
document.all.Submit.disabled=false;
document.all.Submit2.disabled=false;
return false;
}
return true;
}
</script>
</head>
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0" class="bgcolor" >
<%dim action
action=request.QueryString("action")
select case action
case "addform"
call addform()
case "add"
call add()
case "changeform"
call changeform()
case "change"
call change()
case "show"
call show()
case "search"
call search()
case "del"
call del()
Case "delmore"
Call delmore()
end select%>
<%sub addform()%>
<form action="log.asp?action=add" method="post" name="Dvform" οnsubmit="JavaScript:WBTB_CopyData('Body');return Checkpostdata();">
<input type="hidden" name="Body" id="Body" value=""><!--编辑器初始值的设置-->
<table width="98%" border="0" align=center cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<tr>
<th colspan="11" class="topbg">日志发表</th>
</tr>
<tr>
<td class="tdbg" width="14%" ><div align="center">日志标题:<font color="red">*</font></div></td>
<td class="tdbg" colspan="10"><input name="title" type="text" id="title">
最多不应超过50字</td>
</tr>
<tr>
<td class="tdbg"><div align="center">日志分类:<font color="red">*</font></div></td>
<td class="tdbg" colspan="10">
<select name="classx" id="classx">
<option value="">选择分类</option>
<%dim strsql,rs
strsql="select * from class"
set rs=db.execute(strsql)
do while not rs.eof%>
<option value="<%=rs("id")%>"><%=rs("classx")%></option>
<%rs.movenext
loop
set rs=nothing%>
</select>
</td>
</tr>
<tr>
<td class="tdbg"><div align="center">日志标签:</div></td>
<td class="tdbg" colspan="10"><input name="tags" type="text" id="tags" size="30">
标签之间用空格分开</td>
</tr>
<tr>
<td class="tdbg"><div align="center">上传文件:</div></td>
<td class="tdbg" colspan="10"><div><iframe src="upload_form.asp" width="100%" height="80" align="left" id="upload" name="upload" scrolling="no" frameborder="0">
</iframe>
</div></td>
</tr>
<tr>
<td class="tdbg"><div align="center">编辑器:<font color="red">*</font></div></td>
<td class="tdbg" colspan="10"><!--#include file="htmedit.asp"--></td>
</tr>
<tr>
<td class="tdbg" height="26"><div align="center">高级选项:</div></td>
<td class="tdbg" width="7%">隐藏</td>
<td class="tdbg" width="5%"><input name="ishide" type="checkbox" id="ishide" value="true"></td>
<td class="tdbg" width="6%">置定</td>
<td class="tdbg" width="4%"><input name="istop" type="checkbox" id="istop2" value="true"></td>
<td class="tdbg" width="10%">允许回复</td>
<td class="tdbg" width="5%"><input name="iscmt" type="checkbox" id="iscmt" value="true" checked></td>
<td class="tdbg" width="10%">原创声明</td>
<td class="tdbg" width="5%"><input name="copyright" type="checkbox" id="copyright" value="true" checked></td>
<td class="tdbg" width="12%">日志密码:</td>
<td class="tdbg"><input name="logpass" type="text" id="logpass" size="10"></td>
</tr>
<tr>
<td class="tdbg"><div align="center">日志心情:</div></td>
<td class="tdbg" colspan="10"><input name="radiobutton" type="radio" value="" checked>
无
<input type="radio" name="emotion" value="1">
<img src="images/emotion/em01.gif" width="19" height="19">
<input type="radio" name="emotion" value="2">
<img src="images/emotion/em02.gif" width="19" height="19">
<input type="radio" name="emotion" value="3">
<img src="images/emotion/em03.gif" width="19" height="19">
<input type="radio" name="emotion" value="4">
<img src="images/emotion/em04.gif" width="19" height="19">
<input type="radio" name="remotion" value="5">
<img src="images/emotion/em05.gif" width="19" height="19">
<input type="radio" name="emotion" value="6">
<img src="images/emotion/em06.gif" width="19" height="19">
<input type="radio" name="emotion" value="7">
<img src="images/emotion/em07.gif" width="19" height="19">
<input type="radio" name="emotion" value="8">
<img src="images/emotion/em08.gif" width="19" height="19">
<input type="radio" name="emotion" value="9">
<img src="images/emotion/em09.gif" width="19" height="19"></td></tr>
<tr>
<td class="tdbg"><div align="center">引用通告:</div></td>
<td class="tdbg" colspan="10"><textarea name="quote" cols="70" wrap="VIRTUAL" id="quote"></textarea></td>
</tr>
<tr>
<td class="tdbg"><div align="center">发布日期:</div></td>
<td class="tdbg" colspan="10">
<input type="hidden" name="submittime" id="submittime" value=<%=now()%>>
<select name="selecty" id="selecty">
<%
dim y
y=2005
while y<=2010
if year(now())=y then
response.Write "<option value="&y&" selected>"&y&"</option>"
else
response.Write "<option value="&y&">"&y&"</option>"
end if
y=y+1
wend
%>
</select>
年
<select name="selectm" id="selectm" >
<%
dim m
m=1
while m<=12
if month(now())=m then
response.Write "<option value="&m&" selected>"&m&"</option>"
else
response.Write "<option value="&m&">"&m&"</option>"
end if
m=m+1
wend
%>
</select>
月
<select name="selectd" id="selectd" >
<%
dim d,maxday
d=1
while d<=31
if day(now())=d then
response.Write "<option value="&d&" selected>"&d&"</option>"
else
response.Write "<option value="&d&">"&d&"</option>"
end if
d=d+1
wend
%>
</select>
日
</td>
</tr>
<tr>
<td class="tdbg"> </td>
<td class="tdbg" colspan="10"><div align="center">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="清除">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<%end sub%>
<%sub add()
dim title,tags,classx,content,ishide,istop,iscmt,logpass,emotion,quote,submittime,strsql,rs,log_postyear,log_postmonth,log_postday,copyright
title=server.htmlencode(request.Form("title"))
tags=server.htmlencode(request.Form("tags"))
classx=request.Form("classx")
content=request.Form("body")
ishide=request.Form("ishide")
istop=request.Form("istop")
iscmt=request.Form("iscmt")
logpass=request.Form("logpass")
emotion=request.Form("emotion")
quote=request.Form("quote")
copyright=request.Form("copyright")
submittime=request.Form("submittime")
log_postyear=request.Form("selecty")
log_postmonth=request.Form("selectm")
log_postday=request.Form("selectd")
strsql="select * from log"
set rs=server.CreateObject("adodb.recordset")
rs.open strsql,db,0,2
rs.addnew
rs("title")=title
rs("classid")=cint(classx)
rs("content")=content
rs("submittime")=submittime
rs("log_postyear")=log_postyear
rs("log_postmonth")=log_postmonth
rs("log_postday")=log_postday
if tags<>"" then
rs("tags")=tags
end if
if ishide<>"" then
rs("ishide")=ishide
end if
if copyright="" then
rs("copyright")=false
end if
if istop<>"" then
rs("istop")=istop
end if
if iscmt<>"" then
rs("iscmt")=iscmt
end if
if logpass<>"" then
rs("logpass")=logpass
end if
if emotion<>"" then
rs("emotion")=emotion
end if
if quote<>"" then
rs("quote")=quote
end if
rs.update
rs.close
set rs=Nothing
'引用开始
IF Quote<>Empty And Ishide="" Then
Dim TBlogID,TBlogTmp,tbCode,tbMessage
TBlogID=db.Execute("SELECT TOP 1 ID FROM log ORDER BY submittime DESC")(0)
If TBlogID>0 then
TBlogTmp=Split(Trackback(Quote, siteURL&"blogview.asp?ID="&tblogid,Title, CutStr(content,252),show_blogname,tags),"$$")
tbCode=TBlogTmp(0)
tbMessage=TBlogTmp(1)
If tbCode="0" Then
tbMessage="<br><font color=""red"">"&tbMessage&"</font>"
else
tbMessage="<br><font color=""blue"">"&tbMessage&"</font>"
End if
End If
End If
db.execute("update bloginfo set lognum=lognum+1")
response.Write("日志添加成功")
response.write(tbmessage)
end sub%>
<%sub changeform()
dim rss,sql,id
id=request.querystring("id")
sql="select * from log where id="&id
set rss=db.execute(sql)
%>
<form action="log.asp?action=change&id=<%=id%>" method="post" name="Dvform" οnsubmit="JavaScript:WBTB_CopyData('Body');return Checkpostdata();">
<input type="hidden" name="Body" id="Body" value="<%=server.htmlencode(rss("content"))%>"><!--编辑器初始值的设置-->
<table width="98%" border="0" align=center cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<tr>
<th class="topbg" colspan="11">日志修改</th>
</tr>
<tr>
<td class="tdbg" width="14%"><div align="center">日志标题:<font color="red">*</font></div></td>
<td class="tdbg" colspan="10"><input name="title" type="text" id="title" value="<%=rss("title")%>">
最多不应超过50字</td>
</tr>
<tr>
<td class="tdbg"><div align="center">日志分类:<font color="red">*</font></div></td>
<td class="tdbg" colspan="10">
<select name="classx" id="classx">
<option value="">选择分类</option>
<%dim strsql,rs
strsql="select * from class"
set rs=db.execute(strsql)
do while not rs.eof
if rs("id")=rss("classid") then
%>
<option value="<%=rss("classid")%>" selected><%=rs("classx")%></option>
<%else%>
<option value="<%=rss("classid")%>"><%=rs("classx")%></option>
<%End if
rs.movenext
loop
set rs=nothing%>
</select>
</td>
</tr>
<tr>
<td class="tdbg"><div align="center">日志标签:</div></td>
<td class="tdbg" colspan="10"><input name="tags" type="text" id="tags" size="30" value="<%=rss("tags")%>">
标签之间用空格分开</td>
</tr>
<tr>
<td class="tdbg"><div align="center">上传文件:</div></td>
<td class="tdbg" colspan="10"><div><iframe src="upload_form.asp" width="100%" height="80" align="left" id="upload" name="upload" scrolling="no" frameborder="0">
</iframe>
</div></td>
</tr>
<tr>
<td class="tdbg"><div align="center">编辑器:<font color="red">*</font></div></td>
<td class="tdbg" colspan="10"><!--#include file="htmedit.asp"--></td>
</tr>
<tr>
<td class="tdbg" height="26"><div align="center">高级选项:</div></td>
<td class="tdbg" width="7%">隐藏</td>
<td class="tdbg" width="5%"><input name="ishide" type="checkbox" id="ishide" value="true"<%if rss("ishide")=true then%>checked<%end if%>></td>
<td class="tdbg" width="6%">置定</td>
<td class="tdbg" width="4%"><input name="istop" type="checkbox" id="istop2" value="true" <%if rss("istop")=true then%>checked<%end if%>></td>
<td class="tdbg" width="10%">允许回复</td>
<td class="tdbg" width="5%"><input name="iscmt" type="checkbox" id="iscmt" value="true" <%if rss("iscmt")=true then%>checked<%end if%>></td>
<td class="tdbg" width="10%">原创声明</td>
<td class="tdbg" width="5%"><input name="copyright" type="checkbox" id="copywright" value="true" <%if rss("copyright")=true then%>checked<%end if%>></td>
<td class="tdbg" width="12%">日志密码:</td>
<td class="tdbg"><input name="logpass" type="text" id="logpass" size="10" value="<%=rss("logpass")%>"></td>
</tr>
<tr>
<td class="tdbg"><div align="center">日志心情:</div></td>
<td class="tdbg" colspan="10">
<%dim i
if rss("emotion")=0 then%>
<input name="emotion" type="radio" value="0" checked> 无
<%else%>
<input name="emotion" type="radio" value="0"> 无
<%end if%>
<%for i=1 to 9
if rss("emotion")=i then%>
<input type="radio" name="emotion" value="<%=i%>" checked>
<img src="images/emotion/em0<%=i%>.gif" width="19" height="19">
<%else%>
<input type="radio" name="emotion" value="<%=i%>">
<img src="images/emotion/em0<%=i%>.gif" width="19" height="19">
<%end if
next%>
</td></tr>
<tr>
<td class="tdbg"><div align="center">引用通告:</div></td>
<td class="tdbg" colspan="10"><textarea name="quote" cols="70" wrap="VIRTUAL" id="quote"><%=rss("quote")%></textarea></td>
</tr>
<tr>
<td class="tdbg"><div align="center">发布日期:</div></td>
<td class="tdbg" colspan="10">
<input type="hidden" name="submittime" id="submittime" value=<%=now()%>>
<select name="selecty" id="selecty">
<%
dim y
y=2005
while y<=2010
if rss("log_postyear")=y then
response.Write "<option value="&y&" selected>"&y&"</option>"
else
response.Write "<option value="&y&">"&y&"</option>"
end if
y=y+1
wend
%>
</select>
年
<select name="selectm" id="selectm" >
<%
dim m
m=1
while m<=12
if rss("log_postmonth")=m then
response.Write "<option value="&m&" selected>"&m&"</option>"
else
response.Write "<option value="&m&">"&m&"</option>"
end if
m=m+1
wend
%>
</select>
月
<select name="selectd" id="selectd" >
<%
dim d,maxday
d=1
while d<=31
if rss("log_postday")=d then
response.Write "<option value="&d&" selected>"&d&"</option>"
else
response.Write "<option value="&d&">"&d&"</option>"
end if
d=d+1
wend
%>
</select>
日
</td>
</tr>
<tr>
<td class="tdbg"> </td>
<td class="tdbg" colspan="10"><div align="center">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="清除">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<%set rss=nothing
end sub%>
<%sub change()
dim title,tags,classx,content,ishide,istop,iscmt,logpass,emotion,quote,submittime,strsql,rs,id,log_postyear,log_postmonth,log_postday,copyright
id=request.querystring("id")
title=server.htmlencode(request.Form("title"))
tags=server.htmlencode(request.Form("tags"))
classx=request.Form("classx")
content=request.Form("body")
copyright=request.Form("copyright")
ishide=request.Form("ishide")
istop=request.Form("istop")
iscmt=request.Form("iscmt")
logpass=request.Form("logpass")
emotion=request.Form("emotion")
quote=request.Form("quote")
submittime=request.Form("submittime")
log_postyear=request.Form("selecty")
log_postmonth=request.Form("selectm")
log_postday=request.Form("selectd")
strsql="select * from log where id="&id
set rs=server.CreateObject("adodb.recordset")
rs.open strsql,db,0,2
rs("title")=title
rs("classid")=classx
rs("content")=content
rs("submittime")=submittime
rs("log_postyear")=log_postyear
rs("log_postmonth")=log_postmonth
rs("log_postday")=log_postday
if tags<>"" then
rs("tags")=tags
Else
rs("tags")=""
end if
if ishide<>"" then
rs("ishide")=ishide
Else
rs("ishide")=false
end if
if copyright<>"" then
rs("copyright")=copyright
Else
rs("copyright")=false
end if
if istop<>"" then
rs("istop")=istop
Else
rs("istop")=false
end if
if iscmt<>"" then
rs("iscmt")=iscmt
Else
rs("iscmt")=false
end if
if logpass<>"" then
rs("logpass")=logpass
Else
rs("logpass")=""
end if
if emotion<>"" then
rs("emotion")=emotion
Else
rs("emotion")=""
end if
if quote<>"" then
rs("quote")=quote
Else
rs("quote")=""
end if
rs.update
rs.close
set rs=nothing
response.Write("日志修改成功")
end sub%>
<%sub show()%>
<form name="form1" method="post" action="log.asp?action=search">
<table width="98%" border="0" align=center cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<tr>
<td class="tdbg" colspan="6" align="center">日志管理</td>
</tr>
<tr>
<td class="tdbg" width="10%">日志分类
<div align="center"></div></td>
<td class="tdbg" width="21%"><select name="classx" id="classx">
<option value="">选择分类</option>
<%dim strsql,rs
strsql="select * from class"
set rs=db.execute(strsql)
do while not rs.eof%>
<option value="<%=rs("id")%>"><%=rs("classx")%></option>
<%rs.movenext
loop
set rs=nothing%>
</select></td>
<td class="tdbg" width="13%">标题内容</td>
<td class="tdbg" width="24%"><select name="select2" size="1">
<option value="title">日志标题</option>
<option value="content">日志内容</option>
</select></td>
<td class="tdbg" width="24%"><input name="keyword" type="text" size="20"></td>
<td class="tdbg" width="8%"><input type="submit" name="Submit" value="提交"></td>
</tr><tr> <td class="tdbg" colspan="6">如果查找所有日志,请在关键字处留空</td></tr>
</table>
</form>
<%end sub%>
<%sub search()
dim select2,classx,keyword,rs,strsql,strsqla
select2=request("select2")
classx=request("classx")
keyword=request("keyword")
strsql="select class.classx,log.* from class,log"
strsqla="where"
if keyword<>""&classx<>"" then
if select2="title" then
strsqla=strsqla&" title like '%"&keyword&"%'"
else
strsqla=strsqla&" content like '%"&keyword&"%'"
end if
if classx<>"" then
strsqla=strsqla&" and classid="&classx
end if
end if
if keyword<>""&classx="" then
if select2="title" then
strsqla=strsqla&" title like '%"&keyword&"%'"
else
strsqla=strsqla&" content like '%"&keyword&"%'"
end if
end if
if strsqla<>"where" then
strsql=strsql&" "&strsqla&" and class.id=log.classid order by submittime desc"
end if
'response.write(strsql)
'strsql="select * from log where title like '%好%'"
set rs=server.createobject("adodb.recordset")
rs.open strsql,db,1,2
%>
<script language="JavaScript">
function CheckAll()
{
for (var i=0;i<document.manger.elements.length;i++)
{
var e = document.manger.elements[i];
if (e.Name != "allselect")
e.checked = document.all.allselect.checked;
}
}
</script>
<FORM METHOD=POST ACTION="log.asp?action=delmore" name="manger" id="manger">
<table width="98%" border="0" align=center cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">
<tr>
<td class="tdbg" colspan="7"><div align="center">总共搜索到<%=rs.recordcount%>条符合要求的记录</div></td>
</tr>
<tr>
<td class="tdbg" width="6%">选中</td>
<td class="tdbg" width="17%"><div align="center">分类</div></td>
<td class="tdbg" width="31%"><div align="center">标题</div></td>
<td class="tdbg" width="7%">点/评</td>
<td class="tdbg" width="16%"><div align="center">时间</div></td>
<td class="tdbg" colspan="2"><div align="center">操作</div></td>
</tr>
<%if not rs.eof and not rs.bof then
dim page_no
if request.querystring("page")="" then
page_no=1
else
page_no=cint(request.querystring("page"))
end if
rs.pagesize=15 '每页显示记录数
rs.absolutepage=page_no '当前第几页
dim i
i=rs.pagesize
do while not rs.eof and i>0
i=i-1
%>
<tr>
<td class="tdbg">
<div align="left">
<input type="checkbox" name="checkbox" value="<%=rs("id")%>">
</div></td>
<td class="tdbg"><%=rs("classx")%></td>
<td class="tdbg"><a href="blogview.asp?id=<%=rs("id")%>" target=_blank><%=rs("title")%></a></td>
<td class="tdbg"><%=rs("bits")%>/<%=rs("cmt")%></td>
<td class="tdbg"><%=rs("submittime")%></td>
<td class="tdbg" width="11%"><div align="center"><a href="log.asp?action=changeform&id=<%=rs("id")%>">修改</a></div></td>
<td class="tdbg" width="12%"><div align="center"><a href="log.asp?action=del&id=<%=rs("id")%>">删除</a></div></td>
</tr><tr>
<%rs.movenext
loop
%>
<td class="tdbg" colspan="7">共<%=rs.pagecount%>页 请选择:
<%'If keyword<>"" And classx<>"" then
'showpage "log.asp?action=search&select2="&select2&"&classx="&classx&"&keyword="&keyword,rs.recordcount,15,true,false,"条",page_no
'End if
'If keyword="" And classx<>"" then
'showpage "log.asp?action=search&select2="&select2&"&classx="&classx,rs.recordcount,15,true,false,"条",page_no
'End If
' If keyword="" And classx="" Then
'showpage "log.asp?action=search",rs.recordcount,15,true,false,"条",page_no
'End if
If keyword<>"" And classx<>"" Then
showpage "log.asp?action=search&select2="&select2&"&classx="&classx&"&keyword="&keyword,rs.recordcount,15,true,false,"条",page_no
End If
If keyword<>"" And classx="" Then
showpage "log.asp?action=search&select2="&select2&"&keyword="&keyword,rs.recordcount,15,true,false,"条",page_no
End If
If keyword="" And classx<>"" Then
showpage "log.asp?action=search&classx="&classx,rs.recordcount,15,true,false,"条",page_no
End If
If keyword="" And classx="" Then
showpage "log.asp?action=search",rs.recordcount,15,true,false,"条",page_no
End if
end if
%></td></tr>
<tr>
<td class="tdbg"><input type="checkbox" name="allselect" value="allselect" οnclick="JavaScript:CheckAll()"></td>
<td class="tdbg">全选</td>
<td class="tdbg"><INPUT TYPE="radio" NAME="delmore" value="delmore">删除<INPUT TYPE="radio" NAME="delmore" value="moveto">移动到<SELECT NAME="classx">
<%Dim classRs,classSql
classSql="select * from class"
Set classRs=db.execute(classSql)
Do While Not classRs.eof
%>
<option value=<%=classRs("id")%>><%=classRs("classx")%></option>
<%classRs.movenext
loop%>
</SELECT>
</td>
<td class="tdbg"><INPUT TYPE="submit" value="操作"></td>
<td class="tdbg"> </td>
<td class="tdbg" colspan="2"> </td>
</tr>
<tr>
<td class="tdbg"> </td>
<td class="tdbg"> </td>
<td class="tdbg"> </td>
<td class="tdbg"> </td>
<td class="tdbg"> </td>
<td class="tdbg" colspan="2"> </td>
</tr>
</table>
</FORM>
<%end sub%>
<%sub del()
dim id,strsql
id=request.querystring("id")
strsql="delete from log where id="&id
db.execute(strsql)
response.write("删除成功")
end Sub
Sub delmore()
If request.Form("delmore")="delmore" then
Dim arrid,strid,i,strsql
strid=request.Form("checkbox")
arrid=Split(strid,",")
for i=0 to ubound(arrid)
strsql="delete from log where id="&CInt(Trim(arrid(i)))
db.execute(strsql)
'response.write(arrid(i))
'response.write(strsql)
Next
response.write("删除成功")
End If
If request.Form("delmore")="moveto" Then
Dim logid,moveSql,m,classid
classid=request.Form("classx")
logid=request.Form("checkbox")
logid=Split(logid,",")
For m=0 To UBound(logid)
moveSql="update log set classid="&classid&" where id="&logid(m)
db.execute(moveSql)
Next
response.write("移动成功!")
End if
End sub
%>