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
| Imports System.Xml.Serialization
Imports System.IO
Public Class Accueil
Private _FenetreAjout As AjoutFIche
Private _FilmEnVisualisation As Film
Private _ListeFilms As List(Of Film)
Public Property ListeFilms As List(Of Film)
Get
Return _ListeFilms
End Get
Set(ByVal value As List(Of Film))
_ListeFilms = value
End Set
End Property
Private Sub ListeFilms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RichTextBox2.Enabled = False
LBL_NB_FILMS.Text = listbox_films.Items.Count
'Instancie une nouvelle liste
_ListeFilms = New List(Of Film)
'Récupère les infos
Deserialisation()
'MAJ la liste de films
UpdateListe()
End Sub
Private Sub ListeFilms_FormClosing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
'Sérialise les films lors de la fermeture
Serialisation()
End Sub
Private Sub listbox_films_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox_films.SelectedIndexChanged
'On vérifie qu'on a sélectionné quelque chose
If Not listbox_films.SelectedItem Is Nothing Then
'Retrouve le film avec ce nom
For Each FilmALister As Film In _ListeFilms
If FilmALister.Nom = listbox_films.SelectedItem.ToString Then
'L'insère dans une variable globale
Me._FilmEnVisualisation = FilmALister
End If
Next
'On MAJ les infos de la fiche
Me.LBL_TITRE.Text = Me._FilmEnVisualisation.Nom
Me.RichTextBox2.Text = Me._FilmEnVisualisation.Synopsis
Me.LBL_NOTE.Text = Me._FilmEnVisualisation.NotePerso & " / 20"
Me.LBL_DUREE.Text = Me._FilmEnVisualisation.Duree
Me.LBL_TYPE.Text = Me._FilmEnVisualisation.Type
Me.LBL_STATUE.Text = Me._FilmEnVisualisation.Statue
Me.IMG_FILM.ImageLocation = Me._FilmEnVisualisation.IMGURL
End If
End Sub
Public Sub UpdateListe()
'On vide la liste et on la reremplit
listbox_films.Items.Clear()
'Parcourt les films de la bibliothèque
For Each FilmALister As Film In _ListeFilms
'Remplit la liste en se basant sur le nom (vu que j'ai surchargé ToString)
'A le même effet que FilmALister.Nom sans la surcharge.
listbox_films.Items.Add(FilmALister)
Next
LBL_NB_FILMS.Text = listbox_films.Items.Count
End Sub
#Region "Boutons modif fiche"
Private Sub BT_DELETE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_DELETE.Click
'Confirmation
If MsgBox("Etes vous certain de vouloir supprimer ce film ?", vbYesNo, "Confirmation") Then
'On le retire de la liste
Me._ListeFilms.Remove(_FilmEnVisualisation)
End If
'MAJ
UpdateListe()
LBL_DUREE.Text = ""
LBL_NOTE.Text = ""
LBL_STATUE.Text = ""
LBL_TITRE.Text = "Titre"
LBL_TYPE.Text = ""
RichTextBox2.Text = ""
IMG_FILM.ImageLocation = ""
End Sub
Private Sub BT_NEW_FICHE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_NEW_FICHE.Click
'Si nouveau film, on passe nothing
_FenetreAjout = New AjoutFIche(Nothing)
_FenetreAjout.Show()
End Sub
Private Sub BT_MAJ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_MAJ.Click
'Si une MAJ, on passe le paramètre du film actuel
_FenetreAjout = New AjoutFIche(_FilmEnVisualisation)
_FenetreAjout.Show()
End Sub
#End Region
#Region "Sauvegarde et récupération"
Private Sub Deserialisation()
If File.Exists("BibliothequeFilm.xml") Then
'On ouvre le fichier et récupère son flux
Dim FluxDeFichier As Stream = File.OpenRead("BibliothequeFilm.xml")
Dim Deserialiseur As New XmlSerializer(GetType(List(Of Film)))
'Désérialisation et conversion de ce qu'on récupère dans le type « Film »
_ListeFilms = Deserialiseur.Deserialize(FluxDeFichier)
'Fermeture du flux
FluxDeFichier.Close()
End If
End Sub
Private Sub Serialisation()
'On crée le fichier et récupère son flux
Dim FluxDeFichier As FileStream = File.Create("BibliothequeFilm.xml")
Dim Serialiseur As New XmlSerializer(GetType(List(Of Film)))
'Sérialisation et écriture
Serialiseur.Serialize(FluxDeFichier, _ListeFilms)
'Fermeture du fichier
FluxDeFichier.Close()
End Sub
#End Region
#Region "Section recherche"
Private Sub RemplissageChampsRecherche()
'Fonction utilisée plus tard pour préremplir les DDL de genres, réalisateurs
End Sub
Private Sub BT_RECHERCHE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_SEARCH.Click
Recherche()
End Sub
Private Sub Recherche()
'On vide la liste et on la reremplit
listbox_films.Items.Clear()
'Parcourt les films de la bibliothèque
For Each FilmALister As Film In _ListeFilms
If TXT_SEARCH.Text <> "" Then
If FilmALister.Nom.Contains(TXT_SEARCH.Text) Then
listbox_films.Items.Add(FilmALister)
End If
End If
Next
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Serialisation()
End Sub
End Class
Public Class Film
Private _Nom As String
Public Property Nom As String
Get
Return _Nom
End Get
Set(ByVal value As String)
_Nom = value
End Set
End Property
Private _Synopsis As String
Public Property Synopsis As String
Get
Return _Synopsis
End Get
Set(ByVal value As String)
_Synopsis = value
End Set
End Property
Private _NotePerso As Integer
Public Property NotePerso As Integer
Get
Return _NotePerso
End Get
Set(ByVal value As Integer)
_NotePerso = value
End Set
End Property
Private _Duree As Integer
Public Property Duree As Integer
Get
Return _Duree
End Get
Set(ByVal value As Integer)
_Duree = value
End Set
End Property
Private _Statue As String
Public Property Statue As String
Get
Return _Statue
End Get
Set(ByVal value As String)
_Statue = value
End Set
End Property
Private _Type As String
Public Property Type As String
Get
Return _Type
End Get
Set(ByVal value As String)
_Type = value
End Set
End Property
Private _IMGURL As String
Public Property IMGURL As String
Get
Return _IMGURL
End Get
Set(ByVal value As String)
_IMGURL = value
End Set
End Property
Public Sub New(ByVal Nom As String, ByVal Synopsis As String, ByVal NotePerso As Integer, ByVal Duree As Integer, ByVal Statue As String, ByVal Type As String, ByVal IMGURL As String)
_Nom = Nom
_Synopsis = Synopsis
_NotePerso = NotePerso
_Duree = Duree
_Statue = Statue
_Type = Type
_IMGURL = IMGURL
End Sub
Public Sub Update(ByVal Nom As String, ByVal Synopsis As String, ByVal NotePerso As Integer, ByVal Duree As Integer, ByVal Statue As String, ByVal Type As String, ByVal IMGURL As String)
_Nom = Nom
_Synopsis = Synopsis
_NotePerso = NotePerso
_Duree = Duree
_Statue = Statue
_Type = Type
_IMGURL = IMGURL
End Sub
'Je surcharge le Tostring
Public Overrides Function ToString() As String
Return _Nom
End Function
End Class |
Partager