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
|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Si on est en ajout
If Button3.Enabled = False Then
'Divers contrôls derreurs
If Me.TextBox1.Text = "" Then
MsgBox("Veuillez saisir le nom.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Erreur")
Exit Sub
End If
If Me.TextBox2.Text = "" Then
MsgBox("Veuillez saisir le prénom.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Erreur")
Exit Sub
End If
If Not MaskedTextBox1.MaskFull Then
MsgBox("Date incorrecte. Vérifier la date", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Erreur")
Exit Sub
End If
dtr = ObjetDataSet.Tables("Personne").NewRow()
dtr("Nom") = Me.TextBox1.Text
dtr("Prenom") = Me.TextBox2.Text
dtr("Datenaissance") = Me.MaskedTextBox1.Text
ObjetDataSet.Tables("Personne").Rows.Add(dtr)
'Pour modifier les valeurs changées dans le DataAdapter
cmdb = New OleDbCommandBuilder(ObjetDataAdapter)
'Mise à jour
ObjetDataAdapter.Update(ObjetDataSet, "Personne")
'On vide le DataSet et on le 'recharge' de nouveau.
ObjetDataSet.Clear()
ObjetDataAdapter.Fill(ObjetDataSet, "Personne")
ObjetDataTable = ObjetDataSet.Tables("Personne")
Button3.Enabled = True
Button4.Visible = True
End If
'si on est en Modification
If Button4.Enabled = False And Button3.Visible = False Then
Dim choix As String
choix = ListBox1.Text
rownum = ListBox1.SelectedIndex
If MsgBox("Confirmer la modification de la personne " & choix & " ?", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton1 Or MsgBoxStyle.Question, "Confirmation") = MsgBoxResult.Yes Then
'Divers contrôls derreurs
If Me.TextBox1.Text = "" Then
MsgBox("Veuillez saisir le nom.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Erreur")
Exit Sub
End If
If Me.TextBox2.Text = "" Then
MsgBox("Veuillez saisir le prénom.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Erreur")
Exit Sub
End If
If Not MaskedTextBox1.MaskFull Then
MsgBox("Date incorrecte. Vérifier la date", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Erreur")
Exit Sub
End If
' Extraire l'enregistrement courant
dtr = ObjetDataSet.Tables("Personne").Rows(rownum)
'Modifier les valeurs des champs en récupérant le contenu des TextBox
dtr("Nom") = Me.TextBox1.Text
dtr("Prenom") = Me.TextBox2.Text
dtr("Datenaissance") = Me.MaskedTextBox1.Text
'Pour modifier les valeurs changées dans le DataAdapter
cmdb = New OleDbCommandBuilder(ObjetDataAdapter)
'Mise à jour
ObjetDataAdapter.Update(ObjetDataSet, "Personne")
'On vide le DataSet et on le 'recharge' de nouveau.
ObjetDataSet.Clear()
ObjetDataAdapter.Fill(ObjetDataSet, "Personne")
ObjetDataTable = ObjetDataSet.Tables("Personne")
'ObjetConnection.Close()
Button3.Visible = True
Button4.Enabled = True
TextBox1.Enabled = False
TextBox2.Enabled = False
MaskedTextBox1.Enabled = False
End If
End If
End Sub |
Partager