Exercice VB: Examen Fin de Formation TSDI juin 2008 variante 9

Soit le modèle relationnel suivant :

Salarie (Matricule, Nom, Poste, E-mail, DatEmb, Salaire, NumSer, prime)

Service (NumService, NomService, Lieu)

Projet (CodePrj, NomPrj, DateDebut, dateFin)

Participation (Matricule, CodeProjet, Fonction, NbrJours)

Travail à faire :

  1. Créer la base de données sous SQL SERVER (2 Pts)
  2. Faire quelques enregistrements pour le test
  3. Créer une procédure stockée qui permet d’augmenter le salaire de 5% pour tous les employés (2 Pts)
  4. Créer une procédure stockée permettant d’attribuer une prime de 80% du salaire aux employés travaillant dans un service donné. (1,5 Pts)
  5. Créer une procédure stockée permettant de retourner le nombre de jours effectué par un employé pour un projet donné (1,5 Pts)
  6. Créer une interface de mise à jour de la table Salarié (4 Pts)
    1. Ajout (le contrôle de saisie est obligatoire et confirmation d’ajout)
    2. Modification
    3. Suppression
    4. Boutons de navigation
  7. Créer une interface de mise à jour des tables : Service et Projet (4 Pts)
  8. Créer une interface de mise à jour de la table Participation (1 Pt)
  9. Créer une feuille de recherche :
    1. Affichant le liste des participant à un projet (2 Pts)
    2. Les salariés embauchés entre deux dates (2 Pts)
  10. Créer un état pour afficher la liste des employés qui travaillent dans un projet donné. (2Pts)
  11. Créer un état permettant d’afficher le nombre de jours de travail total effectué pour un projet donné. (3Pts)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437Imports System.Data.SqlClientImports System.Data.SqlClient.SqlCommandPublic Class affichage Dim dset As New DataSet Dim strsql As String Dim table As New DataTable Dim cm As CurrencyManager Public adapter As New SqlDataAdapter Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click f5.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click adapter = New SqlDataAdapter("SELECT * FROM participation", con) adapter.Fill(dset, "participation") cm = CType(BindingContext(dset, "participation"), CurrencyManager) table = Dset.Tables(0) table.PrimaryKey = New DataColumn() {table.Columns(0)} If table.Rows.Count > 0 Then ' Afficher(0) End If dg.DataSource = table End SubEnd Class---------------------------------------------------------------------------Public Class index Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click f2.Show() Me.Hide() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click f3.Show() Me.Hide() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click f4.Show() Me.Hide() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click f5.Show() Me.Hide() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click End End SubEnd Class---------------------------------------------------------------------------Imports System.Data.SqlClientImports System.IOModule Module1 Public con As New SqlConnection("server=(local); integrated security=sspi; database= employé") Public f1 As index Public f2 As salarié Public f3 As service Public f4 As projet Public f5 As participation Public f6 As affichageEnd Module----------------------------------------------------------------------------Imports System.Data.SqlClientImports System.Data.SqlClient.SqlCommandPublic Class participation Public Adapter As New SqlDataAdapter Dim cm As CurrencyManager Public Dset As New DataSet Public table As New DataTable Public cmd As New SqlCommand Public dr As SqlDataReader Private Sub participation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Adapter = New SqlDataAdapter("select * from participation", con) Adapter.Fill(Dset, "participation") cm = CType(BindingContext(Dset, "participation"), CurrencyManager) TextBox1.DataBindings.Add("text", Dset, "participation.matricule") TextBox2.DataBindings.Add("text", Dset, "participation.codeprj") TextBox3.DataBindings.Add("text", Dset, "participation.fonction") TextBox4.DataBindings.Add("text", Dset, "participation.nbrjours") table = Dset.Tables(0) table.PrimaryKey = New DataColumn() {table.Columns(0)} If table.Rows.Count > 0 Then ' Afficher(0) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'modifier Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "update from participation where matricule =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'supprimer Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "delete from participation where matricule =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click End End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click f1.Show() Me.Hide() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click cm.Position = 0 End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click cm.Position -= 1 End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click cm.Position += 1 End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click cm.Position = cm.Count End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click f6.Show() Me.Hide() End SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientImports System.Data.SqlClient.SqlCommandPublic Class projet Public Adapter As New SqlDataAdapter Dim cm As CurrencyManager Public Dset As New DataSet Public table As New DataTable Public cmd As New SqlCommand Public dr As SqlDataReader Private Sub projet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Adapter = New SqlDataAdapter("select * from projet", con) Adapter.Fill(Dset, "projet") cm = CType(BindingContext(Dset, "projet"), CurrencyManager) TextBox1.DataBindings.Add("text", Dset, "projet.codeprj") TextBox2.DataBindings.Add("text", Dset, "projet.nomprj") TextBox3.DataBindings.Add("text", Dset, "projet.datedebut") TextBox4.DataBindings.Add("text", Dset, "projet.datefin") table = Dset.Tables(0) table.PrimaryKey = New DataColumn() {table.Columns(0)} If table.Rows.Count > 0 Then ' Afficher(0) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'modifier Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "update from projet where codeprj =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'supprimer Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "delete from projet where codeprj =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click End End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click f1.Show() Me.Hide() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click cm.Position = 0 End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click cm.Position -= 1 End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click cm.Position += 1 End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click cm.Position = cm.Count End SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientImports System.Data.SqlClient.SqlCommandPublic Class salarié Public Adapter As New SqlDataAdapter Dim cm As CurrencyManager Public Dset As New DataSet Public table As New DataTable Public cmd As New SqlCommand Public dr As SqlDataReader Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Adapter = New SqlDataAdapter("select * from salarie", con) Adapter.Fill(Dset, "salarie") cm = CType(BindingContext(Dset, "salarie"), CurrencyManager) TextBox1.DataBindings.Add("text", Dset, "salarie.matricule") TextBox2.DataBindings.Add("text", Dset, "salarie.nom") TextBox3.DataBindings.Add("text", Dset, "salarie.poste") TextBox4.DataBindings.Add("text", Dset, "salarie.E-mail") TextBox5.DataBindings.Add("text", Dset, "salarie.datemb") TextBox6.DataBindings.Add("text", Dset, "salarie.salaire") TextBox7.DataBindings.Add("text", Dset, "salarie.numservice") TextBox8.DataBindings.Add("text", Dset, "salarie.prime") table = Dset.Tables(0) table.PrimaryKey = New DataColumn() {table.Columns(0)} If table.Rows.Count > 0 Then ' Afficher(0) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'modifier Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "update from salarie where matricule =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'supprimer Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "delete from salarie where matricule =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click End End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click cm.Position = 0 End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click cm.Position += 1 End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click cm.Position -= 1 End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click cm.Position = cm.Count End SubEnd Class-----------------------------------------------------------------------------Imports System.Data.SqlClientImports System.Data.SqlClient.SqlCommandPublic Class service Public Adapter As New SqlDataAdapter Dim cm As CurrencyManager Public Dset As New DataSet Public table As New DataTable Public cmd As New SqlCommand Public dr As SqlDataReader Private Sub service_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Adapter = New SqlDataAdapter("select * from service", con) Adapter.Fill(Dset, "service") cm = CType(BindingContext(Dset, "service"), CurrencyManager) TextBox1.DataBindings.Add("text", Dset, "service.numservice") TextBox2.DataBindings.Add("text", Dset, "service.nomservice") TextBox3.DataBindings.Add("text", Dset, "service.lieu") table = Dset.Tables(0) table.PrimaryKey = New DataColumn() {table.Columns(0)} If table.Rows.Count > 0 Then ' Afficher(0) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'modifier Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "update from service where numservice =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'supprimer Try con.Open() cmd.Connection = con cmd.CommandType = Data.CommandType.Text cmd.CommandText = "delete from service where numservice =" & TextBox1.Text cmd.ExecuteNonQuery() MsgBox(" OK ", MsgBoxStyle.Information) con.Close() Catch ex As Exception MsgBox(ex.Message) con.Close() End Try End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click f1.Show() Me.Hide() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click cm.Position = 0 End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click cm.Position -= 1 End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click cm.Position += 1 End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click cm.Position = cm.Count End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click End End SubEnd Class

Une ligne article est décrite par les données suivantes

ATTRIBUTS

Type

Visibilite

NumArticle

Entier

Private

Designation

Caractere

Private

PrixUnitaire

Reel double

Private

QuantiteEn Stock

Entier

Private

QuantiteCommandee

Entier

Private

NumCommande

Entier

Private

On peut connaitre le prix de vente article par la fonction MontantLigneQ.

On peut connaitre le total facture par la fonction TotalFactureQ. On peut connaitre le reste en stock par la fonction RestStockQ.

1- Ecrire la classe LigneArticle avec ses donnees, ses methodes et ses constructeurs :

•    la   methode   MontantLigneQ renvoie  le   calcul   du    total   ligne   (PrixUnitaire   * QuantiteCommandee)

•    la methode TotalFactureQ renvoie le calcul du total facture (somme(MontantLigne))

•    la   methode   RestStockQ renvoie   le   reste   en   stock   lorsque   un   article   est   vendu

(QuantiteEn Stock - QuantiteCommandee )

•   la methode AffichageQ affiche les lignes commande

2- Les objets de la classe LigneArticle sont a stocke dans un vecteur dynamique.

a) Creer une methode SaisieArticleQ permettant de saisir les objets de la classe LigneArticle

Exemple d'objets de la classe LigneArticle 

NumArticle

Designation

PrixUnitaire

QuantiteEnStoc k

QuantiteCommandee

NumCommande

01

Ecran

350

30

10

1

02

Souris

30

100

30

1

01

Ecran

350

20

5

2

03

Imprimante

1000

10

2

1

02

Souris

30

70

5

2

b) Ecrire un programme permettant de realiser le menu suivant: 

1.  Remplissage du vecteur .

2.  Ajout d'une ligne article et affichage du reste en stock pour Particle commande.

3.  Insérer une ligne article a un emplacement précis.

4.  Suppression d'un ligne article.

5.  Afficher les lignes articles.

6.  Afficher les lignes articles d'une même commande.

7.  Trier les lignes articles par numéro d'article.

3 - On désire stocker dans un fichier séquentiel les lignes articles dont la quantité en stock est supérieur a 50.

Ecrire un programme permettant de :

a) Créer le fichier séquentiel a partir des informations contenues dans le vecteur 

b) Afficher 1'ensemble des enregistrements 

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697Public Class ligne_article Private NumArticle As Integer Private Designation As Char Private PrixUnitaire As Double Private QuantiteEn_Stock As Integer Private QuantiteCommandee As Integer Private NumCommande As Integer Dim a As Double Property _numart() Get Return NumArticle End Get Set(ByVal value) NumArticle = value End Set End Property Property _des() Get Return Designation End Get Set(ByVal value) Designation = value End Set End Property Property _prix() Get Return PrixUnitaire End Get Set(ByVal value) PrixUnitaire = value End Set End Property Property _qtstock() Get Return QuantiteEn_Stock End Get Set(ByVal value) QuantiteEn_Stock = value End Set End Property Property _qtcom() Get Return QuantiteCommandee End Get Set(ByVal value) QuantiteCommandee = value End Set End Property Property _numcom() Get Return NumCommande End Get Set(ByVal value) NumCommande = value End Set End Property Public Function montantligne() As Double Return (PrixUnitaire * QuantiteCommandee) End Function Public Function TotalFactureQ() As Double a += montantligne() Return a End Function Public Function RestStockQ() As Double Return (QuantiteEn_Stock - QuantiteCommandee) End Function Public Sub AffichageQ() Console.WriteLine(NumCommande & vbTab & QuantiteCommandee) End SubEnd Class---------------------------------------------------------------------------------------------Module Module1 Public al As New Collections.ArrayList Sub Main() End Sub Public Sub SaisieArticleQ() Dim s As New ligne_article Console.WriteLine("Entrez le numero d'article") s._numart = Console.ReadLine Console.WriteLine("Entrez le designation") s._des = Console.ReadLine Console.WriteLine("Entrez le prix unitaire") s._prix = Console.ReadLine Console.WriteLine("Entrez la qt en stock ") s._qtstock = Console.ReadLine Console.WriteLine("Entrez le qt commandé") s._qtcom = Console.ReadLine Console.WriteLine("Entrez le numero de commande") s._numcom = Console.ReadLine al.Add(s) End SubEnd Module

Exercice Visual Basic : Liste Contact

On a Un contact est reconnu par son:

  • Numéro
  • Nom
  • Prénom
  • Date de naissance
  • Poste
  • Entreprise

-  Créer la Classe Contact

-  Créer les Opération situés dans l’interface suivante :

 

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269Public Class contact Private num As Integer Private nom As String Private prénom As String Private Date_n As Date Private poste As String Private entreprise As String Property _num() As Integer Get Return num End Get Set(ByVal value As Integer) num = 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 _date_n() As Date Get Return Date_n End Get Set(ByVal value As Date) Date_n = value End Set End Property Property _poste() As String Get Return poste End Get Set(ByVal value As String) poste = value End Set End Property Property _Entreprise() As String Get Return entreprise End Get Set(ByVal value As String) entreprise = value End Set End Property Sub New() End Sub Public Sub New(ByVal N As String, ByVal P As String, ByVal po As String, ByVal DN As Date, ByVal En As String) _nom = N _prénom = P _date_n = DN _poste = po _Entreprise = En End Sub Public Sub afficher() Console.WriteLine(_num & vbTab & _nom & vbTab & _poste & vbTab & _date_n & vbTab & _poste & vbTab & _Entreprise) End Sub Public Function age() As String Return DateDiff(DateInterval.Year, Date_n, Today) End Function Sub N_poste(ByVal new_poste As String) ' Do Console.WriteLine("entrer le nouveau poste") new_poste = Console.ReadLine If new_poste "" Then poste = new_poste Exit Do Else Dim postexception As New Exception("entrer le nouveau poste correctement") Console.WriteLine(postexception) End If Loop Until new_poste = "" End Sub Public Sub new_ent(ByVal newE As String) Do Console.WriteLine("saisire le nouvelle entreprise") newE = Console.ReadLine If newE "" Then entreprise = newE Exit Do Else Dim enexception As New Exception("saisire la nouvelle entreprise correctement") Console.WriteLine(enexception) End If Loop Until newE = "" End SubEnd Class------------------------------------------------------------------------------Module Module1 Dim c As New contact Public lst As New ArrayList Sub Main() Dim rep As String Dim choix As Integer Do menu() Console.WriteLine("Tapper le numéro de votre choix") choix = Console.ReadLine Select Case choix Case 1 créer_contacte() Case 2 supprimer() Case 3 afficher_un() Case 4 Modifier_poste() Case 5 modifierEn() Case 6 afficher_tous() Case 7 sauvgarder() Case 8 restaurer() Case 9 End Case Else Console.WriteLine("le choix que vous avez tapper est introuvable") End Select Console.WriteLine("voulez vous continuer O/N") rep = Console.ReadLine Loop Until rep = "n" End Sub Sub menu() Console.WriteLine("*****************************[----MENU----]******************************") Console.WriteLine(" .1. Créer contecte ") Console.WriteLine(" .2. Supprimer un contact ") Console.WriteLine(" .3. Afficher un contact (avec age) ") Console.WriteLine(" .4. Modifier le poste d’un contact ") Console.WriteLine(" .5. Modifier l’entreprise d’un contact ") Console.WriteLine(" .6. Afficher les contacts, ainsi que leur nombre, par nom du contact") Console.WriteLine(" .7. Sauvegarder la liste des contacts ") Console.WriteLine(" .8. Restaurer la liste des contacts ") Console.WriteLine(" .9. Quitter ") Console.WriteLine(" ") Console.WriteLine("*************************************************************************") Console.WriteLine(" ") End Sub Sub créer_contacte() Try c._num = lst.Count + 1 Console.WriteLine("saisirele nom du contecte") c._nom = Console.ReadLine Console.WriteLine("saisire le prénom du contact") c._prénom = Console.ReadLine Console.WriteLine("saisire la date de naissance su contact") c._date_n = Console.ReadLine Console.WriteLine("saisire le poste du contacte") c._poste = Console.ReadLine Console.WriteLine("saisire l'entreprise du contact") c._Entreprise = Console.ReadLine Catch ex As Exception Console.WriteLine("saisire les données correctement") Exit Sub End Try lst.Add(c) End Sub Public Sub afficher_tous() For i = 0 To lst.Count - 1 lst(i).afficher() Next End Sub Public Sub afficher_un() Console.WriteLine("entrer le numéro du contecte à afficher") Dim n As Integer = Console.ReadLine For i = 0 To lst.Count - 1 c = lst(i) If c._num = n Then lst(i).afficher() Exit Sub Else Console.WriteLine("le contacte n'existe pas") End If Next End Sub Public Sub supprimer() Console.WriteLine("saisire le numéro du contacte à supprimer") Dim nc As Integer = Console.ReadLine For i = 0 To lst.Count - 1 c = lst(i) If c._num = nc Then lst.RemoveAt(i) Console.WriteLine("Supprimer avec succé") Exit Sub Else Console.WriteLine("se contacte n'existe pas") End If Next End Sub Public Sub Modifier_poste() Dim new_poste As String Console.WriteLine("saisire le num du ccontacte à modifier le poste") Dim po As String = Console.ReadLine For i = 0 To lst.Count - 1 c = lst(i) If c._num = po Then lst(i).afficher() c.N_poste(new_poste) lst(i) = c Exit Sub Else Console.WriteLine("se contacte n'existe pas") End If Next End Sub Public Sub modifierEn() Dim new_E As String Console.WriteLine("saisire le numéro du contacte à modifier l'entreprise") Dim na As Integer = Console.ReadLine For i = 0 To lst.Count - 1 c = lst(i) If c._num = na Then lst(i).afficher() c.new_ent(new_E) lst(i) = c Exit Sub Else Console.WriteLine("se contacte n'existe pas") End If Next End Sub Public Sub sauvgarder() FileOpen(1, "naziha.txt", OpenMode.Output) For i = 0 To lst.Count - 1 c = lst(i) PrintLine(1, c._num & "/" & c._nom & "/" & c._prénom & "/" & c._date_n & "/" & c._poste & "/" & c._Entreprise) Next Console.WriteLine("sauvgarder avec succé") FileClose() End Sub Public Sub restaurer() Dim tcl() As String Dim i As Integer FileOpen(1, "naziha.txt", OpenMode.Input) While Not EOF(1) Dim len As String = LineInput(1) tcl = Split(len, "/") For i = 0 To tcl.GetUpperBound(0) Console.WriteLine(tcl(i) & vbTab) Next 'Try ' c._num = CInt(tcl(0)) ' c._nom = tcl(1).ToString ' c._prénom = tcl(2).ToString ' c._date_n = CDate(tcl(3)) ' c._poste = tcl(4).ToString ' c._Entreprise = tcl(5).ToString ' lst.Add(c) 'Catch ex As Exception 'End Try End While FileClose() End SubEnd Module

Exercice Visual Basic : Manipuler un Texte

Ecrire le code VB qui permet de réaliser l'interface suivante:



1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677Public Class Form1 Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click Clipboard.SetDataObject(Texte.SelectedText) End Sub Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim a As New ColorDialog a.AnyColor = True 'permet d'apparaitre les couleurs de base seulment a.FullOpen = True 'pour aparaitre arc en ciel a.ShowHelp = True 'pour apparaitre l'icon d'aide a.Color = Texte.backcolor If a.ShowDialog = DialogResult.OK Then Texte.BackColor = a.Color End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Dim a As New FontDialog a.ShowApply = True 'pour apparaitre le boton de "appliquer" a.ShowColor = True 'permet d'apparaitre "couleur" ds un textbox a.ShowEffects = True 'a.AllowVerticalFonts = True a.Font = Texte.SelectionFont a.Color = Texte.SelectionColor If (a.ShowDialog() = DialogResult.OK) Then Texte.SelectionFont = a.Font Texte.SelectionColor = a.Color End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Texte.SelectionAlignment = HorizontalAlignment.Center End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Texte.SelectionAlignment = HorizontalAlignment.Left End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Texte.SelectionAlignment = HorizontalAlignment.Right End Sub Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click Texte.Cut() End Sub Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click Texte.Paste() End Sub Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click Texte.SelectAll() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim a As MessageBox Dim b As MsgBoxResult b = a.Show("Voulez vous vraiment sortir????", "confirmation!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If b = MsgBoxResult.Yes Then End End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp If e.Button = MouseButtons.Right Then Me.ContextMenu1.Show(Texte, New Point(e.X, e.Y)) End If End SubEnd Class

Exercice Visual Basic : Mini Pint

Ecrire le code qui permet de réalser l'interface suivante:
NB: Le principe c'est de réaliser un Mini Pint


123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157Public Class Form1 Dim P As New Pen(Color.Black), AvPoint As Point, PrecColor As Color Dim Graf, g As Graphics, Bitmap_ As Bitmap Private Sub FermerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Bitmap_ = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height) End Sub Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown Dim NewPoint As New Point(e.X, e.Y) AvPoint = NewPoint End Sub Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove Dim p_ As New Point(e.X, e.Y) If (Me.PictureBox1.Capture) Then Graf = Me.PictureBox1.CreateGraphics g = Graphics.FromImage(Bitmap_) Graf.DrawLine(P, p_, AvPoint) g.DrawLine(P, p_, AvPoint) AvPoint = p_ End If End Sub Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.ColorDialog1.ShowDialog() Me.P.Color = Me.ColorDialog1.Color End Sub Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click Me.PictureBox1.Image = Bitmap_ Me.SaveFileDialog1.Title = "Enregistrer l'image" Me.SaveFileDialog1.Filter = "image(*.png)|*.png" Me.SaveFileDialog1.ShowDialog() Try Me.PictureBox1.Image.Save(Me.SaveFileDialog1.FileName) Catch ex As Exception MsgBox("Erreur :" + Err.Description, MsgBoxStyle.Critical) End Try End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click Me.PrecColor = P.Color Me.Cursor = Cursors.No Me.P.Color = Color.White P.Width = 10 End Sub Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click Me.Cursor = Cursors.Default P.Width = 1 P.Color = Me.PrecColor End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ChangeC(Me.Button1) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ChangeC(Me.Button2) End Sub Private Sub ChangeC(ByVal b As Button) Me.PictureBox2.BackColor = b.BackColor P.Color = b.BackColor End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click ChangeC(Me.Button4) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ChangeC(Me.Button3) End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click ChangeC(Me.Button6) End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click ChangeC(Me.Button5) End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click ChangeC(Me.Button8) End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click ChangeC(Me.Button7) End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click ChangeC(Me.Button10) End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click ChangeC(Me.Button9) End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click ChangeC(Me.Button12) End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click ChangeC(Me.Button11) End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click ChangeC(Me.Button14) End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click ChangeC(Me.Button13) End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click ChangeC(Me.Button16) End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click ChangeC(Me.Button15) End Sub Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click ChangeC(Me.Button18) End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click ChangeC(Me.Button17) End Sub Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click ChangeC(Me.Button20) End Sub Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click ChangeC(Me.Button19) End Sub Private Sub ImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImageToolStripMenuItem.Click Me.OpenFileDialog1.Filter = "*.png|(*.png)|*.jpeg|(*.jpeg)|*.jpg|(*.jpg)|*.bmp|(*.bmp)" Me.OpenFileDialog1.ShowDialog() g = Graphics.FromImage(Bitmap_) Try Me.PictureBox1.Image = New Bitmap(Me.OpenFileDialog1.FileName) g.DrawImage(Me.PictureBox1.Image, AvPoint) Catch ex As Exception MsgBox("Erreur :" + Err.Description, MsgBoxStyle.Critical) End Try End SubEnd Class

Exercice Visual Basic : Mini Word

Ecrire le programme qui permet de réaliser l'interface suivante:

 

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980Public Class Form1 Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click TextBox1.Text = String.Empty TextBox2.Text = String.Empty TextBox1.Focus() End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click Me.Close() End Sub Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click If TypeOf Me.ActiveControl Is TextBox Then CType(Me.ActiveControl, TextBox).Undo() End If End Sub Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click If TypeOf Me.ActiveControl Is TextBox Then CType(Me.ActiveControl, TextBox).Cut() End If End Sub Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click If TypeOf Me.ActiveControl Is TextBox Then CType(Me.ActiveControl, TextBox).Copy() End If End Sub Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click If TypeOf Me.ActiveControl Is TextBox Then CType(Me.ActiveControl, TextBox).Paste() End If End Sub Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click If TypeOf Me.ActiveControl Is TextBox Then CType(Me.ActiveControl, TextBox).SelectAll() End If End Sub Private Sub MainToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainToolStripMenuItem.Click If MainToolStripMenuItem.Checked Then ToolStrip1.Visible = True Else ToolStrip1.Visible = False End If End Sub Private Sub FormattingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FormattingToolStripMenuItem.Click If MainToolStripMenuItem.Checked Then ToolStrip2.Visible = True Else ToolStrip2.Visible = False End If End Sub Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click CType(Me.ActiveControl, TextBox).Undo() End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click CType(Me.ActiveControl, TextBox).Cut() End Sub Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click CType(Me.ActiveControl, TextBox).Copy() End Sub Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click CType(Me.ActiveControl, TextBox).Paste() End Sub Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click TextBox1.Text = String.Empty TextBox2.Text = String.Empty TextBox1.Focus() End SubEnd Class

Exercice Visual Basic : Mode connecté

Ecrire le programme qui permet de réaliser l'interface suivante:
avant de commancer le programme vous devez créer une Base de donnée avec les champs cités dans l'interface



12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879Imports System.Data.SqlClientPublic Class Form2 Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Documents and Settings\ista\Bureau\application\application\database1.mdf;Integrated Security=True;User Instance=True") 'ajouter Private Sub ajouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click conn.Open() Dim InsertCommand As New SqlCommand InsertCommand.Connection = conn InsertCommand.CommandType = CommandType.Text InsertCommand.CommandText = "INSERT INTO Information(nom,téléphone) VALUES( Me.t2 & Me.t3 );" InsertCommand.ExecuteNonQuery() InsertCommand.Dispose() conn.Close() MsgBox(" OK ", MsgBoxStyle.Information) End Sub 'mise_à_jour Private Sub mise_à_jour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click Dim MyTransaction As SqlTransaction Dim UpdateCommand As New SqlCommand Try conn.Open() MyTransaction = conn.BeginTransaction UpdateCommand.Connection = conn UpdateCommand.Transaction = MyTransaction UpdateCommand.CommandType = CommandType.Text UpdateCommand.CommandText = "mise à jour Information set nom=? WHERE Id =?;" UpdateCommand.Parameters.Clear() UpdateCommand.Parameters.AddWithValue("?", Me.t2.Text) UpdateCommand.Parameters.AddWithValue("?", Me.t1.Text) UpdateCommand.ExecuteNonQuery() UpdateCommand.CommandText = "mise à jour Information set téléphone=? WHERE Id =?;" UpdateCommand.Parameters.Clear() UpdateCommand.Parameters.AddWithValue("?", Me.t3.Text) UpdateCommand.Parameters.AddWithValue("?", Me.t1.Text) UpdateCommand.ExecuteNonQuery() MyTransaction.Commit() MsgBox(" OK ", MsgBoxStyle.Information) Catch Filed As SqlException MyTransaction.Rollback() MsgBox(Filed.Message, MsgBoxStyle.Exclamation) Finally UpdateCommand.Dispose() conn.Close() End Try End Sub 'supprimer Private Sub supprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click conn.Open() Dim DeleteCommand As New SqlCommand DeleteCommand.Connection = conn DeleteCommand.CommandType = CommandType.Text DeleteCommand.CommandText = "DELETE FROM Information WHERE id = ?;" DeleteCommand.Parameters.Clear() DeleteCommand.Parameters.AddWithValue("?", Me.t1.Text) DeleteCommand.ExecuteNonQuery() DeleteCommand.Dispose() conn.Close() MsgBox(" OK ", MsgBoxStyle.Information) End Sub 'CountId Private Sub CountId_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCountId.Click conn.Open() Dim CountIdCommand As New SqlCommand CountIdCommand.Connection = conn CountIdCommand.CommandType = CommandType.Text CountIdCommand.CommandText = "SELECT Count(id) AS CountID FROM Information;" Dim CountId As String = CountIdCommand.ExecuteScalar() MsgBox(CountId, MsgBoxStyle.Information) CountIdCommand.Dispose() conn.Close() End SubEnd Class

Exercice Visual Basic : Papillon Volante

Ecrire le code VB qui permet de réaliser l'interface suivante:
Le principe c'esr de faire bouger une image dans l'interface selon la vitesse déterminer.

 

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566Option Explicit On Option Strict OnPublic Class frmExo3 Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click End End Sub Private Sub frmExo3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Vsens = 1 Hsens = 1 marge = 10 ouvert = True End Sub Private Sub TimAiles_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimAiles.Tick Dim pasAvance As Int32 'pas d'avance en pixel 'lire la vitesse pasAvance = Me.potPasAvance.Value 'lire Me.TxtAvance.Text = pasAvance.ToString 'afficher 'rebondir sur les bords 'Sens horizontal If Me.PictPapillon.Left + Me.PictPapillon.Width + marge > Me.Width Then Hsens = -1 'à gauche End If If Me.PictPapillon.Left Then Hsens = 1 'à droite End If 'Sens vertical If Me.PictPapillon.Top Then Vsens = -1 'descendre End If If Me.PictPapillon.Top + Me.PictPapillon.Height + marge > Me.Height Then Vsens = 1 'monter End If 'calculer la nouvelle position Me.PictPapillon.Left += pasAvance * Hsens Me.PictPapillon.Top -= pasAvance * Vsens 'attention l'axe windows est vers le bas 'Battre des ailes If ouvert Then 'ailes ouvertes If Hsens > 0 Then Me.PictPapillon.Image = Image.FromFile("BFLYouvertGD.bmp") Else Me.PictPapillon.Image = Image.FromFile("BFLYouvertDG.bmp") End If ouvert = False Else 'ailes fermées If Hsens > 0 Then Me.PictPapillon.Image = Image.FromFile("BFLYfermeGD.bmp") Else Me.PictPapillon.Image = Image.FromFile("BFLYfermeDG.bmp") End If ouvert = True End If Me.PictPapillon.Refresh() End SubEnd Class

Exercice Visual Basic : Réalisation d'un Navigateur

Ecrire le programme qui permet de réaliser un Navigateur.

Interface Graphique:






123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157Imports System.IOPublic Class Form1 Private Const BLOCK_DEFAULT As String = "[DEFAULT]" Private Const BLOCK_INTERNETSHORTCUT As String = "[InternetShortcut]" Private Const ITEM_URL As String = "URL=" Private Const ITEM_BASEURL As String = "BASEURL=" Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged 'Dim DE As String 'DE = ComboBox1.Text ''ComboBox1.Items.Add("www.google.com") 'ComboBox1.Items.Add(DE) WebBrowser1.Navigate(ComboBox1.Text) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Add("www.exercicegratuit.com") ComboBox1.Items.Add("madiha4.e-monsite.com") ComboBox1.Items.Add("naziha.forumactif.com") ComboBox1.Items.Add("www.google.com") ComboBox1.Items.Add("www.menara.ma") ComboBox1.Items.Add("www.youtube.com") ComboBox1.Items.Add("www.altavesta.com") ComboBox1.Items.Add("www.msdn.com") ComboBox1.Items.Add("www.yahoo.fr") ComboBox1.Items.Add("video.google.com") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click WebBrowser1.Navigate(ComboBox1.Text) End Sub Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted With ProgressBar1 .Minimum = 1 .Maximum = 10000 .Value = 1 .Step = 1 ProgressBar1.Visible = True For i As Integer = .Minimum To .Maximum .PerformStep() Next i End With If WebBrowser1.ReadyState Then ProgressBar1.Visible = False End If 'end of progress bar End Sub Private Sub Précédents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Précédents.Click WebBrowser1.GoBack() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click WebBrowser1.GoForward() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click WebBrowser1.GoHome() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click WebBrowser1.GoSearch() End Sub Private Sub EnregistrerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregistrerToolStripMenuItem.Click SaveFileDialog1.InitialDirectory = Application.ExecutablePath SaveFileDialog1.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*" SaveFileDialog1.FilterIndex = 0 If SaveFileDialog1.ShowDialog() = DialogResult.OK Then Dim nomFichier As String = SaveFileDialog1.FileName Dim fichier As StreamWriter = Nothing Try fichier = New StreamWriter(nomFichier) Catch ex As Exception MessageBox.Show("Problème à l'écriture du fichier (" + ex.Message + ")", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Finally Try fichier.Close() Catch End Try End Try End If End Sub Private Sub EnregestrerSousToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregestrerSousToolStripMenuItem.Click Dim save As New SaveFileDialog Dim myStreamWriter As System.IO.StreamWriter save.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*" save.CheckPathExists = True 'save.FileName = webMain.DocumentTitle save.ShowDialog(Me) Try myStreamWriter = System.IO.File.CreateText(save.FileName) myStreamWriter.Write(BLOCK_DEFAULT & vbCrLf & ITEM_BASEURL & vbCrLf & BLOCK_INTERNETSHORTCUT & vbCrLf & ITEM_URL) myStreamWriter.Flush() Catch ex As Exception ' Do nothing on Exception End Try End Sub Private Sub PagePrécédenteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PagePrécédenteToolStripMenuItem.Click WebBrowser1.GoBack() End Sub Private Sub PageSuivanteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PageSuivanteToolStripMenuItem.Click WebBrowser1.GoForward() End Sub Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click WebBrowser1.GoHome() End Sub Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click End End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click WebBrowser1.Navigate("www.google.com") End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged ComboBox2.Items.Add(ComboBox2.Text) End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click WebBrowser1.Navigate("http://www.google.fr/search?sourceid=navclient&hl=fr&ie=UTF-8&rlz=1T4ADBF_frMA313MA313&q=" & ComboBox2.Text) End Sub Private Sub ChercherToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChercherToolStripMenuItem.Click WebBrowser1.GoSearch() End Sub Private Sub ToolStripTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Click ToolStripTextBox1.Text = ComboBox1.Text End Sub Private Sub FenêtreToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FenêtreToolStripMenuItem.Click Form3.Show() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click WebBrowser1.Navigate("http://avg.urlseek.vmn.net/search.php?lg=en&mkt=en&type=dns&tb=ie&tbn=") End Sub Private Sub OuvrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuvrirToolStripMenuItem.Click Dim open As New OpenFileDialog Dim URLFile As String() Dim myStreamReader As System.IO.StreamReader open.Filter = "Internet Favourite (*.url)|*.url|All files (*.*)|*.*" open.CheckFileExists = True open.ShowDialog(Me) Try open.OpenFile() myStreamReader = System.IO.File.OpenText(open.FileName) URLFile = myStreamReader.ReadToEnd().Split(New String() {ControlChars.CrLf}, StringSplitOptions.RemoveEmptyEntries) For Each Item As String In URLFile If Item.StartsWith(ITEM_URL) Then WebBrowser1.Navigate(Item.Substring(ITEM_URL.Length)) Exit For End If Next Catch ex As Exception ' Do nothing on Exception End Try End Sub Private Sub CopierToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopierToolStripMenuItem.Click End SubEnd Class

Exercice Visual Basic : Recherche dans une Phrase

Ecrire le code VB qui permet de réaliser l'interface suivante:



1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556Option Strict OnOption Explicit On Public Class Form1 Inherits System.Windows.Forms.Form Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim caractererecherche As Char Dim resultatrecherche As Int32 resultatrecherche = 0 If Me.Txtcible.Text.Length = 0 Then MessageBox.Show("vous n'avez pa entrez de caractère") Else caractererecherche = Txtcible.Text.Chars(0) If Me.CheckBox1.Checked Then resultatrecherche = recherchecaractere(Me.TextBox1.Text, caractererecherche) End If If Me.CheckBox2.Checked Then resultatrecherche = resultatrecherche + recherchecaractere(Me.TextBox2.Text, caractererecherche) End If If Me.CheckBox3.Checked Then resultatrecherche = resultatrecherche + recherchecaractere(Me.TextBox3.Text, caractererecherche) End If End If Me.txtnboccurence.Text = resultatrecherche.ToString End Sub Private Function recherchecaractere(ByVal zone As String, ByVal caractererecherche As Char) As Int32 Dim longzone As Int32 Dim i As Int32 Dim caractereelementaire As Char Dim nboccurence As Int32 nboccurence = 0 longzone = zone.Length For i = 0 To longzone - 1 caractereelementaire = zone.Chars(i) If caractereelementaire = caractererecherche Then nboccurence = nboccurence + 1 End If Next recherchecaractere = nboccurence End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click Dim i As Integer For i = 0 To 100 Label1.Text = i.ToString : Label1.Refresh() Next i End SubEnd Class

Exercice Visual Basic : Tableau avec Windows Form

Ecrire le code VB qui permet de réaliser l'interface suivante:



1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162Public Class Form1 Dim article, couleur As String Dim t(8, 5) As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load t(1, 1) = 350.25 t(2, 1) = 750.5 t(3, 1) = 49.5 t(5, 1) = 800 t(6, 1) = 1200 t(8, 1) = 350 t(3, 2) = t(3, 1) t(6, 2) = t(6, 1) t(3, 3) = 55.5 t(5, 3) = 355 t(6, 3) = 1100 t(3, 4) = t(3, 3) t(4, 3) = 49 t(4, 4) = 52 t(5, 4) = 700 t(3, 5) = t(3, 3) t(7, 5) = 50 t(1, 0) = "Chaise en teck" t(2, 0) = "Table en teck" t(3, 0) = "Chaise en Pvc" t(4, 0) = "Table en Pvc" t(5, 0) = "Chaise de bureau Prestige" t(6, 0) = "Table de bureau Prestige" t(7, 0) = "Tapis de souris" t(8, 0) = "Visual basic facile" t(0, 1) = "Rouge" t(0, 2) = "Vert" t(0, 3) = "Blanc" t(0, 4) = "Noir" t(0, 5) = "Gris" End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged article = ComboBox1.SelectedItem TextBox2.Text = "" End Sub Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged Dim i, j As Integer couleur = ComboBox2.SelectedItem For i = 1 To 8 If article = t(i, 0) Then Exit For End If Next For j = 1 To 5 If couleur = t(0, j) Then Exit For End If Next TextBox1.Text = article & " " & couleur If t(i, j) 0 Then TextBox2.Text = t(i, j) Else TextBox2.Text = "Cet article n'existe pas dans cette couleur !" End If End SubEnd Class

Exercice Visual Basic : TP Banque

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231Public Class banque Private nom As String Private col As New Hashtable Shared numeroCompte As Integer = 100 Private taux As Double = 0.05 Sub New() End Sub Sub New(ByVal _nom As String) nom = _nom End Sub Function getCompt(ByVal numero As Integer) As compte If col.ContainsKey(numero) Then Return col(numero) End If Return Nothing End Function Sub addCompte(ByVal montant As Double) numeroCompte += 1 Dim cpt As New compte(numeroCompte, montant) col.Add(cpt._numéro, cpt) End Sub Sub add_comptEpagne(ByVal montant As Double) numeroCompte += 1 Dim cpt As New CompteEpargne(numeroCompte, montant, taux) col.Add(cpt._numéro, cpt) End Sub Sub visualiser() Console.WriteLine("Banque " & nom) For Each compte In col.Values compte.afficher() Next End Sub Sub fermerCompte(ByVal Num As Integer) Dim cpt As compte = getCompt(Num) If cpt Is Nothing Then Console.WriteLine("Compte introuvable") Else col.Remove(cpt) End If End Sub Sub calculInteret() For Each cpt In col.Values Dim comp As compte comp = cpt If TypeOf (comp) Is CompteEpargne Then cpt.calculeinteret() End If Next End Sub Sub débiter(ByVal Num As Integer, ByVal montant As Double) Dim cpt As compte = getCompt(Num) If cpt Is Nothing Then Console.WriteLine("Compte introuvable") Else cpt.dèbiter(montant) End If End Sub Sub créditer(ByVal Num As Integer, ByVal montant As Double) Dim cpt As compte = getCompt(Num) If cpt Is Nothing Then Console.WriteLine("Compte introuvable") Else cpt.crèditer(montant) End If End SubEnd Class-----------------------------------------------------------------------------Public Class compte Private numéro As Integer Private solde As Double Public listoperation(9) As opération Dim nb As Integer = 0 Property _numéro() As Integer Get Return numéro End Get Set(ByVal value As Integer) value = numéro End Set End Property Property _solde() As Double Get Return solde End Get Set(ByVal value As Double) value = solde End Set End Property Sub New() End Sub Sub New(ByVal _numéro As Integer, ByVal _solde As Double) numéro = _numéro solde = _solde End Sub Public Overridable Sub afficher() Console.WriteLine(numéro & vbTab & solde) End Sub Sub dèbiter(ByVal montant As Double) If solde Then Console.WriteLine(" le solde est insuffisant") Else solde -= montant End If End Sub Sub crèditer(ByVal montant As Double) solde += montant End Sub Sub ajoutopèration(ByVal type As String, ByVal montant As Double) listoperation(nb Mod 10) = New opération(type, montant) nb += 1 End Sub Sub editerreleve() afficher() Dim op As opération For i = 0 To listoperation.GetUpperBound(0) op = listoperation(i) op.affiche() Next End Sub Protected Overrides Sub Finalize() Console.WriteLine("un compte est fermé") End SubEnd Class-----------------------------------------------------------------------------Public Class CompteEpargne Inherits compte Private taux_int As Double Private interet As Double Property _taux_int() Get Return taux_int End Get Set(ByVal value) value = taux_int End Set End Property Property _interet() Get Return interet End Get Set(ByVal value) value = interet End Set End Property Sub New() End Sub Sub New(ByVal numéro As Double, ByVal _solde As Double, ByVal _taux_int As Double) MyBase.New(numéro, _solde) taux_int = _taux_int End Sub Public Sub calculeinteret() crèditer(_solde * taux_int) interet = _solde * taux_int End Sub Public Overrides Sub afficher() MyBase.afficher() Console.WriteLine(vbTab & vbTab & interet & vbTab & taux_int) End Sub Protected Overrides Sub Finalize() Console.WriteLine("un compte est fermé") End SubEnd Class----------------------------------------------------------------------------(Public Class opération Private type As String Private dat As Date Private montant As Double Property _type() As String Get Return type End Get Set(ByVal value As String) value = type End Set End Property Property _dat() As Date Get Return dat End Get Set(ByVal value As Date) value = dat End Set End Property Property _montant() As Double Get Return montant End Get Set(ByVal value As Double) value = montant End Set End Property Sub New() End Sub Sub New(ByVal _type As String, ByVal _montant As Double) type = _type dat = Date.Now montant = _montant End Sub Public Sub affiche() Console.WriteLine(type & vbTab & dat & vbTab & montant) End SubEnd Class-----------------------------------------------------------------------------Module Module1 Sub Main() Dim bank As New banque("MA BANQUE") bank.addCompte(5000) bank.addCompte(6000) bank.add_comptEpagne(3000) bank.créditer(101, 500) bank.débiter(102, 1000) bank.calculInteret() bank.visualiser() Console.ReadLine() End SubEnd Module

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

Exercice Visual Basic : Voyage


Réalier l'Interface suivante selon les Etapes:

  1. Laboutton OK est désactiver;
  2. Lorsqu'on entre l'Intitulé le Boutton OK est alors activée et l'intitulé s'écrit automatiquement au titre de la Windows Form;
  3. Aprés clique sur Boutton OK un MessageBox s'affiche avec les Informations du Formulaire;
  4. Aprés clique sur Boutton OK du MessageBo un autre MessageBo s'affiche avec la demande de confirmation ou l'annulation des données


1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283Public Class Form1 Dim d, frm, msg As String Dim l, pl, insc As Integer Dim dep, arr As Date Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged pl = NumericUpDown1.Value insc = NumericUpDown2.Value l = pl - insc Label7.Text = "Libres : " & l End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Me.Text = "Voyage : " & TextBox1.Text.Trim frm = Me.Text If TextBox1.Text "" Then Button2.Enabled = True Else Button2.Enabled = False End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load NumericUpDown1.Minimum = 0 NumericUpDown2.Minimum = 0 DateTimePicker1.MinDate = Now DateTimePicker2.MinDate = Now Button2.Enabled = False End Sub Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged NumericUpDown2.Maximum = NumericUpDown1.Value pl = NumericUpDown1.Value insc = NumericUpDown2.Value l = pl - insc Label7.Text = "Libres : " & l End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged dep = Format(DateTimePicker1.Value, "dd/MM/yy") arr = Format(DateTimePicker2.Value, "dd/MM/yy") If arr Then MsgBox("Date Invalide!") DateTimePicker2.MinDate = dep d = 0 Else DateTimePicker2.MinDate = dep End If d = (arr.Day - dep.Day).ToString Label4.Text = d & " jour(s)" End Sub Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged dep = Format(DateTimePicker1.Value, "dd/MM/yy") arr = Format(DateTimePicker2.Value, "dd/MM/yy") If arr Then MsgBox("Date Arrivée Invalide!") DateTimePicker2.MinDate = dep d = 0 Else DateTimePicker2.MinDate = dep End If d = (arr.Day - dep.Day).ToString Label4.Text = d & " jour(s)" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click msg = "Départ : " & dep & vbCrLf & "Arrivée : " & arr & vbCrLf & "Durée : " & d & " jour(s)" & vbCrLf & "Places : " & pl & vbCrLf & "Inscrits : " & insc & vbCrLf & "Libres : " & l & vbCrLf MsgBox(msg, MsgBoxStyle.Information, frm) If MessageBox.Show(msg & vbCrLf & "Voulez-vous enregistrer?", frm, MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then TextBox1.Text = "" DateTimePicker1.Value = Now DateTimePicker2.Value = DateAdd(DateInterval.Day, 1, Now) 'Ajouter un jour à la date system NumericUpDown1.Value = 0 NumericUpDown2.Value = 0 Label4.Text = "###" Label7.Text = "###" End If End SubEnd Class
Article publié le 08 Janvier 2012 Mise à jour le Samedi, 17 Décembre 2022 16:36 par Babachekhe Mohamed