Develop a download system with ASP, NET
Intermediate WEB SERVICE
Overall summary
The intermediate layer is mainly the interactive bridge between the database and the front interface, DownWebService
It mainly provides the following methods;
'------------------------------------- ---------------
'Get the downloaded classification GetDownClass
'Get all the information downloaded with GetDownInfo
'Get downloaded from ID, resulting in a record getDownFromid
'Update Downloads UpdateTotaldown
'------------------------------------- ---------------
We have established a universal class Database.vb to perform universal database operations, which we usually have to be used, so we package them together.
Database connection string is stored in Web.config:
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 Executev (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 "The code" Zone generated by the web service design " Public Sub New () Mybase.new () 'This call is required for the web service designer. InitializeComponent () 'Add your own initialization code after INITIALIZECOMPONENT () call End Sub 'Web service designer necessary Private Components as System.comPonentModel.icontainer 'Note: The following procedure is necessary to use the Web Service Designer to modify this process using the Web Service Designer. 'Don't modify it using the code editor. Components = new system.componentmodel.container () End Sub Protected Overloads Overrides Sub Dispose (Byval Disposing as Boolean) 'Codegen: This process is necessary for the web service designer 'Don't modify it using the code editor. 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" '------------------------------------- --------------- 'Get the downloaded classification '------------------------------------- --------------- Return Database.executeReds (SQL_DOWN_CLASS) END FUNCTION '------------------------------------- --------------- 'Get all information downloaded '------------------------------------- --------------- Return Database.executeReds (SQL_DOWN_SELECT) END FUNCTION '------------------------------------- --------------- 'Get downloaded from ID, resulting as a record '------------------------------------- --------------- Return Database.executeReds (SQL_DOWN_SELECT & "Where dbo.down.id =" & id) End Function '------------------------------------- --------------- 'Update download '------------------------------------- --------------- Return Database.executeSQL (SQL_DOWN_UPDATE & "Where id =" & id) END FUNCTION END CLASS -------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------- Author: lihonggen0 Personal column: http://www.9cbs.net/develop/author/netauthor/lihonggen0/ For quotation, please refer to the place! The purpose of software is to apply, this article is free to reprint! -------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------