1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| Imports System.Data.Objects
Imports System.Linq.Expressions
Imports System.Linq
Imports System.Collections.Generic
Imports System
Imports LinqKit
Imports System.Math
Namespace MvcApplication4
Public Class SearchController
Inherits System.Web.Mvc.Controller
Private db As schema_crmEntities1 = New schema_crmEntities1
'
' GET: /Search
<HttpGet()>
Function contactSearch() As ActionResult
ViewBag.opportunite = New SelectList(db.opportunite, "idOpportunite", "nomOffre")
Dim table(3, 0) As Double
table(3, 0) = 0
ViewBag.distance = table
Return View()
End Function
'
'POST: /Search
<HttpPost()>
Function contactSearch(search As String, opportunite As opportunite, dist As Integer) As ViewResult
Dim chaine As String = Request("searchString")
Dim tabMot() = chaine.Split(New Char() {" "c})
Dim distance As Integer = Request("dist")
Dim message As String = "message"
Dim opport As Integer = Val(Request("opportunite"))
Dim n As Integer = 0
Dim i As Integer = 0
'Tout ce bloc sert à construire une liste de contacts répondant aux critères
Dim predicate As Expression(Of Func(Of contact, Boolean))
predicate = PredicateBuilder.False(Of contact)()
For Each mot In tabMot
Dim tmp = mot
predicate = predicate.Or(Function(m) m.titre.Contains(tmp))
predicate = predicate.Or(Function(m) m.departement.Contains(tmp))
predicate = predicate.Or(Function(m) m.qualifications.Contains(tmp))
predicate = predicate.Or(Function(m) m.langue1.Contains(tmp))
predicate = predicate.Or(Function(m) m.langue2.Contains(tmp))
predicate = predicate.Or(Function(m) m.langue3.Contains(tmp))
predicate = predicate.Or(Function(m) m.langue4.Contains(tmp))
predicate = predicate.Or(Function(m) m.langue5.Contains(tmp))
Next
Dim contacts = db.contact.AsExpandable().Where(predicate).ToList()
'Compte la valeur de l'index du tableau de contacts
For Each contact In contacts
n += 1
Next
n -= 1
'Cette requête sert à chercher le code postal d'une opportunité
ViewBag.opportunite = New SelectList(db.opportunite, "idOpportunite", "nomOffre")
Dim codePostal As Integer = (From a In db.opportunite, b In db.client
Where a.idOpportunite = opport And a.FK_Client = b.idClient
Select b.cpFact).First()
'Requête qui sert à trouver les coordonnées du CP de l'opportunité
Dim longOpp As Double = (From c In db.city
Where c.code = codePostal
Select c.longitude).First()
longOpp = (longOpp * Math.PI) / 180 'conversion d'angles en radians
Dim lattOpp As Double = (From d In db.city
Where d.code = codePostal
Select d.latitude).First()
lattOpp = (lattOpp * Math.PI) / 180 'conversion d'angles en radians
'Boucle qui va servir à récupérer les coordonnées des contacts sélectionnés
Dim table(3, n) As Double
For Each contact In contacts
Dim tmp = contact
table(0, i) = contact.idContact
table(1, i) = (From d In db.city
Where d.code = tmp.adresseCP
Select d.longitude).First()
table(1, i) = (table(1, i) * Math.PI) / 180
table(2, i) = (From d In db.city
Where d.code = tmp.adresseCP
Select d.latitude).First()
table(2, i) = (table(2, i) * Math.PI) / 180
'table(3, i) = 2 * 6370 * Asin(Sqrt((Sin((table(2, i) - lattOpp) / 2) * Sin((table(2, i) - lattOpp) / 2) + Cos(table(1, i)) * Cos(lattOpp) * Sin((table(1, i) - longOpp) / 2) * Sin((table(1, i) - longOpp) / 2))))
table(3, i) = Round(6370 * Acos(Sin(table(2, i)) * Sin(lattOpp) + Cos(table(2, i)) * Cos(lattOpp) * Cos(table(1, i) - longOpp)))
i = i + 1
Next
ViewBag.distance = table
ViewBag.message = message
ViewBag.codePostal = Val(codePostal)
Dim model = New SearchModel With {
.Contacts = contacts
}
Return View(model)
End Function
End Class
End Namespace |
Partager