Dans ce TP vous allez découvrir les fonctionnalités de Arraylist et aussi
l’utilisation d’une classe.
1. créer l’interface
Cette application a pour but la gestion des règlements. Elle permet entre autres le
calcul du montant que doit payer le client après une séance de navigation.
Il existe trois types de clients :
Etudiant : il paye 15 DH /heure
Fonctionnaire : il paye 20 DH /heure
Abonné : il paye 6 DH /heure
Le Cyber café offre trois services :
Navigation : 0DH de plus pour chaque client /heure
Visioconférence : 20DH de plus pour chaque client /heure
Navigation Assistance : 10DH de plus pour chaque client /heure
2. créer une classe comprenant les éléments de l’interface comme
attributs et créer les méthodes et les propriétés.
3. créer une fonction qui calcule le montant.
4. le montant sera calculer automatiquement et afficher dans la zone
de montant après avoir remplir la zone nombre d’heures et
sélectionner le type client et le service utilisé.
5. Programmer les boutons «nouveau », «précédent», «suivant »,
«premier», «dernier».
6. écrire le code des boutons modifier, supprimer et chercher par le N°
du règlement.
7. programmer le bouton quitter pour mettre fin l’application.
Correction
CLASS Gcyber
Public Class Gcyber
Private
_reglement As Integer
Private
_client As String
Private
_typeClient As String
Private
_numPoste As Integer
Private
_service As String
Private
_nbrHeure As Integer
Private
_date As Date
Sub New()
End Sub
Sub New(ByVal r As Integer, ByVal c As String, ByVal tc As String _
, ByVal np As Integer, ByVal s As String, ByVal nh As Integer, ByVal d As Date)
: Me._reglement
= r : Me._client = c : Me._typeClient
= tc
Me._numPoste
= np : Me._service = s : Me._nbrHeure = nh : Me._date
= d
End Sub
Property
reglement() As Integer
Get
Return
_reglement
End Get
Set(ByVal value As Integer)
Me._reglement
= value
End Set
End Property
Property
client() As String
Get
Return
_client
End Get
Set(ByVal value As String)
Me._client
= value
End Set
End Property
Property
typeClient() As String
Get
Return
_typeClient
End Get
Set(ByVal value As String)
Me._typeClient
= value
End Set
End Property
Property
numPoste() As Integer
Get
Return
_numPoste
End Get
Set(ByVal value As Integer)
Me._numPoste
= value
End Set
End Property
Property
service() As String
Get
Return
_service
End Get
Set(ByVal value As String)
Me._service
= value
End Set
End Property
Property
nbrHeure() As Integer
Get
Return
_nbrHeure
End Get
Set(ByVal value As Integer)
Me._nbrHeure
= value
End Set
End Property
Property
ladate() As Date
Get
Return
_date
End Get
Set(ByVal value As Date)
Me._date
= value
End Set
End Property
End Class
Class liste de Gcyber
Public Class list_Gcyber
Private
_list As ArrayList
Public Sub New()
_list = New
ArrayList
End Sub
Public Sub New(ByVal list1 As
ArrayList)
Me._list
= list1
End Sub
Public Property list() As
ArrayList
Get
Return
_list
End Get
Set(ByVal value As
ArrayList)
Me._list
= value
End Set
End Property
Public Sub AjoutS(ByVal s As Gcyber)
list.Add(s)
End Sub
End Class
Class Exeption
Public Class Exeption
Inherits
Exception
Sub New(ByVal msg As String)
MyBase.New(msg)
End Sub
End Class
Code de form
Public Class Form1
Dim g As New Gcyber() : Dim pos As Integer : Public l As New list_Gcyber()
'Afficher
Sub
afficher()
Text1.Text = g.reglement
Text2.Text = g.client
ComboBox1.Text = g.typeClient
Text3.Text = g.numPoste
ComboBox2.Text = g.service
Text4.Text = g.nbrHeure
MaskedTextBox1.Text = g.ladate
Calcule_Montant()
End Sub
'Calcul Montant
Sub
Calcule_Montant()
Dim t As Single
Select Case ComboBox1.Text
Case
"Etudiant" : t = 15
Case
"Fonctionnaire" : t = 20
Case
"Abonné" : t = 6
End Select
Select Case ComboBox2.Text
Case
"Navigation" : Text5.Text = (t *
g.nbrHeure)
Case
"Visioconférence" : Text5.Text =
(t * g.nbrHeure + g.nbrHeure * 10)
Case
"Navigation Assistance" :
Text5.Text = (t * g.nbrHeure + g.nbrHeure * 20)
End Select
End Sub
'Vider Zone
Sub vider()
Text1.Text = ""
Text2.Text = ""
ComboBox1.SelectedIndex = 0
Text3.Text = ""
ComboBox2.SelectedIndex = 0
Text4.Text = ""
MaskedTextBox1.Text = ""
Text5.Text = ""
End Sub
'Nouveau
Private Sub Button4_Click_1(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
vider()
End Sub
'Enregistrer
Private Sub Button1_Click_1(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If
Text1.Text = "" Or Text2.Text = ""
Or Text3.Text = ""
Or Text4.Text = ""
Then
MsgBox("Remplit
les champs ", MsgBoxStyle.Information)
Exit
Sub
End If
For Each g1 In l.list
If
g1.reglement = Text1.Text Then
MsgBox("Client
deja Existe ", MsgBoxStyle.Exclamation)
Exit
Sub
End
If
Next
g.reglement = Text1.Text : g.client =
Text2.Text : g.typeClient = ComboBox1.Text
g.numPoste = Text3.Text : g.service =
ComboBox2.Text : g.nbrHeure = Text4.Text
g.ladate = MaskedTextBox1.Text
l.AjoutS(g)
Calcule_Montant()
vider()
End Sub
'Modifier
Private Sub Button8_Click_1(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles Button8.Click
Dim i As Integer = 0
For Each g1 In l.list
If
g1.reglement = Text1.Text Then
g1 = New
Gcyber(Text1.Text, Text2.Text, Text3.Text, Text4.Text, MaskedTextBox1.Text,
ComboBox1.Text, ComboBox2.Text)
l.list.RemoveAt(i)
l.list.Insert(i, g1)
Exit
For
End
If
i += 1
Next
MsgBox("Modification
effectue", MsgBoxStyle.Information)
vider()
End Sub
'Supprimer
Private Sub Button7_Click_1(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
Dim i As Integer = 0
For Each g1 In l.list
If
MsgBox("vous voulez supprimer ce client",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
l.list.RemoveAt(i)
vider()
MsgBox("Suppression
effectue", MsgBoxStyle.Information)
Exit
Sub
End
If
i += 1
Next
End Sub
'Rechercher
Private Sub Button9_Click_1(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
Dim i As Integer
Dim
choix As Integer
= InputBox("Entrer numero de reglement",
"Rechercher")
For Each g1 In l.list
If
g1.reglement = choix Then
afficher()
Exit
Sub
End
If
i += 1
Next
MsgBox("L'element
rechercher n'existe pas ", MsgBoxStyle.Critical, "Rechercher")
End Sub
'Afficher un
client
Private Sub Button10_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
afficher()
End Sub
'Premier
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
pos = 0
Text1.Text = l.list.Item(pos).reglement
Text2.Text = l.list.Item(pos).client
ComboBox1.Text =
l.list.Item(pos).typeClient
Text3.Text = l.list.Item(pos).numPoste
ComboBox2.Text =
l.list.Item(pos).service
Text4.Text = l.list.Item(pos).nbrHeure
MaskedTextBox1.Text =
l.list.Item(pos).ladate
Calcule_Montant()
End Sub
'Precedent
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If pos
= 0 Or pos >= l.list.Count - 1 Then
MsgBox("index
hors limites")
' Throw
New Exeption("Index hors limites")
Exit
Sub
End If
pos -= 1
Text1.Text = l.list.Item(pos).reglement
Text2.Text = l.list.Item(pos).client
ComboBox1.Text =
l.list.Item(pos).typeClient
Text3.Text = l.list.Item(pos).numPoste
ComboBox2.Text =
l.list.Item(pos).service
Text4.Text = l.list.Item(pos).nbrHeure
MaskedTextBox1.Text =
l.list.Item(pos).ladate
Calcule_Montant()
End Sub
'Suivant
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If pos
>= l.list.Count - 1 Then
MsgBox("index
hors limites")
Exit
Sub
End If
pos += 1
Text1.Text = l.list.Item(pos).reglement
Text2.Text = l.list.Item(pos).client
ComboBox1.Text =
l.list.Item(pos).typeClient
Text3.Text = l.list.Item(pos).numPoste
ComboBox2.Text =
l.list.Item(pos).service
Text4.Text = l.list.Item(pos).nbrHeure
MaskedTextBox1.Text =
l.list.Item(pos).ladate
Calcule_Montant()
End Sub
'Dernier
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
pos = l.list.Count - 1
Text1.Text = l.list.Item(pos).reglement
Text2.Text = l.list.Item(pos).client
ComboBox1.Text =
l.list.Item(pos).typeClient
Text3.Text = l.list.Item(pos).numPoste
ComboBox2.Text =
l.list.Item(pos).service
Text4.Text = l.list.Item(pos).nbrHeure
MaskedTextBox1.Text = l.list.Item(pos).ladate
Calcule_Montant()
End Sub
ConversionConversion EmoticonEmoticon
Remarque : Seul un membre de ce blog est autorisé à enregistrer un commentaire.