diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 202f408..6556a30 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -96,7 +96,7 @@ class Program break; case 2: Console.Clear(); - Theque.Zootheque.AjouterAnimal(Theque.Especetheque); + Theque.Zootheque.AjouterAnimal(); break; case 3: Theque.Zootheque.SelectionnerAnimal(Theque.Especetheque); diff --git a/Sources/Model/Animal.cs b/Sources/Model/Animal.cs index c60dbde..df35800 100644 --- a/Sources/Model/Animal.cs +++ b/Sources/Model/Animal.cs @@ -1,24 +1,110 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace Model { - public class Animal + public class Animal : INotifyPropertyChanged { - public string Nom { get; set; } - public string DateNaissance { get; set; } - public string Sexe { get; set; } - public string DateAdoption { get; set; } - public float? Taille { get; set; } - public float? Poids { get; set; } - public string Alimentation { get; set; } + public event PropertyChangedEventHandler? PropertyChanged; + public string Nom + { + get => nom; + set + { + if (nom == value) + return; + nom = value; + OnPropertyChanged(nameof(Nom)); + } + } + private string nom; + + public string DateNaissance + { + get => dateNaissance; + set + { + if (dateNaissance == value) + return; + dateNaissance = value; + OnPropertyChanged(nameof(DateNaissance)); + } + } + private string dateNaissance; + + public string Sexe + { + get => sexe; + set { + if (sexe == value) + return; + sexe = value; + OnPropertyChanged(nameof(Sexe)); + } + } + private string sexe; + + public string DateAdoption + { + get => dateAdoption; + set + { + if (dateAdoption == value) + return; + dateAdoption = value; + OnPropertyChanged(nameof(DateAdoption)); + } + } + private string dateAdoption; + + public float? Taille + { + get => taille; + set + { + if (taille == value) + return; + taille = value; + OnPropertyChanged(nameof(Taille)); + } + } + private float? taille; + + public float? Poids + { + get => poids; + set + { + if (poids == value) + return; + poids = value; + OnPropertyChanged(nameof(Poids)); + } + } + private float? poids; + + public string Alimentation + { + get => alimentation; + set + { + if (alimentation == value) + return; + alimentation = value; + OnPropertyChanged(nameof(Alimentation)); + } + } + private string alimentation; + public Espece Espece { get; set; } public Race? Race { get; set; } - public Animal(string nom, string dateNaissance = "Inconnue", string sexe = "Inconnu", string dateAdpotion = "Inconnue", float? taille = null, float? poids = null, string alimentation = "Inconnue", Race? race = null) + public Animal(string nom = "", string dateNaissance = "Inconnue", string sexe = "Inconnu", string dateAdpotion = "Inconnue", float? taille = null, float? poids = null, string alimentation = "Inconnue", Race? race = null) { Nom = nom; DateNaissance = dateNaissance; @@ -30,6 +116,14 @@ namespace Model Race = race; } + void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + public void AfficherAnimal(Zootheque zootheque, Especetheque especetheque) { Console.Clear(); diff --git a/Sources/Model/Zootheque.cs b/Sources/Model/Zootheque.cs index 4fa34b2..059d66a 100644 --- a/Sources/Model/Zootheque.cs +++ b/Sources/Model/Zootheque.cs @@ -1,23 +1,22 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.ComponentModel; using System.Linq; using System.Runtime.InteropServices.Marshalling; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Model { - public class Zootheque { + public class Zootheque + { + public ObservableCollection ListeAnimaux { get; set; } = new ObservableCollection(); - //public ReadOnlyCollection ListeAnimaux { get; private set; } - //private readonly List listeAnimaux = new List(); - public List ListeAnimaux { get; set; } = Stub.LoadZootheque(); - - public Zootheque() + public Zootheque() { - //ListeAnimaux = new ReadOnlyCollection(listeAnimaux); - //LoadZootheque(); } public void AfficherListeAnimaux() { @@ -28,21 +27,11 @@ namespace Model } } - public void AjouterAnimal(Especetheque especetheque) + public Animal AjouterAnimal() { - Console.WriteLine("AJOUT ANIMAL"); - Animal animal = new(new(""), ""); - animal.ModifierNom(); - animal.ModifierEspece(especetheque); - animal.ModifierRace(); - animal.ModifierDateNaissance(); - animal.ModifierSexe(); - animal.ModifierDateAdoption(); - animal.ModifierTaille(); - animal.ModifierPoids(); - - ListeAnimaux.Append(animal); - Console.Clear(); + Animal animal = new Animal(); + ListeAnimaux.Add(animal); + return animal; } public Animal? RechercherAnimal(string choix) @@ -79,7 +68,7 @@ namespace Model public void SupprimerAnimal(Animal animal) { - //ListeAnimaux.Remove(animal); + ListeAnimaux.Remove(animal); } } } diff --git a/Sources/Views/Animaux.xaml b/Sources/Views/Animaux.xaml index ec2c572..733601f 100644 --- a/Sources/Views/Animaux.xaml +++ b/Sources/Views/Animaux.xaml @@ -7,43 +7,44 @@