Exercice Visual Basic : Adhérant
Rédigé par GC Team, Publié le 07 Janvier 2012, Mise à jour le Samedi, 17 Décembre 2022 00:09
Participez au vote ☆☆☆☆☆★★★★★
Ecrire le programme VB qui permet de réaliser l'interface suivante:
- La boutton "+" sert à afficher un nouveau Formulaire dans la même Interface qui permet d'ajouter un nouveau Adhérant et l'enregister dans une Base de donnée
- La boutton avec l'icône de disquette sert à Enregestrer les modéfication et les nouveau information concernant un Adhérant dans une Base de donnée
- Les bouttons avec les flèches serts à faire la navigation
- La Boutton "X" sert à supprimer les données d'un Adhérant
- La Boutton Rechercher sert à afficher un formulaire dans le même Interface pour la recherche d'un Adhérant
- La Boutton "C" sert à annuler l'action en cour


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
Public Class Form2 Inherits System.Windows.Forms.Form Dim rownumber As Integer Dim caption As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Odataset.Clear() Odataset.Reset() Connection() Ocommande.CommandText = "select * FROM ADHERANTS ;" Ocommande.Connection = Oconnexion Odadapter.SelectCommand = Ocommande Odadapter.Fill(Odataset) Otable = Odataset.Tables(0) Remplirchamps(rownumber) If Otable.Rows.Count < 1 Then PictureBox3.Enabled = False PictureBox4.Enabled = False PictureBox5.Enabled = False PictureBox6.Enabled = False PictureBox8.Enabled = False PictureBox9.Enabled = False End If PictureBox1.Image = Image.FromFile(Application.StartupPath & "\img\add.yo") PictureBox2.Image = Image.FromFile(Application.StartupPath & "\img\save.yo") PictureBox3.Image = Image.FromFile(Application.StartupPath & "\img\next.yo") PictureBox4.Image = Image.FromFile(Application.StartupPath & "\img\pre.yo") PictureBox5.Image = Image.FromFile(Application.StartupPath & "\img\del.yo") PictureBox6.Image = Image.FromFile(Application.StartupPath & "\img\search.yo") PictureBox7.Image = Image.FromFile(Application.StartupPath & "\img\cancel.yo") PictureBox8.Image = Image.FromFile(Application.StartupPath & "\img\first.yo") PictureBox9.Image = Image.FromFile(Application.StartupPath & "\img\last.yo") End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click 'preparation d'ajout Viderchamps() Oligne = Odataset.Tables(0).NewRow PictureBox1.Enabled = False PictureBox3.Enabled = False PictureBox4.Enabled = False PictureBox5.Enabled = False PictureBox6.Enabled = False PictureBox8.Enabled = False PictureBox9.Enabled = False PictureBox2.Enabled = True PictureBox7.Enabled = True Panel1.Visible = True Panel2.Visible = False TxtNom.Focus() End Sub Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click 'ajout d'adherants If Me.TxtCode.Text = "" Or Me.TxtPrenom.Text = "" Or Me.TxtNom.Text = "" Or TxtDNais.TextLength < 8 Or TxtDNais.TextLength > 10 Or TxtDInsc.TextLength < 8 Or TxtDInsc.TextLength > 10 Then MsgBox("Il faut remplire les champs d'abord !§!", MsgBoxStyle.Information, "Smah lia") Else Oligne("code") = Me.TxtCode.Text Oligne("nom") = Me.TxtNom.Text Oligne("prenom") = Me.TxtPrenom.Text Oligne("typefor") = Me.ComboForm.Text Oligne("duree") = Me.ComboDuree.Text Oligne("niveauconn") = Me.ComboConn.Text Oligne("datenaissance") = Me.TxtDNais.Text Oligne("lieunaissance") = Me.TxtLNais.Text Oligne("niveauscol") = Me.TxtNScol.Text Oligne("institut") = Me.TxtInst.Text Oligne("adresse") = Me.TxtAdresse.Text Oligne("tel") = Me.TxtTel.Text Oligne("dateinscription") = Me.TxtDInsc.Text Odataset.Tables(0).Rows.Add(Oligne) Ocbuilder.DataAdapter = Odadapter Odadapter.Update(Odataset) Odataset.Clear() Odadapter.Fill(Odataset) Otable = Odataset.Tables(0) Remplirchamps(rownumber) PictureBox1.Enabled = True PictureBox3.Enabled = True PictureBox4.Enabled = True PictureBox5.Enabled = True PictureBox6.Enabled = True PictureBox8.Enabled = True PictureBox9.Enabled = True PictureBox2.Enabled = False PictureBox7.Enabled = False Panel1.Visible = False Panel2.Visible = True End If End Sub Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click rownumber += 1 If rownumber <= Otable.Rows.Count - 1 Then Remplirchamps(rownumber) Else rownumber -= 1 End If End Sub Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click rownumber -= 1 If rownumber >= 0 Then Remplirchamps(rownumber) Else rownumber += 1 End If End Sub Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click PictureBox1.Enabled = True PictureBox3.Enabled = True PictureBox4.Enabled = True PictureBox5.Enabled = True PictureBox6.Enabled = True PictureBox8.Enabled = True PictureBox9.Enabled = True PictureBox2.Enabled = False PictureBox7.Enabled = False Panel1.Visible = False Panel3.Visible = False Panel2.Visible = True End Sub Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click PictureBox1.Enabled = False PictureBox3.Enabled = False PictureBox4.Enabled = False PictureBox5.Enabled = False PictureBox6.Enabled = False PictureBox2.Enabled = False PictureBox8.Enabled = False PictureBox9.Enabled = False PictureBox7.Enabled = True Panel1.Visible = False Panel2.Visible = False Panel3.Visible = True TextBox1.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer For i = rownumber To Otable.Rows.Count - 1 If TextBox1.Text = Otable.Rows(i).Item("code") Then Remplirchamps(i) Panel3.Visible = False Panel2.Visible = True Panel1.Visible = False PictureBox1.Enabled = True PictureBox3.Enabled = True PictureBox4.Enabled = True PictureBox5.Enabled = True PictureBox6.Enabled = True PictureBox8.Enabled = True PictureBox9.Enabled = True PictureBox2.Enabled = False PictureBox7.Enabled = False Exit For ElseIf i = Otable.Rows.Count - 1 Then MsgBox("Pas d'adhérant avec ce code la !§!", MsgBoxStyle.Information, "Smah lia") End If Next End Sub Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click rownumber = Otable.Rows.Count - 1 Remplirchamps(rownumber) End Sub Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click rownumber = 0 Remplirchamps(rownumber) End Sub Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click Odataset.Tables(0).Rows(rownumber).Delete() Ocbuilder.DataAdapter = Odadapter Odadapter.Update(Odataset) Odataset.Clear() Odadapter.Fill(Odataset) rownumber = 0 Otable = Odataset.Tables(rownumber) If Odataset.Tables(0).Rows.Count < 1 Then PictureBox5.Enabled = False End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim f4 As New Form3 f4.Show() End Sub Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick If (Label19.Left < Panel1.Width) Then Label19.Left += 6 Else Label19.Left = -Panel1.Width End If End Sub End Class ----------------------------------------------------------------------------- Imports System.Data.OleDb Module Module1 Public Oconnexion As New OleDbConnection Public Ocommande As New OleDbCommand Public Odadapter As New OleDbDataAdapter Public Odataset As New DataSet Public Ocbuilder As New OleDbCommandBuilder Public Otable As New DataTable Public Oligne As DataRow Public strconn As String Public strsql As String Public comptopacity As Integer Public Sub Connection() strconn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=img\bd1.yo;" Try Oconnexion = New OleDbConnection Oconnexion.ConnectionString = strconn Oconnexion.Open() Catch ex As OleDbException MsgBox(ex.Message) End Try End Sub End Module |
