Ajout de la validation de nom Console + View

pull/18/head
Leana BESSON 2 years ago
parent 498b81e5fb
commit 87c66c26ea

@ -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<Espece> 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)

@ -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;
}
}
}

@ -22,7 +22,20 @@
Margin="20"
Clicked="TakePhoto"/>
<Entry Text="{Binding Nom}"
HorizontalOptions="Center"/>
HorizontalOptions="Center">
<Entry.Triggers>
<DataTrigger TargetType="Entry"
Binding="{Binding NomIsValid}"
Value="false">
<Setter Property="BackgroundColor" Value="{StaticResource Error}" />
</DataTrigger>
<DataTrigger TargetType="Entry"
Binding="{Binding NomIsValid}"
Value="true">
<Setter Property="BackgroundColor" Value="{StaticResource White}" />
</DataTrigger>
</Entry.Triggers>
</Entry>
<Border Stroke="{StaticResource Secondary}"
StrokeThickness="2"
Margin="20"

@ -36,7 +36,6 @@ public partial class DetailAnimal : ContentPage
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();

@ -6,6 +6,7 @@
<Color x:Key="Primary">#ff9d5e</Color>
<Color x:Key="Secondary">#402e32</Color>
<Color x:Key="Error">#FF5349</Color>
<Color x:Key="Tertiary">#2B0B98</Color>
<Color x:Key="White">White</Color>
<Color x:Key="Black">Black</Color>

Loading…
Cancel
Save