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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
Imports System
Imports System.IO
Imports System.Windows
Imports System.Collections.Generic
Public Class Form1
Private objFiche As Fiche_Du_Livre
Private lienLivre As LinkedList(Of Fiche_Du_Livre) = New LinkedList(Of Fiche_Du_Livre)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cboBoxInsertBefore.DisplayMember = "Auteur"
cboBoxInsertBefore.ValueMember = "ID"
cboBoxInsertBefore.Enabled = False
'
cboBoxInsertAfter.DisplayMember = "Auteur"
cboBoxInsertAfter.ValueMember = "ID"
cboBoxInsertAfter.Enabled = False
End Sub
Private Sub btnOuvrirFichier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOuvrirFichier.Click
Dim fichierChemin As String = ""
Me.OpenFileDialog1.Filter = "Fichier Texte(*.txt)|*.txt"
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
fichierChemin = Me.OpenFileDialog1.FileName
If Len(fichierChemin) = 0 Then
MessageBox.Show("erreur fichier...")
Exit Sub
Else
Call LitFichier(fichierChemin)
End If
End If
End Sub
Private Sub LitFichier(ByVal cheminfichier As String)
Using monReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(cheminfichier)
monReader.TextFieldType = FileIO.FieldType.Delimited
monReader.SetDelimiters(",")
Dim ligneCourante As String()
Dim afficheLigCourante As String = ""
Dim numChamp As Integer = 1
While Not monReader.EndOfData
Try
ligneCourante = monReader.ReadFields()
Dim champCourant As String = String.Empty
objFiche = New Fiche_Du_Livre
numChamp = 1
For Each champCourant In ligneCourante
Select Case numChamp
Case 1
objFiche.Genre = CType(champCourant, String)
Case 2
objFiche.Auteur = CType(champCourant, String)
Case 3
objFiche.Titre = CType(champCourant, String)
Case 4
objFiche.ID = Integer.Parse(champCourant)
Case 5
objFiche.Disponibilite = Integer.Parse(champCourant)
End Select
'champ suivant
numChamp = numChamp + 1
afficheLigCourante = afficheLigCourante & champCourant
'MsgBox(champCourant)
Next
Call stockeFicheDuLIVRE(objFiche)
'ligne suivante
MessageBox.Show(afficheLigCourante)
afficheLigCourante = ""
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Ligne " & ex.Message & _
"non valide,sera saute....")
End Try
End While
End Using
End Sub
Private Sub stockeFicheDuLIVRE(ByVal objFiche As Fiche_Du_Livre)
Dim noeud As LinkedListNode(Of Fiche_Du_Livre) = New LinkedListNode(Of Fiche_Du_Livre)(objFiche)
lienLivre.AddFirst(noeud)
End Sub
Private Sub btnListeLie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAffDGVListe.Click
Call FillDataGridView()
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPremier.Click
Call ClearTextBox()
Me.txtGenre.Text = lienLivre.First.Value.Genre
Me.txtAuteur.Text = lienLivre.First.Value.Auteur
Me.txtTitre.Text = lienLivre.First.Value.Titre
Me.txtID.Text = lienLivre.First.Value.ID.ToString
Me.txtDisponibilte.Text = lienLivre.First.Value.Disponibilite.ToString
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDernier.Click
Call ClearTextBox()
Me.txtGenre.Text = lienLivre.Last.Value.Genre
Me.txtAuteur.Text = lienLivre.Last.Value.Auteur
Me.txtTitre.Text = lienLivre.Last.Value.Titre
Me.txtID.Text = lienLivre.Last.Value.ID.ToString
Me.txtDisponibilte.Text = lienLivre.Last.Value.Disponibilite.ToString
End Sub
Private Sub cboBoxInsertBefore_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBoxInsertBefore.SelectedIndexChanged
'Inserer nouvel ouvrage avant ouvrage -x-
Dim nouvOuvrage As Fiche_Du_Livre = New Fiche_Du_Livre
nouvOuvrage.Genre = txtGenre.Text
nouvOuvrage.Auteur = txtAuteur.Text
nouvOuvrage.Titre = txtTitre.Text
If IsNumeric(txtID.Text) Then
nouvOuvrage.ID = Integer.Parse(txtID.Text)
Else
MessageBox.Show("Err Texte Absent ou non Numerique...")
txtID.Focus()
End If
If IsNumeric(txtDisponibilte.Text) Then
nouvOuvrage.Disponibilite = Integer.Parse(txtDisponibilte.Text)
Else
MessageBox.Show("Err Texte Absent ou non Numerique...")
txtDisponibilte.Focus()
End If
Dim objLivreSel As Fiche_Du_Livre = CType(cboBoxInsertBefore.SelectedItem, Fiche_Du_Livre)
Dim noeudSel As LinkedListNode(Of Fiche_Du_Livre) = lienLivre.Find(objLivreSel)
lienLivre.AddBefore(noeudSel, nouvOuvrage)
Call FillDataGridView()
cboBoxInsertBefore.Enabled = False
Call ClearTextBox()
End Sub
Private Sub cboBoxInsertAfter_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBoxInsertAfter.SelectedIndexChanged
'Inserer nouvel ouvrage apres -x-
Dim nouvOuvrage As Fiche_Du_Livre = New Fiche_Du_Livre
nouvOuvrage.Genre = txtGenre.Text
nouvOuvrage.Auteur = txtAuteur.Text
nouvOuvrage.Titre = txtTitre.Text
If IsNumeric(txtID.Text) Then
nouvOuvrage.ID = Integer.Parse(txtID.Text)
Else
MessageBox.Show("Err non Numerique...")
txtID.Focus()
End If
If IsNumeric(txtDisponibilte.Text) Then
nouvOuvrage.Disponibilite = Integer.Parse(txtDisponibilte.Text)
Else
MessageBox.Show("Err non Numerique...")
txtDisponibilte.Focus()
End If
Dim objLivreSel As Fiche_Du_Livre = CType(cboBoxInsertAfter.SelectedItem, Fiche_Du_Livre)
Dim noeudSel As LinkedListNode(Of Fiche_Du_Livre) = lienLivre.Find(objLivreSel)
lienLivre.AddAfter(noeudSel, nouvOuvrage)
Call FillDataGridView()
Call ClearTextBox()
cboBoxInsertAfter.Enabled = False
End Sub
Private Sub cboBoxRemove_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBoxRemove.SelectedIndexChanged
Call ClearTextBox()
'Supprime l'ouvrage selectionne -x-
Dim objLivreSel As Fiche_Du_Livre = CType(cboBoxInsertBefore.SelectedItem, Fiche_Du_Livre)
txtGenre.Text = objLivreSel.Genre
txtAuteur.Text = objLivreSel.Auteur
txtTitre.Text = objLivreSel.Titre
txtID.Text = objLivreSel.ID.ToString
txtDisponibilte.Text = objLivreSel.Disponibilite.ToString
lienLivre.Remove(objLivreSel)
Call FillDataGridView()
End Sub
Private Sub btnClearTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearTextBox.Click
Call ClearTextBox()
End Sub
Private Sub FillDataGridView()
Dim tableAffichage(lienLivre.Count) As Fiche_Du_Livre
lienLivre.CopyTo(tableAffichage, 0)
DataGridView1.DataSource = tableAffichage
DataGridView1.Refresh()
For Each obj As Fiche_Du_Livre In lienLivre
cboBoxInsertBefore.Items.Add(obj)
cboBoxInsertAfter.Items.Add(obj)
Next
DataGridView1.Update()
DataGridView1.Refresh()
End Sub
Private Sub ClearTextBox()
Me.txtGenre.Text = ""
Me.txtAuteur.Text = ""
Me.txtTitre.Text = ""
Me.txtID.Text = ""
Me.txtDisponibilte.Text = ""
End Sub
Private Sub btnEnregFichier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnregFichier.Click
Dim fichierChemin As String = ""
Me.SaveFileDialog1.Filter = "Fichier Texte(*.txt)|*.txt"
If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
fichierChemin = Me.SaveFileDialog1.FileName
If Len(fichierChemin) = 0 Then
MessageBox.Show("erreur fichier...")
Exit Sub
Else
Call EcritFichier(fichierChemin)
End If
End If
End Sub
Private Sub EcritFichier(ByVal cheminfichier As String)
Dim MonWriter As System.IO.StreamWriter = New System.IO.StreamWriter(cheminfichier, False)
Dim strLigne As String = ""
Dim sep As String = ","
Try
For Each objLivre In lienLivre
strLigne = objLivre.Genre & sep & objLivre.Auteur & objLivre.Titre & sep & objLivre.ID.ToString & sep & objLivre.Titre
MonWriter.WriteLine(strLigne)
Next
MonWriter.Close()
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Ligne " & ex.Message & _
"non valide,sera saute....")
End Try
End Sub
Private Sub btnValider_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValider.Click
If txtGenre.Text <> "" And txtAuteur.Text <> "" _
And txtTitre.Text <> "" And txtID.Text <> "" _
And txtDisponibilte.Text <> "" Then
cboBoxInsertBefore.Enabled = True
cboBoxInsertAfter.Enabled = True
End If
End Sub
End Class
'La classe Fiche_Du_Livre
Public Class Fiche_Du_Livre
'Dim Genre As String
'Dim Auteur As String
'Dim Titre As String
'Dim ID As Integer
'Dim Disponibilite As Integer
Private m_Genre As String
Public Property Genre() As String
Get
Return m_Genre
End Get
Set(ByVal value As String)
m_Genre = value
End Set
End Property
Private m_Auteur As String
Public Property Auteur() As String
Get
Return m_Auteur
End Get
Set(ByVal value As String)
m_Auteur = value
End Set
End Property
Private m_Titre As String
Public Property Titre() As String
Get
Return m_Titre
End Get
Set(ByVal value As String)
m_Titre = value
End Set
End Property
Private m_ID As Integer
Public Property ID() As Integer
Get
Return m_ID
End Get
Set(ByVal value As Integer)
m_ID = value
End Set
End Property
Private m_Disponibilite As String
Public Property Disponibilite() As String
Get
Return m_Disponibilite
End Get
Set(ByVal value As String)
m_Disponibilite = value
End Set
End Property
End Class |
Partager