Mis à jour avec ajout de test pour les Int et float

pull/18/head
Leana BESSON 2 years ago
parent d854da1bdd
commit b0d8089d49

@ -1,4 +1,5 @@
using Model; using Microsoft.Win32.SafeHandles;
using Model;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -12,358 +13,391 @@ class Program
{ {
static private Theque Theque { get; set; } = Stub.LoadTheque(); static private Theque Theque { get; set; } = Stub.LoadTheque();
static void Main(string[] args) static void Main(string[] args)
{ {
MenusPrincipal(); MenusPrincipal();
} }
static private void MenusPrincipal() static private void MenusPrincipal()
{ {
while (true) while (true)
{ {
Console.WriteLine("MENUS PRINCIPAL"); Console.WriteLine("MENUS PRINCIPAL");
Console.WriteLine("\t1- Les espèces"); Console.WriteLine("\t1- Les espèces");
Console.WriteLine("\t2- Vos animaux"); Console.WriteLine("\t2- Vos animaux");
Console.WriteLine("\t9- Quitter"); Console.WriteLine("\t9- Quitter");
Console.Write("\n\tEntrer votre choix : "); Console.Write("\n\tEntrer votre choix : ");
int choix = Convert.ToInt32(Console.ReadLine()); string? choix = Console.ReadLine();
while(!Theque.IntValidate(choix))
switch (choix) {
{ Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
case 1: choix = Console.ReadLine();
Console.Clear(); }
MenusEspece();
break; switch (Convert.ToInt32(choix))
case 2: {
Console.Clear(); case 1:
MenusAnimal(); Console.Clear();
break; MenusEspece();
case 9: break;
return; case 2:
default: Console.Clear();
Console.WriteLine("\tChoix incorrect\n"); MenusAnimal();
break; break;
} case 9:
} return;
} default:
Console.WriteLine("\tChoix incorrect\n");
static private void MenusEspece() break;
{ }
while (true) }
{ }
Console.WriteLine("LES ESPECES");
Console.WriteLine("\t1- Afficher les espèces"); static private void MenusEspece()
Console.WriteLine("\t2- Sélectionner une espèce"); {
Console.WriteLine("\t9- Retour"); while (true)
{
Console.Write("\n\tEntrer votre choix : "); Console.WriteLine("LES ESPECES");
int choix = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\t1- Afficher les espèces");
Console.WriteLine("\t2- Sélectionner une espèce");
switch (choix) Console.WriteLine("\t9- Retour");
{
case 1: Console.Write("\n\tEntrer votre choix : ");
Console.Clear(); string? choix = Console.ReadLine();
AfficherListeEspece(); while (!Theque.IntValidate(choix))
break; {
case 2: Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
Console.Clear(); choix = Console.ReadLine();
SelectionnerEspece(); }
break;
case 9: switch (Convert.ToInt32(choix))
Console.Clear(); {
return; case 1:
default: Console.Clear();
Console.WriteLine("\tChoix incorrect\n"); AfficherListeEspece();
break; break;
} case 2:
} Console.Clear();
} SelectionnerEspece();
break;
static private void AfficherListeEspece() case 9:
{ Console.Clear();
Console.WriteLine("LISTE DES ESPECES : "); return;
foreach (Espece espece in Theque.ListeEspeces) default:
{ Console.WriteLine("\tChoix incorrect\n");
Console.WriteLine("\t" + espece.Nom + " (" + espece.NomScientifique + ")"); break;
} }
Console.WriteLine("\n"); }
} }
static private void SelectionnerEspece() static private void AfficherListeEspece()
{ {
string choix = ""; Console.WriteLine("LISTE DES ESPECES : ");
while (choix != "-1") foreach (Espece espece in Theque.ListeEspeces)
{ {
AfficherListeEspece(); Console.WriteLine("\t" + espece.Nom + " (" + espece.NomScientifique + ")");
}
Console.Write("\n\tEntrer le nom de l'espèce à sélectionner (-1 pour annuler) : "); Console.WriteLine("\n");
choix = Console.ReadLine(); }
Espece? espece = Theque.RechercherEspece(choix); static private void SelectionnerEspece()
{
if (espece != null) string? choix = null;
{ while (choix != "-1")
AfficherEspece(espece); {
} AfficherListeEspece();
else Console.WriteLine("\tChoix incorrect\n");
} Console.Write("\n\tEntrer le nom de l'espèce à sélectionner (-1 pour annuler) : ");
} choix = Console.ReadLine();
static private void AfficherEspece(Espece espece) if(choix != null)
{ {
Console.WriteLine("\n" + espece.Nom); Espece? espece = Theque.RechercherEspece(choix);
Console.WriteLine("\tNom scientifique : " + espece.NomScientifique);
Console.WriteLine("\tEspérance de vie : " + espece.EsperanceVie); if (espece != null)
Console.WriteLine("\tPoids moyen : " + espece.PoidsMoyen); {
Console.WriteLine("\tTaille moyenne : " + espece.TailleMoyenne); AfficherEspece(espece);
Console.WriteLine("\tComportement : " + espece.Comportement); }
Console.WriteLine("\tSanté : " + espece.Sante); else Console.WriteLine("\tChoix incorrect\n");
Console.WriteLine("\tEducation : " + espece.Education); }
Console.WriteLine("\tEntretien : " + espece.Entretien); }
Console.WriteLine("\tCout : " + espece.Cout); }
Console.WriteLine("\tConseil : " + espece.Conseil);
static private void AfficherEspece(Espece espece)
AfficherListeRace(espece); {
Console.WriteLine("\n" + espece.Nom);
while (true) Console.WriteLine("\tNom scientifique : " + espece.NomScientifique);
{ Console.WriteLine("\tEspérance de vie : " + espece.EsperanceVie);
Console.WriteLine("\n\t1- Sélectionner une race"); Console.WriteLine("\tPoids moyen : " + espece.PoidsMoyen);
Console.WriteLine("\t9- Retour"); Console.WriteLine("\tTaille moyenne : " + espece.TailleMoyenne);
Console.WriteLine("\tComportement : " + espece.Comportement);
Console.Write("\n\tEntrer votre choix : "); Console.WriteLine("\tSanté : " + espece.Sante);
int decision = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\tEducation : " + espece.Education);
Console.WriteLine("\tEntretien : " + espece.Entretien);
switch (decision) Console.WriteLine("\tCout : " + espece.Cout);
{ Console.WriteLine("\tConseil : " + espece.Conseil);
case 1:
SelectionnerRace(espece); AfficherListeRace(espece);
break;
case 9: while (true)
return; {
default: Console.WriteLine("\n\t1- Sélectionner une race");
Console.WriteLine("\tChoix incorrect\n"); Console.WriteLine("\t9- Retour");
break;
} Console.Write("\n\tEntrer votre choix : ");
} string? choix = Console.ReadLine();
} while (!Theque.IntValidate(choix))
{
static private void AfficherListeRace(Espece espece) Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
{ choix = Console.ReadLine();
Console.WriteLine("\nLISTE DES RACES : "); }
if (espece.ListeRaces != null)
{ switch (Convert.ToInt32(choix))
foreach (Race race in espece.ListeRaces) {
{ case 1:
Console.WriteLine("\t" + race.Nom + " (" + race.NomScientifique + ")"); SelectionnerRace(espece);
} break;
Console.WriteLine("\n"); case 9:
} return;
else Console.WriteLine("\tAucune race connue.\n"); default:
} Console.WriteLine("\tChoix incorrect\n");
break;
static private void SelectionnerRace(Espece espece) }
{ }
string choix = ""; }
while (choix != "-1")
{ static private void AfficherListeRace(Espece espece)
Console.Write("\n\tEntrer le nom de la race à sélectionner (-1 pour annuler) : "); {
choix = Console.ReadLine(); Console.WriteLine("\nLISTE DES RACES : ");
if (espece.ListeRaces != null)
if (choix != "-1") {
{ foreach (Race race in espece.ListeRaces)
Race? race = espece.RechercherRace(choix); {
Console.WriteLine("\t" + race.Nom + " (" + race.NomScientifique + ")");
if (race != null) }
{ Console.WriteLine("\n");
AfficherRace(race); }
} else Console.WriteLine("\tAucune race connue.\n");
else Console.WriteLine("\tChoix incorrect\n"); }
}
} static private void SelectionnerRace(Espece espece)
} {
string? choix = "";
static private void AfficherRace(Race race) while (choix != "-1")
{ {
Console.WriteLine("\n " + race.Nom); Console.Write("\n\tEntrer le nom de la race à sélectionner (-1 pour annuler) : ");
Console.WriteLine("\tNom scientifique : " + race.NomScientifique); choix = Console.ReadLine();
Console.WriteLine("\tEspérance de vie : " + race.EsperanceVie);
Console.WriteLine("\tPoids moyen : " + race.PoidsMoyen); if (choix != "-1")
Console.WriteLine("\tTaille moyenne : " + race.TailleMoyenne); {
Console.WriteLine("\tComportement : " + race.Comportement); Race? race = espece.RechercherRace(choix);
Console.WriteLine("\tSante : " + race.Sante);
Console.WriteLine("\tEducation : " + race.Education); if (race != null)
Console.WriteLine("\tEntretien : " + race.Entretien); {
Console.WriteLine("\tCout : " + race.Cout); AfficherRace(race);
Console.WriteLine("\tConseil : " + race.Conseil + "\n\n"); }
} else Console.WriteLine("\tChoix incorrect\n");
}
static private void MenusAnimal() }
{ }
while (true)
{ static private void AfficherRace(Race race)
Console.WriteLine("LES ANIMAUX"); {
Console.WriteLine("\t1- Afficher les animaux"); Console.WriteLine("\n " + race.Nom);
Console.WriteLine("\t2- Ajouter un animal"); Console.WriteLine("\tNom scientifique : " + race.NomScientifique);
Console.WriteLine("\t3- Sélectionner un animal"); Console.WriteLine("\tEspérance de vie : " + race.EsperanceVie);
Console.WriteLine("\t9- Retour"); Console.WriteLine("\tPoids moyen : " + race.PoidsMoyen);
Console.WriteLine("\tTaille moyenne : " + race.TailleMoyenne);
Console.Write("\n\tEntrer votre choix : "); Console.WriteLine("\tComportement : " + race.Comportement);
int choix = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\tSante : " + race.Sante);
Console.WriteLine("\tEducation : " + race.Education);
switch (choix) Console.WriteLine("\tEntretien : " + race.Entretien);
{ Console.WriteLine("\tCout : " + race.Cout);
case 1: Console.WriteLine("\tConseil : " + race.Conseil + "\n\n");
Console.Clear(); }
AfficherListeAnimaux();
break; static private void MenusAnimal()
case 2: {
Console.Clear(); while (true)
Animal animal = Theque.AjouterAnimal(); {
ModifierNom(animal); Console.WriteLine("LES ANIMAUX");
ModifierAnimal(animal); Console.WriteLine("\t1- Afficher les animaux");
break; Console.WriteLine("\t2- Ajouter un animal");
case 3: Console.WriteLine("\t3- Sélectionner un animal");
Console.Clear(); Console.WriteLine("\t9- Retour");
SelectionnerAnimal();
break; Console.Write("\n\tEntrer votre choix : ");
case 9: string? choix = Console.ReadLine();
Console.Clear(); while (!Theque.IntValidate(choix))
return; {
default: Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
Console.WriteLine("\tChoix incorrect\n"); choix = Console.ReadLine();
break; }
}
} switch (Convert.ToInt32(choix))
} {
case 1:
static private void AfficherListeAnimaux() Console.Clear();
{ AfficherListeAnimaux();
Console.WriteLine("VOS ANIMAUX : "); break;
foreach (Animal animal in Theque.ListeAnimaux) case 2:
{ Console.Clear();
Console.WriteLine(animal.Nom); Animal animal = Theque.AjouterAnimal();
} ModifierNom(animal);
} ModifierAnimal(animal);
break;
static private void SelectionnerAnimal() case 3:
{ Console.Clear();
string choix = ""; SelectionnerAnimal();
while (choix != "-1") break;
{ case 9:
AfficherListeAnimaux(); Console.Clear();
return;
Console.Write("\n\tEntrer le nom de l'animal à sélectionner (-1 pour annuler) : "); default:
choix = Console.ReadLine(); Console.WriteLine("\tChoix incorrect\n");
break;
Animal? animal = Theque.RechercherAnimal(choix); }
}
if (animal != null) }
{
AfficherAnimal(animal); static private void AfficherListeAnimaux()
} {
else Console.WriteLine("\tChoix incorrect\n"); Console.WriteLine("VOS ANIMAUX : ");
} foreach (Animal animal in Theque.ListeAnimaux)
} {
Console.WriteLine(animal.Nom);
static private void AfficherAnimal(Animal animal) }
{ }
Console.Clear();
while (true) static private void SelectionnerAnimal()
{ {
Console.WriteLine("\n" + animal.Nom); string? choix = "";
if (animal.Espece != null) Console.WriteLine("\tEspece : " + animal.Espece.Nom); while (choix != "-1")
if (animal.Race != null) Console.WriteLine("\tRace : " + animal.Race.Nom); {
Console.WriteLine("\tDate de naissance : " + animal.DateNaissance); AfficherListeAnimaux();
Console.WriteLine("\tSexe : " + animal.Sexe);
Console.WriteLine("\tDate d'adoption : " + animal.DateAdoption); Console.Write("\n\tEntrer le nom de l'animal à sélectionner (-1 pour annuler) : ");
Console.WriteLine("\tTaille : " + animal.Taille); choix = Console.ReadLine();
Console.WriteLine("\tPoids : " + animal.Poids);
Console.WriteLine("\tAlimentation : " + animal.Alimentation); Animal? animal = Theque.RechercherAnimal(choix);
Console.WriteLine("\tPETSITTER : ");
AfficherEntite(animal.Petsitter); if (animal != null)
Console.WriteLine("\tCHENIL : "); {
AfficherEntite(animal.Chenil); AfficherAnimal(animal);
Console.WriteLine("\tVETERINAIRE : "); }
AfficherEntite(animal.Veterinaire); else Console.WriteLine("\tChoix incorrect\n");
Console.WriteLine("\tMAGASIN ALIMENTAIRE : "); }
AfficherEntite(animal.MagasinAlimentaire); }
Console.WriteLine("\tREFUGE, ELEVAGE, CHENIL DE PROVENANCE : ");
AfficherEntite(animal.Provenance); static private void AfficherAnimal(Animal animal)
{
Console.Clear();
Console.WriteLine("\n\t1- Modifier"); while (true)
Console.WriteLine("\t2- Supprimer"); {
Console.WriteLine("\t9- Retour"); Console.WriteLine("\n" + animal.Nom);
if (animal.Espece != null) Console.WriteLine("\tEspece : " + animal.Espece.Nom);
Console.Write("\n\tEntrer votre choix : "); if (animal.Race != null) Console.WriteLine("\tRace : " + animal.Race.Nom);
int decision = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\tDate de naissance : " + animal.DateNaissance);
Console.WriteLine("\tSexe : " + animal.Sexe);
switch (decision) Console.WriteLine("\tDate d'adoption : " + animal.DateAdoption);
{ Console.WriteLine("\tTaille : " + animal.Taille);
case 1: Console.WriteLine("\tPoids : " + animal.Poids);
ModifierAnimal(animal); Console.WriteLine("\tAlimentation : " + animal.Alimentation);
break; Console.WriteLine("\tPETSITTER : ");
case 2: AfficherEntite(animal.Petsitter);
Theque.SupprimerAnimal(animal); Console.WriteLine("\tCHENIL : ");
return; AfficherEntite(animal.Chenil);
case 9: Console.WriteLine("\tVETERINAIRE : ");
return; AfficherEntite(animal.Veterinaire);
default: Console.WriteLine("\tMAGASIN ALIMENTAIRE : ");
Console.WriteLine("\tChoix incorrect\n"); AfficherEntite(animal.MagasinAlimentaire);
break; Console.WriteLine("\tREFUGE, ELEVAGE, CHENIL DE PROVENANCE : ");
} AfficherEntite(animal.Provenance);
}
}
Console.WriteLine("\n\t1- Modifier");
static private void AfficherEntite(Entite entite) Console.WriteLine("\t2- Supprimer");
{ Console.WriteLine("\t9- Retour");
Console.WriteLine("\t\tNom : " + entite.Nom);
Console.WriteLine("\t\tAdresse : " + entite.Adresse + "," + Convert.ToInt32(entite.CodePostal) + " " + entite.Ville); Console.Write("\n\tEntrer votre choix : ");
Console.WriteLine("\t\tNuméro de téléphone : " + entite.NumTel); string? choix = Console.ReadLine();
} while (!Theque.IntValidate(choix))
{
static private void ModifierAnimal(Animal animal) Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
{ choix = Console.ReadLine();
while (true) }
{
Console.WriteLine("MODIFIER L'ANIMAL ", animal.Nom); switch (Convert.ToInt32(choix))
Console.WriteLine("\t1- Nom"); {
Console.WriteLine("\t2- Espece"); case 1:
Console.WriteLine("\t3- Race"); ModifierAnimal(animal);
Console.WriteLine("\t4- Date de naissance"); break;
Console.WriteLine("\t5- Sexe"); case 2:
Console.WriteLine("\t6- Date d'adoption"); Theque.SupprimerAnimal(animal);
Console.WriteLine("\t7- Taille"); return;
Console.WriteLine("\t8- Poids"); case 9:
Console.WriteLine("\t9- Alimentation"); return;
Console.WriteLine("\t10- Petsitter"); default:
Console.WriteLine("\t11- Chenil"); Console.WriteLine("\tChoix incorrect\n");
Console.WriteLine("\t12- Vétérinaire"); break;
Console.WriteLine("\t13- Magasin alimentaire"); }
Console.WriteLine("\t14- Refuge, élevage et chenil de provenance"); }
Console.WriteLine("\t19- Retour"); }
Console.Write("\n\tEntrer votre choix : "); static private void AfficherEntite(Entite entite)
int decision = Convert.ToInt32(Console.ReadLine()); {
Console.WriteLine("\t\tNom : " + entite.Nom);
switch (decision) Console.WriteLine("\t\tAdresse : " + entite.Adresse + "," + Convert.ToInt32(entite.CodePostal) + " " + entite.Ville);
{ Console.WriteLine("\t\tNuméro de téléphone : " + entite.NumTel);
case 1: }
ModifierNom(animal);
break; static private void ModifierAnimal(Animal animal)
case 2: {
ModifierEspece(animal); while (true)
break; {
case 3: Console.WriteLine("MODIFIER L'ANIMAL ", animal.Nom);
ModifierRace(animal); Console.WriteLine("\t1- Nom");
break; Console.WriteLine("\t2- Espece");
case 4: Console.WriteLine("\t3- Race");
ModifierDateNaissance(animal); Console.WriteLine("\t4- Date de naissance");
break; Console.WriteLine("\t5- Sexe");
case 5: Console.WriteLine("\t6- Date d'adoption");
ModifierSexe(animal); Console.WriteLine("\t7- Taille");
break; Console.WriteLine("\t8- Poids");
Console.WriteLine("\t9- Alimentation");
Console.WriteLine("\t10- Petsitter");
Console.WriteLine("\t11- Chenil");
Console.WriteLine("\t12- Vétérinaire");
Console.WriteLine("\t13- Magasin alimentaire");
Console.WriteLine("\t14- Refuge, élevage et chenil de provenance");
Console.WriteLine("\t19- Retour");
Console.Write("\n\tEntrer votre choix : ");
string? choix = Console.ReadLine();
while (!Theque.IntValidate(choix))
{
Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
choix = Console.ReadLine();
}
switch (Convert.ToInt32(choix))
{
case 1:
ModifierNom(animal);
break;
case 2:
ModifierEspece(animal);
break;
case 3:
ModifierRace(animal);
break;
case 4:
ModifierDateNaissance(animal);
break;
case 5:
ModifierSexe(animal);
break;
case 6: case 6:
ModifierDateAdoption(animal); ModifierDateAdoption(animal);
break; break;
@ -402,36 +436,39 @@ class Program
static private void ModifierNom(Animal animal) static private void ModifierNom(Animal animal)
{ {
while (animal.Nom.Length <= 0 || animal.Nom.StartsWith(" ")) Console.Write("\tNom : ");
string nom = Console.ReadLine()??"";
while(!animal.NomValidate(nom))
{ {
Console.Write("\tNom : "); Console.WriteLine("\nNom incorrect. Nom : ");
animal.Nom = Console.ReadLine(); nom = Console.ReadLine() ??"";
} }
animal.Nom = nom;
} }
static private void ModifierEspece(Animal animal) static private void ModifierEspece(Animal animal)
{ {
Espece? espece = null; Console.Write("\tEspèce (appuyer sur entrée pour passer): ");
while (espece == null) string? nomEspece = Console.ReadLine();
Espece? espece = Theque.RechercherEspece(nomEspece);
while (nomEspece != null && espece == null)
{ {
Console.Write("\tEspèce : "); Console.Write("\tEspèce inconnue. Espèce : ");
string nomEspece = Console.ReadLine(); nomEspece = Console.ReadLine();
espece = Theque.RechercherEspece(nomEspece); espece = Theque.RechercherEspece(nomEspece);
if (espece == null)
{
Console.WriteLine("Espece inconnue\n");
}
} }
animal.Espece = espece; animal.Espece = espece;
} }
static private void ModifierSexe(Animal animal) static private void ModifierSexe(Animal animal)
{ {
string sexe = "sexe"; string? sexe = null;
while (sexe != "Male" && sexe != "Femelle" && sexe != "") while (sexe != "Male" && sexe != "Femelle" && sexe != null)
{ {
Console.Write("\tSexe [Male|Femelle|] (appuyer sur entrer pour passer) : "); Console.Write("\tSexe [Male|Femelle] (appuyer sur entrer pour passer) : ");
sexe = Console.ReadLine(); sexe = Console.ReadLine();
} }
animal.Sexe = sexe; animal.Sexe = sexe;
@ -440,17 +477,27 @@ class Program
static private void ModifierTaille(Animal animal) static private void ModifierTaille(Animal animal)
{ {
Console.Write("\tTaille (appuyer sur entrer pour passer) : "); Console.Write("\tTaille (appuyer sur entrer pour passer) : ");
string taille = Console.ReadLine(); string? taille = Console.ReadLine();
if (taille == "") animal.Taille = null;
else animal.Taille = Single.Parse(taille); while(taille != null && !Theque.FloatValidate(taille))
{
Console.WriteLine("\tTaille incorrect. Taille : ");
taille = Console.ReadLine();
}
animal.Taille = Convert.ToSingle(taille);
} }
static private void ModifierPoids(Animal animal) static private void ModifierPoids(Animal animal)
{ {
Console.Write("\tPoids (appuyer sur entrer pour passer) : "); Console.Write("\tPoids (appuyer sur entrer pour passer) : ");
string poids = Console.ReadLine(); string? poids = Console.ReadLine();
if (poids == "") animal.Poids = null;
else animal.Poids = Single.Parse(poids); while (poids != null && !Theque.FloatValidate(poids))
{
Console.WriteLine("\tTaille incorrect. Poids : ");
poids = Console.ReadLine();
}
animal.Poids = Convert.ToSingle(poids);
} }
static private void ModifierAlimentation(Animal animal) static private void ModifierAlimentation(Animal animal)
@ -462,22 +509,49 @@ class Program
static private void ModifierDateNaissance(Animal animal) static private void ModifierDateNaissance(Animal animal)
{ {
Console.Write("\tDate de naissance (appuyer sur entrer pour passer) : "); Console.Write("\tDate de naissance (appuyer sur entrer pour passer) : ");
animal.DateNaissance = Console.ReadLine(); string? dateNaissance = Console.ReadLine();
while (dateNaissance != null && !Theque.DateTimeValidate(dateNaissance))
{
Console.WriteLine("\tTaille incorrect. Date de naissance : ");
dateNaissance = Console.ReadLine();
}
animal.DateNaissance = Convert.ToDateTime(dateNaissance);
} }
static private void ModifierDateAdoption(Animal animal) static private void ModifierDateAdoption(Animal animal)
{ {
Console.Write("\tDate d'adoption (appuyer sur entrer pour passer) : "); Console.Write("\tDate d'adoption (appuyer sur entrer pour passer) : ");
animal.DateAdoption = Console.ReadLine(); string? dateAdoption = Console.ReadLine();
while (dateAdoption != null && !Theque.DateTimeValidate(dateAdoption))
{
Console.WriteLine("\tTaille incorrect. Date d'adoption : ");
dateAdoption = Console.ReadLine();
}
animal.DateAdoption = Convert.ToDateTime(dateAdoption);
} }
static private void ModifierRace(Animal animal) static private void ModifierRace(Animal animal)
{ {
Console.Write("\tRace (appuyer sur entrer pour passer) : "); if (animal.Espece != null)
string nomRace = Console.ReadLine(); {
animal.Race = animal.Espece.RechercherRace(nomRace); Console.Write("\tRace (appuyer sur entrée pour passer): ");
string? nomRace = Console.ReadLine();
Race? race = animal.Espece.RechercherRace(nomRace);
while (nomRace != null && race == null)
{
Console.Write("\tRace inconnue. Race : ");
nomRace = Console.ReadLine();
race = animal.Espece.RechercherRace(nomRace);
}
animal.Race = race;
}
else Console.WriteLine("\tL'animal ne peut pas avoir une race sans espèce");
} }
static private void ModifierEntite(Entite entite) static private void ModifierEntite(Entite entite)
@ -492,9 +566,14 @@ class Program
Console.WriteLine("\t9- Retour"); Console.WriteLine("\t9- Retour");
Console.Write("\n\tEntrer votre choix : "); Console.Write("\n\tEntrer votre choix : ");
int decision = Convert.ToInt32(Console.ReadLine()); string? choix = Console.ReadLine();
while (!Theque.IntValidate(choix))
{
Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
choix = Console.ReadLine();
}
switch (decision) switch (Convert.ToInt32(choix))
{ {
case 1: case 1:
ModifierNomEntite(entite); ModifierNomEntite(entite);
@ -531,12 +610,16 @@ class Program
static private void ModifierCodePostalEntite(Entite entite) static private void ModifierCodePostalEntite(Entite entite)
{ {
int? codePostal = null; Console.Write("\tCode postal (appuyer sur entrer pour passer) : ");
while(codePostal != null || (codePostal < 10000 && codePostal > 99999)) { string? codePostal = Console.ReadLine();
while((codePostal != null && !Theque.IntValidate(codePostal)) ||
(codePostal != null && Theque.IntValidate(codePostal) && Convert.ToInt32(codePostal) < 10000 && Convert.ToInt32(codePostal) > 99999)) {
Console.Write("\tCode postal (appuyer sur entrer pour passer) : "); Console.Write("\tCode postal (appuyer sur entrer pour passer) : ");
codePostal = Convert.ToInt32(Console.ReadLine()); codePostal = Console.ReadLine();
} }
entite.CodePostal = codePostal;
entite.CodePostal = Convert.ToInt32(codePostal);
} }
static private void ModifierVilleEntite(Entite entite) static private void ModifierVilleEntite(Entite entite)

@ -24,7 +24,7 @@ namespace Model
if (nom == value) if (nom == value)
return; return;
nom = value; nom = value;
NomIsValid = NomValidate(); NomIsValid = NomValidate(nom);
OnPropertyChanged(nameof(Nom)); OnPropertyChanged(nameof(Nom));
} }
} }
@ -44,7 +44,7 @@ namespace Model
private bool nomIsValid; private bool nomIsValid;
[DataMember(Name = "naissance")] [DataMember(Name = "naissance")]
public string DateNaissance public DateTime? DateNaissance
{ {
get => dateNaissance; get => dateNaissance;
set set
@ -55,7 +55,7 @@ namespace Model
OnPropertyChanged(nameof(DateNaissance)); OnPropertyChanged(nameof(DateNaissance));
} }
} }
private string dateNaissance; private DateTime? dateNaissance;
[DataMember(Name = "sexe")] [DataMember(Name = "sexe")]
public string Sexe public string Sexe
@ -71,7 +71,7 @@ namespace Model
private string sexe; private string sexe;
[DataMember(Name = "adoption")] [DataMember(Name = "adoption")]
public string DateAdoption public DateTime? DateAdoption
{ {
get => dateAdoption; get => dateAdoption;
set set
@ -82,7 +82,7 @@ namespace Model
OnPropertyChanged(nameof(DateAdoption)); OnPropertyChanged(nameof(DateAdoption));
} }
} }
private string dateAdoption; private DateTime? dateAdoption;
[DataMember(Name = "taille")] [DataMember(Name = "taille")]
public float? Taille public float? Taille
@ -113,7 +113,7 @@ namespace Model
private float? poids; private float? poids;
[DataMember(Name = "alimentation")] [DataMember(Name = "alimentation")]
public string Alimentation public string? Alimentation
{ {
get => alimentation; get => alimentation;
set set
@ -124,7 +124,7 @@ namespace Model
OnPropertyChanged(nameof(Alimentation)); OnPropertyChanged(nameof(Alimentation));
} }
} }
private string alimentation; private string? alimentation;
[DataMember(Name = "espèce")] [DataMember(Name = "espèce")]
public Espece? Espece public Espece? Espece
@ -225,7 +225,7 @@ namespace Model
private Entite? petsitter = new Entite(); private Entite? petsitter = new Entite();
[DataMember(Name = "image")] [DataMember(Name = "image")]
public string Image public string? Image
{ {
get => image; get => image;
set set
@ -236,21 +236,14 @@ namespace Model
OnPropertyChanged(nameof(Image)); OnPropertyChanged(nameof(Image));
} }
} }
private string image; 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") public Animal()
{ {
Nom = nom;
DateNaissance = dateNaissance;
Sexe = sexe;
DateAdoption = dateAdpotion;
Taille = taille;
Poids = poids;
Alimentation = alimentation;
NomIsValid = false; NomIsValid = false;
} }
void OnPropertyChanged(string propertyName) private void OnPropertyChanged(string propertyName)
{ {
if (PropertyChanged != null) if (PropertyChanged != null)
{ {
@ -258,9 +251,9 @@ namespace Model
} }
} }
bool NomValidate() public bool NomValidate(string? nom)
{ {
if(Nom.Length <= 0 || Nom.StartsWith(" ")) return false; if (nom == null || nom.Length <= 0 || nom.StartsWith(" ")) return false;
return true; return true;
} }
} }

@ -1,105 +1,105 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.IO.Pipes; using System.IO.Pipes;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model
{ {
[DataContract(Name = "entite")] [DataContract(Name = "entite")]
public class Entite : INotifyPropertyChanged public class Entite : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
[DataMember(Name = "nom")] [DataMember(Name = "nom")]
public string Nom public string? Nom
{ {
get => nom; get => nom;
set set
{ {
if (nom == value) if (nom == value)
return; return;
nom = value; nom = value;
OnPropertyChanged(nameof(Nom)); OnPropertyChanged(nameof(Nom));
} }
} }
private string nom; private string? nom;
[DataMember(Name = "adresse")] [DataMember(Name = "adresse")]
public string Adresse public string? Adresse
{ {
get => adresse; get => adresse;
set set
{ {
if (adresse == value) if (adresse == value)
return; return;
adresse = value; adresse = value;
OnPropertyChanged(nameof(Adresse)); OnPropertyChanged(nameof(Adresse));
} }
} }
private string adresse; private string? adresse;
[DataMember(Name = "codePostal")] [DataMember(Name = "codePostal")]
public int? CodePostal public int? CodePostal
{ {
get => codePostal; get => codePostal;
set set
{ {
if (codePostal == value) if (codePostal == value)
return; return;
codePostal = value; codePostal = value;
OnPropertyChanged(nameof(CodePostal)); OnPropertyChanged(nameof(CodePostal));
} }
} }
private int? codePostal; private int? codePostal;
[DataMember(Name = "ville")] [DataMember(Name = "ville")]
public string Ville public string? Ville
{ {
get => ville; get => ville;
set set
{ {
if (ville == value) if (ville == value)
return; return;
ville = value; ville = value;
OnPropertyChanged(nameof(Ville)); OnPropertyChanged(nameof(Ville));
} }
} }
private string ville; private string? ville;
[DataMember(Name = "numTel")] [DataMember(Name = "numTel")]
public int? NumTel public int? NumTel
{ {
get => numTel; get => numTel;
set set
{ {
if(numTel == value) if(numTel == value)
return; return;
numTel = value; numTel = value;
OnPropertyChanged(nameof(NumTel)); OnPropertyChanged(nameof(NumTel));
} }
} }
private int? numTel; private int? numTel;
public Entite(string nom = "", string adresse = "", int? codePostal = null, string ville = "", int? numTel = null) public Entite(string nom = "", string adresse = "", int? codePostal = null, string ville = "", int? numTel = null)
{ {
Nom = nom; Nom = nom;
Adresse = adresse; Adresse = adresse;
CodePostal = codePostal; CodePostal = codePostal;
Ville = ville; Ville = ville;
NumTel = numTel; NumTel = numTel;
} }
public void OnPropertyChanged(string propertyName) public void OnPropertyChanged(string propertyName)
{ {
if (PropertyChanged != null) if (PropertyChanged != null)
{ {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
} }
} }
} }

@ -74,7 +74,7 @@ namespace Model
return Nom; return Nom;
} }
public Race? RechercherRace(string choix) public Race? RechercherRace(string? choix)
{ {
if (ListeRaces != null && choix != "") if (ListeRaces != null && choix != "")
{ {

@ -23,20 +23,6 @@ namespace Model
return ListeEspeces; return ListeEspeces;
} }
public static List<Animal> LoadZootheque()
{
List<Animal> listeAnimaux = new List<Animal>();
listeAnimaux.Add(new("Kiki"));
listeAnimaux.Add(new("PouetPouet"));
listeAnimaux.Add(new("Chouchou"));
listeAnimaux.Add(new("Pupuce"));
listeAnimaux.Add(new("AucuneIdée"));
listeAnimaux.Add(new("Minou"));
return listeAnimaux;
}
public static Theque LoadTheque() public static Theque LoadTheque()
{ {
Theque theque = new Theque(); Theque theque = new Theque();

@ -36,7 +36,7 @@ namespace Model
ListeAnimaux.Remove(animal); ListeAnimaux.Remove(animal);
} }
public Animal? RechercherAnimal(string choix) public Animal? RechercherAnimal(string? choix)
{ {
foreach (Animal animal in ListeAnimaux) foreach (Animal animal in ListeAnimaux)
{ {
@ -48,7 +48,7 @@ namespace Model
return null; return null;
} }
public Espece? RechercherEspece(string choix) public Espece? RechercherEspece(string? choix)
{ {
foreach (Espece espece in ListeEspeces) foreach (Espece espece in ListeEspeces)
{ {
@ -59,5 +59,47 @@ namespace Model
} }
return null; return null;
} }
public bool IntValidate(string? response)
{
if (response == null) return false;
try
{
int number = Convert.ToInt32(response);
return true;
}
catch (Exception ex)
{
return false;
}
}
public bool FloatValidate(string? response)
{
if (response == null) return false;
try
{
float numFloat = Convert.ToSingle(response);
return true;
}
catch (Exception ex)
{
return false;
}
}
public bool DateTimeValidate(string? response)
{
if (response == null) return false;
try
{
DateTime date = Convert.ToDateTime(response);
return true;
}
catch (Exception ex)
{
return false;
}
}
} }
} }

@ -12,7 +12,7 @@ namespace Model
public class Veterinaire : Entite public class Veterinaire : Entite
{ {
[DataMember(Name = "clinique")] [DataMember(Name = "clinique")]
public string Clinique public string? Clinique
{ {
get => clinique; get => clinique;
set set
@ -23,6 +23,6 @@ namespace Model
OnPropertyChanged(nameof(Clinique)); OnPropertyChanged(nameof(Clinique));
} }
} }
private string clinique; private string? clinique;
} }
} }

Loading…
Cancel
Save