用ASP、NET开发下载系统
用ASP、NET开发下载系统(三)
http://blog.csdn.net/lihonggen0/archive/2003/07/07/13640.aspx
前台界面部分
主界面
主界面是左上部分是一个TreeView控件,用来添加分类信息。
主界面是左下部分是一个List控件,用来显示下载信息排行榜。
主界面是右边部分是一个DataGrid控件,用来显示下载信息。
这是一个基本的界面,如果需要更多功能,请自行扩充!
步骤:新建一项目(选择asp.net应用程序),添加Web 引用, 重命名为DownWS
在窗体上添加DataGrid,用属性生成器设置其属性:列、分页、格式等,然后在代码中为DataGrid设置数据源,再绑定后,呈现上述样式。
再添加TreeView,List等控件。在程序中将数据添加到TreeView,详细代码请见下面:
注:
Internet Explorer WebControls不在VS.NET的标准Server Control中,到微软的站点下载:http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/Downloads/samples/Internet/ASP_DOT_NET_ServerControls/WebControls/default.asp 下载安装后第一次使用时,要右击工具箱Customize Toolbox…→.NET Framework Components中找到Micosoft.Web.UI.WebControls.Treeview后选中,这样Treeview控件就出现在工具箱中了。
downinfo.aspx.vb:
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Web.UI.WebControls
Public Class downInfo
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents TreeView1 As Microsoft.Web.UI.WebControls.TreeView
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
#Region ” Web 窗体设计器生成的代码 “
\’该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
\’ CODEGEN: 此方法调用是 Web 窗体设计器所必需的
\’不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Dim downDv As New DataView()
Dim strName As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
\’
strName = Request.QueryString(“strName”)
\’实例化一个DownWebService
Dim WS As New DownWS.DownWebService()
Dim dsTree As DataSet
\’得到所有的分类
dsTree = WS.GetDownClass
\’填充到树状结构中
TreeView1.Nodes.Clear()
Dim Row As DataRow
For Each Row In dsTree.Tables(0).Rows
Dim item As New TreeNode()
item.Text = Row.Item(“classname”).ToString
\’点击时的网址跳转
item.NavigateUrl = “downinfo.aspx?strname=” & Row.Item(“classname”).ToString
\’每个分支的图片
item.ImageUrl = ResolveUrl(Me.TemplateSourceDirectory & “\tree.jpg”)
TreeView1.Nodes.Add(item)
Next
\’得到所有下载信息,进行分类的过滤后,填充到DataGrid
downDv = WS.GetDownInfo().Tables(0).DefaultView
If strName <> “” Then
downDv.RowFilter = “classname=\'” & strName & “\'”
End If
DataGrid1.DataSource = downDv
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
\’得到当前的ID
Dim nID As Int32 = DataGrid1.SelectedItem.Cells(0).Text
\’得到URL
Dim strUrl As String = “downdetail.aspx?ID=” + nID.ToString()
\’打开一个窗口,没有工具栏,状态条
Response.Write(“<script language=\’javascript\’>open(\'” + strUrl + “\’,\’pop\’,\’directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=450,width=595\’);</script>”)
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
\’处理分页
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataSource = downDv
DataGrid1.DataBind()
End Sub
End Class
downinfo.aspx:
<%@ Register TagPrefix=”iewc” Namespace=”Microsoft.Web.UI.WebControls” Assembly=”Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ %>
<%@ Page Language=”vb” AutoEventWireup=”false” Codebehind=”downInfo.aspx.vb” Inherits=”WebApplication9.downInfo”%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<title>XX下载系统</title>
<meta content=”Microsoft Visual Studio .NET 7.0″ name=”GENERATOR”>
<meta content=”Visual Basic 7.0″ name=”CODE_LANGUAGE”>
<meta content=”JavaScript” name=”vs_defaultClientScript”>
<meta content=”http://schemas.microsoft.com/intellisense/ie5″ name=”vs_targetSchema”>
</HEAD>
<body MS_POSITIONING=”GridLayout”>
<form id=”Form1″ method=”post” runat=”server”>
<FONT face=”宋体“>
<DIV style=”Z-INDEX: 101; LEFT: 150px; WIDTH: 741px; POSITION: absolute; TOP: 82px; HEIGHT: 412px” ms_positioning=”FlowLayout”><FONT face=”宋体“><asp:datagrid id=”DataGrid1″ runat=”server” ForeColor=”Black” BackColor=”White” AllowPaging=”True” AutoGenerateColumns=”False” Height=”212px” Width=”739px” BorderColor=”#6876C5″ GridLines=”Vertical” PageSize=”20″>
<SelectedItemStyle ForeColor=”White” BackColor=”DeepSkyBlue”></SelectedItemStyle>
<AlternatingItemStyle BackColor=”#EEEEEE”></AlternatingItemStyle>
<HeaderStyle ForeColor=”White” BackColor=”#6876C5″></HeaderStyle>
<FooterStyle ForeColor=”White” BackColor=”#6876C5″></FooterStyle>
<Columns>
<asp:BoundColumn DataField=”id” HeaderText=”编号“>
<HeaderStyle Width=”80px”></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField=”classname” HeaderText=”分类名称“>
<HeaderStyle Width=”120px”></HeaderStyle>
</asp:BoundColumn>
<asp:HyperLinkColumn DataNavigateUrlFormatString=”webform2.aspx?ID={0}” DataTextField=”title” HeaderText=”标题” NavigateUrl=”filename”>
<HeaderStyle Width=”320px”></HeaderStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField=”uploadtime” HeaderText=”上传时间“>
<HeaderStyle Width=”180px”></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField=”totaldown” HeaderText=”下载次数“>
<HeaderStyle Width=”100px”></HeaderStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text=”下载” HeaderText=”下载” CommandName=”Select”>
<HeaderStyle Width=”60px”></HeaderStyle>
</asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign=”Center” ForeColor=”White” BackColor=”#6876C5″ Mode=”NumericPages”></PagerStyle>
</asp:datagrid></FONT></DIV>
<DIV style=”Z-INDEX: 103; LEFT: 19px; WIDTH: 131px; POSITION: absolute; TOP: 81px; HEIGHT: 497px” ms_positioning=”FlowLayout”><asp:label id=”Label2″ runat=”server” ForeColor=”White” BackColor=”#6876C5″ Width=”129px”>软件分类 </asp:label><iewc:treeview id=”TreeView1″ runat=”server”></iewc:treeview><asp:label id=”Label3″ runat=”server” ForeColor=”White” BackColor=”#6876C5″ Width=”129px”>下载排行</asp:label><asp:listbox id=”ListBox1″ runat=”server” Height=”191px” Width=”130px”></asp:listbox></DIV>
</form>
</FONT>
</body>
</HTML>
————————————————————————–
Author : lihonggen0
个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/
如需引用,请指明出处!软件的目的在于应用,本文可自由转载!
————————————————————————–
用ASP、NET开发下载系统(四)
前台界面部分
下载详细信息页面
下载信息页面其实就是一个Table,左边一列是固定了的,右边一列信息其实就是从数据库中取出当前行的信息,填充到label中。
downDetail.aspx.vb
Public Class downDetail
Inherits System.Web.UI.Page
Protected WithEvents Lbclassname As System.Web.UI.WebControls.Label
Protected WithEvents Lbtitle As System.Web.UI.WebControls.Label
Protected WithEvents lbuploadtime As System.Web.UI.WebControls.Label
Protected WithEvents lbtotaldown As System.Web.UI.WebControls.Label
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Protected WithEvents lbdescription As System.Web.UI.WebControls.Label
Dim downDs As DataSet
Dim WS As New DownWS.DownWebService()
Dim nID As Int32
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
\’得到当前的ID
nID = Request.QueryString(“id”)
\’将当前记录的数据传给几个label
downDs = WS.GetDownFromID(nID)
lbdescription.Text = downDs.Tables(0).Rows(0).Item(“description”).ToString
lbtotaldown.Text = downDs.Tables(0).Rows(0).Item(“totaldown”)
Lbclassname.Text = downDs.Tables(0).Rows(0).Item(“classname”)
lbuploadtime.Text = downDs.Tables(0).Rows(0).Item(“uploadtime”)
Lbtitle.Text = downDs.Tables(0).Rows(0).Item(“title”)
\’下载次数加1
WS.UpdateTotalDown(nID)
\’下载地址赋值
HyperLink1.NavigateUrl = ResolveUrl(downDs.Tables(0).Rows(0).Item(“filename”))
End Sub
Private Sub InitializeComponent()
End Sub
End Class
关于界面中Table的设置,请看
downDetail.aspx
<%@ Page Language=”vb” AutoEventWireup=”false” Codebehind=”downDetail.aspx.vb” Inherits=”WebApplication9.downDetail”%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<title>下载详细信息</title>
<meta content=”Microsoft Visual Studio .NET 7.0″ name=”GENERATOR”>
<meta content=”Visual Basic 7.0″ name=”CODE_LANGUAGE”>
<meta content=”JavaScript” name=”vs_defaultClientScript”>
<meta content=”http://schemas.microsoft.com/intellisense/ie5″ name=”vs_targetSchema”>
</HEAD>
<body MS_POSITIONING=”GridLayout”>
<form id=”Form1″ method=”post” runat=”server”>
<FONT face=”宋体“>
<DIV style=”Z-INDEX: 101; LEFT: 6px; WIDTH: 537px; POSITION: absolute; TOP: 2px; HEIGHT: 344px” ms_positioning=”FlowLayout”>
<table cellSpacing=”0″ cellPadding=”0″ width=”100%” bgColor=”#6876c5″ border=”0″>
<tr>
<td height=”25″><font color=”white”> 详细信息</font></td>
</tr>
</table>
<table style=”WIDTH: 537px; BORDER-COLLAPSE: collapse; HEIGHT: 359px” borderColor=”#a0abeb” cellSpacing=”0″ cellPadding=”2″ width=”537″ bgColor=”#6876c5″ border=”1″>
<TR bgColor=”#eeeeee”>
<TD style=”WIDTH: 235px; HEIGHT: 28px”>软件分类:</TD>
<TD style=”HEIGHT: 28px”><asp:label id=”Lbclassname” runat=”server” Width=”430px”>Label</asp:label></TD>
</TR>
<TR bgColor=”#ffffff”>
<TD style=”WIDTH: 235px; HEIGHT: 28px”>软件名称:</TD>
<TD style=”HEIGHT: 28px”><asp:label id=”Lbtitle” runat=”server” Width=”149px”>Label</asp:label></TD>
</TR>
<TR bgColor=”#eeeeee”>
<TD style=”WIDTH: 235px; HEIGHT: 28px”>上传时间:</TD>
<TD style=”HEIGHT: 28px”><asp:label id=”lbuploadtime” runat=”server” Width=”432px”>Label</asp:label></TD>
</TR>
<TR bgColor=”#ffffff”>
<TD style=”WIDTH: 235px; HEIGHT: 28px”>下载次数:</TD>
<TD style=”HEIGHT: 28px”><asp:label id=”lbtotaldown” runat=”server” Width=”432px”>Label</asp:label></TD>
</TR>
<TR bgColor=”#eeeeee”>
<TD style=”WIDTH: 235px; HEIGHT: 28px”>详细信息:</TD>
<TD style=”HEIGHT: 128px”><asp:label id=”lbdescription” runat=”server” Width=”432px”>Label</asp:label></TD>
</TR>
<TR bgColor=”#ffffff”>
<TD style=”WIDTH: 235px; HEIGHT: 28px”>说明:</TD>
<TD style=”HEIGHT: 50px”>
<P><FONT color=”red”>*</FONT> 如出现文件不能正常解压,请下载<A href=”/soft/winrar.exe”>Winrar3.0</A><BR>
<FONT color=”red”>*</FONT> 如发现你的超星阅读器不能阅读在本站下载的图书,请重新下载<A href=”/soft/ss360.rar”><FONT color=”#ff0000″>超星阅读器</FONT></A>
安装</A><BR>
<FONT color=”red”>*</FONT> Author: lihonggen0
</P>
</TD>
</TR>
</table>
<asp:HyperLink id=”HyperLink1″ runat=”server” Width=”135px” Height=”29px”>点击此处下载</asp:HyperLink></DIV>
</FONT>
</form>
</body>
</HTML>
上述代码可存为一个html,在装在Vs.net机器上打开就会出现界面的样子。
总结
通过此实例,我们可以看见一个系统开发的原形,也就是我们在.NET下进行开发的一个典型的例子
本实例只是一个下载系统的原形,在数据库设计和前台界面的设计中,可以有许多改进和功能增强!比如分页可以考虑用SQL SERVER中的存储过程,每次传一页的数据。界面部分的显示可以考虑用DataList,会更加丰富!功能可以再扩展等等!还有就是Web动态引用, 其实就是WS.Url = http://….,再 WS.Discover(),因为篇幅,本文不再描述。
————————————————————————–
Author : lihonggen0
个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/
如需引用,请指明出处!软件的目的在于应用,本文可自由转载!
————————————————————————–