ITPub博客

首页 > 应用开发 > IT综合 > 用ASP、NET开发下载系统(二) (转)

用ASP、NET开发下载系统(二) (转)

原创 IT综合 作者:amyz 时间:2007-11-13 15:15:06 0 删除 编辑
用ASP、NET开发下载系统(二) (转)[@more@]

ASP.NET开发下载系统(二)XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />

中间层web Service

总体概括

中间层主要是数据库与前台界面的交互桥梁,Downwebservice

主要提供以下方法;

  '----------------------------------------------------------------

  '得到下载的分类GetDownClass

  '得到下载的所有信息GetDownInfo

  '从ID得到下载的信息,结果为一条记录GetDownFromID

  '更新下载次数UpdateTotalDown

  '----------------------------------------------------------------

我们建立了一个通用的类DataBase.vb 来进行通用的数据库操作,这些代码是我们通常都要用到的,所以我们封装到了一起。

数据库连接字符串存储在Web.config中:

 

  word=sa;User ID=sa;Initial Catalog=Northwind;Data source=pmserver;Packet Size=4096">

 

2003-7-21653590.jpg">

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

_

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 服务设计器修改此过程。

  '不要使用代码编辑器修改它。

  buggerStepThrough()> 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 "

  '----------------------------------------------------------------

  '得到下载的分类

  '----------------------------------------------------------------

  Public Function GetDownClass() As DataSet

  Return DataBase.ExecuteReDS(SQL_DOWN_CLASS)

  End Function

  '----------------------------------------------------------------

  '得到下载的所有信息

  '----------------------------------------------------------------

  Public Function GetDownInfo() As DataSet

  Return DataBase.ExecuteReDS(SQL_DOWN_SELECT)

  End Function

  '----------------------------------------------------------------

  '从ID得到下载的信息,结果为一条记录

  '----------------------------------------------------------------

  Public Function GetDownFromID(ByVal ID As Integer) As DataSet

  Return DataBase.ExecuteReDS(SQL_DOWN_SELECT & " where dbo.Down.id= " & ID)

  End Function

  '----------------------------------------------------------------

  '更新下载次数

  '----------------------------------------------------------------

  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/

如需引用,请指明出处!软件的目的在于应用,本文可自由转载!

--------------------------------------------------------------------------


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-982268/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7335632