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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
| Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents txtTitre As System.Windows.Forms.TextBox
Friend WithEvents txtAuteur As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents btnValider As System.Windows.Forms.Button
Friend WithEvents btnSupprimer As System.Windows.Forms.Button
Friend WithEvents btnAjouter As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.btnAjouter = New System.Windows.Forms.Button()
Me.btnSupprimer = New System.Windows.Forms.Button()
Me.txtTitre = New System.Windows.Forms.TextBox()
Me.txtAuteur = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.btnValider = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(88, 16)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(208, 21)
Me.ComboBox1.TabIndex = 0
'
'btnAjouter
'
Me.btnAjouter.Location = New System.Drawing.Point(88, 136)
Me.btnAjouter.Name = "btnAjouter"
Me.btnAjouter.Size = New System.Drawing.Size(88, 24)
Me.btnAjouter.TabIndex = 3
Me.btnAjouter.Text = "Ajouter"
'
'btnSupprimer
'
Me.btnSupprimer.Location = New System.Drawing.Point(208, 136)
Me.btnSupprimer.Name = "btnSupprimer"
Me.btnSupprimer.Size = New System.Drawing.Size(88, 24)
Me.btnSupprimer.TabIndex = 4
Me.btnSupprimer.Text = "Supprimer"
'
'txtTitre
'
Me.txtTitre.Location = New System.Drawing.Point(88, 64)
Me.txtTitre.Name = "txtTitre"
Me.txtTitre.Size = New System.Drawing.Size(208, 20)
Me.txtTitre.TabIndex = 5
Me.txtTitre.Text = ""
'
'txtAuteur
'
Me.txtAuteur.Location = New System.Drawing.Point(88, 96)
Me.txtAuteur.Name = "txtAuteur"
Me.txtAuteur.Size = New System.Drawing.Size(208, 20)
Me.txtAuteur.TabIndex = 6
Me.txtAuteur.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 72)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "Titre"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 96)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 8
Me.Label2.Text = "Auteur"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 16)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 16)
Me.Label3.TabIndex = 9
Me.Label3.Text = "Atteindre"
'
'btnValider
'
Me.btnValider.Location = New System.Drawing.Point(88, 136)
Me.btnValider.Name = "btnValider"
Me.btnValider.Size = New System.Drawing.Size(88, 24)
Me.btnValider.TabIndex = 10
Me.btnValider.Text = "Valider"
Me.btnValider.Visible = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(368, 190)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.Label2, Me.Label1, Me.txtAuteur, Me.txtTitre, Me.btnSupprimer, Me.btnAjouter, Me.ComboBox1, Me.btnValider})
Me.Name = "Form1"
Me.Text = "Document XML"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
RemplirListeAtteindre()
ComboBox1.SelectedIndex = 0
End Sub
Sub RemplirListeAtteindre()
ComboBox1.Items.Clear()
Dim xmlr As New XmlTextReader("mediatheque.xml")
Do While xmlr.Read
If xmlr.NodeType = XmlNodeType.Element Then
If xmlr.Name = "TITRE" Then
ComboBox1.Items.Add(xmlr.ReadElementString)
End If
End If
Loop
xmlr.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
Dim DocXml As New XmlDocument()
Dim Noeud As XmlNode
Dim Noeuds As XmlNodeList
Dim sCritere As String
'sCritere = "//OEUVRE[TITRE=""" & ComboBox1.SelectedItem & """]/AUTEUR"
'sCritere = "//OEUVRE[TITRE='Blade Runner']/AUTEUR"
'Noeud = DocXml.SelectSingleNode(sCritere)
'MsgBox(Noeud.InnerText)
If ComboBox1.SelectedItem Is Nothing Then
Exit Sub
End If
DocXml.Load("mediatheque.xml")
sCritere = "//OEUVRE[TITRE=""" & ComboBox1.SelectedItem & """]"
Noeud = DocXml.SelectSingleNode(sCritere)
Noeuds = Noeud.ChildNodes
For Each Noeud In Noeuds
Select Case Noeud.Name
Case "TITRE"
txtTitre.Text = Noeud.InnerText
Case "AUTEUR"
txtAuteur.Text = Noeud.InnerText
End Select
Next
End Sub
Private Sub btnAjouter_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAjouter.Click
txtTitre.Text = String.Empty
txtAuteur.Text = String.Empty
ComboBox1.SelectedIndex = -1
txtTitre.Select()
btnAjouter.Visible = False
btnValider.Visible = True
btnSupprimer.Enabled = False
End Sub
Private Sub btnValider_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnValider.Click
Dim DocXml As New XmlDocument()
Dim Oeuvre As XmlElement
Dim Element As XmlElement
DocXml.Load("mediatheque.xml")
' Créer un nouvel élément OEUVRE
Oeuvre = DocXml.CreateElement("OEUVRE")
' Créer un nouvel élément TITRE
Element = DocXml.CreateElement("TITRE")
Element.InnerText = txtTitre.Text
' Rattacher l'élément au noeud Oeuvre
Oeuvre.AppendChild(Element)
' Créer un nouvel élément AUTEUR
Element = DocXml.CreateElement("AUTEUR")
Element.InnerText = txtAuteur.Text
' Rattacher l'élément au noeud Oeuvre
Oeuvre.AppendChild(Element)
' Rattacher l'élément Oeuvre sous la racine du document
DocXml.DocumentElement.AppendChild(Oeuvre)
DocXml.Save("mediatheque.xml")
RemplirListeAtteindre()
txtTitre.Select()
btnValider.Visible = False
btnAjouter.Visible = True
btnSupprimer.Enabled = True
End Sub
Private Sub btnSupprimer_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSupprimer.Click
Dim DocXml As New XmlDocument()
Dim Noeud As XmlNode
Dim NoeudPere As XmlNode
DocXml.Load("mediatheque.xml")
Dim sCritere As String
If ComboBox1.SelectedItem Is Nothing Then
MsgBox("Veuillez sélectionner un titre")
Exit Sub
End If
sCritere = "//OEUVRE[TITRE=""" & ComboBox1.SelectedItem & """]"
Noeud = DocXml.SelectSingleNode(sCritere)
NoeudPere = Noeud.ParentNode
NoeudPere.RemoveChild(Noeud)
DocXml.Save("mediatheque.xml")
RemplirListeAtteindre()
ComboBox1.SelectedIndex = 0
End Sub
End Class |
Partager