public void Add(Animaux unAnimal) { try { SqlParameter monParametre; Clients proprietaire = new ADO_Clients().GetOne(unAnimal.CodeClient.Value); if (!unAnimal.Archive.HasValue) { unAnimal.Archive = false; } SqlCommand cmd = (SqlCommand)maConnexion().CreateCommand(); cmd.CommandText = " exec ajout_animal @Nomclient, @PrenomClient, @NomAnimal, @Sexe, @Couleur, @Espece, @Race, @Archive;"; monParametre = new SqlParameter("@Nomclient", proprietaire.NomClient); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@PrenomClient", proprietaire.PrenomClient); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@NomAnimal", unAnimal.NomAnimal); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@Sexe", unAnimal.Sexe); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@Couleur", unAnimal.Couleur); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@Race", unAnimal.Race.Race); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@Espece", unAnimal.Race.Espece); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@Archive", unAnimal.Archive.Value); cmd.Parameters.Add(monParametre); cmd.ExecuteScalar(); } catch (Exception ex) { throw new Exception("Echec de l'insertion d'un animal :\n" + ex.Message); } finally { cnx.Close(); } }
public static void Add(Agendas monAgenda) { ADO_Animal animalDAL = new ADO_Animal(); ADO_Clients clientDAL = new ADO_Clients(); Animaux monAnimal = animalDAL.GetOne(monAgenda.CodeAnimal.Value); Clients monClient = clientDAL.GetOne(monAnimal.CodeClient.Value); Veterinaires monVeto = ADO_Veterinaires.getOneVeto(monAgenda.CodeVeto.Value); using (DbConnection cnx = ConnectionBDD.SeConnecter()) { SqlParameter monParametre; SqlCommand cmd = (SqlCommand)cnx.CreateCommand(); cmd.CommandText = " exec ajout_agenda @nomClient, @prenomClient, @nomAnimal, @nomVeto, @dateRdv ;"; monParametre = new SqlParameter("@nomClient", monClient.NomClient); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@prenomClient", monClient.PrenomClient); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@nomAnimal", monAnimal.NomAnimal); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@nomVeto", monVeto.NomVeto); cmd.Parameters.Add(monParametre); monParametre = new SqlParameter("@dateRdv", monAgenda.DateRDV); cmd.Parameters.Add(monParametre); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Echec de l'insertion dans l'agnda :\n" + ex.Message); } } }