Imports System.Data
Imports System.Data.SqlClient
Partial Class ProductDisplay_Buyer
    Inherits System.Web.UI.UserControl
    Dim cmd As New SqlCommand
    Dim cmd1 As New SqlCommand
    Dim dr As SqlDataReader
    Dim CatSearch As String
    Dim prodid As String
    Dim catid As String
    Dim strr As String
    Dim searchopt As String
    Dim keyval As Integer
    Dim BrandId As String
    Shared prodkey As String
    Shared searchkey As String
    Dim da As SqlDataAdapter
    Dim da1 As SqlDataAdapter
    Dim ds As New DataSet
    Dim ds1 As New DataSet
    Shared val1 As String
    Shared val2 As String
    Shared val3 As String
    Shared flag As Boolean
    Dim total As Integer = 0

    Dim dtCategoryDistinct As DataTable


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try

            If Not IsPostBack Then

                '' Session Form ProductDetail Control by Kalpesh Patel
                If Session("backcatid") <> Nothing Then '' Session For ProductDisplay Control by Kalpesh Patel
                    catid = Session("backcatid")
                    Session("catid") = catid
                ElseIf Request.QueryString("Product_Id") <> Nothing Then
                    catid = DecodeURL(Request.QueryString("Product_Id").ToString)
                    Session("catid") = catid
                End If
                '' Session Form ProductDetail Control by Kalpesh Patel 30.10.2007

                ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                CatSearch = Request.QueryString("Prod_Kid") 'Search from Category Wise(Search Product.Aspx)
                'catid = Request.QueryString("Product_Id") 'Search from Category Wise(Home Page)
                prodid = Request.QueryString("Product_KId") 'Search from Product Name(Home Page) 

                keyval = Request.QueryString("Value") 'Search Box
                searchopt = Request.QueryString("key") 'Search Box
                'prodid = Request.QueryString("Product_Id")
                GVProdDisplay.Visible = False
                btnCompare.Visible = False
                lbtnAddtocart.Visible = False
                lbtnAddtoWiseList.Visible = False
                ItemFound.Visible = False
                Label1.Visible = False
                'Label2.Visible = False
                tdURL.Visible = False
                Label3.Visible = False
                lnkInquiry.Visible = False
                'hiren
                If IsNothing(CatDistinct) Then
                    GetCatDistinct()
                End If
                dtCategoryDistinct = CatDistinct
                ''
                ItemMinMax.Visible = False
                If Not IsPostBack Then

                    If Not catid = Nothing Then
                        Session("catid") = catid
                        CategorySelectedInfo(catid)
                    End If
                    If Not CatSearch = Nothing Then
                        Session("catid") = CatSearch
                        CategorySelectedInfo(CatSearch)
                    End If
                    If Not prodid = Nothing Then
                        Session("catid") = prodid
                        productinfo()
                        fillURL(CType(Session("Product_buyer"), DataTable).Rows(0)("Product_CategoryId").ToString)
                    End If
                    If Not Request.QueryString("Brand_KId") = Nothing Then
                        BrandId = DecodeURL(Request.QueryString("Brand_KId").ToString) 'Search from Brand Name (Home Page)
                        Session("brandid") = BrandId
                        BrandSelectedInfo()
                    End If
                    If Not searchopt = Nothing Then
                        search_product()
                    End If

                    If Label1.Visible = False Then
                        lnkInquiry.Visible = False
                    Else
                        lnkInquiry.Visible = True
                    End If
                    For Each row As GridViewRow In GVProdDisplay.Rows
                        Dim id As String = GVProdDisplay.DataKeys(row.RowIndex).Value
                        Dim lnk As LinkButton = CType(row.Cells(6).FindControl("lnkprice"), LinkButton)
                        ''  lnk.Attributes.Add("onclick", "return openform('" & id & "');")
                        CType(row.Cells(6).FindControl("lnkprice"), LinkButton).Attributes.Add("onclick", "return openform('" & EncodeURL(id) & "');")
                    Next







                End If
                If Label1.Visible = True Then
                    lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
                End If
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    Private Sub CategorySelectedInfo(ByVal strid As String)
        Try
            'CatSearch = Request.QueryString("Prod_Kid")
            'catid = Request.QueryString("Product_Id")
            Dim strProductName As String
            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            'cmd = New SqlCommand("SELECT * from Product_Information where Product_Approved='Y'and Product_CategoryId='" & strid & "'", con)
            cmd = New SqlCommand("SELECT * from ProductDisplay where Product_Approved='Y'and Product_CategoryId='" & strid & "'", con)
            con.Open()
            da = New SqlDataAdapter(cmd)
            If Not da.Fill(ds, "Product_M") = Nothing Then

                GVProdDisplay.Visible = True
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ''  lbtnAddtocart.Visible = True
                ItemFound.Visible = True
                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & strid & "'")
                'strProductName = strProductName.Remove(0, 1)
                'strProductName = strProductName.Remove(strProductName.Length - 1)
                ItemFound.Text = ds.Tables(0).Rows.Count & " Item(s) Found in  " & strProductName & " Category."

                GVProdDisplay.DataSource = ds.Tables("Product_M")
                GVProdDisplay.DataBind()
                Label1.Visible = False
                tdURL.Visible = True
                Label3.Visible = True
                'Label2.Visible = True
                con.Close()
                Session("backcatid") = Nothing
                Dim count As Integer
                For count = 0 To GVProdDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = ResolveUrl(Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds.Tables("Product_M").Rows(count).Item("Product_Image").ToString()))
                    CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds.Tables("Product_M").Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next
            Else
                Session("sub2catid") = Nothing
                Session("sub2catid") = strid
                strProductName = ReturnValue("SELECT     Category_Name         FROM Category_Master  WHERE     Category_Kid ='" & strid & "'")
                GVProdDisplay.Visible = False
                ''Label2.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for <b> " & strProductName & " </b> category ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                ItemFound.Visible = False
                btnCompare.Visible = False
                tdURL.Visible = False
                Label3.Visible = False
                lbtnAddtoWiseList.Visible = False
                lbtnAddtocart.Visible = False
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    Private Sub productinfo()
        Try
            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            'cmd = New SqlCommand("SELECT *from Product_Information where Product_KId=" & prodid & "", con)
            cmd = New SqlCommand("SELECT * from ProductDisplay where Product_Approved='Y' and  Product_name=" & prodid, con)
            Dim str As String = "SELECT * from ProductDisplay where Product_Approved='Y' and  Product_name=" & prodid
            con.Open()
            da = New SqlDataAdapter(cmd)
            da.Fill(ds, "Product_Mast")
            If ds.Tables(0).Rows.Count > 0 Then
                ItemFound.Visible = True
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ''   lbtnAddtocart.Visible = True
                GVProdDisplay.Visible = True
                Dim i As String = prodid
                Dim strProductName As String = ReturnValue("SELECT DISTINCT Product_Name FROM Product_Master WHERE Product_Name =" & prodid & "")
                prodid = prodid.Remove(0, 1)
                prodid = prodid.Remove(prodid.Length - 1)
                ItemFound.Text = ds.Tables(0).Rows.Count & " Item(s) Found for " & prodid & "."
                GVProdDisplay.DataSource = ds.Tables("Product_Mast")
                GVProdDisplay.DataBind()

                'hiren-03-10
                Dim con1 As New SqlConnection
                con1.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                cmd1 = New SqlCommand("select ProductDisplay.* from ProductDisplay where (ProductDisplay.Product_Name LIKE '%" & strProductName.Trim.Replace("'", "") & "%') order by Product_Name", con1)
                con1.Open()
                da1 = New SqlDataAdapter(cmd1)
                da1.Fill(ds, "Product_Mast")
                Session("Product_buyer") = ds.Tables("Product_Mast")
                '
                Dim count As Integer
                For count = 0 To GVProdDisplay.Rows.Count - 1
                    Dim imgpath As String
                    imgpath = ResolveUrl(Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds.Tables("Product_Mast").Rows(count).Item("Product_Image").ToString()))
                    CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds.Tables("Product_Mast").Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)
                Next

                Label1.Visible = False
                tdURL.Visible = True
                Label3.Visible = True
                ''Label2.Visible = True
                Session("backcatid") = Nothing
            Else

                ItemFound.Visible = False
                ItemFound.Text = ""
                btnCompare.Visible = False
                lbtnAddtoWiseList.Visible = False
                lbtnAddtocart.Visible = False
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for <b> " & prodid & " </b> search ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                lnkInquiry.Visible = True
                Label1.Visible = True
                tdURL.Visible = False
                Label3.Visible = False
                ''Label2.Visible = False
            End If
            con.Close()
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    Private Sub BrandSelectedInfo()
        Try
            BrandId = DecodeURL(Request.QueryString("Brand_KId"))
            Dim brandname As String
            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            cmd = New SqlCommand("SELECT * from ProductDisplay where Product_Approved='Y' and Product_BrandId='" & BrandId & "'", con)
            Dim da As New SqlDataAdapter(cmd)
            'dr = cmd.ExecuteReader
            Dim ds As New DataSet
            da.Fill(ds, "BrandInfo")
            If ds.Tables(0).Rows.Count > 0 Then
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ''  lbtnAddtocart.Visible = True
                GVProdDisplay.Visible = True
                ItemFound.Visible = True
                brandname = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                'brandname = brandname.Remove(0, 1)
                'brandname = brandname.Remove(brandname.Length - 1)
                ItemFound.Text = ds.Tables(0).Rows.Count & " Item(s) Found in " & brandname & " Brand."
                GVProdDisplay.DataSource = ds
                GVProdDisplay.DataBind()
                Dim count As Integer
                For count = 0 To GVProdDisplay.Rows.Count - 1
                    Dim imgpath As String

                    CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds.Tables("BrandInfo").Rows(count).Item("Product_Image").ToString())
                    imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds.Tables("BrandInfo").Rows(count).Item("Product_Image").ToString())
                    KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)


                Next

                Label1.Visible = False
                tdURL.Visible = True
                Label3.Visible = True
                ''Label2.Visible = True
                Session("backcatid") = Nothing
            Else
                Session("brandid") = Nothing
                Session("brandid") = BrandId
                brandname = ReturnValue("SELECT    Brand_Name    FROM Brand_Master WHERE     Brand_Kid ='" & BrandId & "'")
                ItemFound.Visible = False
                ItemFound.Text = ""
                btnCompare.Visible = False
                lbtnAddtoWiseList.Visible = False
                lbtnAddtocart.Visible = False
                tdURL.Visible = False
                Label3.Visible = False
                Label1.Visible = True
                Label4.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for  <b>" & brandname & "</b>   brand ! and will be up soon...<br />please Fill Up Your&nbsp; <strong>inquiry</strong>..."
                ''Label2.Visible = False
            End If
            con.Close()
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    ''Private Sub productBrandinfo()
    ''    Try
    ''        Dim con As New SqlConnection
    ''        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    ''        cmd = New SqlCommand("SELECT *from Product_Master where Product_BrandId=" & BrandId, con)
    ''        con.Open()
    ''        da = New SqlDataAdapter(cmd)
    ''        da.Fill(ds, "Product_Master")
    ''        GVProdDisplay.DataSource = ds
    ''        GVProdDisplay.DataBind()
    ''        con.Close()
    ''    Catch ex As Exception
    ''        ex.Message.ToString()
    ''    End Try
    ''End Sub

    Private Sub search_product()
        Try
            If keyval = 0 Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                prodkey = "select Keyword_ProductId from Product_Keyword where Keyword_Name='" & searchopt & "'"
                cmd = New SqlCommand(prodkey, con)
                con.Open()
                dr = cmd.ExecuteReader
                If dr.Read Then
                    searchkey = dr(0)
                End If
                con.Close()
                dr.Close()
                If con.State = ConnectionState.Open Then
                    con.Close()
                End If
                strr = "select * from ProductDisplay where Product_Approved='Y' and product_kid='" & searchkey & "'"
                cmd = New SqlCommand(strr, con)
                ' con.Open()
                ' dr = cmd.ExecuteReader
                Dim da As New SqlDataAdapter(cmd)
                Dim ds As New DataSet
                If Not da.Fill(ds, "Info") = Nothing Then
                    GVProdDisplay.Visible = True
                    btnCompare.Visible = True
                    lbtnAddtoWiseList.Visible = True
                    ''   lbtnAddtocart.Visible = True
                    ItemFound.Visible = True
                    ItemFound.Text = ds.Tables(0).Rows.Count & " Item(s) Found for " & searchopt & " Keyword."
                    GVProdDisplay.DataSource = ds
                    GVProdDisplay.DataBind()
                    Dim count As Integer
                    For count = 0 To GVProdDisplay.Rows.Count - 1
                        Dim imgpath As String

                        CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds.Tables(0).Rows(count).Item("Product_Image").ToString())
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds.Tables(0).Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)


                    Next
                    Label1.Visible = False
                    tdURL.Visible = True
                    Label3.Visible = True
                    ''Label2.Visible = True
                    Session("backcatid") = Nothing
                    'con.Close()
                Else
                    Label1.Visible = True
                    ItemFound.Visible = False
                    ItemFound.Text = ""
                    btnCompare.Visible = False
                    lbtnAddtoWiseList.Visible = False
                    lbtnAddtocart.Visible = False
                    tdURL.Visible = False
                    Label3.Visible = False
                    ''Label2.Visible = False
                End If
            ElseIf keyval = 1 Then
                strr = "select *from ProductDisplay where Product_Approved='Y' and product_ModelNo like '%" & searchopt & "%'"
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                cmd = New SqlCommand(strr, con)
                'con.Open()
                'dr = cmd.ExecuteReader
                Dim da1 As New SqlDataAdapter(cmd)
                Dim ds1 As New DataSet
                If Not da1.Fill(ds1, "info1") = Nothing Then
                    GVProdDisplay.DataSource = ds1
                    GVProdDisplay.DataBind()
                    Dim count As Integer
                    For count = 0 To GVProdDisplay.Rows.Count - 1
                        Dim imgpath As String

                        CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds1.Tables(0).Rows(count).Item("Product_Image").ToString())
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds1.Tables(0).Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)


                    Next
                    Label1.Visible = False
                    tdURL.Visible = True
                    Label3.Visible = True
                    'Label2.Visible = True
                    'con.Close()
                Else
                    Label1.Visible = True
                    tdURL.Visible = False
                    Label3.Visible = False
                    'Label2.Visible = False
                End If
            ElseIf keyval = 2 Then
                ' strr = "select *from product_information where product_Code like '%" & searchopt & "%'"
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                cmd = New SqlCommand("select * from ProductDisplay where Product_Approved='Y' and product_Code like '%" & searchopt & "%'", con)
                con.Open()
                'dr = cmd.ExecuteReader
                Dim da2 As New SqlDataAdapter(cmd)
                Dim ds2 As New DataSet
                If Not da2.Fill(ds2, "info2") = Nothing Then
                    GVProdDisplay.DataSource = ds2
                    GVProdDisplay.DataBind()
                    Dim count As Integer
                    For count = 0 To GVProdDisplay.Rows.Count - 1
                        Dim imgpath As String

                        CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds2.Tables(0).Rows(count).Item("Product_Image").ToString())
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds2.Tables(0).Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)


                    Next
                    'Label2.Visible = True
                    Label1.Visible = False
                    'con.Close()
                Else
                    'Label2.Visible = False
                    Label1.Visible = True
                End If
            ElseIf keyval = 3 Then
                strr = "select *from ProductDisplay where Product_Approved='Y' and brand_name like '%" & searchopt & "%'"
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                cmd = New SqlCommand(strr, con)
                'con.Open()
                'dr = cmd.ExecuteReader
                Dim da3 As New SqlDataAdapter(cmd)
                Dim ds3 As New DataSet
                If Not da3.Fill(ds3, "info3") = Nothing Then
                    ItemFound.Visible = True
                    ItemFound.Text = ds3.Tables(0).Rows.Count & " Item(s) Found in " & searchopt & " Brand."

                    GVProdDisplay.DataSource = ds3
                    GVProdDisplay.DataBind()
                    Dim count As Integer
                    For count = 0 To GVProdDisplay.Rows.Count - 1
                        Dim imgpath As String

                        CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image).ImageUrl = ResolveUrl("~/Upload Image/Product Image/UploadImages/" & ds3.Tables(0).Rows(count).Item("Product_Image").ToString())
                        imgpath = Server.MapPath("~/Upload Image/Product Image/UploadImages/" & ds3.Tables(0).Rows(count).Item("Product_Image").ToString())
                        KeepAspectRatioNew(CType(GVProdDisplay.Rows(count).Cells(1).FindControl("Imgbtn"), Image), imgpath, 100, 100)


                    Next
                    'Label2.Visible = True
                    Label1.Visible = False
                    con.Close()
                Else
                    ItemFound.Visible = False
                    'Label2.Visible = False
                    Label1.Visible = True
                End If
            End If
            GVProdDisplay.Visible = True
            btnCompare.Visible = True
            lbtnAddtoWiseList.Visible = True
            ''    lbtnAddtocart.Visible = True
            ItemFound.Visible = True

        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    Protected Sub lnkbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim i As New LinkButton()
            i = CType(sender, LinkButton)
            Dim intId As String = i.CommandArgument
            createheaderlabel(intId)
            Session("backcatid") = Nothing   '' Session Form ProductDetail Control by Kalpesh Patel
            If Session("ID") = "Buyer" Then
                Page_Load(sender, e)
                btnCompare.Visible = True
                lbtnAddtoWiseList.Visible = True
                ''   lbtnAddtocart.Visible = True
                GVProdDisplay.Visible = True
                'Label2.Visible = True
                Label1.Visible = False
                ' Exit Sub
            Else
                Response.Redirect("SearchProductDetails.aspx?ProductCode=" & intId)
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    
    Protected Sub GVProdDisplay_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GVProdDisplay.PageIndexChanging
        Try
            GVProdDisplay.PageIndex = e.NewPageIndex
            If Not CatSearch = Nothing Then
                CategorySelectedInfo(CatSearch)
            End If
            If Not prodid = Nothing Then
                productinfo()
            End If
            If Not BrandId = Nothing Then
                BrandSelectedInfo()
            End If
            If Not searchopt = Nothing Then
                search_product()
            End If
            If Not Session("catid") = Nothing Then
                CategorySelectedInfo(Session("catid"))
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    Protected Sub createheaderlabel(ByVal prodid As String)
        Try
            Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
            Dim str As String = "SELECT     Category_Master.Category_Kid, Category_Master.Category_Name FROM         ProductDisplay INNER JOIN                     Category_Master ON ProductDisplay.Product_CategoryId = Category_Master.Category_Kid WHERE     ProductDisplay.Product_Kid = '" & prodid & "' AND (Category_Master.Category_IsDeleted = N'0')"
            Dim ds As New DataSet
            Dim sda As New SqlDataAdapter(str, con)
            sda.Fill(ds)
            Dim lblhead As String
            Dim parent As String = ds.Tables(0).Rows(0)(1).ToString()

            lblhead = parent & " -"
            While parent <> "Root Category"
                parent = ReturnValue("SELECT     Category_Master.Category_Name AS Expr2 FROM         Category_Master INNER JOIN                    Category_Master AS Category_Master_1 ON Category_Master.Category_Kid = Category_Master_1.Category_ParentId WHERE     (Category_Master.Category_IsDeleted = N'0') AND (Category_Master.Category_IsDeleted = N'0') AND Category_Master_1.Category_Name = '" & parent & "'")
                If parent = "" Then
                    Exit While
                End If
                lblhead = parent & " -" & lblhead
            End While
            Session("HLabel") = lblhead
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

   

    Protected Sub btnCompare_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            GVProdDisplay.Visible = True
            btnCompare.Visible = True
            ItemFound.Visible = True
            lbtnAddtoWiseList.Visible = True
            '' lbtnAddtocart.Visible = True

            Dim hashData As New Hashtable
            Dim i As Integer
            Dim j As Integer = 0
            For i = 0 To GVProdDisplay.Rows.Count - 1
                If CType(GVProdDisplay.Rows(i).FindControl("CheckBox2"), CheckBox).Checked = True Then
                    hashData.Add("ItemMaxMin" & j, GVProdDisplay.DataKeys(i).Value)
                    j += 1
                End If
            Next
            Session("ItemMaxMin") = hashData
            Session("ItemCount") = j
            If j < 2 Or j > 3 Then
                ItemMinMax.Visible = True
                ItemMinMax.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "' />  Please Select Minimum Two Products/Maximum Three Products."
                ''Label2.Visible = False
            Else
                ItemMinMax.Text = ""
                ItemMinMax.Visible = False
                Response.Redirect("~/Buyer/buyer_compare.aspx")
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    Protected Sub lbtnAddtocart_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            GVProdDisplay.Visible = True
            btnCompare.Visible = True
            ItemFound.Visible = True
            lbtnAddtoWiseList.Visible = True
            ''   lbtnAddtocart.Visible = True
            Dim hashData As New Hashtable
            Dim gvRow As GridViewRow
            Dim chk As New CheckBox
            Dim i As Integer
            Dim j As Integer = 0
            For i = 0 To GVProdDisplay.Rows.Count - 1
                If CType(GVProdDisplay.Rows(i).FindControl("CheckBox2"), CheckBox).Checked = True Then
                    hashData.Add("ItemMaxMin" & j, GVProdDisplay.DataKeys(i).Value)
                    j += 1
                End If
            Next
            Session("ItemMaxMin") = hashData
            If j < 1 Then
                ItemMinMax.Visible = True
                ItemMinMax.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "' />  Please select minimum One  Product."
            Else
                Dim shoptabel As New DataTable
                shoptabel.Columns.Add("ProductId")

                If Session("BuyId") = Nothing Then
                    'If Session("ID") = "Buyer" Then
                    For Each gvRow In GVProdDisplay.Rows
                        If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
                            Dim shrow As DataRow = shoptabel.NewRow

                            shrow("ProductId") = CType(gvRow.FindControl("Imgbtn"), ImageButton).CommandArgument
                            shoptabel.Rows.Add(shrow)
                        End If
                    Next
                    Session("Checkstatus") = "ShopCart"
                    Session("ShopTabel") = shoptabel
                    ItemMinMax.Text = ""
                    ItemMinMax.Visible = False
                    Response.Redirect("~/Buyer/BuyerLogin.aspx")

                    ' 'Label2.Text = Convert.ToString(total) & "items added to the shopping cart"


                    'Response.Redirect("~/Buyer/newBuyerSearch.aspx")
                Else
                    For Each gvRow In GVProdDisplay.Rows
                        If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
                            If ShopCartProcedure("Insert", gvRow) = True Then
                                total = total + 1
                            End If
                        End If
                    Next
                    Response.Redirect("~/Buyer/ShopCart.aspx")
                End If
            End If
            'End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    Protected Sub lbtnAddtoWiseList_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            GVProdDisplay.Visible = True
            btnCompare.Visible = True
            ItemFound.Visible = True
            lbtnAddtoWiseList.Visible = True
            ''    lbtnAddtocart.Visible = True
            Dim gvRow As GridViewRow

            Dim hashData As New Hashtable
            Dim i As Integer
            Dim j As Integer = 0
            For i = 0 To GVProdDisplay.Rows.Count - 1
                If CType(GVProdDisplay.Rows(i).FindControl("CheckBox2"), CheckBox).Checked = True Then
                    hashData.Add("ItemMaxMin" & j, GVProdDisplay.DataKeys(i).Value)
                    j += 1
                End If
            Next
            Session("ItemMaxMin") = hashData
            Session("ItemMaxMin") = hashData
            If j < 1 Then
                ItemMinMax.Visible = True
                ItemMinMax.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "' /> Please select minimum One  Product."
            Else

                Dim Wishtabel As New DataTable
                Wishtabel.Columns.Add("ProductId")

                If Session("BuyId") = Nothing Then
                    'If Session("ID") = "Buyer" Then
                    For Each gvRow In GVProdDisplay.Rows
                        If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
                            Dim wsrow As DataRow = Wishtabel.NewRow
                            wsrow("ProductId") = CType(gvRow.FindControl("Imgbtn"), ImageButton).CommandArgument
                            Wishtabel.Rows.Add(wsrow)
                        End If
                    Next
                    Session("WishTabel") = Wishtabel
                    Session("Checkstatus") = "WishLsit"
                    ItemMinMax.Text = ""
                    ItemMinMax.Visible = False
                    Response.Redirect("~/Buyer/BuyerLogin.aspx")

                Else

                    For Each gvRow In GVProdDisplay.Rows
                        If CType(gvRow.FindControl("CheckBox2"), CheckBox).Checked = True Then
                            If WishListProcedure("Insert", gvRow) = True Then
                                total = total + 1
                            End If

                        End If
                    Next

                    Response.Redirect("~/Buyer/WishList.aspx")

                End If
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    Protected Function ShopCartProcedure(ByVal StrMode As String, ByVal GridViewRow As GridViewRow) As Boolean
        Try
            Dim shopid As String = NewPrimaryKey(Me.Page)
            shopid = RemoveLiterals(shopid)
            Dim shopCode As String = Generate_Code("select count(*) from ShopCart where ShopCart_Code='", "SC")
            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 sqlcol As Data.SqlClient.SqlParameterCollection = cmd.Parameters
            sqlcol.Add("@ShopCart_Kid", SqlDbType.NVarChar, 10).Value = shopid.Trim
            sqlcol.Add("@ShopCart_Code", SqlDbType.NVarChar, 25).Value = shopCode.Trim
            sqlcol.Add("@ShopCart_ProductId", SqlDbType.NVarChar, 10).Value = CType(GridViewRow.FindControl("Imgbtn"), ImageButton).CommandArgument
            sqlcol.Add("@ShopCart_BuyerUserId", SqlDbType.NVarChar, 25).Value = Session("BuyId")
            sqlcol.Add("@ShopCart_Quantity", SqlDbType.Int).Value = 1
            sqlcol.Add("@ShopCart_SpecialPrice", SqlDbType.Decimal, 18).Value = CType(GridViewRow.FindControl("lblprice"), Label).Text
            sqlcol.Add("@ShopCart_FinancialYearId", SqlDbType.NVarChar, 10).Value = "2007"
            sqlcol.Add("@ShopCart_CompanyId", SqlDbType.NVarChar, 10).Value = Session("companyId")
            sqlcol.Add("@ShopCart_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("ShopCart_Proc", sqlcol).StartsWith("True")
            sqlcol = Nothing
            cmd = Nothing
            Return True
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Function

    Protected Function WishListProcedure(ByVal StrMode As String, ByVal GridViewRow As GridViewRow) As Boolean
        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='" & CType(GridViewRow.FindControl("Imgbtn"), ImageButton).CommandArgument & "' 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
                Return False
            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 = CType(GridViewRow.FindControl("Imgbtn"), ImageButton).CommandArgument
                sqlcol.Add("@AddWishList_BuyerUserId", SqlDbType.NVarChar, 25).Value = Session("BuyId")
                sqlcol.Add("@AddWishList_FinancialYearId", SqlDbType.NVarChar, 10).Value = "2008"
                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
                Return True
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Function

    'Protected Sub lnkprice_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    '    Try
    '        Dim lnk As LinkButton = CType(sender, LinkButton)
    '        Session("ProductCode") = RemoveLiterals(lnk.CommandArgument)
    '    Catch ex As Exception

    '    End Try
    'End Sub

    Protected Sub GVProdDisplay_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVProdDisplay.RowDataBound
        Try

            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim lblprice As Label = CType(e.Row.Cells(6).FindControl("lblprice"), Label)
                Dim lnkprice As LinkButton = CType(e.Row.Cells(6).FindControl("lnkprice"), LinkButton)

                'CType(e.Row.Cells(1).FindControl("Imgbtn"), Image).Attributes.Add("onmouseover", "enlargimg(this,event,'" & Panel1.ClientID.ToString & "');")
                'CType(e.Row.Cells(1).FindControl("Imgbtn"), Image).Attributes.Add("onmouseout", "enlargimgout(this,'" & Panel1.ClientID.ToString & "');")

                CType(e.Row.FindControl("CheckBox2"), CheckBox).Attributes.Add("onclick", "return CheckOnOff(this);")

                If Convert.ToDouble(lblprice.Text.Trim) = 0 Then
                    lblprice.Visible = False
                    lnkprice.Visible = True
                Else
                    lblprice.Visible = True
                    lnkprice.Visible = False
                End If
            End If
            If e.Row.RowType = DataControlRowType.Header Then
                CType(e.Row.FindControl("CheckBox1"), CheckBox).Attributes.Add("onclick", "return FindCheckBox(this);")
            End If
            If e.Row.RowType <> DataControlRowType.Header Then
                If e.Row.RowState = DataControlRowState.Normal Then
                    e.Row.BackColor = Drawing.Color.White
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#B7CBE3'")
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
                End If
            End If
            If e.Row.RowState = DataControlRowState.Alternate Then
                Dim c As Drawing.Color
                c = Drawing.Color.FromArgb(230, 239, 246)
                e.Row.BackColor = c
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#B7CBE3'")
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E6EFF6'")
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
       
    End Sub


    Public Sub fillURL(ByVal Cat_KID As String)
        Try
            Dim dr() As DataRow
            dr = dtCategoryDistinct.Select("Category_KId='" & Cat_KID & "'")
            Dim url As String
            url = ""
            If dr.Length = 0 Then
                tdURL.Text += RemoveLiterals(Cat_KID.ToString) + ReturnValue("Select Category_Name from Category_Distinct where Category_KId ='" & RemoveLiterals(Cat_KID.ToString) & "'")
                Session("MainCat") = RemoveLiterals(Cat_KID.ToString)
                Exit Sub
            Else
                Dim dr1() As DataRow
                dr1 = dr
                While dr1.Length <> 0
                  