日期:2011-01-25  浏览次数:20938 次

一个功能完善的专栏管理的程序->这是asp.net的第二个应用(五)
/*
豆腐制作,都是精品
http://www.asp888.net 豆腐技术站
如转载,请保留完整版权信息
*/
好了,截止到这里,我们基本上可以说是 公德圆满了!大家可以休息休息了,我们在本章中所讲的内容就是做一个 专栏管理的 首页,首页应该包括 所有的栏目类别,最近的10篇文章和最热门的10篇文章我们现在来看看这个本来第一个写的aspx文件:default.aspx
<!--#include file="func.aspx"-->
<script language=vb runat=server>
sub WriteLanmuClass()
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim sRead as SQLDataReader
strSQL="select * from lanmuclass"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.open()
sqlCmd.execute(sRead)
dim i as integer
response.write("<table border=1 width=100%><tr><td>")
while(sRead.Read())
response.write("<a href=showarticle.aspx?classid=" & sRead("classid") & ">" & sRead("classname") & "</a>(<font color=red>" & GetClassNum(cStr(sRead("classid"))) & "</font>)")
end while
response.write("</td></tr></table>")
end sub
function GetClassNum(strClassId as string) as string
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim numRead as SQLDataReader
strSQL="select count(*) as ccount from lanmu where classid='" & strClassId & "'"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.Open()
sqlCmd.Execute(numRead)
numRead.Read()
GetClassNum=numRead(0)
end function

sub WriteLastArticle()
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim sRead as SQLDataReader
strSQL="select top 10 * from lanmu,lanmuclass where lanmu.classid=lanmuclass.classid and lanmu.isuse='1' order by id desc"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.open()
sqlCmd.execute(sRead)
response.Write("<p><font color=gray>最近的文章</font></p>")
response.Write("<table border=0 width=100%>")
while(sRead.Read())
response.Write("<tr>")
response.Write("<td width=100% align=left>")
response.Write("[<a href='showarticle.asp?classid=" & sRead("classid") & "'>" & sRead("classname") & "</a>]")
response.Write("<a href='viewarticle.asp?id=" & sRead("id") & "' target='_blank'>" & sRead("title") & "</a><font color=gray size=1>" & sRead("dtime") & "</gray>")
response.Write("</td>")
response.Write("</tr>")
End While
response.Write("</table>")
end sub

sub WriteMostClick()
dim conn as SQLConnection
conn=getConn()
dim sqlCmd as SqlCommand
dim strSQL as string
dim sRead as SQLDataReader
strSQL="select top 10 * from lanmu,lanmuclass where lanmu.classid=lanmuclass.classid and lanmu.isuse='1' order by viewnum desc"
sqlCmd=new sqlCommand(strSQL,conn)
sqlCmd.ActiveConnection.open()
sqlCmd.execute(sRead)
response.Write("<p><font color=gray>最近的文章</font></p>")
response.Write("<table border=0 width=100%>")
while(sRead.Read())
response.Write("<tr>")
response.Write("<td width=100% align=left>")
response.Write("[<a href='showarticle.asp?classid=" & sRead("classid") & "'>" & sRead("classname") & "</a>]")
response.Write("<a href='viewarticle.asp?id=" & sRead("id") & "' target='_blank'>" & sRead("title") & "</a><font color=gray size=1>" & sRead("dtime") & "</gray>")
response.Write("</td>")
response.Write("</tr>")
End While
response.Write("</table>")
end sub
</script>
<html>
<head>
<title>豆腐技术站-->技术专栏</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Description" Content="探讨ASp,Php 编程,介绍Visual Basic ,Visual C++
等业界最新技术 并提供 免费的各种服务