Tuesday 11 March 2014

Use SoundEX Function (Retrieve Sound Matching Data from Sql Server)

   Dim newcolegeprin() As String
  Private Sub cmdloaddata()
  Me.Cursor = Cursors.WaitCursor
        Dim data As DataTable = objdb.getdata("select director_name,no_of_occurances,sno,statecode from frequency where  statecode='" & cmbstate.Tag & "' order by no_of_occurances desc  ", objdb.localconnection)
        If data.Rows.Count > 0 Then

            For i As Integer = 0 To data.Rows.Count - 1
                DataGridView3.Rows.Add()
                DataGridView3.Rows(i).Cells("principal_name").Style.BackColor = Color.White
                DataGridView3.Rows(i).Cells("principal_name").Value = data.Rows(i).Item("director_name")
                DataGridView3.Rows(i).Cells("Frequncy").Value = data.Rows(i).Item("no_of_occurances")
                DataGridView3.Rows(i).Cells("sr_no").Value = data.Rows(i).Item("sno")
                DataGridView3.Rows(i).Cells("statecode").Value = data.Rows(i).Item("statecode")
            Next
        End If

        Dim dt As DataTable = objdb.getdata("select  college_name,principalname,college_code from tmphistory where state_code='" & cmbstate.Tag & "'order by college_name", objdb.localconnection)
        If dt.Rows.Count > 0 Then
            For i As Integer = 0 To dt.Rows.Count - 1
                DataGridView1.Rows.Add()
                DataGridView1.Rows(i).Cells("Principal_name").Value = dt.Rows(i).Item("principalname")
                DataGridView1.Rows(i).Cells("college_name").Value = dt.Rows(i).Item("college_name")
                DataGridView1.Rows(i).Cells("collegecode").Value = dt.Rows(i).Item("college_code")
            Next

        End If
        Dim j As Integer = 1

        txtcollegename.Text = DataGridView3.CurrentRow.Cells(1).Value
        txtcollegename.Tag = DataGridView3.CurrentRow.Cells(0).Value
        Dim chh() As String = Split(txtcollegename.Text, Space(1))
        Dim z As Integer = 0
        For i = LBound(chh) To UBound(chh)
            DataGridView2.Rows.Add()
            DataGridView2.Rows(z).Cells("Keyword").Value = Trim(chh(i))

            DataGridView2.Rows(z).Cells("Select").Style.Font = New Font("Wingdings 2", 10, FontStyle.Bold)
            DataGridView2.Rows(z).Cells("Select").Value = "P"
            z = z + 1
        Next
        DataGridView2.Rows.Add()
        DataGridView2.Rows(z).Cells("Keyword").Value = txtcollegename.Text
        Dim ubndarry As Integer
        ReDim newcolegeprin(0)
        newcolegeprin(0) = ""
        ubndarry = 0
        For i = 0 To DataGridView2.Rows.Count - 1
            If DataGridView2.Rows(i).Cells("Select").Value = "P" And DataGridView2.Rows(i).Cells("select").Value <> "" Then
                ubndarry = Val(ubndarry) + 1
            End If
        Next
        ReDim newcolegeprin(Val(ubndarry) - 1)

        j = 0

        For i = 0 To DataGridView2.Rows.Count - 1
            If DataGridView2.Rows(i).Cells("Select").Value = "P" And DataGridView2.Rows(i).Cells("keyword").Value <> "" Then

                newcolegeprin(j) = Trim(UCase(DataGridView2.Rows(i).Cells("keyword").Value))
                j = j + 1
            End If
        Next
        If j <> 0 Then
            FilterExactName()
            filterbykeyword()
            sound_fun()
            DataGridView3.Sort(DataGridView3.Columns(2), System.ComponentModel.ListSortDirection.Descending)

        End If
        DataGridView3.ClearSelection()
        Me.Cursor = Cursors.Default
End sub
===========================
  Private Sub sound_fun()
        Dim subkey As String = ""
        For i = LBound(newcolegeprin) To UBound(newcolegeprin)
            If UBound(newcolegeprin) And Len(newcolegeprin(i)) > 1 Then
                subkey = subkey & "" & Trim(newcolegeprin(i))
            End If
        Next
        soundpatterndata(subkey)
    End Sub
===============================================
    Sub soundpatterndata(ByVal subkey As String)
        Dim abc As Boolean
        For i = 1 To DataGridView3.Rows.Count - 1
            If DataGridView3.Rows(i).Cells("Principal_Name").Style.BackColor = Color.White Then
                abc = False
                If getsound(Trim(UCase(DataGridView3.Rows(i).Cells(1).Value))) = getsound(Trim(UCase(subkey))) Then
                    abc = True
                End If
                If abc = True Then
                    DataGridView3.Rows(i).Cells(2).Value = "3"
                    DataGridView3.Rows(i).Cells(1).Style.BackColor = Color.Yellow
                End If
            End If
        Next
    End Sub
======================
    Private Function getsound(ByVal mystring As String) As String
        getsound = ""
        Dim dt As DataTable = objdb.getdata(" select soundex('" & Replace(mystring, "'", " ''") & "') as sound", objdb.localconnection)
        If dt.Rows.Count > 0 Then
            getsound = dt.Rows(0).Item("sound")
        End If
    End Function

No comments:

Post a Comment

Followers