Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class CategoriesControl
    Inherits System.Web.UI.UserControl
    Dim intLimit As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objMainCategory As New entmainCategory
        Dim intCategoryID As New Integer

        'Get main category details
        If Not Request.QueryString("cid") Is Nothing Then
            intCategoryID = Convert.ToInt32(Request.QueryString("cid"))
            objMainCategory = GetCategory(intCategoryID)
            With objMainCategory

                Dim cpl As ContentPlaceHolder = TryCast(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
                Dim lbl As Label = TryCast(cpl.FindControl("lblCatPageTitle"), Label)
                lbl.Text = .CategoryName

                divContent.InnerHtml = .CategorySummary
                'Find div on master page
                Dim masterPage As main = DirectCast(Me.Page.Master, main)
                masterPage.BodyTag.Attributes.Add("class", .DropDownValue.ToString())

                Dim func As New miscFunctions

                CType(Me.Parent.FindControl("breadcrumb"), Breadcrumb).SetProductLinks(.CategoryName, "")

                '22/2/2011 taken out of the build and replaced with product list
                ''Build Sub Category repeater
                'Dim objSubCategory As New List(Of entmainCategory)
                'objSubCategory = GetAll(intCategoryID)
                'rptSubCategories.DataSource = objSubCategory
                'rptSubCategories.DataBind()
                Dim objMainProduct As New List(Of entMainProduct)
                objMainProduct = GetAllProducts(intCategoryID)

                rptProducts.DataSource = objMainProduct
                rptProducts.DataBind()

                'Build enquire button
                hplContactUs.NavigateUrl += "?cid=" + .CategoryID.ToString() & "&cat=&pid="
                hplContactUs.Text += " " + .CategoryName.ToString()


                hplContactUsGeneralIT.NavigateUrl += "?cid=" + Request.QueryString("cid") & "&srv=t&catid=&pid="
            End With
        End If


    End Sub
    Private Function GetAll(ByVal intCategoryID As Integer) As List(Of entmainCategory)
        Dim objMain As New dbMainCategory
        Dim objMainEntity As List(Of entmainCategory) = objMain.GetAll("  AND ParentCategoryID = " & intCategoryID & " AND mainCategory.Active = 1 AND IsUnique = 0", "ORDER BY OrderBy ASC")
        Return objMainEntity
    End Function
    Private Function GetCategory(ByVal intCategoryID As Integer) As entmainCategory
        Dim objMain As New dbMainCategory
        Dim objMainCategory As entmainCategory = objMain.GetItem(intCategoryID)
        Return objMainCategory
    End Function
    Private Function GetAllProducts(ByVal intCategoryID As Integer) As List(Of entMainProduct)
        Dim objMain As New dbMainProduct
        Dim objMainProduct As List(Of entMainProduct) = objMain.GetAllByCategoryID(intCategoryID)
        Return objMainProduct
    End Function
    Public Function CleanUrlRewriter(ByVal strInput As String) As String
        Dim strOutput As String = ""
        Dim func As New miscFunctions
        strOutput = func.CleanUrlString(strInput)

        Return strOutput
    End Function

End Class