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
|
'---------------------------------------------------------------------
'Déclaration des variables publiques utilisées pour les requêtes du formulaire
'---------------------------------------------------------------------
Dim taille As Integer
Dim indice As Integer
Dim strswitch As String
Dim myConnection As New System.Data.Odbc.OdbcConnection
Dim MyCommand1 As New System.Data.Odbc.OdbcCommand
Dim MyCommand2 As New System.Data.Odbc.OdbcCommand
Dim MyCommand3 As New System.Data.Odbc.OdbcCommand
Dim MyCommand4 As New System.Data.Odbc.OdbcCommand
Dim enregistrer As New System.Data.Odbc.OdbcCommand
Dim myReaderType1 As System.Data.Odbc.OdbcDataReader
Dim myReaderType2 As System.Data.Odbc.OdbcDataReader
Dim myReaderType3 As System.Data.Odbc.OdbcDataReader
Dim myReaderType4 As System.Data.Odbc.OdbcDataReader
Private Sub btn_export_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_export.Click
Dim i As Integer
'------------------------------------------------------
' Création du fichier XML
'------------------------------------------------------
Dim xmlexport As Xml.XmlDocument = New Xml.XmlDocument()
xmlexport.LoadXml("<ListeSwitch> </ListeSwitch>")
'------------------------------------------------------
'Création et définition des balises XML
'------------------------------------------------------
Dim elemswitch As Xml.XmlElement
Dim coltypeswitch As Xml.XmlElement
Dim colsecteurswitch As Xml.XmlElement
Dim collocswitch As Xml.XmlElement
Dim colconstructeur As Xml.XmlElement
elemswitch = xmlexport.CreateElement("Switch")
coltypeswitch = xmlexport.CreateElement("Type")
colsecteurswitch = xmlexport.CreateElement("Secteur")
collocswitch = xmlexport.CreateElement("Localite")
colconstructeur = xmlexport.CreateElement("Constructeur")
'---------------------------------------------------------------------
'Définition de la chaîne de connection à la base de donnée Intranet
'---------------------------------------------------------------------
myConnection.ConnectionString = ConfigBDD.lbl_connectstring.Text
'---------------------------------------------------------------------
'Définition des requêtes qui rammèneront le résultat à inclure dans le XML
'---------------------------------------------------------------------
MyCommand1.CommandText = "select modele_mat from materiel where type_mat ='ELEMENT_ACTIF' and sortie = 0 order by num_mat asc"
MyCommand2.CommandText = "select secteur from materiel where type_mat ='ELEMENT_ACTIF' and sortie = 0 order by num_mat asc"
MyCommand3.CommandText = "select localisation from materiel where type_mat ='ELEMENT_ACTIF' and sortie = 0 order by num_mat asc"
MyCommand4.CommandText = "select constructeur from materiel where type_mat ='ELEMENT_ACTIF' and sortie = 0 order by num_mat asc"
'------------------------------------------------------
'Définition des liens de parenté entre les balises parents/enfants
'------------------------------------------------------
elemswitch.AppendChild(coltypeswitch)
elemswitch.AppendChild(colsecteurswitch)
elemswitch.AppendChild(collocswitch)
elemswitch.AppendChild(colconstructeur)
xmlexport.DocumentElement.AppendChild(elemswitch)
'---------------------------------------------------------------------
'Execution des requêtes et insertion des donées dans les listes
'---------------------------------------------------------------------
MyCommand1.Connection = myConnection
MyCommand1.Connection.Open()
myReaderType1 = MyCommand1.ExecuteReader(CommandBehavior.CloseConnection)
i = 1
If myReaderType1.HasRows = True Then
While myReaderType1.Read
List_modelemat.Items.Add(myReaderType1.GetString(0))
End While
End If
MyCommand1.Connection.Close()
MyCommand2.Connection = myConnection
MyCommand2.Connection.Open()
myReaderType2 = MyCommand2.ExecuteReader(CommandBehavior.CloseConnection)
i = 1
If myReaderType2.HasRows = True Then
While myReaderType2.Read
List_secteur.Items.Add(myReaderType2.GetString(0))
End While
End If
MyCommand2.Connection.Close()
MyCommand3.Connection = myConnection
MyCommand3.Connection.Open()
myReaderType3 = MyCommand3.ExecuteReader(CommandBehavior.CloseConnection)
i = 1
If myReaderType3.HasRows = True Then
While myReaderType3.Read
List_loca.Items.Add(myReaderType3.GetString(0))
End While
End If
MyCommand3.Connection.Close()
MyCommand4.Connection = myConnection
MyCommand4.Connection.Open()
myReaderType4 = MyCommand4.ExecuteReader(CommandBehavior.CloseConnection)
i = 1
If myReaderType4.HasRows = True Then
While myReaderType4.Read
List_constructeur.Items.Add(myReaderType4.GetString(0))
End While
End If
MyCommand4.Connection.Close()
'---------------------------------------------------------------------
'Remplissage du fichier XML à partir des listes.
'---------------------------------------------------------------------
taille = List_constructeur.Items.Count
indice = 1
For Me.indice = 1 To (taille - 1)
elemswitch = xmlexport.CreateElement("Switch")
elemswitch.InnerText = Str(indice)
coltypeswitch = xmlexport.CreateElement("Type")
coltypeswitch.InnerText = List_modelemat.Items(index:=indice)
colsecteurswitch = xmlexport.CreateElement("Secteur")
colsecteurswitch.InnerText = List_secteur.Items(index:=indice)
collocswitch = xmlexport.CreateElement("Localite")
collocswitch.InnerText = List_loca.Items(index:=indice)
colconstructeur = xmlexport.CreateElement("Constructeur")
colconstructeur.InnerText = List_constructeur.Items(index:=indice)
Next indice
'---------------------------------------------------------------------
'Sauvegarde du fichier XML dans le repertoire du programme et avertissement
'---------------------------------------------------------------------
xmlexport.Save("c:\SwitchXML.XML")
MsgBox("Fichier XML enregistré avec succès dans le repertoire du programme") |
Partager