Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class SidebarNewsControl
    Inherits System.Web.UI.UserControl
    Dim intLimit As Integer
    Dim categoryID As New Integer
    Dim subcategory As New Integer
    Dim productID As New Integer
    Dim newType As New Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


       
        'Check that the page is category only

        If Request.QueryString("pid") = "" Then
            'Get the category
            If Request.QueryString("cid") <> "" Then
                categoryID = Convert.ToInt32(Request.QueryString("cid"))
                newType = Convert.ToInt32(Request.QueryString("cid"))
                GetNewsDetails(newType, 0)
            End If

            If Request.QueryString("id") = "1" Then
                categoryID = Convert.ToInt32(Request.QueryString("id"))
                newType = Convert.ToInt32(Request.QueryString("id"))
                GetNewsDetails(newType, 0)
            End If

            If newType = 0 Then
                GetNewsDetails(newType, 0)
            End If
        Else
            newType = Convert.ToInt32(Request.QueryString("cid"))
            productID = Convert.ToInt32(Request.QueryString("pid"))
            If Not IsPostBack Then
                GetNewsDetails(newType, productID)
            End If


        End If


    End Sub
    Public Sub GetNewsDetails(ByVal id As Integer, ByVal productID As Integer)
        Dim func As New miscFunctions
        Dim main As New dbMainNews
        Dim newsItem As New entMainNews
        If productID > 0 Then
            newsItem = main.GetItemSideBar_Product(id, productID)
        Else
            newsItem = main.GetItemSideBar(id)
        End If
        If Not newsItem.NewsID Is Nothing Then
            With newsItem

                lnkNewsTitle.Text = .NewsHeadline
                lnkNewsTitle.NavigateUrl = "~/news/news-" & CleanUrlRewriter(.NewsHeadline) & "-" & categoryID & "-" & subcategory & "-" & .NewsID
                lnkViewArticle.NavigateUrl = "~/news/news-" & CleanUrlRewriter(.NewsHeadline) & "-" & categoryID & "-" & subcategory & "-" & .NewsID
                lblNewsSummary.Text = .NewsSummary

                lnkViewAllArticles.NavigateUrl = "~/news/lastestnews.html?n=" & categoryID & "&ns=" & subcategory
                If .ThumbImage <> "" Then
                    imgNewsImage.ImageUrl += .ThumbImage
                    imgNewsImage.NavigateUrl = "~/news-" + func.CleanUrlString(.NewsHeadline) + "-" + id.ToString() + "-" + .NewsID.ToString
                Else
                    imgNewsImage.Visible = False
                End If

            End With
        Else
            divNews.Visible = False
        End If

    End Sub

    Private Function CheckStringValue(ByVal strInput As String) As String
        Dim strOutput As String = ""
        If Not strInput Is Nothing AndAlso strInput <> "" Then
            strOutput = strInput
        End If
        Return strOutput
    End Function
    Public Property Limitnewslist() As Integer
        Get
            Return intLimit
        End Get
        Set(ByVal value As Integer)
            intLimit = value
        End Set
    End Property
    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
