Exercice Visual Basic : Utilisation des collections

On souhaite maintenant re-développer quelques fonctionnalités de cette application (suite à l'exercice gestion Stagiaire) en Vb (Utilisation des collections)

  1. Créer un formulaire permettant d’ajouter, modifier, supprimer et rechercher un stagiaire 
  2. Programmer les fonctionnalités suivantes :
    1. Ajout 
    2. Modification 
    3. Suppression 
    4. Recherche 
  1. Ajouter un formulaire contenant une liste permettant d’afficher les stagiaires et leurs notes ainsi que la moyenne par stagiaire triés par filière.
  2. Afin d’imprimer cette liste, nous souhaitons enregistrer l’ensemble des enregistrement dans un fichier texte. Ecrire le programme permettant de réaliser cette fonctionnalité 
  3. Protéger l’accès à cette application par : 
  •  
    • Compte : Admin
    • Mot de passe : Cmoi

Rappel:

Soit la class Stagiaire qui modélise un stagiaire , cette class comportera les attributs suivants :

Matricule                                            INT

Nom                                                   String

Prénom                                               String

Filière                                                 String

Note1                                                 Double

Note2                                                 Double

Note3                                                 Double

 Interface Graphique:

 


123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272Public Class Stagiaire Private Matricule As Integer Private Nom As String Private Prénom As String Private Filière As String Private Note1 As Double Private Note2 As Double Private Note3 As Double Public moy As Double Shared compteur As Integer = 1 Property _Matricule() As Integer Get Return Matricule End Get Set(ByVal value As Integer) Matricule = value End Set End Property Property _nom() As String Get Return Nom End Get Set(ByVal value As String) Nom = value End Set End Property Property _Prénom() As String Get Return Prénom End Get Set(ByVal value As String) Prénom = value End Set End Property Property _Filière() As String Get Return Filière End Get Set(ByVal value As String) Filière = value End Set End Property Property _note1() As Double Get Return Note1 End Get Set(ByVal value As Double) Note1 = value End Set End Property Property _note2() As Double Get Return Note2 End Get Set(ByVal value As Double) Note2 = value End Set End Property Property _note3() As Double Get Return Note3 End Get Set(ByVal value As Double) Note3 = value End Set End Property Sub New() Matricule = compteur End Sub Public Sub New(ByVal N As String, ByVal P As String, ByVal F As String) compteur += 1 _Matricule = compteur _nom = N _Prénom = P _Filière = F End Sub Public Sub New(ByVal N As String, ByVal P As String, ByVal F As String, ByVal N1 As Double, ByVal N2 As Double, ByVal N3 As Double) compteur += 1 _Matricule = compteur _nom = N _Prénom = P _Filière = F _note1 = N1 _note2 = N2 _note3 = N3 End Sub Sub RAZ() compteur = 0 End Sub Public Sub EQUAL(ByVal s1 As Stagiaire, ByVal s2 As Stagiaire) If s1.Matricule = s2.Matricule Then Console.WriteLine("Se stagiaire existe déjà") End If End Sub Public Function CALCUL() As Double Return Math.Round((Note1 + Note2 + Note3) / 3, 2) End Function Sub ERRORNOTE() If Note1 > 20 Or Note1 Then Dim ERRORNOTE As New Exception("Entrer la note1 correctement") ElseIf Note2 > 20 Or Note2 Then Dim ERRORNOTE As New Exception("Entrer la note2 correctement") ElseIf Note3 > 20 Or Note3 Then Dim ERRORNOTE As New Exception("Entrer la note3 correctement") End If End Sub Public Sub Afficher() Console.WriteLine(_Matricule & vbTab & _nom & vbTab & _Prénom & vbTab & _Filière) End Sub Public Sub affichage() Console.WriteLine(_Matricule & vbTab & _nom & vbTab & _Prénom & vbTab & _Filière & Note1 & vbTab & Note2 & vbTab & Note3) End SubEnd Class----------------------------------------------------------------------------Public Class Form1 Dim stag As New Stagiaire Public i, pos, n As Integer Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click stag._Matricule += 1 Txtmat.Text = stag._Matricule txtnom.Text = "" txtprénom.Text = "" txtfil.Text = "" Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click If MsgBox("Voulez vous vraiment quitter l'application", MsgBoxStyle.YesNoCancel, "Confirmation Sortie") = MsgBoxResult.Yes Then End End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim stag As New Stagiaire(txtnom.Text, txtprénom.Text, txtfil.Text, Text1.Text, Text2.Text, Text3.Text) stag._Matricule = Txtmat.Text stag._nom = txtnom.Text stag._Prénom = txtprénom.Text stag._Filière = txtfil.Text stag._note1 = Text1.Text stag._note2 = Text2.Text stag._note3 = Text3.Text stag.moy = Text4.Text lst.Add(stag) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Txtmat.Text = stag._Matricule End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Text4.Text = Math.Round((CDbl(Text1.Text) + CDbl(Text2.Text) + CDbl(Text3.Text)) / 3, 2) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If MsgBox("Voulez vous vraiment modifier cette enregestrement", MsgBoxStyle.YesNoCancel, "Confirmation Modification") = MsgBoxResult.Yes Then For Each ele In lst If ele._matricule = Txtmat.Text Then Try lst.RemoveAt(i) If lst.Count Then lst.Add(ele) Else lst.Insert(i, ele) End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information) End Try Exit For End If i += 1 Next End If End Sub Sub lire(ByVal pos As Integer) stag = lst(i) remplire() End Sub Sub remplire() Txtmat.Text = stag._Matricule txtnom.Text = stag._nom txtprénom.Text = stag._Prénom txtfil.Text = stag._Filière Text1.Text = stag._note1 Text2.Text = stag._note2 Text3.Text = stag._note3 Text4.Text = stag.moy End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If MsgBox("Voulez vous vraiment Supprimer cette enregestrement", MsgBoxStyle.YesNoCancel, "Confirmation Suppression") = MsgBoxResult.Yes Then For Each elem In lst If elem._matricule = Txtmat.Text Then lst.RemoveAt(i) Try lire(i) pos = i Catch ex As Exception If lst.Count Then raz() Else lire(i - 1) pos = i - 1 End If End Try Exit For End If i += 1 Next End If End Sub Sub raz() stag._Matricule += 1 Txtmat.Text = stag._Matricule txtnom.Text = "" txtprénom.Text = "" txtfil.Text = "" Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim a As Integer = InputBox("Entrer le num du stagiaire sue vous voulez rechercher", "Recherche") For i = 0 To lst.Count - 1 stag = lst(i) If a = stag._Matricule Then remplire() pos = i Exit Sub End If Next i += 1 MsgBox("Lélément que vous chercher n'existe pas", MsgBoxStyle.Exclamation, "Rechercher") End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Affichage.Show() End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click FileOpen(1, "naziha.txt", OpenMode.Output) For i = 0 To lst.Count - 1 stag = lst(i) PrintLine(1, stag._Matricule & "/" & stag._nom & "/" & stag._Prénom & "/" & stag._Filière & "/" & stag._note1 & "/" & stag._note2 & "/" & stag._note3 & "/" & stag.moy) Next FileClose() End SubEnd Class-------------------------------------------------------------------------------Public Class Affichage Dim lvi As New ListViewItem Dim stag As New Stagiaire Private Sub Affichage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For i = 0 To lst.Count - 1 stag = lst(i) Dim lvi = New ListViewItem(stag._Matricule) lvi.SubItems.Add(stag._nom) lvi.SubItems.Add(stag._Prénom) lvi.SubItems.Add(stag._Filière) lvi.SubItems.Add(stag._note1) lvi.SubItems.Add(stag._note2) lvi.SubItems.Add(stag._note3) lvi.SubItems.Add(stag.moy) ListView1.Items.Add(lvi) ListView1.Select() Next End SubEnd Class
Article publié le 06 Janvier 2012 Mise à jour le Samedi, 17 Décembre 2022 16:35 par GC Team