Gestion conflit

pull/18/head
Leana BESSON 2 years ago
commit 0467de0fad

@ -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;
@ -27,9 +28,14 @@ class Program
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))
{
Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
choix = Console.ReadLine();
}
switch (choix) switch (Convert.ToInt32(choix))
{ {
case 1: case 1:
Console.Clear(); Console.Clear();
@ -58,9 +64,14 @@ class Program
Console.WriteLine("\t9- Retour"); Console.WriteLine("\t9- Retour");
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))
{
Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
choix = Console.ReadLine();
}
switch (choix) switch (Convert.ToInt32(choix))
{ {
case 1: case 1:
Console.Clear(); Console.Clear();
@ -92,7 +103,7 @@ class Program
static private void SelectionnerEspece() static private void SelectionnerEspece()
{ {
string choix = ""; string? choix = null;
while (choix != "-1") while (choix != "-1")
{ {
AfficherListeEspece(); AfficherListeEspece();
@ -100,13 +111,16 @@ class Program
Console.Write("\n\tEntrer le nom de l'espèce à sélectionner (-1 pour annuler) : "); Console.Write("\n\tEntrer le nom de l'espèce à sélectionner (-1 pour annuler) : ");
choix = Console.ReadLine(); choix = Console.ReadLine();
Espece? espece = Theque.RechercherEspece(choix); if(choix != null)
if (espece != null)
{ {
AfficherEspece(espece); Espece? espece = Theque.RechercherEspece(choix);
if (espece != null)
{
AfficherEspece(espece);
}
else Console.WriteLine("\tChoix incorrect\n");
} }
else Console.WriteLine("\tChoix incorrect\n");
} }
} }
@ -132,9 +146,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:
SelectionnerRace(espece); SelectionnerRace(espece);
@ -164,7 +183,7 @@ class Program
static private void SelectionnerRace(Espece espece) static private void SelectionnerRace(Espece espece)
{ {
string choix = ""; string? choix = "";
while (choix != "-1") while (choix != "-1")
{ {
Console.Write("\n\tEntrer le nom de la race à sélectionner (-1 pour annuler) : "); Console.Write("\n\tEntrer le nom de la race à sélectionner (-1 pour annuler) : ");
@ -209,9 +228,14 @@ class Program
Console.WriteLine("\t9- Retour"); Console.WriteLine("\t9- Retour");
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))
{
Console.Write("\n\tChoix incorrect. Entrer votre choix : ");
choix = Console.ReadLine();
}
switch (choix) switch (Convert.ToInt32(choix))
{ {
case 1: case 1:
Console.Clear(); Console.Clear();
@ -248,7 +272,7 @@ class Program
static private void SelectionnerAnimal() static private void SelectionnerAnimal()
{ {
string choix = ""; string? choix = "";
while (choix != "-1") while (choix != "-1")
{ {
AfficherListeAnimaux(); AfficherListeAnimaux();
@ -297,9 +321,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:
ModifierAnimal(animal); ModifierAnimal(animal);
@ -345,9 +374,14 @@ class Program
Console.WriteLine("\t19- Retour"); Console.WriteLine("\t19- 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:
ModifierNom(animal); ModifierNom(animal);
@ -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)

@ -32,7 +32,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));
} }
} }
@ -53,7 +53,8 @@ namespace Model
private bool nomIsValid; private bool nomIsValid;
[DataMember(Name = "naissance")] [DataMember(Name = "naissance")]
public DateTime DateNaissance
public DateTime? DateNaissance
{ {
get => dateNaissance; get => dateNaissance;
set set
@ -64,7 +65,7 @@ namespace Model
OnPropertyChanged(nameof(DateNaissance)); OnPropertyChanged(nameof(DateNaissance));
} }
} }
private DateTime dateNaissance; private DateTime? dateNaissance;
[DataMember(Name = "sexe")] [DataMember(Name = "sexe")]
public string? Sexe public string? Sexe
@ -80,7 +81,8 @@ namespace Model
private string? sexe; private string? sexe;
[DataMember(Name = "adoption")] [DataMember(Name = "adoption")]
public DateTime DateAdoption
public DateTime? DateAdoption
{ {
get => dateAdoption; get => dateAdoption;
set set
@ -91,7 +93,7 @@ namespace Model
OnPropertyChanged(nameof(DateAdoption)); OnPropertyChanged(nameof(DateAdoption));
} }
} }
private DateTime dateAdoption; private DateTime? dateAdoption;
[DataMember(Name = "taille")] [DataMember(Name = "taille")]
public float? Taille public float? Taille
@ -271,7 +273,7 @@ namespace Model
* \param propertyName string - * \param propertyName string -
* \return bool - * \return bool -
*/ */
void OnPropertyChanged(string propertyName) private void OnPropertyChanged(string propertyName)
{ {
if (PropertyChanged != null) if (PropertyChanged != null)
{ {
@ -282,9 +284,9 @@ namespace Model
/*! \brief /*! \brief
* \return bool - * \return bool -
*/ */
bool NomValidate() public bool NomValidate(string? nom)
{ {
if(Nom == null || Nom.Length <= 0 || Nom.StartsWith(" ")) return false; if (nom == null || nom.Length <= 0 || nom.StartsWith(" ")) return false;
return true; return true;
} }
} }

@ -16,7 +16,7 @@ namespace Model
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
@ -27,10 +27,10 @@ namespace Model
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
@ -41,7 +41,7 @@ namespace Model
OnPropertyChanged(nameof(Adresse)); OnPropertyChanged(nameof(Adresse));
} }
} }
private string adresse; private string? adresse;
[DataMember(Name = "codePostal")] [DataMember(Name = "codePostal")]
public int? CodePostal public int? CodePostal
@ -58,7 +58,7 @@ namespace Model
private int? codePostal; private int? codePostal;
[DataMember(Name = "ville")] [DataMember(Name = "ville")]
public string Ville public string? Ville
{ {
get => ville; get => ville;
set set
@ -69,7 +69,7 @@ namespace Model
OnPropertyChanged(nameof(Ville)); OnPropertyChanged(nameof(Ville));
} }
} }
private string ville; private string? ville;
[DataMember(Name = "numTel")] [DataMember(Name = "numTel")]
public int? NumTel public int? NumTel

@ -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 != "")
{ {

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