public static void CreateCotisation(Cotisation cotiz) { string sqlQuery = ($"Insert into cotisations (annee, montant, personne_id) Values('{cotiz.Annee}', '{cotiz.Montant}', '{cotiz.MotardId}');"); SqlCommand command = new SqlCommand(sqlQuery, connection); command.ExecuteNonQuery(); command.Dispose(); }
private void BtnAjoutCotis_Click(object sender, RoutedEventArgs e) { Cotisation newCotiz = new Cotisation(); double montant; bool isOK = double.TryParse(txtbMontant.Text, out montant); if (isOK) { newCotiz.Montant = montant; } else { MessageBox.Show("Montant incorrect", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); return; } int annee; bool isYOK = int.TryParse(txtbAnnee.Text, out annee); if (isYOK && annee > 1950 && annee <= DateTime.Now.Year) { newCotiz.Annee = annee; } else { MessageBox.Show("Année incorrect", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); return; } newCotiz.Annee = annee; newCotiz.MotardId = Motard.Id; DAL.CreateCotisation(newCotiz); listeCotisations.ItemsSource = DAL.GetCotisation(Motard); }
public static List <Cotisation> GetCotisation(Personne motard) { List <Cotisation> Cotisations = new List <Cotisation>(); string sqlQuery = ($"SELECT * FROM cotisations WHERE personne_id = {motard.Id} ORDER BY annee;"); SqlCommand command = new SqlCommand(sqlQuery, connection); SqlDataReader dataReader = command.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { Cotisation newCotiz = new Cotisation(); newCotiz.Annee = Convert.ToInt32(dataReader["annee"]); newCotiz.Montant = Convert.ToDouble(dataReader["montant"]); newCotiz.MotardId = Convert.ToInt32(dataReader["personne_id"]); newCotiz.Id = Convert.ToInt32(dataReader["id"]); Cotisations.Add(newCotiz); } } dataReader.Close(); command.Dispose(); return(Cotisations); }