总体架构
在互联网飞速发展的时代,许多网站都有自己的下载系统!在ASP、NET中我们可以很快地完成一个下载系统模块。
系统模型:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
以下是系统的屏幕截图效果:
不知道大家注意到没有,这种表格方式List数据在许多网站上都有应用!还有就是点击一条数据,弹出一个窗体,然后执行用户的操作,这种方式的应用效果还是比较好的!
为了实现分类信息,主界面的窗口的左边是一个Web Treeview控件,实现树状分类!
这种界面的布局,操作方式在这个系统中是发挥得淋漓尽致!
这样的方式可以用在许多系统中!(由于是介绍,只是一个简单的下载系统!在此基础上扩充,是很容易的!如果读者需要更丰富的显示效果,可考虑用asp.net中的DataList控件,目前是DataGrid)
后台数据库部分
建表:Down下载信息表
DownClass下载信息的分类
CREATE TABLE [DownClass] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[classname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
CONSTRAINT [PK_DownClass] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [Down] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[classID] [int] NULL ,
[title] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[description] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[filename] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[uploadtime] [smalldatetime] NULL CONSTRAINT [DF_Down_uploadtime] DEFAULT (getdate()),
[totaldown] [int] NULL ,
CONSTRAINT [PK_Down] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY] ,
CONSTRAINT [FK_Down_DownClass] FOREIGN KEY
(
[classID]
) REFERENCES [DownClass] (
[id]
)
) ON [PRIMARY]
GO
以下是系统的屏幕截图效果
--------------------------------------------------------------------------
Author : lihonggen0
个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/
如需引用,请指明出处!软件的目的在于应用,本文可自由转载!
用ASP、NET开发下载系统(二)
中间层Web Service
总体概括
中间层主要是数据库与前台界面的交互桥梁,DownWebService
主要提供以下方法;
'----------------------------------------------------------------
'得到下载的分类GetDownClass
'得到下载的所有信息GetDownInfo
'从ID得到下载的信息,结果为一条记录GetDownFromID
'更新下载次数UpdateTotalDown
'----------------------------------------------------------------
我们建立了一个通用的类DataBase.vb 来进行通用的数据库操作,这些代码是我们通常都要用到的,所以我们封装到了一起。
数据库连接字符串存储在Web.config中:
<appSettings>
<add key="connString" value="Password=sa;User ID=sa;Initial Catalog=Northwind;Data Source=pmserver;Packet Size=4096"></add>
</appSettings>
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
DataBase.vb类
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Public Class DataBase
'----------------------------------------------------------------
' Sub ExecuteReDS:
' Used for query operations
' Return: result in a dataset
' Parameters:
' [in] cmdText: Sql or Sp name.
'----------------------------------------------------------------
Public Shared Function ExecuteReDS(ByVal cmdText As String) As DataSet
Dim connString As String = ConfigurationSettings.AppSettings("connString")
Dim conn As New SqlConnection(connString)
Dim adp As SqlDataAdapter = New SqlDataAdapter(cmdText, conn)
Dim ds As DataSet = New DataSet("tb")
Try
adp.Fill(ds)
Catch e As Exception
Throw e
Finally
conn.Close()
End Try
Return ds
End Function
'----------------------------------------------------------------
' Sub ExecuteReDV:
' Return: result in a DataView
' Parameters:
' [in] cmdText: Sql or Sp name.
'----------------------------------------------------------------
Public Shared Function ExecuteReDV(ByVal cmdText As String) As DataView
Dim connString As String = ConfigurationSettings.AppSettings("connString")
Dim conn As New SqlConnection(connString)
Dim adp As SqlDataAdapter = New SqlDataAdapter(cmdText, conn)
Dim dv As DataView
Dim dt As DataTable
Try
adp.Fill(dt)
dv = dt.DefaultView
Catch e As Exception
Throw e
Finally
conn.Close()
End Try
Return dv
End Function
'----------------------------------------------------------------
' Sub ExecuteSQL:
' Execute SQL
' Return: True or False
' Parameters:
' [in] cmdText: Sql or Sp name.
'----------------------------------------------------------------
Public Shared Function ExecuteSQL(ByVal cmdText As String) As Boolean
Dim connString As String = ConfigurationSettings.AppSettings("connString")
Dim conn As New SqlConnection(connString)
conn.Open()
Dim cmd As New SqlCommand(cmdText, conn)
Try
cmd.ExecuteScalar()
Catch e As Exception
Return False
Throw e
Finally
conn.Close()
End Try
Return True
End Function
End Class
WebService
DownWebService.asmx.vb
Imports System.Web.Services
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
<WebService(Namespace:="http://tempuri.org/")> _
Public Class DownWebService
Inherits System.Web.Services.WebService
#Region " Web 服务设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Web 服务设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加您自己的初始化代码
End Sub
'Web 服务设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Web 服务设计器所必需的
'可以使用 Web 服务设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: 此过程是 Web 服务设计器所必需的
'不要使用代码编辑器修改它。
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
Public SQL_DOWN_SELECT As String = "SELECT Down.ID,Down.title,Down.description,Down.filename,Down.uploadtime, Down.totaldown, DownClass.classname FROM dbo.Down INNER JOIN dbo.DownClass ON dbo.Down.classID = dbo.DownClass.id"
Public SQL_DOWN_Update As String = "update down set totaldown=totaldown+1 "
Public SQL_DOWN_CLASS As String = "SELECT * from downclass "
'----------------------------------------------------------------
'得到下载的分类
'----------------------------------------------------------------
<WebMethod()> Public Function GetDownClass() As DataSet
Return DataBase.ExecuteReDS(SQL_DOWN_CLASS)
End Function
'----------------------------------------------------------------
'得到下载的所有信息
'----------------------------------------------------------------
<WebMethod()> Public Function GetDownInfo() As DataSet
Return DataBase.ExecuteReDS(SQL_DOWN_SELECT)
End Function
'----------------------------------------------------------------
'从ID得到下载的信息,结果为一条记录
'----------------------------------------------------------------
<WebMethod()> Public Function GetDownFromID(ByVal ID As Integer) As DataSet
Return DataBase.ExecuteReDS(SQL_DOWN_SELECT & " where dbo.Down.id= " & ID)
End Function
'----------------------------------------------------------------
'更新下载次数
'----------------------------------------------------------------
<WebMethod()> Public Function UpdateTotalDown(ByVal ID As Integer) As Boolean
Return DataBase.ExecuteSQL(SQL_DOWN_Update & " where id= " & ID)
End Function
End Class
--------------------------------------------------------------------------
Author : lihonggen0
个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/
如需引用,请指明出处!软件的目的在于应用,本文可自由转载!
--------------------------------------------------------------------------