⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productsdb.vb

📁 很好的学习用c#构件网站的asp.net代码
💻 VB
字号:
Imports System
Imports System.Data
Imports System.Data.ADO

Namespace EComNet 

    '*******************************************************
    '
    ' ProductDetails Class
    '
    ' A simple data Class that encapsulates details about
    ' a particular product inside the EComNet Product 
    ' database.
    '
    '*******************************************************

    Public Class ProductDetails 
    
        Public ModelNumber As String
        Public ModelName As String
        Public ProductImage As String
        Public UnitCost As Decimal
        Public Description As String
        
    End Class

    '*******************************************************
    '
    ' ProductsDB Class
    '
    ' Business/Data Logic Class that encapsulates all data
    ' logic necessary to query products within
    ' the EComNet Products database.
    ' 
    '*******************************************************

    Public Class ProductsDB 

        '*******************************************************
        '
        ' ProductsDB.GetProductCategories() Method <a name="GetProductCategories"></a>
        '
        ' The GetProductCategories method returns a bindable, cacheable
        ' DataSet containing all product categories (and their
        ' ProductIDs) within the EComNet Products database.
        '
        ' Other relevant sources:  
        '     + <a href="srcview.aspx?path=../Menu.src&file=docs/ProductCategoryList.htm" style="color:green">ProductCategoryList Stored Procedure</a>
        '
        '*******************************************************

        Public Function GetProductCategories() As DataSet

            Dim myConnection As ADOConnection = new ADOConnection(EComNetDB.ConnectionString)
            Dim myCommand As ADODataSetCommand = new ADODataSetCommand("Select * From Class", myConnection)

            ' Create and Fill the DataSet
            Dim myDataSet As DataSet = new DataSet()
            myCommand.FillDataSet(myDataSet, "CategoryList")

            ' Return the DataSet
            return myDataSet
        
        End Function
       
        '*******************************************************
        '
        ' ProductsDB.GetProducts() Method <a name="GetProducts"></a>
        '
        ' The GetProducts method returns a struct containing a forward-only,
        ' read-only DataReader. This displays all products within a specified
        ' product category.  The ADODataReaderResult struct also returns the
        ' ADO connection, which must be explicitly closed after the
        ' data from the DataReader is bound into the controls.
        '
        ' Other relevant sources:  
        '     + <a href="srcview.aspx?path=../ProductsList.src&file=docs/ProductsByCategory.htm" style="color:green">ProductsByCategory Stored Procedure</a>
        '
        '*******************************************************       
       
        Public Function GetProducts(categoryID As Integer) As ADODataReaderResult

            ' Create Instance of Connection and Command Object
            Dim myConnection As ADOConnection = new ADOConnection(EComNetDB.ConnectionString)
            Dim myCommand As ADOCommand = new ADOCommand("Select * From Product Where Class_No=" & categoryID & "", myConnection)

            ' Create a ADODataReaderResult
            Dim result As ADODataReaderResult = New ADODataReaderResult()
            result.conn = myConnection

            Try    
                myConnection.Open()
                myCommand.Execute(result.dr)

            Catch e As Exception
                throw e
            End Try

            ' Return the datareader result
            return result
            
        End Function

        '*******************************************************
        '
        ' ProductsDB.GetProductDetails() Method <a name="GetProductDetails"></a>
        '
        ' The GetProductDetails method returns a ProductDetails
        ' struct containing specific details about a specified
        ' product within the EComNet Products Database.
        '
        ' Other relevant sources:  
        '     + <a href="srcview.aspx?path=../ProductsList.src&file=docs/ProductDetail.htm" style="color:green">ProductDetail Stored Procedure</a>
        '        
        '*******************************************************    

        Public Function GetProductDetails(productID As Integer) As ProductDetails

            Dim myConnection As ADOConnection = new ADOConnection(EComNetDB.ConnectionString)
            Dim myCommand As ADOCommand = new ADOCommand("Select * From Product Where Product_No = " &   ProductID & "", myConnection)

	    Dim Reader As ADODataReader

            Try 
                myConnection.Open()
                myCommand.Execute(Reader)
            Catch e As Exception
                throw e
            Finally 
                If myConnection.State = DBObjectState.Open then
                   myConnection.Close()
                End If
            End Try
           
            ' Create and Populate ProductDetails Struct Imports 
            ' Output Params from the SPROC

            Dim myProductDetails As ProductDetails = new ProductDetails()

            While Reader.Read()

             myProductDetails.ModelNumber = CStr(Reader.Item("Product_No"))
             myProductDetails.ModelName = CStr(Reader.Item("Product_Name"))
             myProductDetails.ProductImage = CStr(Reader.Item("Product_Picture"))
             myProductDetails.UnitCost = CType(Reader.Item("Product_Price"), Decimal)
             myProductDetails.Description = CStr(Reader.Item("Product_Des"))

            End While
            
            return myProductDetails
        
        End Function

        '*******************************************************
        '
        ' ProductsDB.GetProductsAlsoPurchased() Method <a name="GetProductsAlsoPurchased"></a>
        '
        ' The GetPGetProductsAlsoPurchasedroducts method returns a struct containing
        ' a forward-only, read-only DataReader.  This displays a list of other products
        ' also purchased with a specified product  The ADODataReaderResult struct also
        ' returns the ADO connection, which must be explicitly closed after the
        ' data from the DataReader is bound into the controls.
        '
        ' Other relevant sources:  
        '     + <a href="srcview.aspx?path=../AlsoBought.src&file=docs/CustomerAlsoBought.htm" style="color:green">CustomerAlsoBought Stored Procedure</a>
        '
        '******************************************************* 

        Public Function GetProductsAlsoPurchased(productID As Integer) As ADODataReaderResult

            ' Create Instance of Connection and Command Object
            Dim myConnection As ADOConnection = new ADOConnection(EComNetDB.ConnectionString)
            Dim myCommand As ADOCommand = new ADOCommand("CustomerAlsoBought", myConnection)

            ' Create a ADODataReaderResult
            Dim result As ADODataReaderResult = New ADODataReaderResult()
            result.conn = myConnection

            ' Execute the command
            Try
                myConnection.Open()
                myCommand.Execute(result.dr)

            Catch e As Exception
                throw e
            End Try

            ' Return the datareader result
            return result
        
        End Function

        '*******************************************************
        '
        ' ProductsDB.GetMostPopularProductsOfWeek() Method <a name="GetMostPopularProductsOfWeek"></a>
        '
        ' The GetMostPopularProductsOfWeek method returns a bindable, cacheable
        ' DataSet containing a list of the most popular products
        ' of the week within the EComNet Product database.
        '
        ' Other relevant sources:  
        '     + <a href="srcview.aspx?path=../PopularItems.src&file=docs/ProductsMostPopular.htm" style="color:green">ProductsMostPopular Stored Procedure</a>
        '
        '******************************************************* 

        Public Function GetMostPopularProductsOfWeek() As DataSet

            ' Create Instance of Connection and Command Object
            Dim myConnection As ADOConnection = new ADOConnection(EComNetDB.ConnectionString)
            Dim myCommand As ADODataSetCommand = new ADODataSetCommand("ProductsMostPopular", myConnection)

            ' Create and Fill the DataSet
            Dim myDataSet As DataSet = new DataSet()
            myCommand.FillDataSet(myDataSet, "CategoryList")

            ' Return the DataSet
            return myDataSet
        
        End Function
        
        '*******************************************************
        '
        ' ProductsDB.SearchProductDescriptions() Method <a name="SearchProductDescriptions"></a>
        '
        ' The SearchProductDescriptions method returns a struct containing
        ' a forward-only, read-only DataReader.  This displays a list of all
        ' products whose name and/or description contains the specified search
        ' string. The ADODataReaderResult struct also returns the ADO connection,
        ' which must be explicitly closed after the data from the DataReader
        ' is bound into the controls.
        '
        ' Other relevant sources:  
        '     + <a href="srcview.aspx?path=../SearchResults.src&file=docs/ProductSearch.htm" style="color:green">ProductSearch Stored Procedure</a>
        '
        '*******************************************************         
        
        Public Function SearchProductDescriptions(searchString As String) As ADODataReaderResult

            ' Create Instance of Connection and Command Object
            Dim myConnection As ADOConnection = new ADOConnection(EComNetDB.ConnectionString)
            Dim myCommand As ADOCommand = new ADOCommand("ProductSearch", myConnection)

            ' Create a ADODataReaderResult
            Dim result As ADODataReaderResult = New ADODataReaderResult()
            result.conn = myConnection

            ' Execute the command
            Try
                ' Open the connection and execute the Command
                myConnection.Open()
                myCommand.Execute(result.dr)

            Catch e As Exception
                ' An error occurred, pass the exception up
                throw e
            
            End Try

            ' Return the datareader result
            return result
            
        End Function
        
    End Class

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -