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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
| Public Class Contact
Dim currentrow As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Contact_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Definition du type de base
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
'Chemin de la base
dbSource = "Data Source = |DataDirectory|\cont.accdb"
'Connection
con.ConnectionString = dbProvider & dbSource
'Ouverture de la connection (base)
con.Open()
'Requete SQL
sql = "SELECT * FROM Individu"
'Definition et commande de remplissage du DataAdapter
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "cont")
'Positionnement dans la base
currentrow = 0
'Definition du nombre de ligne dans la base
MaxRows = ds.Tables("cont").Rows.Count
End Sub
Private Sub NavigateRecords()
nom1.Text = ds.Tables("cont").Rows(currentrow).Item(1).ToString
prenom1.text = ds.Tables("cont").Rows(currentrow).Item(2).ToString
surnom1.Text = ds.Tables("cont").Rows(currentrow).Item(3).ToString
admess1.text = ds.Tables("cont").Rows(currentrow).Item(4).ToString
admess2.Text = ds.Tables("cont").Rows(currentrow).Item(5).ToString
admess3.text = ds.Tables("cont").Rows(currentrow).Item(6).ToString
site1.Text = ds.Tables("cont").Rows(currentrow).Item(7).ToString
adr1.text = ds.Tables("cont").Rows(currentrow).Item(8).ToString
ville1.Text = ds.Tables("cont").Rows(currentrow).Item(9).ToString
region1.text = ds.Tables("cont").Rows(currentrow).Item(10).ToString
cp1.Text = ds.Tables("cont").Rows(currentrow).Item(11).ToString
pays1.text = ds.Tables("cont").Rows(currentrow).Item(12).ToString
tel1.Text = ds.Tables("cont").Rows(currentrow).Item(13).ToString
fax1.text = ds.Tables("cont").Rows(currentrow).Item(14).ToString
cell1.Text = ds.Tables("cont").Rows(currentrow).Item(15).ToString
adr2.text = ds.Tables("cont").Rows(currentrow).Item(16).ToString
ville2.Text = ds.Tables("cont").Rows(currentrow).Item(17).ToString
region2.text = ds.Tables("cont").Rows(currentrow).Item(18).ToString
cp2.Text = ds.Tables("cont").Rows(currentrow).Item(19).ToString
pays2.text = ds.Tables("cont").Rows(currentrow).Item(20).ToString
soc.Text = ds.Tables("cont").Rows(currentrow).Item(21).ToString
fonc.text = ds.Tables("cont").Rows(currentrow).Item(22).ToString
service.Text = ds.Tables("cont").Rows(currentrow).Item(23).ToString
bureau.text = ds.Tables("cont").Rows(currentrow).Item(24).ToString
tel2.Text = ds.Tables("cont").Rows(currentrow).Item(25).ToString
fax2.text = ds.Tables("cont").Rows(currentrow).Item(26).ToString
cell2.Text = ds.Tables("cont").Rows(currentrow).Item(27).ToString
site2.text = ds.Tables("cont").Rows(currentrow).Item(28).ToString
sexe.Text = ds.Tables("cont").Rows(currentrow).Item(29).ToString
datenai.text = ds.Tables("cont").Rows(currentrow).Item(31).ToString
datemar.Text = ds.Tables("cont").Rows(currentrow).Item(31).ToString
conj.text = ds.Tables("cont").Rows(currentrow).Item(32).ToString
enf1.Text = ds.Tables("cont").Rows(currentrow).Item(33).ToString
enf2.text = ds.Tables("cont").Rows(currentrow).Item(34).ToString
enf3.Text = ds.Tables("cont").Rows(currentrow).Item(35).ToString
enf4.text = ds.Tables("cont").Rows(currentrow).Item(36).ToString
note.Text = ds.Tables("cont").Rows(currentrow).Item(37).ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
da.Update(ds, "cont")
Me.Hide()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'Bouton Premier Individu
'On se place sur la premiere rangee
currentrow = 0
'Puis on l'affiche avec la procedure:
NavigateRecords()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'Bouton Dernier Individu
'On verifie sur la derniere rangee (Rows.Count -1)
currentrow = ds.Tables("cont").Rows.Count - 1
'Puis on l'affiche avec la procedure:
NavigateRecords()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
'Bouton Precedent
'On verifie qu'il y aie toujours des donnees a afficher...
If currentrow > 0 Then
currentrow -= 1
'...Puis on les affiche avec la procedure:
NavigateRecords()
'Sinon on est au debut de la base....
ElseIf currentrow = 0 Then
MsgBox("Premier Individu de la Base !")
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
'Bouton Suivant
'On verifie qu'il y aie toujours des donnees a afficher...
If currentrow < ds.Tables("cont").Rows.Count - 1 Then
currentrow += 1
'...Puis on les affiche avec la procedure:
NavigateRecords()
Else
'Sinon on est au bout de la base....
MsgBox("Dernier Individu de la Base !" & vbCrLf & ds.Tables("cont").Rows.Count & " " & "Individus dans la Base.")
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
'Bouton Enregistrer Individu (INSERT & UPDATE)
If currentrow <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("cont").NewRow()
dsNewRow.Item(1) = nom1.Text
dsNewRow.Item(2) = prenom1.Text
dsNewRow.Item(3) = surnom1.Text
dsNewRow.Item(4) = admess1.Text
dsNewRow.Item(5) = admess2.Text
dsNewRow.Item(6) = admess3.Text
dsNewRow.Item(7) = site1.Text
dsNewRow.Item(8) = adr1.Text
dsNewRow.Item(9) = ville1.Text
dsNewRow.Item(10) = region1.Text
dsNewRow.Item(11) = cp1.Text
dsNewRow.Item(12) = pays1.Text
dsNewRow.Item(13) = tel1.Text
dsNewRow.Item(14) = fax1.Text
dsNewRow.Item(15) = cell1.Text
dsNewRow.Item(16) = adr2.Text
dsNewRow.Item(17) = ville2.Text
dsNewRow.Item(18) = region2.Text
dsNewRow.Item(19) = cp2.Text
dsNewRow.Item(20) = pays2.Text
dsNewRow.Item(21) = soc.Text
dsNewRow.Item(22) = fonc.Text
dsNewRow.Item(23) = service.Text
dsNewRow.Item(24) = bureau.Text
dsNewRow.Item(25) = tel2.Text
dsNewRow.Item(26) = fax2.Text
dsNewRow.Item(27) = cell2.Text
dsNewRow.Item(28) = site2.Text
dsNewRow.Item(29) = sexe.Text
dsNewRow.Item(30) = datenai.Text
dsNewRow.Item(31) = datemar.Text
dsNewRow.Item(32) = conj.Text
dsNewRow.Item(33) = enf1.Text
dsNewRow.Item(34) = enf2.Text
dsNewRow.Item(35) = enf3.Text
dsNewRow.Item(36) = enf4.Text
dsNewRow.Item(37) = note.Text
ds.Tables("cont").Rows.Add(dsNewRow)
ds.Tables("cont").Rows(currentrow).Item(1) = nom1.Text
ds.Tables("cont").Rows(currentrow).Item(2) = prenom1.Text
ds.Tables("cont").Rows(currentrow).Item(3) = surnom1.Text
ds.Tables("cont").Rows(currentrow).Item(4) = admess1.Text
ds.Tables("cont").Rows(currentrow).Item(5) = admess2.Text
ds.Tables("cont").Rows(currentrow).Item(6) = admess3.Text
ds.Tables("cont").Rows(currentrow).Item(7) = site1.Text
ds.Tables("cont").Rows(currentrow).Item(8) = adr1.Text
ds.Tables("cont").Rows(currentrow).Item(9) = ville1.Text
ds.Tables("cont").Rows(currentrow).Item(10) = region1.Text
ds.Tables("cont").Rows(currentrow).Item(11) = cp1.Text
ds.Tables("cont").Rows(currentrow).Item(12) = pays1.Text
ds.Tables("cont").Rows(currentrow).Item(13) = tel1.Text
ds.Tables("cont").Rows(currentrow).Item(14) = fax1.Text
ds.Tables("cont").Rows(currentrow).Item(15) = cell1.Text
ds.Tables("cont").Rows(currentrow).Item(16) = adr2.Text
ds.Tables("cont").Rows(currentrow).Item(17) = ville2.Text
ds.Tables("cont").Rows(currentrow).Item(18) = region2.Text
ds.Tables("cont").Rows(currentrow).Item(19) = cp2.Text
ds.Tables("cont").Rows(currentrow).Item(20) = pays2.Text
ds.Tables("cont").Rows(currentrow).Item(21) = soc.Text
ds.Tables("cont").Rows(currentrow).Item(22) = fonc.Text
ds.Tables("cont").Rows(currentrow).Item(23) = service.Text
ds.Tables("cont").Rows(currentrow).Item(24) = bureau.Text
ds.Tables("cont").Rows(currentrow).Item(25) = tel2.Text
ds.Tables("cont").Rows(currentrow).Item(26) = fax2.Text
ds.Tables("cont").Rows(currentrow).Item(27) = cell2.Text
ds.Tables("cont").Rows(currentrow).Item(28) = site2.Text
ds.Tables("cont").Rows(currentrow).Item(29) = sexe.Text
ds.Tables("cont").Rows(currentrow).Item(30) = datenai.Text
ds.Tables("cont").Rows(currentrow).Item(31) = datemar.Text
ds.Tables("cont").Rows(currentrow).Item(32) = conj.Text
ds.Tables("cont").Rows(currentrow).Item(33) = enf1.Text
ds.Tables("cont").Rows(currentrow).Item(34) = enf2.Text
ds.Tables("cont").Rows(currentrow).Item(35) = enf3.Text
ds.Tables("cont").Rows(currentrow).Item(36) = enf4.Text
ds.Tables("cont").Rows(currentrow).Item(37) = note.Text
'Mise a jour de la base
da.Update(ds, "cont")
'Message si succes de l'enregistrement
MsgBox("Individu Enregistrer avec succès !" & vbCrLf & "Mise à jour de la Base réussis !" & vbCrLf & ds.Tables("cont").Rows.Count & " " & "Individus dans la base.")
currentrow = 0
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
'Bouton Effacer
'Demande si on veux vraiment effacer l'entree
If MessageBox.Show("Voulez-vous vraiment effacer cette entrée ?", "Effacer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
'Si NON...
MsgBox("Operation Annuler")
Exit Sub
End If
'Si OUI...
Dim cb As New OleDb.OleDbCommandBuilder(da)
'On efface la ligne en cours
ds.Tables("cont").Rows(currentrow).Delete()
MaxRows = MaxRows - 1
'On reviens sur la position de depart
currentrow = 0
'Puis on continue de naviguer avec la procedure:
NavigateRecords()
'On met la base a jour
da.Update(ds, "cont")
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
nom1.Clear()
prenom1.Clear()
surnom1.Clear()
admess1.Clear()
admess2.Clear()
admess3.Clear()
site1.Clear()
adr1.Clear()
ville1.Clear()
region1.Clear()
cp1.Clear()
pays1.Clear()
tel1.Clear()
fax1.Clear()
cell1.Clear()
adr2.Clear()
ville2.Clear()
region2.Clear()
cp2.Clear()
pays2.Clear()
soc.Clear()
fonc.Clear()
service.Clear()
bureau.Clear()
tel2.Clear()
fax2.Clear()
cell2.Clear()
site2.Clear()
sexe.Clear()
datenai.Clear()
datemar.Clear()
conj.Clear()
enf1.Clear()
enf2.Clear()
enf3.Clear()
enf4.Clear()
note.Clear()
End Sub
End Class |
Partager