Imports System
Imports System.IO
Imports Microsoft.VisualBasic.Constants
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient
Imports QueryString
Partial Class SearchProductDetails
    Inherits System.Web.UI.Page
    Shared a As String
    Dim cmd As New SqlCommand
    Dim dr As SqlDataReader
    Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
    Dim prodcode As String
    '    Dim dcodestr As New QueryString
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Session("three") = "yes"
        'checkqrstr((RemoveLiterals(Request.QueryString("ProductCode"))))
        If Not IsPostBack Then
            Dim Keyid As String
            Keyid = ReturnValue("Select Keyword_Kid from Product_Keyword where Keyword_Productid ='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'")
            Dim keyWordPresent As String
            keyWordPresent = ReturnValue("Select Keyword_auto from Product_Keyword where Keyword_ProductId='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'")
            Dim KeyAuto As String
            Dim keyproductDesc As String
            KeyAuto = ReturnValue("Select Product_Name from Product_Master where Product_Kid ='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'")
            keyproductDesc = ReturnValue("Select Product_Description from Product_Master where Product_Kid ='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'")
            If Keyid = "" Then
                ExecuteQuery("Insert into Product_Keyword (Keyword_Kid, Keyword_ProductId, Keyword_Name, Keyword_Auto,Keyword_Flag) values ('" & NewPrimaryKey(Me.Page) & "','" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "', '' , '" & KeyAuto & "','0')")
            ElseIf Keyid <> "" And keyWordPresent = "" Then
                ExecuteQuery("Update Product_Keyword set Keyword_Flag='0' , Keyword_Auto ='" & KeyAuto & "' where Keyword_Kid ='" & Keyid & "'")
            End If


            'Me.Title = FgenerateTags(RemoveLiterals(Request.QueryString("ProductCode").ToString.Trim), "")

            Dim str As String()
            str = FgenerateTags((RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))), "")
            'str(0) = limitWords(str(0).ToString(), 10, 90, " ")    ' For Title including productname - category herarchy
            str(1) = limitWords(str(1).ToString(), 0, 170, " ")    ' For meta description Content Category Herarchy
            str(2) = limitWords(str(2).ToString(), 20, 900, ", ") ' For Meta Keyword Content From Product_Keyword Value of Keyword_Auto Field

            Dim strTitle As String
            strTitle = StrConv(str(0), VbStrConv.ProperCase)

            Me.Header.Title = strTitle & " - Atcomaart Industrial Supply"

            Dim mt1 As New HtmlMeta
            mt1.Name = "description"
            mt1.Content = str(1)
            Me.Header.Controls.Add(mt1)

            Dim mt2 As New HtmlMeta
            mt2.Name = "keywords"
            mt2.Content = str(2).Trim.Remove(str(2).Length - 2).ToLower
            Me.Header.Controls.Add(mt2)

            'Dim sc As New HtmlGenericControl
            'sc.TagName = "script"

            'sc.InnerText = "XYZ"
            'Me.Header.Controls.Add(sc)
            'sc.
            Me.Header.Controls.Add(New LiteralControl("<script type='text/javascript' src='" & ResolveUrl("~/App_Script/JScript.js") & "'></script>"))
            '            head.Controls.Add(new LiteralControl("<LINK rel='stylesheet'
            'href='include/inputbox.css' type='text/css'>"));
            getdivdata()

            'Response.Cache.SetCacheability(HttpCacheability.NoCache)
        End If

    End Sub
    Public Sub checkqrstr(ByVal qsrt As String)
        If qsrt.Length > 9 Or qsrt.Length < 7 Then
            Response.Redirect("home.aspx")
        End If

    End Sub

    Public Function limitWords(ByVal str As String, ByVal words As Integer, ByVal chars As Integer, ByVal delimiter As String) As String
        If (chars) Then
            If (str.Length() > chars) Then
                str = str.Substring(0, chars)
            End If
        End If

        If (words) Then
            Dim temp() As String
            temp = str.Split(" ")

            If (temp.Length > words) Then
                Array.Resize(temp, words)

            End If
            Dim i As Integer = 0
            str = ""
            While (i < temp.Length)
                'If temp(i) <> "" Then
                str += temp(i) & delimiter
                i = i + 1
                'End If

            End While
        End If
        Return str
    End Function
    Public Sub getdivdata()
        cmd = New SqlCommand("select prodApp_Application from ProductApplication where prodApp_ProductId='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'", con)
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()
        dr = cmd.ExecuteReader
        datadiv.InnerHtml = "<b>" & "Applications :" & "</b>" & "<Br>"
        While dr.Read
            datadiv.InnerHtml &= "<li>" & dr(0) & "<br>"
        End While
        dr.Close()
        con.Close()
        cmd.Dispose()
        cmd = New SqlCommand("select prodfeatures_features from ProductFeatures where prodfeatures_ProductId='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'", con)
        con.Open()
        dr = cmd.ExecuteReader
        datadiv.InnerHtml += "<b>" & "Features :" & "</b>" & "<Br>"
        While dr.Read
            datadiv.InnerHtml &= "<li>" & dr(0) & "<br>"
        End While
        dr.Close()
        con.Close()
        cmd.Dispose()
        cmd = New SqlCommand("select TechSpec_parameter from ProductTechnicalSpecification where TechSpec_ProductId='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'", con)
        con.Open()
        dr = cmd.ExecuteReader
        datadiv.InnerHtml += "<b>" & "Technical Specification :" & "</b>" & "<Br>"
        While dr.Read
            datadiv.InnerHtml &= "<li>" & dr(0) & "<br>"
        End While
        dr.Close()
        con.Close()
        cmd.Dispose()
        cmd = New SqlCommand("select ProdSpecInstr_Instruction from ProductSpecialNotesInstruction where ProdSpecInstr_ProductId='" & (RemoveLiterals(DecodeURL(Request.QueryString("ProductCode")))) & "'", con)
        con.Open()
        dr = cmd.ExecuteReader
        datadiv.InnerHtml += "<b>" & "Special Notes :" & "</b>" & "<Br>"
        While dr.Read
            datadiv.InnerHtml &= "<li>" & dr(0) & "<br>"
        End While
        dr.Close()
        con.Close()
        cmd.Dispose()
    End Sub
End Class

