Exercice Visual Basic : Examen Passage 2007 TSDI Variante 3 Programmation événementielle

Gestion des voyages organisés

Une entreprise de transports en commun souhaite informatiser la gestion de ses voyages organisés en car.

Un voyage est caractérisé par un code voyage, une date de départ, une durée de séjour, la ville de destination, un numéro d’immatriculation du car et un chauffeur (nom et prénom).

1-      Créer l’interface suivante :(1 point)

ExerciceVB-id2100 

NB : la zone de texte qui concerne le numéro de voyage doit être verrouiller et incrémenter par 1 à chaque nouveau voyage. 

2-      Créer la classe voyage et la collection qui va contenir touts les voyages.(2 points) 

3-      Ecrire les fonctions qui correspondent aux différents boutons de l’interface :

  1. Premier                                                                                                         (1 point)
  2. Précédant                                                                                          (1 point)
  3. Suivant                                                                                                          (1 point)
  4. Dernier                                                                                              (1 point)
  5. Nouveau                                                                                           (1.5 points)
  6. Enregistrer                                                                                         (1.5 points)
  7. g. Supprimer                                                                                         (2 points)


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
Public Class Form1
    Dim voy As New Voyage
    Dim i As Integer
    Dim pos As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = voy.num
        voy.num += 1
    End Sub
    Sub vider_zon()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        MaskedTextBox1.Text = ""
    End Sub
    Sub remplirzone()
        TextBox1.Text = voy.num
        TextBox2.Text = voy.nomCh
        TextBox4.Text = voy.durée
        TextBox5.Text = voy.ville
        TextBox6.Text = voy.immatriculation
        MaskedTextBox1.Text = voy.dated
    End Sub
    Sub lire(ByVal pos As Integer)
        voy = lst(pos)
        remplirzone()
    End Sub
 
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        TextBox1.Text = voy.num
        voy.num += 1
        TextBox2.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        MaskedTextBox1.Text = ""
    End Sub
 
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim voy As New Voyage(TextBox2.Text, MaskedTextBox1.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text)
        voy.num = TextBox1.Text
        voy.nomCh = TextBox2.Text
        voy.durée = TextBox4.Text
        voy.ville = TextBox5.Text
        voy.immatriculation = TextBox6.Text
        voy.dated = MaskedTextBox1.Text
        lst.Add(voy)
    End Sub
    '
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If MsgBox("voulez vous vraiment supprimer cette enregestrement", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, "confirmation suppression") = MsgBoxResult.Yes Then
            For Each elem In lst
                If elem.num = TextBox1.Text Then
                    lst.RemoveAt(i)
                    Try
                        lire(i)
                        pos = 1
                    Catch ex As Exception
                        If lst.Count Then
                            vider_zon()
                        Else
                            lire(i - 1)
                            pos = i - 1
                        End If
                    End Try
                    Exit Sub
                End If
                i += 1
            Next
        End If
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.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
        pos = 0
        lire(pos)
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        pos = lst.Count - 1
        lire(pos)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            pos -= 1
            lire(pos)
        Catch ex As Exception
        End Try
        Exit Sub
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            pos += 1
            lire(pos)
        Catch ex As Exception
        End Try
    End Sub
End Class
 
------------------------------------------------------------------------------------------------------------------
 
Public Class FormMain
 
    Private Sub FicheInformatioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FicheInformatioToolStripMenuItem.Click
        Dim fr As New Form1
        fr.Hide()
        fr.MdiParent = Me
        fr.Show()
    End Sub
 
    Private Sub AffichageDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AffichageDataToolStripMenuItem.Click
        Dim fr2 As New Liste_Affichage
        fr2.Hide()
        fr2.MdiParent = Me
        fr2.show()
    End Sub
End Class
 
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Public Class Liste_Affichage
    Public dt As New DataTable
    Public dr As DataRow
    Public voy As New Voyage
    Private Sub Liste_Affichage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        For i = 0 To lst.Count - 1
            voy = lst(i)
            ComboBox1.Items.Add(voy.num)
            ComboBox2.Items.Add(voy.immatriculation)
        Next
        dt.Columns.Add(New DataColumn("Num", GetType(String)))
        dt.Columns.Add(New DataColumn("Nom choufeur", GetType(String)))
        dt.Columns.Add(New DataColumn("Durée", GetType(Integer)))
        dt.Columns.Add(New DataColumn("Ville", GetType(String)))
        dt.Columns.Add(New DataColumn("Immatriculation", GetType(String)))
        dt.Columns.Add(New DataColumn("Date départ", GetType(String)))
    End Sub
 
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        For i = 0 To lst.Count - 1
            voy = lst(i)
            If ComboBox1.Text = voy.num Then
                dr = dt.NewRow()
                dr("Num") = voy.num
                dr("Nom choufeur") = voy.nomCh
                dr("Durée") = voy.durée
                dr("Ville") = voy.ville
                dr("Immatriculation") = voy.immatriculation
                dr("Date départ") = voy.dated
                dt.Rows.Add(dr)
            End If
            DG.DataSource = dt
        Next
    End Sub
 
    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        For i = 0 To lst.Count - 1
            voy = lst(i)
            If ComboBox2.Text = voy.immatriculation Then
                dr = dt.NewRow()
                dr("Num") = voy.num
                dr("Nom choufeur") = voy.nomCh
                dr("Durée") = voy.durée
                dr("Ville") = voy.ville
                dr("Immatriculation") = voy.immatriculation
                dr("Date départ") = voy.dated
                dt.Rows.Add(dr)
            End If
        Next
        DG.DataSource = dt
    End Sub
End Class
 
------------------------------------------------------------------------------
 
Public Class Voyage
    Public num As Integer = 1
    Public nomCh As String
    Public dated As String
    Public durée As Integer
    Public ville As String
    Public immatriculation As String
    Sub New()
    End Sub
    Sub New(ByVal nom As String, ByVal date1 As String, ByVal duré As Integer, ByVal ville1 As String, ByVal imm As String)
        num += 1
        nomCh = nom
        dated = date1
        durée = duré
        ville = ville1
        immatriculation = imm
    End Sub
End Class
ABONNEZ-VOUS À LA NEWSLETTER !

Télécharger votre Calendrier 2022

X