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

📄 categorycontroller.vb

📁 C#语言制作asp.net网上商店的
💻 VB
📖 第 1 页 / 共 2 页
字号:
            Dim s As New StringBuilder
            'Dim link As String = "&gt;<a href=CatDefault.aspx?CatID={0}><strong>{1}</strong></a>"
            Dim link As String = " > {0}"

            Using reader As IDataReader = db.ExecuteReader(dbCommand)
                While reader.Read
                    s.Append(String.Format(link, reader.Item("CategoryName")))
                End While
            End Using
            Return s.ToString.Substring(1)
        End Function


        Public Shared Function GetCategoryMapPath(ByVal categoryID As Integer, ByVal renderCurrentNodeAsLink As Boolean) As String
            Dim s As New StringBuilder
            s.Append(" <a href=Categories.aspx?catID=-1>主类别</a>")
            If categoryID <> -1 Then
                Dim db As Database = DatabaseFactory.CreateDatabase
                Dim dbCommand As DbCommand = db.GetStoredProcCommand("nsf_Category_GetCategoryFatherList")
                ' Add paramters
                ' Input parameters can specify the input value
                db.AddInParameter(dbCommand, "@CategoryID", DbType.Int32, categoryID)

                'Dim link As String = "&gt;<a href=CatDefault.aspx?CatID={0}><strong>{1}</strong></a>"
                Dim link As String = " <a href=Categories.aspx?catID={0}>{1}</a>"

                Using reader As IDataReader = db.ExecuteReader(dbCommand)
                    While reader.Read
                        Dim cID As String = reader.Item("CategoryID")
                        Dim cName As String = reader.Item("CategoryName")
                        If CInt(cID) = categoryID AndAlso Not renderCurrentNodeAsLink Then
                            s.Append("&nbsp" & cName)
                        Else
                            s.Append(String.Format(link, cID, cName))
                        End If

                    End While
                End Using
            End If
            'Return s.ToString.Substring(4)
            Return s.ToString

        End Function


        Public Shared Function GetNProductbyCategory(ByVal categoryId As Integer) As Integer

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

            ' Add paramters
            ' Input parameters can specify the input value
            db.AddInParameter(dbCommand, "@CategoryID", DbType.Int32, categoryId)
            Return CInt(db.ExecuteScalar(dbCommand))
        End Function

        Public Shared Function GetNSubCatbyCategory(ByVal categoryFatherID As Integer) As Integer
            Using dt As DataTable = GetSubCategoryTable(categoryFatherID)
                If Not IsNothing(dt) Then
                    Return dt.Rows.Count
                Else
                    Return 0
                End If
            End Using
        End Function

        Public Shared Function GetTreeTable() As DataTable

            Using dt As DataTable = System.Web.HttpContext.Current.Cache("CategoryTable")
                If IsNothing(dt) Then
                    Using t As DataTable = CategoryController.GetCategoryList().Tables(0)
                        System.Web.HttpContext.Current.Cache.Insert("CategoryTable", t)
                        Return t
                    End Using
                End If
                Return dt
            End Using

        End Function

        Public Shared Function GetCategoryName(ByVal categoryID As Integer) As String
            Using dt As DataTable = GetTreeTable()

                Dim foundRows() As DataRow
                foundRows = dt.Select(String.Format("[CategoryID]={0}", categoryID.ToString))
                If Not IsNothing(foundRows) Then
                    Return CStr(foundRows(0).Item("CategoryName"))
                Else
                    Return ""
                End If

            End Using

        End Function

        Public Shared Function GetCategoryFatherID(ByVal categoryID As Integer) As Integer
            Using dt As DataTable = GetTreeTable()

                Dim foundRows() As DataRow
                foundRows = dt.Select(String.Format("[CategoryID]={0}", categoryID.ToString))
                If Not IsNothing(foundRows) Then
                    Return CInt(foundRows(0).Item("CategoryFatherID"))
                Else
                    Return ""
                End If

            End Using
        End Function

        Public Shared Function GetSubCategoryTable(ByVal categoryFatherID As Integer) As DataTable
            Using dt As DataTable = GetTreeTable()

                Dim foundRows() As DataRow
                foundRows = dt.Select(String.Format("[CategoryFatherID]={0}", categoryFatherID.ToString))

                Using dtt As DataTable = dt.Clone
                    For i As Integer = 0 To foundRows.Length - 1
                        dtt.ImportRow(foundRows(i))
                    Next
                    Return dtt
                End Using

            End Using
        End Function

#End Region

#Region "---Private Shared Method----"

        Private Shared Sub GetCategoryDictionary(ByRef cDictionary As Dictionary(Of Integer, String), ByVal categoryFatherID As Integer, ByVal categoryFatherName As String)
            Dim db As Database = DatabaseFactory.CreateDatabase()
            Dim sqlCommand As String = "nsf_Category_GetCategoryList"
            Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand)
            ' Retrieve products from the specified category.
            db.AddInParameter(dbCommand, "CategoryFatherID", DbType.Int32, categoryFatherID)
            ' DataSet that will hold the returned results		
            Using reader As IDataReader = db.ExecuteReader(dbCommand)
                While reader.Read

                    Dim categoryName As String = ""

                    If categoryFatherID <> -1 Then
                        categoryName = categoryName + "/" & reader.Item("CategoryName")
                    Else
                        categoryName = reader.Item("CategoryName")
                    End If

                    Dim categoryID As Integer = CInt(reader.Item("categoryID"))
                    cDictionary.Add(categoryID, categoryName)
                    GetCategoryDictionary(cDictionary, categoryID, categoryName)

                End While
            End Using

        End Sub

        Private Shared Function FillCategoryInfo(ByVal dr As IDataReader) As CategoryInfo

            Dim objCI As New CategoryInfo

            objCI.CategoryID = dr.Item("CategoryID")
            objCI.CategoryFatherID = dr.Item("CategoryFatherID")
            objCI.CategoryName = dr.Item("CategoryName")
            objCI.ImagePath = dr.Item("ImagePath")
            objCI.IsValid = CBool(dr.Item("IsValid"))
            objCI.ItemOrder = CInt(dr.Item("ItemOrder"))
            objCI.MetaDescription = dr.Item("MetaDescription")
            objCI.MetaKeywords = dr.Item("MetaKeywords")
            objCI.Description = dr.Item("Description")
            Return objCI

        End Function

#End Region


    End Class
End Namespace

⌨️ 快捷键说明

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