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

📄 productcontroller.vb

📁 C#语言制作asp.net网上商店的
💻 VB
📖 第 1 页 / 共 3 页
字号:

Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Data
Imports System.Collections.Generic
Imports System.Text
Imports NetShopForge.Common
Imports NetShopForge.Library.Category

Namespace NetShopForge.Library.Product

    Public Class ProductController


        Public Enum ProductSortType
            ascProductID
            descSale
            descTime
            ascPrice
            descPrice
        End Enum
        Public Shared Sub UpdateProductAttributes(ByVal productID As Integer, ByVal attributeCollecion As ProductAttributeCollection)
            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_UpdateAttributeXML")

            db.AddInParameter(dbCommand, "@ProductID", DbType.Int32, productID)
            db.AddInParameter(dbCommand, "@AttributeXML", DbType.String, attributeCollecion.ToXML)

            db.ExecuteNonQuery(dbCommand)

        End Sub
        Public Shared Sub UpdateProductDescriptor(ByVal productDescriptorInfo As ProductDescriptorInfo)
            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_UpdateProductDescriptor")

            db.AddInParameter(dbCommand, "@DescriptorID", DbType.Int32, productDescriptorInfo.DescriptorID)
            '    db.AddInParameter(dbCommand, "@Title", DbType.String, productDescriptorInfo.Title)
            db.AddInParameter(dbCommand, "@Descriptor", DbType.String, productDescriptorInfo.Descriptor)
            db.AddInParameter(dbCommand, "@IsBulletedList", DbType.Boolean, productDescriptorInfo.IsBulletedList)
            db.AddInParameter(dbCommand, "@ItemOrder ", DbType.Int32, productDescriptorInfo.ItemOrder)
            db.AddInParameter(dbCommand, "@IsValid", DbType.Boolean, productDescriptorInfo.IsValid)

            db.ExecuteNonQuery(dbCommand)
        End Sub
        Public Shared Sub UpdateProductLinks(ByVal ProductLinksID As Integer, ByVal linkType As Integer)
            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_UpdateProducLinks")
            db.AddInParameter(dbCommand, "@ProductLinksID ", DbType.Int32, ProductLinksID)
            db.AddInParameter(dbCommand, "@LinkType", DbType.Int32, linkType)
            db.ExecuteNonQuery(dbCommand)

        End Sub


        Public Shared Sub DeleteProductDescriptor(ByVal descriptorID As Integer)
            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_DeleteProductDescriptor")

            db.AddInParameter(dbCommand, "@DescriptorID", DbType.Int32, descriptorID)
            db.ExecuteNonQuery(dbCommand)

        End Sub
        Public Shared Sub DeleteProductCategory(ByVal productID As String, ByVal categoryID As Integer)

            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_DeleteProductCategory")


            db.AddInParameter(dbCommand, "@CategoryID", DbType.Int32, categoryID)
            db.AddInParameter(dbCommand, "@ProductID", DbType.Int32, productID)

            db.ExecuteNonQuery(dbCommand)

        End Sub


        Public Shared Function GetProductIDStringByCategoryID(ByVal categoryID As Integer) As String
            Dim Products As New List(Of ProductInfo)

            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_GetProductIDByCategoryID")
            Dim pIDs As New StringBuilder
            db.AddInParameter(dbCommand, "@CategoryID", DbType.Int32, categoryID)


            Using reader As IDataReader = db.ExecuteReader(dbCommand)
                While reader.Read
                    pIDs.Append(String.Format(",{0}", reader.Item(0).ToString))
                End While
                If pIDs.Length = 0 Then Return ""
                Return pIDs.ToString.Substring(1)
            End Using
        End Function

        Public Shared Function GetProductNormalImagePath(ByVal ProductID As Integer) As String
            Dim pList As New List(Of ProductImageInfo)

            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_GetProductImageList")

            db.AddInParameter(dbCommand, "@productID", DbType.Int32, ProductID)
            db.AddInParameter(dbCommand, "Type", DbType.Int32, 0)

            Using reader As IDataReader = db.ExecuteReader(dbCommand)
                While reader.Read
                    Return reader.Item("ImagePath").ToString
                End While
            End Using
            Return ""
        End Function

#Region "-------GetProductList--------"
        Public Shared Function GetProductList() As List(Of ProductInfo)
            Return GetProductList("")

        End Function
        Public Shared Function GetProductList(ByVal sqlWhere As String) As List(Of ProductInfo)
            Return GetProductList(9999999, 1, -2, sqlWhere)
        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer) As List(Of ProductInfo)
            Return GetProductList(pageSize, pageIndex, totalRecords, "")
        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer, ByVal sqlWhere As String) As List(Of ProductInfo)
            Return GetProductList(pageSize, pageIndex, totalRecords, sqlWhere, True, "ItemOrder")
        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer, ByVal CategoryID As Integer) As List(Of ProductInfo)
            Return GetProductList(pageSize, pageIndex, totalRecords, CategoryID, ProductSortType.ascProductID)
        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer, ByVal CategoryID As Integer, ByVal productSort As ProductSortType) As List(Of ProductInfo)

            'Dim pIDstring As String = GetProductIDStringByCategoryID(CategoryID)
            'If pIDstring.Length = 0 Then Return Nothing
            'Dim sqlWhereString As String = String.Format("productID IN({0})", pIDstring)

            Dim sqlWhereString As String = String.Format("productID IN(select ProductID from nsf_f_GetProductIDByCategoryID({0}))", CategoryID.ToString)

            Select Case productSort
                Case ProductController.ProductSortType.ascPrice
                    Return GetProductList(pageSize, pageIndex, totalRecords, sqlWhereString, False, "Price")
                Case ProductController.ProductSortType.descPrice
                    Return GetProductList(pageSize, pageIndex, totalRecords, sqlWhereString, True, "Price")
                Case ProductController.ProductSortType.descTime
                    Return GetProductList(pageSize, pageIndex, totalRecords, sqlWhereString, True, "ItemOrder")
                Case ProductController.ProductSortType.descSale
                    Return Nothing
                Case Else
                    Return GetProductList(pageSize, pageIndex, totalRecords, sqlWhereString, False, "ItemOrder")
            End Select

        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer, ByVal CategoryID As Integer, ByVal productSort As ProductSortType, ByVal sqlWhere As String) As List(Of ProductInfo)

            If sqlWhere.Trim.Length > 0 Then

                'Dim objCC As New CategoryController
                'Dim pIDstring As String = GetProductIDStringByCategoryID(CategoryID)

                Dim sqlWhereString As String = String.Format("productID IN(select ProductID from nsf_f_GetProductIDByCategoryID({0}))", CategoryID.ToString)

                '  Dim sqlCategoryWhereString As String = String.Format("productID IN({0})", pIDstring)
                Dim sql As String = String.Format("{0} AND {1}", sqlWhereString, sqlWhere)
                Select Case productSort
                    Case ProductController.ProductSortType.ascPrice
                        Return GetProductList(pageSize, pageIndex, totalRecords, sql, False, "Price")
                    Case ProductController.ProductSortType.descPrice
                        Return GetProductList(pageSize, pageIndex, totalRecords, sql, True, "Price")
                    Case ProductController.ProductSortType.descTime
                        Return GetProductList(pageSize, pageIndex, totalRecords, sql, True, "ItemOrder")
                    Case ProductController.ProductSortType.descSale
                        Return Nothing
                    Case Else
                        Return GetProductList(pageSize, pageIndex, totalRecords, sql, False, "ItemOrder")
                End Select
            Else
                Return GetProductList(pageSize, pageIndex, totalRecords, CategoryID, productSort)
            End If
        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer, ByVal CategoryID As Integer, ByVal sqlWhere As String) As List(Of ProductInfo)
            Return GetProductList(pageSize, pageIndex, totalRecords, CategoryID, ProductSortType.ascProductID, sqlWhere)
        End Function
        Public Shared Function GetProductList(ByVal pageSize As Integer, ByVal pageIndex As Integer, ByRef totalRecords As Integer, ByVal sqlWhere As String, ByVal isDesc As Boolean, ByVal sortFiled As String) As List(Of ProductInfo)
            Dim Products As New List(Of ProductInfo)
            Dim db As Database = DatabaseFactory.CreateDatabase
            If totalRecords <> -2 Then
                Dim dbCommand1 As DbCommand = db.GetStoredProcCommand("nsf_Product_GetProductList")
                db.AddInParameter(dbCommand1, "@IsReCount", DbType.Boolean, True)
                db.AddInParameter(dbCommand1, "@fldName", DbType.String, sortFiled)
                db.AddInParameter(dbCommand1, "@OrderType", DbType.Boolean, isDesc)
                If sqlWhere.Trim.Length > 0 Then
                    db.AddInParameter(dbCommand1, "@strWhere", DbType.String, sqlWhere)
                End If
                totalRecords = CInt(db.ExecuteScalar(dbCommand1))
            End If

            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_GetProductList")
            db.AddInParameter(dbCommand, "@fldName", DbType.String, sortFiled)
            db.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize)
            db.AddInParameter(dbCommand, "@PageIndex", DbType.Int32, pageIndex)
            db.AddInParameter(dbCommand, "@OrderType", DbType.Boolean, isDesc)
            If sqlWhere.Trim.Length > 0 Then
                db.AddInParameter(dbCommand, "@strWhere", DbType.String, sqlWhere)
            End If

            Using reader As IDataReader = db.ExecuteReader(dbCommand)
                While reader.Read
                    Products.Add(FillProductInfo(reader))
                End While
                Return Products
            End Using

        End Function



#End Region

        Public Shared Function GetProduct(ByVal productID As Integer) As ProductInfo

            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Product_GetProduct")
            ' Add paramters

⌨️ 快捷键说明

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