Gestion du stub

pull/18/head
Leana BESSON 2 years ago
parent e42162ecd1
commit 5dae25eaa8

@ -6,9 +6,7 @@ using System.Runtime.InteropServices;
namespace MyProject; namespace MyProject;
class Program class Program
{ {
public static Especetheque Especetheque { get; } = new Especetheque(); static public Theque Theque { get; set; } = new ();
public static Zootheque Zootheque { get; set; } = new Zootheque();
static void Main(string[] args) static void Main(string[] args)
{ {
MenusPrincipal(); MenusPrincipal();
@ -61,11 +59,11 @@ class Program
{ {
case 1: case 1:
Console.Clear(); Console.Clear();
Especetheque.AfficherListeEspece(); Theque.Especetheque.AfficherListeEspece();
break; break;
case 2: case 2:
Console.Clear(); Console.Clear();
Especetheque.SelectionnerEspece(); Theque.Especetheque.SelectionnerEspece();
break; break;
case 9: case 9:
Console.Clear(); Console.Clear();
@ -94,14 +92,14 @@ class Program
{ {
case 1: case 1:
Console.Clear(); Console.Clear();
Zootheque.AfficherListeAnimaux(); Theque.Zootheque.AfficherListeAnimaux();
break; break;
case 2: case 2:
Console.Clear(); Console.Clear();
Zootheque.AjouterAnimal(Especetheque); Theque.Zootheque.AjouterAnimal(Theque.Especetheque);
break; break;
case 3: case 3:
Zootheque.SelectionnerAnimal(Especetheque); Theque.Zootheque.SelectionnerAnimal(Theque.Especetheque);
break; break;
case 9: case 9:
Console.Clear(); Console.Clear();

@ -18,9 +18,8 @@ namespace Model
public Espece Espece { get; set; } public Espece Espece { get; set; }
public Race? Race { get; set; } public Race? Race { get; set; }
public Animal(Espece espece, string nom, string dateNaissance = "", string sexe = "", string dateAdpotion = "", float? taille = null, float? poids = null, string alimentation = "", Race? race = null) public Animal(string nom, string dateNaissance = "", string sexe = "", string dateAdpotion = "", float? taille = null, float? poids = null, string alimentation = "", Race? race = null)
{ {
Espece = espece;
Nom = nom; Nom = nom;
DateNaissance = dateNaissance; DateNaissance = dateNaissance;
Sexe = sexe; Sexe = sexe;

@ -10,16 +10,16 @@ namespace Model
{ {
public class Especetheque public class Especetheque
{ {
public ReadOnlyCollection<Espece> ListeEspeces { get; private set; } //public ReadOnlyCollection<Espece> ListeEspeces { get; private set; }
private readonly List<Espece> listeEspeces = new List<Espece>(); //private readonly List<Espece> listeEspeces = new List<Espece>();
public List<Espece> ListeEspeces { get; set; } = Stub.LoadEspecetheque();
public Especetheque() public Especetheque()
{ {
ListeEspeces = new ReadOnlyCollection<Espece>(listeEspeces); //ListeEspeces = new ReadOnlyCollection<Espece>(listeEspeces);
LoadEspecetheque();
} }
private void LoadEspecetheque() /*private void LoadEspecetheque()
{ {
HashSet<Race> Races = new HashSet<Race>(); HashSet<Race> Races = new HashSet<Race>();
Races.Add(new("Abyssin")); Races.Add(new("Abyssin"));
@ -29,7 +29,7 @@ namespace Model
listeEspeces.Add(new("Chat", "Felis catus", "chat.jpg", "15 à 20 ans", "15 à 20 kg", "10 à 15 cm", Races, "Les chats ont un comportement très solitaire", "Les chats ont une bonne santé", "Les chats s'éduque assez facilement", "Il faut changé leur caisse mais il se nettoie seul, sauf les chatons", "Vétérinaire, alimentation adapté, jouet", "Un conseil")); listeEspeces.Add(new("Chat", "Felis catus", "chat.jpg", "15 à 20 ans", "15 à 20 kg", "10 à 15 cm", Races, "Les chats ont un comportement très solitaire", "Les chats ont une bonne santé", "Les chats s'éduque assez facilement", "Il faut changé leur caisse mais il se nettoie seul, sauf les chatons", "Vétérinaire, alimentation adapté, jouet", "Un conseil"));
listeEspeces.Add(new("Hamster", "Cricetinae")); listeEspeces.Add(new("Hamster", "Cricetinae"));
listeEspeces.Add(new("Lapin", "Oryctolagus cuniculus")); listeEspeces.Add(new("Lapin", "Oryctolagus cuniculus"));
} }*/
public void AfficherListeEspece() public void AfficherListeEspece()
{ {

@ -8,6 +8,29 @@ namespace Model
{ {
public class Stub public class Stub
{ {
public static List<Espece> LoadEspecetheque()
{
List<Espece> ListeEspeces = new List<Espece>();
HashSet<Race> Races = new HashSet<Race>();
Races.Add(new("Abyssin"));
Races.Add(new("American curl"));
ListeEspeces.Add(new("Chien", "Canis lupus familiaris", "chien.jpg"));
ListeEspeces.Add(new("Chat", "Felis catus", "chat.jpg", "15 à 20 ans", "15 à 20 kg", "10 à 15 cm", Races, "Les chats ont un comportement très solitaire", "Les chats ont une bonne santé", "Les chats s'éduque assez facilement", "Il faut changé leur caisse mais il se nettoie seul, sauf les chatons", "Vétérinaire, alimentation adapté, jouet", "Un conseil"));
ListeEspeces.Add(new("Hamster", "Cricetinae"));
ListeEspeces.Add(new("Lapin", "Oryctolagus cuniculus"));
return ListeEspeces;
}
public static List<Animal> LoadZootheque()
{
List<Animal> listeAnimaux = new List<Animal>();
listeAnimaux.Add(new("Kiki"));
listeAnimaux.Add(new("PouetPouet"));
return listeAnimaux;
}
} }
} }

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class Theque
{
public Especetheque Especetheque { get; } = new Especetheque();
public Zootheque Zootheque { get; set; } = new Zootheque();
public Theque() { }
}
}

@ -1,19 +1,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.Marshalling;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Zootheque { public class Zootheque {
public HashSet<Animal> ListeAnimaux = new HashSet<Animal>(); //public ReadOnlyCollection<Animal> ListeAnimaux { get; private set; }
//private readonly List<Animal> listeAnimaux = new List<Animal>();
public List<Animal> ListeAnimaux { get; set; } = Stub.LoadZootheque();
public Zootheque() public Zootheque()
{ {
//ListeAnimaux = new ReadOnlyCollection<Animal>(listeAnimaux);
//LoadZootheque();
} }
public void AfficherListeAnimaux() public void AfficherListeAnimaux()
{ {
Console.WriteLine("VOS ANIMAUX : "); Console.WriteLine("VOS ANIMAUX : ");
@ -36,7 +41,7 @@ namespace Model
animal.ModifierTaille(); animal.ModifierTaille();
animal.ModifierPoids(); animal.ModifierPoids();
ListeAnimaux.Add(animal); ListeAnimaux.Append(animal);
Console.Clear(); Console.Clear();
} }
@ -74,7 +79,7 @@ namespace Model
public void SupprimerAnimal(Animal animal) public void SupprimerAnimal(Animal animal)
{ {
ListeAnimaux.Remove(animal); //ListeAnimaux.Remove(animal);
} }
} }
} }

@ -2,44 +2,50 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.Animaux" x:Class="Views.Animaux"
Title="Animaux"> Title="Vos animaux">
<Grid RowDefinitions="Auto, *" <VerticalStackLayout>
RowSpacing="20" <Grid RowDefinitions="Auto, *"
Padding="20"> RowSpacing="20"
<Label Text="Les espèces" Padding="20">
FontSize="Large"/> <ListView ItemsSource="{Binding ListeAnimaux}"
<ListView ItemsSource="{Binding ListeAnimal}" Grid.Row="1">
Grid.Row="1"> <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" WidthRequest="80"
WidthRequest="80" HeightRequest="80"
HeightRequest="80" Padding="0"
Padding="0" Margin="10"
Margin="10" BorderColor="{StaticResource Primary}" >
BorderColor="{StaticResource Primary}" > <Image Source="{Binding Image}"/>
<Image Source="{Binding Image}"/> </Frame>
</Frame> <Label Text="{Binding Nom}"
<Label Text="{Binding Nom}" Grid.Column="1"
Grid.Column="1" Grid.Row="0"
Grid.Row="0" FontSize="Medium"/>
FontSize="Medium"/> </Grid>
</Grid> </Border>
</Border> </Grid>
</Grid> </ViewCell>
</ViewCell> </DataTemplate>
</DataTemplate> </ListView.ItemTemplate>
</ListView.ItemTemplate> </ListView>
</ListView> </Grid>
</Grid> <Button Text="+"
FontSize="Large"
Background="{StaticResource Primary}"
VerticalOptions="End"
HorizontalOptions="End"
Margin="20"/>
</VerticalStackLayout>
</ContentPage> </ContentPage>

@ -4,10 +4,10 @@ namespace Views;
public partial class Animaux : ContentPage public partial class Animaux : ContentPage
{ {
public Zootheque Zootheque { get; set; } = new Zootheque();
public Animaux() public Animaux()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = Zootheque; BindingContext = (App.Current as App).Theque.Zootheque;
} }
} }

@ -6,15 +6,17 @@ namespace Views
{ {
public partial class App : Application, INotifyPropertyChanged public partial class App : Application, INotifyPropertyChanged
{ {
public Especetheque Especetheque { get; private set; } = new Especetheque(); public Theque Theque { get; set; } = new Theque();
public Animal AnimalSelectionner;
public Espece EspeceSelectionner; public Espece EspeceSelectionner;
public Race RaceSelectionner; public Race RaceSelectionner;
public App() public App()
{ {
InitializeComponent(); InitializeComponent();
MainPage = new AppShell(); MainPage = new AppShell();
BindingContext = Especetheque;
} }
} }
} }

@ -6,48 +6,45 @@
<ScrollView> <ScrollView>
<VerticalStackLayout> <VerticalStackLayout>
<Image Source="{Binding Image}" <Image Source="{Binding Image}"
MaximumWidthRequest="300" MaximumWidthRequest="300"
Margin="20" Margin="20"
HorizontalOptions="Center"/> HorizontalOptions="Center"/>
<Border Stroke="{StaticResource Secondary}" <Border Stroke="{StaticResource Secondary}"
StrokeThickness="2" StrokeThickness="2"
Margin="20" Margin="20"
Padding="10" Padding="10"
Background="{StaticResource Primary}" Background="{StaticResource Primary}"
VerticalOptions="Start" VerticalOptions="Start"
Grid.Column="1"> Grid.Column="1">
<Grid RowDefinitions="Auto, *, *, *, *" <Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto"
ColumnDefinitions="*, *" ColumnDefinitions="*, *"
RowSpacing="10"> RowSpacing="8">
<Label FontAttributes="Bold" <Label FontAttributes="Bold"
Text="Nom Scientifique"/> Text="Nom scientifique"/>
<Label Grid.Column="1" <Label Grid.Column="1"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding NomScientifique}"/> Text="{Binding NomScientifique}"/>
<Label Grid.Row="1" <Label Grid.Row="1"
FontAttributes="Bold" FontAttributes="Bold"
Text="Espérance de vie"/> Text="Espérance de vie"/>
<Label Grid.Column="2" <Label Grid.Column="2"
Grid.Row="1" Grid.Row="1"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding EsperanceVie}"/> Text="{Binding EsperanceVie}"/>
<Label Grid.Row="2" <Label Grid.Row="2"
FontAttributes="Bold" FontAttributes="Bold"
Text="Poids moyen"/> Text="Poids moyen"/>
<Label Grid.Column="2" <Label Grid.Column="2"
Grid.Row="2" Grid.Row="2"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding PoidsMoyen}"/> Text="{Binding PoidsMoyen}"/>
<Label Grid.Row="3" <Label Grid.Row="3"
FontAttributes="Bold" FontAttributes="Bold"
Text="Taille moyenne"/> Text="Taille moyenne"/>
<Label Grid.Column="2" <Label Grid.Column="2"
Grid.Row="3" Grid.Row="3"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding TailleMoyenne}"/> Text="{Binding TailleMoyenne}"/>
</Grid> </Grid>
</Border> </Border>
@ -55,92 +52,106 @@
Margin="20"> Margin="20">
<Label Text="Comportement" <Label Text="Comportement"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding Comportement}" <Border Stroke="{StaticResource Secondary}"
Padding="10" StrokeThickness="2"
Background="{StaticResource Primary}"/> Padding="10"
Background="{StaticResource Primary}">
<Label Text="{Binding Comportement}"/>
</Border>
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout <VerticalStackLayout
Margin="20"> Margin="20">
<Label Text="Santé" <Label Text="Santé"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding Sante}" <Border Stroke="{StaticResource Secondary}"
Padding="10" StrokeThickness="2"
Background="{StaticResource Primary}"/> Padding="10"
Background="{StaticResource Primary}">
<Label Text="{Binding Sante}"/>
</Border>
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout <VerticalStackLayout
Margin="20"> Margin="20">
<Label Text="Education" <Label Text="Education"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding Education}" <Border Stroke="{StaticResource Secondary}"
Padding="10" StrokeThickness="2"
Background="{StaticResource Primary}"/> Padding="10"
Background="{StaticResource Primary}">
<Label Text="{Binding Education}"/>
</Border>
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout <VerticalStackLayout
Margin="20"> Margin="20">
<Label Text="Entretien" <Label Text="Entretien"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding Entretien}" <Border Stroke="{StaticResource Secondary}"
Padding="10" StrokeThickness="2"
Background="{StaticResource Primary}"/> Padding="10"
Background="{StaticResource Primary}">
<Label Text="{Binding Entretien}"/>
</Border>
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout <VerticalStackLayout Margin="20">
Margin="20">
<Label Text="Coût potentiel" <Label Text="Coût potentiel"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding Cout}" <Border Stroke="{StaticResource Secondary}"
Padding="10" StrokeThickness="2"
Background="{StaticResource Primary}"/> Padding="10"
Background="{StaticResource Primary}">
<Label Text="{Binding Cout}"/>
</Border>
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout <VerticalStackLayout Margin="20">
Margin="20">
<Label Text="Conseils" <Label Text="Conseils"
FontSize="Large"/> FontSize="Large"/>
<Label Text="{Binding Conseil}" <Border Stroke="{StaticResource Secondary}"
Padding="10" StrokeThickness="2"
Background="{StaticResource Primary}"/> Padding="10"
Background="{StaticResource Primary}">
<Label Text="{Binding Conseil}"/>
</Border>
</VerticalStackLayout> </VerticalStackLayout>
<Grid RowDefinitions="Auto, *" <Grid RowDefinitions="Auto, *"
RowSpacing="20" RowSpacing="20"
Padding="20"> Padding="20">
<Label Text="Les races" <Label Text="Les races"
FontSize="Large"/> FontSize="Large"/>
<ListView ItemsSource="{Binding ListeRaces}" <ListView ItemsSource="{Binding ListeRaces}"
Grid.Row="1" Grid.Row="1"
ItemSelected="OnClick"> ItemSelected="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"
WidthRequest="80" HeightRequest="60"
HeightRequest="80" 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>
<Label Text="{Binding Nom}" <VerticalStackLayout Grid.Column="1">
Grid.Column="1" <Label Text="{Binding Nom}"
Grid.Row="0" FontSize="Large"/>
FontSize="Medium"/> <Label Text="{Binding NomScientifique}"
<Label Text="{Binding NomScientifique}" FontSize="12"/>
Grid.Column="1" </VerticalStackLayout>
Grid.Row="1"
FontSize="15"/>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>

@ -14,29 +14,27 @@
<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"
WidthRequest="80" HeightRequest="60"
HeightRequest="80" 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>
<Label Text="{Binding Nom}" <VerticalStackLayout Grid.Column="1">
Grid.Column="1" <Label Text="{Binding Nom}"
Grid.Row="0" FontSize="Large"/>
FontSize="Medium"/> <Label Text="{Binding NomScientifique}"
<Label Text="{Binding NomScientifique}" FontSize="12"/>
Grid.Column="1" </VerticalStackLayout>
Grid.Row="1"
FontSize="15"/>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>

@ -9,12 +9,12 @@ public partial class Especes : ContentPage
public Especes() public Especes()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = (App.Current as App).Especetheque; BindingContext = (App.Current as App).Theque.Especetheque;
} }
public async void OnClick(object sender, SelectedItemChangedEventArgs e) public void OnClick(object sender, SelectedItemChangedEventArgs e)
{ {
(App.Current as App).EspeceSelectionner = e.SelectedItem as Espece; (App.Current as App).EspeceSelectionner = e.SelectedItem as Espece;
await Navigation.PushAsync(new DetailEspece()); Navigation.PushAsync(new DetailEspece());
} }
} }

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Views"
x:Class="Views.MainPage"> x:Class="Views.MainPage">
<Label Text="Bienvenue !"/>
</ContentPage> </ContentPage>

Loading…
Cancel
Save