Dim document As XmlReader = New XmlTextReader("ListeAdhérents" & Year(Date.Today) & ".xml".ToString())
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name = "Nom") Then
If StrComp(document.ReadInnerXml.ToString(), NomAdherentRechercher.Text.ToString()) = 0 Then
MessageBox.Show("Le nom de l'adhérent a été trouvé")
If (document.Name = "Prénom") Then
If StrComp(document.ReadInnerXml.ToString(), PrenomAdherentRechercher.Text.ToString()) = 0 Then
MessageBox.Show("L'adhérent a été trouvé")
Else
MessageBox.Show("L'adhérent n'existe pas. Vérifiez l'orthographe et essayez à nouveau bibi")
End If
End If
Else
MessageBox.Show("L'adhérent n'existe pas. Vérifiez l'orthographe et essayez à nouveau")
End If
End If
End If
End While
Public Class Adherent
Public nom As String
Public prenom As String
Public Age As Integer
End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Dim xmldoc As XmlDocument = New XmlDocument
Dim Adherent_trouve As Boolean = False
xmldoc.Load("ListeAdhérents" & Year(Date.Today) & ".xml".ToString())
'On récupère tous les noeuds personnes
'à l'intérieur d'un noeud personnes
For Each personneElement In xmldoc.SelectNodes("/Liste_Adhérents/Adherents")
'On récupère les informations sur la personne
If StrComp(personneElement.SelectSingleNode("Nom").InnerText, NomAdherentRechercher.Text.ToString()) = 0 Then
If StrComp(personneElement.SelectSingleNode("Prenom").InnerText, PrenomAdherentRechercher.Text.ToString()) = 0 Then
Adherent_trouve = True
'Si on trouve l'adhérent dans la liste, on charge les données puis on ouvre la page de visualisation
Visualisation_adherent.NomAdherentVisu.Text = personneElement.SelectSingleNode("Nom").InnerText
Visualisation_adherent.PrenomAdherentVisu.Text = personneElement.SelectSingleNode("Prenom").InnerText
Visualisation_adherent.AgeAdherentVisu.Text = personneElement.SelectSingleNode("Age").InnerText
Visualisation_adherent.AdresseAdherentVisu.Text = personneElement.SelectSingleNode("Adresse").InnerText
Visualisation_adherent.CodePostalAdherentVisu.Text = personneElement.SelectSingleNode("CodePostal").InnerText
Visualisation_adherent.VilleAdherentVisu.Text = personneElement.SelectSingleNode("Ville").InnerText
Visualisation_adherent.TelephoneAdherentVisu.Text = personneElement.SelectSingleNode("Telephone").InnerText
Visualisation_adherent.EmailAdherentVisu.Text = personneElement.SelectSingleNode("Email").InnerText
Visualisation_adherent.JourNaissanceAdherentVisu.Text = personneElement.SelectSingleNode("JourNaissance").InnerText
Visualisation_adherent.MoisNaissanceAdherentVisu.Text = personneElement.SelectSingleNode("MoisNaissance").InnerText
Visualisation_adherent.AnneeNaissanceAdherentVisu.Text = personneElement.SelectSingleNode("AnnéeNaissance").InnerText
Visualisation_adherent.PremiereAnneChasseAdherentVisu.Text = personneElement.SelectSingleNode("PremiereAnnéeChasse").InnerText
If StrComp(personneElement.SelectSingleNode("VenerieSousTerre").InnerText, "OUI") = 0 Then
Visualisation_adherent.AdherentVisuPratiqueVenerieSousTerre.Visible = True
End If
If StrComp(personneElement.SelectSingleNode("GrandeVenerie").InnerText, "OUI") = 0 Then
Visualisation_adherent.AdherentVisuPratiqueGrandeVenerie.Visible = True
Else
Visualisation_adherent.AdherentVisuPratiqueGrandeVenerie.Visible = False
End If
If StrComp(personneElement.SelectSingleNode("ChasseChienArret").InnerText, "OUI") = 0 Then
Visualisation_adherent.AdherentVisuPratiqueChasseChienArret.Visible = True
End If
If StrComp(personneElement.SelectSingleNode("ChasseChienCourant").InnerText, "OUI") = 0 Then
Visualisation_adherent.AdherentVisuPratiqueChasseChienCourant.Visible = True
End If
If StrComp(personneElement.SelectSingleNode("ChasseSansChien").InnerText, "OUI") = 0 Then
Visualisation_adherent.AdherentVisuPratiqueChasseSansChien.Visible = True
End If
If StrComp(personneElement.SelectSingleNode("Cotisation").InnerText, "OUI") = 0 Then
Visualisation_adherent.AdherentVisuCotisationPaye.Visible = True
Visualisation_adherent.AdherentVisuCotisationNonPaye.Visible = False
Else
Visualisation_adherent.AdherentVisuCotisationPaye.Visible = False
Visualisation_adherent.AdherentVisuCotisationNonPaye.Visible = True
End If
Visualisation_adherent.Show()
Me.Close()
Exit For
End If
End If
Next
If Not Adherent_trouve Then
MessageBox.Show("L'adhérent rechercher n'a pas été trouvé. Veuillez vérifier l'orthographe et essayer à nouveau")
End If
<?xml version="1.0" encoding="UTF-8"?> <!--XML Database.--> -<Liste_Adhérents> -<Adherents> <Nom>Dupont</Nom> <Prenom>Jean-Marc</Prenom> <Age>57</Age> <Adresse>Chez moi</Adresse> <CodePostal>22180</CodePostal> <Ville>Je sais plus</Ville> <Telephone>0607080910</Telephone> <Email>j'en ai pas</Email> <JourNaissance>10</JourNaissance> <MoisNaissance>Mars</MoisNaissance> <AnnéeNaissance>1968</AnnéeNaissance> <PremiereAnnéeChasse>2014</PremiereAnnéeChasse> <VenerieSousTerre>NON</VenerieSousTerre> <GrandeVenerie>NON</GrandeVenerie> <ChasseChienArret>NON</ChasseChienArret> <ChasseChienCourant>NON</ChasseChienCourant> <ChasseSansChien>OUI</ChasseSansChien> <Cotisation>OUI</Cotisation> </Adherents> </Liste_Adhérents>
Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Xml.Linq Namespace Test_Winform Public Class AdherentChasse Public Sub New(ByVal E As XElement) Nom = E.Element("Nom").Value Prenom = E.Element("Prenom").Value Adresse = E.Element("Adresse").Value CodePostal = Convert.ToInt32(E.Element("CodePostal").Value) Ville = E.Element("Ville").Value Email = E.Element("Email").Value Telephone = Convert.ToInt32(E.Element("Telephone").Value) Dim jour As String = E.Element("JourNaissance").Value Dim moi As String = E.Element("MoisNaissance").Value Dim annee As String = E.Element("AnneeNaissance").Value Dim datenaiss As String = jour & " " & moi & " " & annee DateNaissance = Date.Parse(datenaiss) PremiereAnnne2Chasse = Convert.ToInt32(E.Element("PremiereAnneeChasse").Value) VenerieSousTerre = (E.Element("VenerieSousTerre").Value = "OUI") GrandeVenerie = (E.Element("GrandeVenerie").Value = "OUI") ChasseChienArret = (E.Element("ChasseChienArret").Value = "OUI") ChasseChienCourant = (E.Element("ChasseChienCourant").Value = "OUI") ChasseSansChien = (E.Element("ChasseSansChien").Value = "OUI") Cotisation = (E.Element("Cotisation").Value = "OUI") End Sub Public Property Nom() As String Public Property Prenom() As String Public Property Adresse() As String Public Property CodePostal() As Integer Public Property Ville() As String Public Property Email() As String Public Property Telephone() As Integer Public Property DateNaissance() As Date Public ReadOnly Property Age() As Integer Get Return Date.Now.Year - DateNaissance.Year End Get End Property Public Property PremiereAnnne2Chasse() As Integer Public Property VenerieSousTerre() As Boolean Public Property GrandeVenerie() As Boolean Public Property ChasseChienArret() As Boolean Public Property ChasseChienCourant() As Boolean Public Property ChasseSansChien() As Boolean Public Property Cotisation() As Boolean Public Shared Function ImportXml(ByVal CheminFichier As String) As List(Of AdherentChasse) Dim xdoc As XDocument = XDocument.Load(CheminFichier) Return ( From a In xdoc.Descendants("Adherents") Select New AdherentChasse(a)).ToList() End Function End Class End Namespace
Dim mesChasseurs As List(Of AdherentChasse) = AdherentChasse.ImportXml("quentin22breizh.xml")
Dim AdherentATrouver As AdherentChasse = mesChasseurs.SingleOrDefault(Function(a) a.Nom = "Dupont" AndAlso a.Prenom = "Jean") If AdherentATrouver Is Nothing Then MessageBox.Show("L'adhérent recherché n'existe pas.") End If