From d854da1bddb820d83aed1b4cff6523b4d84858f7 Mon Sep 17 00:00:00 2001 From: Leana BESSON Date: Fri, 2 Jun 2023 12:06:39 +0200 Subject: [PATCH] =?UTF-8?q?Reglage=20probl=C3=A8me=20route=20New=5FDetailA?= =?UTF-8?q?nimal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Console/Program.cs | 1 + ...ontractSerializer.cs => DataSerializer.cs} | 21 ++++++++++++---- Sources/Views/Animaux.xaml.cs | 6 +++-- Sources/Views/App.xaml.cs | 13 +++++++++- Sources/Views/AppShell.xaml | 4 ++++ Sources/Views/AppShell.xaml.cs | 2 +- Sources/Views/New_DetailAnimal.xaml | 2 +- Sources/Views/New_DetailAnimal.xaml.cs | 24 +++++++++++++------ 8 files changed, 57 insertions(+), 16 deletions(-) rename Sources/Persistance/{DataContractSerializer.cs => DataSerializer.cs} (55%) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 90dde41..738fd3a 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -13,6 +13,7 @@ class Program static private Theque Theque { get; set; } = Stub.LoadTheque(); static void Main(string[] args) { + MenusPrincipal(); } diff --git a/Sources/Persistance/DataContractSerializer.cs b/Sources/Persistance/DataSerializer.cs similarity index 55% rename from Sources/Persistance/DataContractSerializer.cs rename to Sources/Persistance/DataSerializer.cs index 2faf35e..cd3216f 100644 --- a/Sources/Persistance/DataContractSerializer.cs +++ b/Sources/Persistance/DataSerializer.cs @@ -5,12 +5,14 @@ using System.Runtime.Serialization.Json; using System.Xml; using static System.Console; using Model; +using Microsoft.VisualBasic; +using System.Data; namespace Persistance { - public class DataContractSerializer + public class DataSerializer { - public Theque DataContractSerializer() + public void Serializer() { Theque theque = new Theque(); @@ -23,12 +25,23 @@ namespace Persistance { serializer.WriteObject(s, theque); } + } + + public Theque Deserializer() + { + string path = FileSystem. + Directory.SetCurrentDirectory(); + string xmlFile = "theque.xml"; - Theque theque2; + var serializer = new DataContractSerializer(typeof(Theque)); + + Theque theque = new Theque(); using (Stream s = File.OpenRead(xmlFile)) { - theque2 = serializer.ReadObject(s) as Theque; + theque = serializer.ReadObject(s) as Theque; } + + return theque; } } } \ No newline at end of file diff --git a/Sources/Views/Animaux.xaml.cs b/Sources/Views/Animaux.xaml.cs index 54a8d68..187c2ec 100644 --- a/Sources/Views/Animaux.xaml.cs +++ b/Sources/Views/Animaux.xaml.cs @@ -19,8 +19,10 @@ public partial class Animaux : ContentPage } public async void Button_OnClick(object sender, EventArgs e) - { - await Shell.Current.GoToAsync($"New_DetailAnimal"); + { + (App.Current as App).AnimalSelectionner = (App.Current as App).Theque.AjouterAnimal(); + (App.Current as App).PageDeSaisie?.InitBinding(); + await Shell.Current.GoToAsync("//New_DetailAnimal"); } } diff --git a/Sources/Views/App.xaml.cs b/Sources/Views/App.xaml.cs index 8eb3e18..abc4431 100644 --- a/Sources/Views/App.xaml.cs +++ b/Sources/Views/App.xaml.cs @@ -6,8 +6,19 @@ namespace Views { public partial class App : Application, INotifyPropertyChanged { + string path = FileSystem.Current.AppDataDirectory; public Theque Theque { get; set; } = Stub.LoadTheque(); - public Animal AnimalSelectionner { get; set; } + public Animal AnimalSelectionner + { + get => animalSelectionner; + set + { + animalSelectionner = value; + OnPropertyChanged(nameof(AnimalSelectionner)); + } + } + public New_DetailAnimal PageDeSaisie { get; set; } + private Animal animalSelectionner; public Espece EspeceSelectionner { get; set; } public Race RaceSelectionner { get; set; } diff --git a/Sources/Views/AppShell.xaml b/Sources/Views/AppShell.xaml index a5c41d0..6d16e09 100644 --- a/Sources/Views/AppShell.xaml +++ b/Sources/Views/AppShell.xaml @@ -20,4 +20,8 @@ Title="Vos animaux" ContentTemplate="{DataTemplate local:Animaux}" Route="Animaux"/> + + diff --git a/Sources/Views/AppShell.xaml.cs b/Sources/Views/AppShell.xaml.cs index 9f9c90a..66e6bc6 100644 --- a/Sources/Views/AppShell.xaml.cs +++ b/Sources/Views/AppShell.xaml.cs @@ -5,7 +5,7 @@ public AppShell() { InitializeComponent(); - Routing.RegisterRoute("New_DetailAnimal", typeof(New_DetailAnimal)); + //Routing.RegisterRoute("New_DetailAnimal", typeof(New_DetailAnimal)); } } } \ No newline at end of file diff --git a/Sources/Views/New_DetailAnimal.xaml b/Sources/Views/New_DetailAnimal.xaml index 88d625d..b15af7b 100644 --- a/Sources/Views/New_DetailAnimal.xaml +++ b/Sources/Views/New_DetailAnimal.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Views.New_DetailAnimal" Title="{Binding Nom}" x:Name="page_creation"> - + (App.Current as App).AnimalSelectionner; + public New_DetailAnimal() { InitializeComponent(); - (App.Current as App).AnimalSelectionner = (App.Current as App).Theque.AjouterAnimal(); - BindingContext = (App.Current as App).AnimalSelectionner; - Picker_especes.BindingContext = (App.Current as App).Theque; - OnBackButtonPressed(); - } + (App.Current as App).PageDeSaisie = this; + InitBinding(); + } + + public void InitBinding() + { + BindingContext = AnimalSelectione; + Picker_especes.BindingContext = (App.Current as App).Theque; + } public async void Button_OnClick(object sender, EventArgs e) { @@ -21,7 +28,10 @@ public partial class New_DetailAnimal : ContentPage public async void Validate_OnClick(object sender, EventArgs e) { - await Shell.Current.GoToAsync("//Animaux"); + if ((App.Current as App).AnimalSelectionner.NomIsValid == true) + { + await Shell.Current.GoToAsync("//Animaux"); + } } private void EspeceClic(object sender, EventArgs e)