Ajout des fonctionnalités de modification, d'ajout et de suppression d'un animal

pull/18/head
Leana BESSON 2 years ago
parent aa94c63978
commit 2d66b21206

@ -96,7 +96,7 @@ class Program
break; break;
case 2: case 2:
Console.Clear(); Console.Clear();
Theque.Zootheque.AjouterAnimal(Theque.Especetheque); Theque.Zootheque.AjouterAnimal();
break; break;
case 3: case 3:
Theque.Zootheque.SelectionnerAnimal(Theque.Especetheque); Theque.Zootheque.SelectionnerAnimal(Theque.Especetheque);

@ -1,24 +1,110 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Animal public class Animal : INotifyPropertyChanged
{ {
public string Nom { get; set; } public event PropertyChangedEventHandler? PropertyChanged;
public string DateNaissance { get; set; } public string Nom
public string Sexe { get; set; } {
public string DateAdoption { get; set; } get => nom;
public float? Taille { get; set; } set
public float? Poids { get; set; } {
public string Alimentation { get; set; } if (nom == value)
return;
nom = value;
OnPropertyChanged(nameof(Nom));
}
}
private string nom;
public string DateNaissance
{
get => dateNaissance;
set
{
if (dateNaissance == value)
return;
dateNaissance = value;
OnPropertyChanged(nameof(DateNaissance));
}
}
private string dateNaissance;
public string Sexe
{
get => sexe;
set {
if (sexe == value)
return;
sexe = value;
OnPropertyChanged(nameof(Sexe));
}
}
private string sexe;
public string DateAdoption
{
get => dateAdoption;
set
{
if (dateAdoption == value)
return;
dateAdoption = value;
OnPropertyChanged(nameof(DateAdoption));
}
}
private string dateAdoption;
public float? Taille
{
get => taille;
set
{
if (taille == value)
return;
taille = value;
OnPropertyChanged(nameof(Taille));
}
}
private float? taille;
public float? Poids
{
get => poids;
set
{
if (poids == value)
return;
poids = value;
OnPropertyChanged(nameof(Poids));
}
}
private float? poids;
public string Alimentation
{
get => alimentation;
set
{
if (alimentation == value)
return;
alimentation = value;
OnPropertyChanged(nameof(Alimentation));
}
}
private string alimentation;
public Espece Espece { get; set; } public Espece Espece { get; set; }
public Race? Race { get; set; } public Race? Race { get; set; }
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", Race? race = null)
{ {
Nom = nom; Nom = nom;
DateNaissance = dateNaissance; DateNaissance = dateNaissance;
@ -30,6 +116,14 @@ namespace Model
Race = race; Race = race;
} }
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public void AfficherAnimal(Zootheque zootheque, Especetheque especetheque) public void AfficherAnimal(Zootheque zootheque, Especetheque especetheque)
{ {
Console.Clear(); Console.Clear();

@ -1,23 +1,22 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.Marshalling; using System.Runtime.InteropServices.Marshalling;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Zootheque { public class Zootheque
{
public ObservableCollection<Animal> ListeAnimaux { get; set; } = new ObservableCollection<Animal>();
//public ReadOnlyCollection<Animal> ListeAnimaux { get; private set; } public Zootheque()
//private readonly List<Animal> listeAnimaux = new List<Animal>();
public List<Animal> ListeAnimaux { get; set; } = Stub.LoadZootheque();
public Zootheque()
{ {
//ListeAnimaux = new ReadOnlyCollection<Animal>(listeAnimaux);
//LoadZootheque();
} }
public void AfficherListeAnimaux() public void AfficherListeAnimaux()
{ {
@ -28,21 +27,11 @@ namespace Model
} }
} }
public void AjouterAnimal(Especetheque especetheque) public Animal AjouterAnimal()
{ {
Console.WriteLine("AJOUT ANIMAL"); Animal animal = new Animal();
Animal animal = new(new(""), ""); ListeAnimaux.Add(animal);
animal.ModifierNom(); return animal;
animal.ModifierEspece(especetheque);
animal.ModifierRace();
animal.ModifierDateNaissance();
animal.ModifierSexe();
animal.ModifierDateAdoption();
animal.ModifierTaille();
animal.ModifierPoids();
ListeAnimaux.Append(animal);
Console.Clear();
} }
public Animal? RechercherAnimal(string choix) public Animal? RechercherAnimal(string choix)
@ -79,7 +68,7 @@ namespace Model
public void SupprimerAnimal(Animal animal) public void SupprimerAnimal(Animal animal)
{ {
//ListeAnimaux.Remove(animal); ListeAnimaux.Remove(animal);
} }
} }
} }

@ -7,43 +7,44 @@
<ScrollView> <ScrollView>
<toolkit:DockLayout> <toolkit:DockLayout>
<Button Text="+" <Button Text="+"
FontSize="Large" FontSize="Large"
Background="{StaticResource Primary}" Background="{StaticResource Primary}"
toolkit:DockLayout.DockPosition="Bottom" toolkit:DockLayout.DockPosition="Bottom"
VerticalOptions="End" VerticalOptions="End"
HorizontalOptions="End" HorizontalOptions="End"
Margin="20"/> Margin="20"
Clicked="Button_OnClick"/>
<VerticalStackLayout> <VerticalStackLayout>
<Grid RowDefinitions="Auto, *" <Grid RowDefinitions="Auto, *"
RowSpacing="20"> RowSpacing="20">
<ListView ItemsSource="{Binding ListeAnimaux}" <ListView ItemsSource="{Binding ListeAnimaux}"
Grid.Row="1" Grid.Row="1"
ItemTapped="OnClick"> ItemTapped="OnClick">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<ViewCell> <ViewCell>
<Grid Margin="0,0,0,4"> <Grid Margin="0,0,0,4">
<Border Stroke="{StaticResource Secondary}" <Border Stroke="{StaticResource Secondary}"
StrokeThickness="2" StrokeThickness="2"
Margin="10" Margin="10"
Padding="10" Padding="10"
BackgroundColor="{StaticResource Primary}"> BackgroundColor="{StaticResource Primary}">
<Grid ColumnDefinitions="Auto, *" <Grid ColumnDefinitions="Auto, *"
RowDefinitions="3*" RowDefinitions="3*"
ColumnSpacing="15"> ColumnSpacing="15">
<Frame Grid.RowSpan="3" <Frame Grid.RowSpan="3"
HeightRequest="60" HeightRequest="60"
WidthRequest="60" WidthRequest="60"
Padding="0" Padding="0"
Margin="10" Margin="10"
BorderColor="{StaticResource Primary}"> BorderColor="{StaticResource Primary}">
<Image Source="{Binding Image}"/> <Image Source="{Binding Image}"/>
</Frame> </Frame>
<VerticalStackLayout Grid.Column="1"> <VerticalStackLayout Grid.Column="1">
<Label Text="{Binding Nom}" <Label Text="{Binding Nom}"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding NomScientifique}" <Label Text="{Binding NomScientifique}"
FontSize="12"/> FontSize="12"/>
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
</Border> </Border>

@ -18,9 +18,10 @@ public partial class Animaux : ContentPage
Navigation.PushAsync(new DetailAnimal()); Navigation.PushAsync(new DetailAnimal());
} }
private void ListView_ItemTapped(object sender, ItemTappedEventArgs e) public void Button_OnClick(object sender, EventArgs e)
{ {
(App.Current as App).AnimalSelectionner = (App.Current as App).Theque.Zootheque.AjouterAnimal();
Navigation.PushAsync(new DetailAnimal());
} }
} }

@ -5,10 +5,18 @@
Title="{Binding Nom}"> Title="{Binding Nom}">
<ScrollView> <ScrollView>
<VerticalStackLayout> <VerticalStackLayout>
<Button Text="Supprimer"
Background="{StaticResource Primary}"
VerticalOptions="Start"
HorizontalOptions="End"
Margin="20"
Clicked="Button_OnClick"/>
<Image Source="{Binding Image}" <Image Source="{Binding Image}"
MaximumWidthRequest="300" MaximumWidthRequest="300"
Margin="20" Margin="20"
HorizontalOptions="Center"/> HorizontalOptions="Center"/>
<Entry Text="{Binding Nom}"
HorizontalOptions="Center"/>
<Border Stroke="{StaticResource Secondary}" <Border Stroke="{StaticResource Secondary}"
StrokeThickness="2" StrokeThickness="2"
Margin="20" Margin="20"
@ -21,41 +29,45 @@
RowSpacing="8"> RowSpacing="8">
<Label FontAttributes="Bold" <Label FontAttributes="Bold"
Text="Date de naissance"/> Text="Date de naissance"/>
<Label Grid.Column="1" <Entry Grid.Column="1"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding DateNaissance}"/> Text="{Binding DateNaissance}"/>
<Label Grid.Row="1" <Label Grid.Row="1"
FontAttributes="Bold" FontAttributes="Bold"
Text="Sexe"/> Text="Sexe"/>
<Label Grid.Column="2" <Entry Grid.Column="2"
Grid.Row="1" Grid.Row="1"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding Sexe}"/> Text="{Binding Sexe}"/>
<Label Grid.Row="2" <Label Grid.Row="2"
FontAttributes="Bold" FontAttributes="Bold"
Text="Date d'adoption"/> Text="Date d'adoption"/>
<Label Grid.Column="2" <Entry Grid.Column="2"
Grid.Row="2" Grid.Row="2"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding DateAdoption}"/> Text="{Binding DateAdoption}"/>
<Label Grid.Row="3" <Label Grid.Row="3"
FontAttributes="Bold" FontAttributes="Bold"
Text="Taille"/> Text="Taille"/>
<Label Grid.Column="2" <HorizontalStackLayout Grid.Column="2"
Grid.Row="3" Grid.Row="3"
HorizontalOptions="End" HorizontalOptions="End">
Text="{Binding Taille}"/> <Entry Text="{Binding Taille}"/>
<Label Text=" cm" VerticalOptions="Center"/>
</HorizontalStackLayout>
<Label Grid.Row="4" <Label Grid.Row="4"
FontAttributes="Bold" FontAttributes="Bold"
Text="Poids"/> Text="Poids"/>
<Label Grid.Column="2" <HorizontalStackLayout Grid.Column="2"
Grid.Row="4" Grid.Row="4"
HorizontalOptions="End" HorizontalOptions="End">
Text="{Binding Poids}"/> <Entry Text="{Binding Poids}"/>
<Label Text=" kg" VerticalOptions="Center"/>
</HorizontalStackLayout>
<Label Grid.Row="5" <Label Grid.Row="5"
FontAttributes="Bold" FontAttributes="Bold"
Text="Alimentation"/> Text="Alimentation"/>
<Label Grid.Column="2" <Entry Grid.Column="2"
Grid.Row="5" Grid.Row="5"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding Alimentation}"/> Text="{Binding Alimentation}"/>

@ -7,4 +7,10 @@ public partial class DetailAnimal : ContentPage
InitializeComponent(); InitializeComponent();
BindingContext = (App.Current as App).AnimalSelectionner; BindingContext = (App.Current as App).AnimalSelectionner;
} }
public void Button_OnClick(object sender, EventArgs e)
{
(App.Current as App).Theque.Zootheque.SupprimerAnimal((App.Current as App).AnimalSelectionner);
Navigation.PopAsync();
}
} }
Loading…
Cancel
Save