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;
case 2:
Console.Clear();
Theque.Zootheque.AjouterAnimal(Theque.Especetheque);
Theque.Zootheque.AjouterAnimal();
break;
case 3:
Theque.Zootheque.SelectionnerAnimal(Theque.Especetheque);

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

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

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

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

@ -7,4 +7,10 @@ public partial class DetailAnimal : ContentPage
InitializeComponent();
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