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
| Protected Sub btnEnregistrer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnregistrer.Click
If txtBoxNom.Text = "" Or txtBoxPrenom.Text = "" Or txtBoxDateNaissance.Text = "" Or (radiobtnM.Checked = False And radiobtnF.Checked = False) Or txtBoxRue.Text = "" Or txtBoxNumero.Text = "" Or txtBoxCodePostal.Text = "" Or txtBoxLocalite.Text = "" Or txtBoxPays.Text = "" Then
lblEncodage.Text = "Vous n'avez pas rempli tous les champs obligatoires !"
lbldata_src.Text = ""
lblcon_open.Text = ""
lblcon_close.Text = ""
lblcon_open2.Text = ""
lblcon_close2.Text = ""
lblresults.Text = ""
ElseIf radiobtnM.Checked = False And radiobtnF.Checked = False Then
lblEncodage.Text = "Vous n'avez pas rempli tous les champs obligatoires !"
lbldata_src.Text = ""
lblcon_open.Text = ""
lblcon_close.Text = ""
lblcon_open2.Text = ""
lblcon_close2.Text = ""
lblresults.Text = ""
Else
Dim StrConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Request.MapPath("..\App_Data") & "\BDGest_Client.mdb"
lbldata_src.Text = "Lecture des données depuis" & StrConnection
Dim StrSQL As String
Dim IntResultsHolder As Integer
StrSQL = "SELECT Id_Adresse FROM TAdresse WHERE Rue='"
StrSQL &= Replace(txtBoxRue.Text, "'", "''")
StrSQL &= "' AND Numero='"
StrSQL &= Replace(txtBoxNumero.Text, "'", "''")
StrSQL &= "' AND BoitePostale='"
StrSQL &= Replace(txtBoxBoitePostale.Text, "'", "''")
StrSQL &= "' AND CodePostal='"
StrSQL &= Replace(txtBoxCodePostal.Text, "'", "''")
StrSQL &= "' AND Localite='"
StrSQL &= Replace(txtBoxLocalite.Text, "'", "''")
StrSQL &= "' AND Pays='"
StrSQL &= Replace(txtBoxPays.Text, "'", "''")
StrSQL &= "'"
IntResultsHolder = 0
Dim ObjConnection As New System.Data.OleDb.OleDbConnection(StrConnection)
Dim ObjCommand As New System.Data.OleDb.OleDbCommand(StrSQL, ObjConnection)
Dim ObjDataReader As System.Data.OleDb.OleDbDataReader
Try
ObjConnection.Open()
lblcon_open.Text = "Connexion ouverte sans erreur..."
ObjDataReader = ObjCommand.ExecuteReader()
Do While ObjDataReader.Read() = True
IntResultsHolder += ObjDataReader("Id_Adresse")
Loop
ObjDataReader.Close()
ObjConnection.Close()
Catch ex As Exception
End Try
If IntResultsHolder = 0 Then
Dim StrSQL2 As String
StrSQL2 = "INSERT INTO TAdresse(Rue, Numero, BoitePostale, CodePostal, Localite, Pays) VALUES('"
StrSQL2 &= Replace(txtBoxRue.Text, "'", "''") & "','"
StrSQL2 &= Replace(txtBoxNumero.Text, "'", "''") & "','"
StrSQL2 &= Replace(txtBoxBoitePostale.Text, "'", "''") & "','"
StrSQL2 &= Replace(txtBoxCodePostal.Text, "'", "''") & "','"
StrSQL2 &= Replace(txtBoxLocalite.Text, "'", "''") & "','"
StrSQL2 &= Replace(txtBoxPays.Text, "'", "''") & "')"
Dim objCommand2 As New System.Data.OleDb.OleDbCommand(StrSQL2, ObjConnection)
Try
ObjConnection.Open()
ObjConnection.Close()
Catch ex As Exception
End Try
Dim StrSQL3 As String
Dim IntResultsHolder2 As Integer
StrSQL3 = "SELECT Id_Adresse FROM TAdresse WHERE Rue='"
StrSQL3 &= Replace(txtBoxRue.Text, "'", "''")
StrSQL3 &= "' AND Numero='"
StrSQL3 &= Replace(txtBoxNumero.Text, "'", "''")
StrSQL3 &= "' AND BoitePostale='"
StrSQL3 &= Replace(txtBoxBoitePostale.Text, "'", "''")
StrSQL3 &= "' AND CodePostal='"
StrSQL3 &= Replace(txtBoxCodePostal.Text, "'", "''")
StrSQL3 &= "' AND Localite='"
StrSQL3 &= Replace(txtBoxLocalite.Text, "'", "''")
StrSQL3 &= "' AND Pays='"
StrSQL3 &= Replace(txtBoxPays.Text, "'", "''")
StrSQL3 &= "'"
IntResultsHolder2 = 0
Dim ObjCommand3 As New System.Data.OleDb.OleDbCommand(StrSQL, ObjConnection)
Dim ObjDataReader2 As System.Data.OleDb.OleDbDataReader
Try
ObjConnection.Open()
ObjDataReader2 = ObjCommand3.ExecuteReader()
Do While ObjDataReader2.Read() = True
IntResultsHolder2 += ObjDataReader2("Id_Adresse")
Loop
ObjDataReader2.Close()
ObjConnection.Close()
lblcon_open.Text = "Connexion ouverte sans erreur..."
lblcon_close.Text = "Connexion fermée sans erreur..."
Catch ex As Exception
lblcon_open.Text = "Erreur dans la procédure de connexion à la base de données"
lblcon_close.Text = "Erreur de type: " & ex.ToString
End Try
Dim StrSQL4 As String
StrSQL4 = "INSERT INTO TClient(ID_Adresse, Nom, Prenom, DateNaissance, Civilite, NTel, GSM, EMail) VALUES('"
StrSQL4 &= IntResultsHolder2 & "','"
StrSQL4 &= Replace(txtBoxNom.Text, "'", "''") & "','"
StrSQL4 &= Replace(txtBoxPrenom.Text, "'", "''") & "')"
StrSQL4 &= Replace(txtBoxDateNaissance.Text, "'", "''") & "','"
If radiobtnM.Checked = True Then
StrSQL4 &= "M','"
Else
StrSQL4 &= "F','"
End If
StrSQL4 &= Replace(txtBoxTelephone.Text, "'", "''") & "','"
StrSQL4 &= Replace(txtBoxGsm.Text, "'", "''") & "','"
StrSQL4 &= Replace(txtBoxEmail.Text, "'", "''") & "',')"
Dim objCommand4 As New System.Data.OleDb.OleDbCommand(StrSQL2, ObjConnection)
Try
ObjConnection.Open()
lblresults.Text = "Nombre d'éléments insérés: " & objCommand4.ExecuteNonQuery()
ObjConnection.Close()
lblEncodage.Text = "Enregistrement Réussi !"
Catch ex As Exception
lblEncodage.Text = "L'enregistrement n'a pas pu avoir lieu !"
End Try
Else
Dim StrSQL5 As String
StrSQL5 = "INSERT INTO TClient(Nom, Prenom, DateNaissance, Civilite, NTel, GSM, EMail) VALUES('"
StrSQL5 &= Replace(txtBoxNom.Text, "'", "''") & "','"
StrSQL5 &= Replace(txtBoxPrenom.Text, "'", "''") & "')"
StrSQL5 &= Replace(txtBoxDateNaissance.Text, "'", "''") & "','"
If radiobtnM.Checked = True Then
StrSQL5 &= "M','"
Else
StrSQL5 &= "F','"
End If
StrSQL5 &= Replace(txtBoxTelephone.Text, "'", "''") & "','"
StrSQL5 &= Replace(txtBoxGsm.Text, "'", "''") & "','"
StrSQL5 &= Replace(txtBoxEmail.Text, "'", "''") & "',')"
Dim objCommand5 As New System.Data.OleDb.OleDbCommand(StrSQL5, ObjConnection)
Try
ObjConnection.Open()
lblresults.Text = "Nombre d'éléments insérés: " & objCommand5.ExecuteNonQuery()
ObjConnection.Close()
lblEncodage.Text = "Enregistrement Réussi !"
Catch ex As Exception
lblEncodage.Text = "L'enregistrement n'a pas pu avoir lieu !"
End Try
End If
End If
End Sub |