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.IO;
using System.Runtime.CompilerServices;
@ -27,9 +28,14 @@ class Program
Console.WriteLine("\t9- Quitter");
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:
Console.Clear();
@ -58,9 +64,14 @@ class Program
Console.WriteLine("\t9- Retour");
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:
Console.Clear();
@ -92,7 +103,7 @@ class Program
static private void SelectionnerEspece()
{
string choix = "";
string? choix = null;
while (choix != "-1")
{
AfficherListeEspece();
@ -100,6 +111,8 @@ class Program
Console.Write("\n\tEntrer le nom de l'espèce à sélectionner (-1 pour annuler) : ");
choix = Console.ReadLine();
if(choix != null)
{
Espece? espece = Theque.RechercherEspece(choix);
if (espece != null)
@ -109,6 +122,7 @@ class Program
else Console.WriteLine("\tChoix incorrect\n");
}
}
}
static private void AfficherEspece(Espece espece)
{
@ -132,9 +146,14 @@ class Program
Console.WriteLine("\t9- Retour");
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:
SelectionnerRace(espece);
@ -164,7 +183,7 @@ class Program
static private void SelectionnerRace(Espece espece)
{
string choix = "";
string? choix = "";
while (choix != "-1")
{
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.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:
Console.Clear();
@ -248,7 +272,7 @@ class Program
static private void SelectionnerAnimal()
{
string choix = "";
string? choix = "";
while (choix != "-1")
{
AfficherListeAnimaux();
@ -297,9 +321,14 @@ class Program
Console.WriteLine("\t9- Retour");
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:
ModifierAnimal(animal);
@ -345,9 +374,14 @@ class Program
Console.WriteLine("\t19- Retour");
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:
ModifierNom(animal);
@ -401,37 +435,40 @@ class Program
}
static private void ModifierNom(Animal animal)
{
while (animal.Nom.Length <= 0 || animal.Nom.StartsWith(" "))
{
Console.Write("\tNom : ");
animal.Nom = Console.ReadLine();
string nom = Console.ReadLine()??"";
while(!animal.NomValidate(nom))
{
Console.WriteLine("\nNom incorrect. Nom : ");
nom = Console.ReadLine() ??"";
}
animal.Nom = nom;
}
static private void ModifierEspece(Animal animal)
{
Espece? espece = null;
while (espece == null)
Console.Write("\tEspèce (appuyer sur entrée pour passer): ");
string? nomEspece = Console.ReadLine();
Espece? espece = Theque.RechercherEspece(nomEspece);
while (nomEspece != null && espece == null)
{
Console.Write("\tEspèce : ");
string nomEspece = Console.ReadLine();
Console.Write("\tEspèce inconnue. Espèce : ");
nomEspece = Console.ReadLine();
espece = Theque.RechercherEspece(nomEspece);
if (espece == null)
{
Console.WriteLine("Espece inconnue\n");
}
}
animal.Espece = espece;
}
static private void ModifierSexe(Animal animal)
{
string sexe = "sexe";
while (sexe != "Male" && sexe != "Femelle" && sexe != "")
string? sexe = null;
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();
}
animal.Sexe = sexe;
@ -440,17 +477,27 @@ class Program
static private void ModifierTaille(Animal animal)
{
Console.Write("\tTaille (appuyer sur entrer pour passer) : ");
string taille = Console.ReadLine();
if (taille == "") animal.Taille = null;
else animal.Taille = Single.Parse(taille);
string? taille = Console.ReadLine();
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)
{
Console.Write("\tPoids (appuyer sur entrer pour passer) : ");
string poids = Console.ReadLine();
if (poids == "") animal.Poids = null;
else animal.Poids = Single.Parse(poids);
string? poids = Console.ReadLine();
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)
@ -462,22 +509,49 @@ class Program
static private void ModifierDateNaissance(Animal animal)
{
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)
{
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)
{
Console.Write("\tRace (appuyer sur entrer pour passer) : ");
string nomRace = Console.ReadLine();
animal.Race = animal.Espece.RechercherRace(nomRace);
if (animal.Espece != null)
{
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)
@ -492,9 +566,14 @@ class Program
Console.WriteLine("\t9- Retour");
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:
ModifierNomEntite(entite);
@ -531,12 +610,16 @@ class Program
static private void ModifierCodePostalEntite(Entite entite)
{
int? codePostal = null;
while(codePostal != null || (codePostal < 10000 && codePostal > 99999)) {
Console.Write("\tCode postal (appuyer sur entrer pour passer) : ");
codePostal = Convert.ToInt32(Console.ReadLine());
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) : ");
codePostal = Console.ReadLine();
}
entite.CodePostal = codePostal;
entite.CodePostal = Convert.ToInt32(codePostal);
}
static private void ModifierVilleEntite(Entite entite)

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

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

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

@ -36,7 +36,7 @@ namespace Model
ListeAnimaux.Remove(animal);
}
public Animal? RechercherAnimal(string choix)
public Animal? RechercherAnimal(string? choix)
{
foreach (Animal animal in ListeAnimaux)
{
@ -48,7 +48,7 @@ namespace Model
return null;
}
public Espece? RechercherEspece(string choix)
public Espece? RechercherEspece(string? choix)
{
foreach (Espece espece in ListeEspeces)
{
@ -59,5 +59,47 @@ namespace Model
}
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
{
[DataMember(Name = "clinique")]
public string Clinique
public string? Clinique
{
get => clinique;
set
@ -23,6 +23,6 @@ namespace Model
OnPropertyChanged(nameof(Clinique));
}
}
private string clinique;
private string? clinique;
}
}

Loading…
Cancel
Save