From 87c66c26ea14ff7a5a33bdc7632c695e6eef3591 Mon Sep 17 00:00:00 2001 From: Leana BESSON Date: Tue, 30 May 2023 17:31:33 +0200 Subject: [PATCH] Ajout de la validation de nom Console + View --- Sources/Console/Program.cs | 24 +++++++++++++--------- Sources/Model/Animal.cs | 24 +++++++++++++++++++--- Sources/Views/DetailAnimal.xaml | 15 +++++++++++++- Sources/Views/DetailAnimal.xaml.cs | 1 - Sources/Views/Resources/Styles/Colors.xaml | 1 + 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 7620648..47362a8 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -216,7 +216,8 @@ class Program case 2: Console.Clear(); Animal animal = Theque.AjouterAnimal(); - ModifierAnimal(animal, Theque.ListeEspeces); + ModifierNom(animal); + ModifierAnimal(animal); break; case 3: Console.Clear(); @@ -297,7 +298,7 @@ class Program switch (decision) { case 1: - ModifierAnimal(animal, especetheque); + ModifierAnimal(animal); break; case 2: Theque.SupprimerAnimal(animal); @@ -318,7 +319,7 @@ class Program Console.WriteLine("\t\tNuméro de téléphone : " + entite.NumTel); } - static private void ModifierAnimal(Animal animal, List especetheque) + static private void ModifierAnimal(Animal animal) { while (true) { @@ -372,19 +373,19 @@ class Program ModifierAlimentation(animal); break; case 10: - ModifierEntite(animal.Petsitter.Entite); + ModifierEntite(animal.Petsitter); break; case 11: - ModifierEntite(animal.Chenil.Entite); + ModifierEntite(animal.Chenil); break; case 12: - ModifierEntite(animal.Veterinaire.Entite); + ModifierEntite(animal.Veterinaire); break; case 13: - ModifierEntite(animal.MagasinAlimentaire.Entite); + ModifierEntite(animal.MagasinAlimentaire); break; case 14: - ModifierEntite(animal.Provenance.Entite); + ModifierEntite(animal.Provenance); break; case 19: return; @@ -397,8 +398,11 @@ class Program static private void ModifierNom(Animal animal) { - Console.Write("\tNom : "); - animal.Nom = Console.ReadLine(); + while (animal.Nom.Length <= 0 || animal.Nom.StartsWith(" ")) + { + Console.Write("\tNom : "); + animal.Nom = Console.ReadLine(); + } } static private void ModifierEspece(Animal animal) diff --git a/Sources/Model/Animal.cs b/Sources/Model/Animal.cs index 12d9e26..db85eab 100644 --- a/Sources/Model/Animal.cs +++ b/Sources/Model/Animal.cs @@ -24,11 +24,24 @@ namespace Model if (nom == value) return; nom = value; + NomIsValid = NomValidate(); OnPropertyChanged(nameof(Nom)); } } private string nom; + public bool NomIsValid + { + get => nomIsValid; + set + { + if (nomIsValid == value) + return; + nomIsValid = value; + OnPropertyChanged(nameof(NomIsValid)); + } + } + private bool nomIsValid; [DataMember(Name = "naissance")] public string DateNaissance @@ -225,7 +238,7 @@ namespace Model } private string image; - 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") { Nom = nom; DateNaissance = dateNaissance; @@ -234,8 +247,7 @@ namespace Model Taille = taille; Poids = poids; Alimentation = alimentation; - Race = race; - Petsitter = petsitter; + NomIsValid = false; } void OnPropertyChanged(string propertyName) @@ -245,5 +257,11 @@ namespace Model PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } + + bool NomValidate() + { + if(Nom.Length <= 0 || Nom.StartsWith(" ")) return false; + return true; + } } } diff --git a/Sources/Views/DetailAnimal.xaml b/Sources/Views/DetailAnimal.xaml index 5f2be63..597da41 100644 --- a/Sources/Views/DetailAnimal.xaml +++ b/Sources/Views/DetailAnimal.xaml @@ -22,7 +22,20 @@ Margin="20" Clicked="TakePhoto"/> + HorizontalOptions="Center"> + + + + + + + + + #ff9d5e #402e32 + #FF5349 #2B0B98 White Black