Posted By: JoshRoss | Jul 24th @ 7:53 PM
page 1 of 1
Comments: 1 | Views: 1059 | Downloads: 0
JoshRoss
JoshRoss
JoshRoss
Download:code.png(68 KB)[Pending]
Public Class FuzzyLookupForm 
Dim dc As New DataClasses1DataContext 
Private Sub UserInput_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles UserInput.KeyDown 
If e.KeyCode = Keys.Enter Then 
'Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator. 
'HACK: cast customers to AsEnumerable. 
Dim customers = (From x In dc.oe_customers _ 
Let Location = x.name.Trim & " " & x.addr1.Trim & " " & x.city.Trim & " " & x.zip.Substring(0, 5) _ 
Select x.cust_code, Location).AsEnumerable 
'I made the Location a concation of a bunch of fields in order not to have to reaggerate them in linq, at a later step. 


Dim q = From x In customers _ 
Let matches = UserInput.Text.ToLower.Split(New Char() {" "c, vbTab}).IntersectContains(x.Location.ToLower.Split(" ")).Count _ 
+ UserInput.Text.ToLower.Split(New Char() {" "c, vbTab}).Intersect(x.Location.ToLower.Split(" ")).Count _ 
Where matches > 0 _ 
Select x.cust_code, x.Location, matches _ 
Order By matches Descending 
Me.DataGridView1.DataSource = q.ToArray 
End If 
End Sub 
End Class 
Module MatchingExtensions 
 _ 
Function IntersectContains(ByVal first As IEnumerable(Of String), ByVal second As IEnumerable(Of String)) As IEnumerable(Of String) 
'If first containts Det it will match Detroit in second. 
Return From f In first, s In second Where s.Contains(f) Select s Distinct 
End Function 
End Module 
page 1 of 1
Comments: 1 | Views: 1059 | Downloads: 0