Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class CatalogueControl
    Inherits System.Web.UI.UserControl
    Dim strWHEREClause As String = ""
    Dim intTotalPageCount As Integer
    Const m_DISPLAYEDROWS = 5
    Const m_PAGESIZE As Integer = 5
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Call LoadData()
    End Sub
    Private Sub LoadData()
        'Build Category information first
        Dim objMainCategory As New entmainCategory
        Dim intCategoryID As New Integer

        intCategoryID = Convert.ToInt32(Request.QueryString("catid"))
        objMainCategory = GetCategory(intCategoryID)
        With objMainCategory
            Dim cpl As ContentPlaceHolder = TryCast(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
            Dim lbl As Label = TryCast(cpl.FindControl("lblCatPageTitle"), Label)

 


            Dim parentCategory As New entmainCategory
            Dim objMainParent As New dbMainCategory
            parentCategory = objMainParent.GetItem(Convert.ToInt32(Request.QueryString("cid")))
            Dim categoryList As String
            categoryList = parentCategory.CategoryID.ToString() & "," & parentCategory.CategoryName
            CType(Me.Parent.FindControl("breadcrumb"), Breadcrumb).SetProductLinks(.CategoryName, categoryList)

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

            lbl.Text = .CategoryName
            divContent.InnerHtml = .CategorySummary
            divBulletList.InnerHtml = .BulletList
            'Build enquire button

            hplContactUs.Text += " " + .CategoryName.ToString()
            hplContactUs.NavigateUrl += "?cid=" + Request.QueryString("cid") & "&catid=" & .CategoryID.ToString() & "&pid = "


        End With

        Dim objMainProduct As New List(Of entMainProduct)
        objMainProduct = GetAllProducts(intCategoryID)

        rptProducts.DataSource = objMainProduct
        rptProducts.DataBind()

 


    End Sub

    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 GetAll(ByVal strWHEREClause As String) As List(Of entMainProduct)
        Dim objMain As New dbMainProduct
        Dim objMainProduct As List(Of entMainProduct) = objMain.GetAll(strWHEREClause, " ORDER BY ProductName")
        Return objMainProduct
    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

    Private Function CheckStringValue(ByVal strInput As String) As String
        Dim strOutput As String = ""
        If Not strInput Is Nothing AndAlso strInput <> "" Then
            strOutput = strInput & "<br />"
        End If
        Return strOutput
    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


#Region "Internal properties"
    Private Property CurrentPage() As Integer
        Get
            Return CInt(Me.ViewState("_CurrentPage"))
        End Get
        Set(ByVal value As Integer)
            Me.ViewState("_CurrentPage") = value
        End Set
    End Property
    Private Property TotalPageCount() As Integer
        Get
            Return intTotalPageCount
        End Get
        Set(ByVal value As Integer)
            intTotalPageCount = value
        End Set
    End Property
    Private Property WHEREClause() As String
        Get
            Return strWHEREClause
        End Get
        Set(ByVal value As String)
            strWHEREClause = value
        End Set
    End Property
#End Region
End Class
