﻿Imports System
Imports System.Data
Imports System.Data.SqlClient

Partial Class bearings_and_blocks
    Inherits System.Web.UI.Page
    Dim dtCategoryDistinct As DataTable
    Dim strCategory_Name As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'lblMSG.Visible = False
        If Not IsPostBack Then

            If IsNothing(CatDistinct) Then
                GetCatDistinct()
            End If
            dtCategoryDistinct = CatDistinct

            If Request.QueryString("Product_CategoryId") <> Nothing Then
                strCategory_Name = ReturnValue("Select Category_Name from Category_Master where Category_KId='" & RemoveLiterals(DecodeURL(Request.QueryString("Product_CategoryId").ToString)) & "'")
                ' ''CategorySelectedInfo(DecodeURL(Request.QueryString("Product_CategoryId")))
                getbearingsproducts(DecodeURL(Request.QueryString("Product_CategoryId")))
                'strTitle = ""
                fillURL(DecodeURL(Request.QueryString("Product_CategoryId")))
                'Dim str As String()
                'str = FgenerateTags((RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))), "")
                'Dim strTitle A
                'strTitle = StrConv(Str(0), VbStrConv.ProperCase)
                'Dim strCatName As String = ""
                'Dim strCatID As String = RemoveLiterals(DecodeURL(Request.QueryString("Product_CategoryId").ToString))
                'While strCatName <> "Root Category"
                '    strCatName += ReturnValue("Select Category_Name from Category_Master where Category_KId='" & RemoveLiterals(DecodeURL(Request.QueryString("Product_CategoryId").ToString)) & "'")
                'End While
                Dim strTitle As String = ""
                strTitle = getTitle(DecodeURL(Request.QueryString("Product_CategoryId")))
                Me.Header.Title = strTitle '& " - Atcomaart Industrial Supply"

                Dim mt1 As New HtmlMeta
                mt1.Name = "description"
                mt1.Content = "Bearings and Blocks are essential parts for industrial and business units and Atcomaart is a leading provider of bearings and blocks, Collar Bearings, Pillow block bearings and many more."
                Me.Header.Controls.Add(mt1)

                Dim mt2 As New HtmlMeta
                mt2.Name = "keywords"
                mt2.Content = "Bearings and Blocks, Collar Bearings, Pillow Block Bearings, Ball Bearings, Cylindrical Roller Bearings, Flanged Bearings, Mounted Bearings, Insert Bearings, Linear bearings, Flange Mount Bearing, Industrial  Equipments available at atcomaart.com"
                Me.Header.Controls.Add(mt2)

            End If
        End If
        If Session("catid") = Nothing Then
            Session("catid") = RemoveLiterals(DecodeURL(Request.QueryString("Product_CategoryId")))
        End If

    End Sub

    Public Function getTitle(ByVal Cat_KID As String) As String
        Dim Title As String = ""
        Dim dr() As DataRow
        dr = dtCategoryDistinct.Select("Category_KId='" & Cat_KID & "'")
        While dr.Length <> 0
            Title += dr(0).Item("Category_Name").ToString & "|"
            dr = dtCategoryDistinct.Select("Category_KId='" & dr(0).Item("Category_ParentId").ToString & "'")
        End While
        Dim url1() As String
        url1 = Title.Split("|")
        Array.Reverse(url1)
        Title = "Bearings and Blocks, "
        Dim i As Integer
        For i = 1 To url1.Length - 1
            If i = url1.Length - 1 Then
                Title += url1(i).ToString & " - Atcomaart Industrial Supply"
            Else
                Title += url1(i).ToString & ", "
            End If


        Next


        Return Title
    End Function

    Public Sub getbearingsproducts(ByVal Category_KID As String)
        Dim dtModelNo As DataTable
        dtModelNo = ReturnDataTable("Select distinct Product_ModelNo from Product_Master where Product_CategoryId='" & RemoveLiterals(Category_KID.ToString) & "' and Product_Approved='Y' and Product_Isdeleted='0'")
        If dtModelNo.Rows.Count = 0 Then
            tdMSG.Visible = True
            tdBearings.Visible = False
            lnkInquiry.Attributes.Add("onclick", "return OpenInquery();")
            lblMSG.Text = "<img alt='' src='" & Page.ResolveUrl("~/Images/javascripts.gif") & "'/>&nbsp; We Are registering products for <b> " & strCategory_Name & " </b> category ! and will be up soon...<br /> For more details please Fill Up Your&nbsp; <strong>inquiry</strong>..."
        Else
            tdMSG.Visible = False
            tdBearings.Visible = True
            lblProductName.Text = "<br/>" & strCategory_Name.ToString
            imgProductImage.ImageUrl = Page.ResolveUrl("~/Upload Image/Bearings/" & strCategory_Name.ToString.Replace(" ", "-") & ".jpg")
            imgProductImage.AlternateText = strCategory_Name.ToString
            ddlModelNo.DataSource = dtModelNo
            ddlModelNo.DataTextField = "Product_ModelNo"
            ddlModelNo.DataValueField = "Product_ModelNo"
            ddlModelNo.DataBind()
            ddlModelNo.Items.Insert(0, New ListItem("Select Model No.", "Select"))
            'ddlModelNo.SelectedIndex = 0
            ddlBrand.Items.Insert(0, New ListItem("Select Brand", "Select"))
            btnSearch.Attributes.Add("onclick", "return CheckBearings();")

        End If


    End Sub

    Public Sub fillURL(ByVal Cat_KID As String)

        Dim dr() As DataRow
        dr = dtCategoryDistinct.Select("Category_KId='" & Cat_KID & "'")
        Dim url As String
        url = ""
        If dr.Length = 0 Then
            tdURL.InnerHtml += "<a href='" & ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(Cat_KID.ToString)) & "/" & ReturnValue("Select CategoryName from Category_Distinct where Category_Kid='" & RemoveLiterals(Cat_KID.ToString) & "'") & ".aspx") & "' >" & ReturnValue("Select Category_Name from Category_Distinct where Category_KId ='" & RemoveLiterals(Cat_KID.ToString) & "'") & "</a> > "
            Session("MainCat") = RemoveLiterals(Cat_KID.ToString)
            Exit Sub
        Else
            Dim dr1() As DataRow
            dr1 = dr
            While dr1.Length <> 0
                url += "<a href='" & ResolveUrl("~/JJJ/" & EncodeURL(dr(0).Item("Category_Kid").ToString) & "/" & dr(0).Item("ParentName").ToString & "/" & dr(0).Item("CategoryName").ToString & ".aspx") & "' > " & dr(0).Item("Category_Name").ToString & "</a> > | "
                dr = dtCategoryDistinct.Select("Category_KId='" & dr1(0).Item("Category_ParentId") & "'")
                If dr.Length = 0 Then
                    url += "<a href='" & ResolveUrl("~/main/" & EncodeURL(RemoveLiterals(dr1(0).Item("Category_ParentId"))) & "/" & dr1(0).Item("ParentName").ToString & ".aspx") & "' >" & dr1(0).Item("Category_ParentName").ToString & "</a> > "
                End If
                dr1 = dr
            End While
        End If

        tdURL.InnerHtml = "<a href='http://www.atcomaart.com'> <b>Product Category  </b></a> > <span style='color:#155799'>"
        Dim url1() As String
        url1 = url.Split("|")
        Array.Reverse(url1)

        Dim i As Integer
        For i = 0 To url1.Length - 1
            If i = 0 Then
                tdURL.InnerHtml += url1(0).ToString
                Continue For
            Else

                If i = url1.Length - 1 Then

                    If Request.QueryString("Product_HId") = Nothing Then
                        tdURL.InnerHtml += url1(i).Replace("JJJ", "bearings")
                    Else
                        tdURL.InnerHtml += url1(i).Replace("JJJ", "s" & i + 1)
                    End If
                Else
                    tdURL.InnerHtml += url1(i).Replace("JJJ", "s" & i + 1)
                End If
            End If
        Next
    End Sub

    Protected Sub ddlModelNo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlModelNo.SelectedIndexChanged
        If ddlModelNo.SelectedIndex > 0 Then
            Dim strModelNo As String
            strModelNo = ddlModelNo.SelectedItem.Value.ToString
            Dim dtBrand As DataTable
            dtBrand = ReturnDataTable("SELECT DISTINCT Brand_Master.Brand_Name, Brand_Master.Brand_Kid FROM Product_Master INNER JOIN Brand_Master ON Product_Master.Product_BrandId = Brand_Master.Brand_Kid WHERE     (Product_Master.Product_CategoryId = N'" & RemoveLiterals(DecodeURL(Request.QueryString("Product_CategoryId"))) & "') AND (Product_Master.Product_Approved = N'Y') and Product_ModelNo='" & RemoveLiterals(ddlModelNo.SelectedValue.ToString) & "'")
            ddlBrand.DataSource = dtBrand
            ddlBrand.DataTextField = "Brand_Name"
            ddlBrand.DataValueField = "Brand_Kid"
            ddlBrand.DataBind()
            ddlBrand.Items.Insert(0, New ListItem("Select Brand", "Select"))
        Else
            ddlBrand.Items.Clear()
            ddlBrand.Items.Insert(0, New ListItem("Select Brand", "Select"))
        End If
    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim dt As DataTable
        dt = ReturnDataTable("Select Product_Kid, ProdName, CatName from ProductDisplay where Product_ModelNo='" & RemoveLiterals(ddlModelNo.SelectedValue.ToString) & "'and Product_BrandId ='" & RemoveLiterals(ddlBrand.SelectedItem.Value.ToString) & "' and Product_CategoryId='" & RemoveLiterals(DecodeURL(Request.QueryString("Product_CategoryId"))) & "' ")
        Response.Redirect(Page.ResolveUrl("~/pd/" & EncodeURL(RemoveLiterals(dt.Rows(0).Item("Product_Kid").ToString)) & "/" & dt.Rows(0).Item("CatName").ToString & "/" & dt.Rows(0).Item("ProdName").ToString & ".aspx"))

    End Sub
End Class
