Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class UserControl_NewArticleRightBanner
    Inherits System.Web.UI.UserControl
    Dim pdt As New DataTable
    Dim rcon As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'imgbtnGo.ImageUrl = Page.ResolveUrl("~/Images/go.jpg")
        If Not IsPostBack Then
            'imgbtnGo.ImageUrl = Page.ResolveUrl("~/Images/go.jpg")
            Try
                Dim str As String

                fillArticle()

                If Session("MailId") <> "" Or Session("three") <> Nothing Then
                    ' PrAlert.Visible = False
                    str = "SELECT top(2) Product_Kid,CatName,ProdName,Product_Name,Product_Image,Brand_Name,SUBSTRING(ISNULL(Product_Description, N'N.A.'), 1, 50) as Product_Description,Product_MarketPrice  from ProductDisplay ORDER BY Product_RegDate desc"
                    If Not IsNothing(Session("dt1")) Then
                        pdt = Session("dt1")
                        DataList1.DataSource = pdt
                        DataList1.DataBind()
                    Else
                        ' str = "SELECT Product_Information.Product_Kid, Product_Information.Product_Code, Product_Information.Product_Name, Product_Information.Product_ModelNo, Product_Information.Product_AtcoPrice, Product_Information.Brand_Name, Product_Information.Product_Image, Product_Information.Product_BrandId, Product_Information.Product_Approved, SUBSTRING(ISNULL(Product_Information.Product_Description, N'N.A.'), 1, 100) + '' + SUBSTRING(ISNULL(Product_Information.Product_Description, N'N.A.'), 101, CHARINDEX('.', SUBSTRING(ISNULL(Product_Information.Product_Description, N'N.A.'), 101, 400))) AS Product_Description, REPLACE(REPLACE(REPLACE(LOWER(RTRIM(LTRIM(Category_Master.Category_Name))), ' ', '-'), '  ', '-'), '&', '-') AS CatName, REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(RTRIM(LTRIM(Product_Information.Product_Name))), ' ', '-'), '  ', '-'), '&', '-'),'/','-'),'\','-') AS ProdName, Product_Information.Product_CategoryId FROM Product_Information INNER JOIN Category_Master ON Product_Information.Product_CategoryId = Category_Master.Category_Kid WHERE     (Product_Information.Product_Approved = 'Y') AND (Product_Information.Product_Code='ABT001')" ','ABT002'))" 'AHP006', 'AJP001'))"
                        'TOP (2) Product_Kid,Product_Master.Product_Name, Product_Master.Product_BrandId, Brand_Master.Brand_Name, Product_Master.Product_Image FROM  Product_Master INNER JOIN  Brand_Master ON Product_Master.Product_BrandId = Brand_Master.Brand_Kid  where Product_Master.Product_Approved='Y' and Product_Master.Product_Isdeleted='0'     ORDER BY Product_Master.Product_RegDate desc"
                        rcon.Open()
                        Dim pdadtr As New SqlDataAdapter(str, rcon)
                        pdadtr.Fill(pdt)
                        Session("dt1") = pdt
                        DataList1.DataSource = pdt
                        DataList1.DataBind()
                    End If
                    rcon.Close()
                Else
                    ' PrAlert.Visible = True
                    str = "SELECT top (1) Product_Kid,CatName,ProdName,Product_Name,Product_Image,Brand_Name,SUBSTRING(ISNULL(Product_Description, N'N.A.'), 1, 50) as Product_Description,Product_MarketPrice  from ProductDisplay ORDER BY Product_RegDate desc"
                    If Not IsNothing(Session("dt")) Then
                        pdt = Session("dt")
                        DataList1.DataSource = pdt
                        DataList1.DataBind()
                    Else
                        ' str = "SELECT Product_Information.Product_Kid, Product_Information.Product_Code, Product_Information.Product_Name, Product_Information.Product_ModelNo, Product_Information.Product_AtcoPrice, Product_Information.Brand_Name, Product_Information.Product_Image, Product_Information.Product_BrandId, Product_Information.Product_Approved, SUBSTRING(ISNULL(Product_Information.Product_Description, N'N.A.'), 1, 100) + '' + SUBSTRING(ISNULL(Product_Information.Product_Description, N'N.A.'), 101, CHARINDEX('.', SUBSTRING(ISNULL(Product_Information.Product_Description, N'N.A.'), 101, 400))) AS Product_Description, REPLACE(REPLACE(REPLACE(LOWER(RTRIM(LTRIM(Category_Master.Category_Name))), ' ', '-'), '  ', '-'), '&', '-') AS CatName, REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(RTRIM(LTRIM(Product_Information.Product_Name))), ' ', '-'), '  ', '-'), '&', '-'),'/','-'),'\','-') AS ProdName, Product_Information.Product_CategoryId FROM Product_Information INNER JOIN Category_Master ON Product_Information.Product_CategoryId = Category_Master.Category_Kid WHERE     (Product_Information.Product_Approved = 'Y') AND (Product_Information.Product_Code='ABT001')" ','ABT002'))" 'AHP006', 'AJP001'))"
                        'TOP (2) Product_Kid,Product_Master.Product_Name, Product_Master.Product_BrandId, Brand_Master.Brand_Name, Product_Master.Product_Image FROM  Product_Master INNER JOIN  Brand_Master ON Product_Master.Product_BrandId = Brand_Master.Brand_Kid  where Product_Master.Product_Approved='Y' and Product_Master.Product_Isdeleted='0'     ORDER BY Product_Master.Product_RegDate desc"
                        rcon.Open()
                        Dim pdadtr As New SqlDataAdapter(str, rcon)
                        pdadtr.Fill(pdt)
                        Session("dt") = pdt
                        DataList1.DataSource = pdt
                        DataList1.DataBind()
                    End If
                    rcon.Close()
                End If
            Catch ex As Exception

            End Try
        End If
    End Sub

    Public Sub fillArticle()
        Dim dt As DataTable
        dt = ReturnDataTable("Select top(3) * from ArticleTitle order by Article_PublishDate desc")
        Dim i As Integer
        Dim count As Integer
        count = 0
        For i = 0 To dt.Rows.Count - 1
            Dim h1, h2 As HyperLink
            count = count + 1
            h1 = CType(Me.FindControl("HyperLink" & count), HyperLink)
            count = count + 1
            h2 = CType(Me.FindControl("HyperLink" & count), HyperLink)
            h1.Text = dt.Rows(i).Item("Article_Title").ToString
            h1.NavigateUrl = ResolveUrl("~/article/" & EncodeURL(dt.Rows(i).Item("Article_Kid")) & "/content/" & dt.Rows(i).Item("CategoryName").ToString & "/" & dt.Rows(i).Item("ArticleTitle").ToString & ".aspx")
            h2.Text = "More >>"
            'Dim strCategoryID
            h2.NavigateUrl = ResolveUrl("~/article/" & EncodeURL(dt.Rows(i).Item("Category_Kid").ToString) & "/category/" & dt.Rows(i).Item("CategoryName").ToString & ".aspx")

            'http://localhost:1332/Atco-2008/article/48484848488458/category/weighing-scales-systems.aspx
            '            hl.NavigateUrl = Page.ResolveUrl("~/article/" & EncodeURL(dt.Rows(0).Item("Article_Kid").ToString) & "/content/" & dt.Rows(0).Item("CategoryName").ToString & "/" & dt.Rows(0).Item("ArticleTitle").ToString & ".aspx")


        Next


    End Sub

    Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim str As String
        Dim lnk As LinkButton
        lnk = CType(sender, LinkButton)
        str = lnk.CommandArgument
        Dim Wishtabel As New DataTable
        Wishtabel.Columns.Add("ProductId")
        If Session("BuyId") = Nothing Then
            Dim wsrow As DataRow = Wishtabel.NewRow
            wsrow("ProductId") = str
            Wishtabel.Rows.Add(wsrow)
            Session("WishTabel") = Nothing
            Session("WishTabel") = Wishtabel
            Session("Checkstatus") = "WishLsit"
            Response.Redirect("~/Buyer/buyer-home.aspx")
        Else
            WishListProcedure("Insert", str)
            Response.Redirect("~/Buyer/WishList.aspx")
        End If
    End Sub

    Protected Sub WishListProcedure(ByVal StrMode As String, ByVal prodid As String)
        Try
            Dim wishlistid As String = NewPrimaryKey(Me.Page)
            wishlistid = RemoveLiterals(wishlistid)
            Dim wishlistCode As String = Generate_Code("select count(*) from AddWishList where AddWishList_Code='", "WL")
            Dim con As New SqlConnection                        'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            Dim cmd As New SqlCommand
            con.Open()
            Dim str As String = "select AddWishList_Code from AddWishList where AddWishList_ProductId='" & prodid & "' and AddWishList_BuyerUserId='" & Session("BuyId") & "'"
            Dim da As New SqlDataAdapter(str, con)
            Dim ds As New DataSet
            da.Fill(ds)
            If ds.Tables(0).Rows.Count > 0 Then

            Else
                Dim sqlcol As Data.SqlClient.SqlParameterCollection = cmd.Parameters
                sqlcol.Add("@AddWishList_Kid", SqlDbType.NVarChar, 10).Value = wishlistid.Trim
                sqlcol.Add("@AddWishList_Code", SqlDbType.NVarChar, 25).Value = wishlistCode.Trim
                sqlcol.Add("@AddWishList_ProductId", SqlDbType.NVarChar, 10).Value = prodid
                sqlcol.Add("@AddWishList_BuyerUserId", SqlDbType.NVarChar, 25).Value = Session("BuyId")
                sqlcol.Add("@AddWishList_FinancialYearId", SqlDbType.NVarChar, 10).Value = "2007"
                sqlcol.Add("@AddWishList_CompanyId", SqlDbType.NVarChar, 10).Value = Session("companyId")
                sqlcol.Add("@AddWishList_UserId", SqlDbType.NVarChar, 10).Value = Session("UserId")
                sqlcol.Add("@FormName", SqlDbType.NVarChar, 50).Value = Me.Page.ToString
                sqlcol.Add("@Mode", SqlDbType.VarChar, 10).Value = StrMode.Trim
                ExecQuery("AddWishList_Proc", sqlcol).StartsWith("True")
                sqlcol = Nothing
                cmd = Nothing
                ' Dim gvRow As GridViewRow
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class