Transformation string to DateTime

pull/18/head
Leana BESSON 2 years ago
parent d854da1bdd
commit ae2fa75b01

@ -44,7 +44,7 @@ namespace Model
private bool nomIsValid; private bool nomIsValid;
[DataMember(Name = "naissance")] [DataMember(Name = "naissance")]
public string DateNaissance public DateTime DateNaissance
{ {
get => dateNaissance; get => dateNaissance;
set set
@ -55,7 +55,7 @@ namespace Model
OnPropertyChanged(nameof(DateNaissance)); OnPropertyChanged(nameof(DateNaissance));
} }
} }
private string dateNaissance; private DateTime dateNaissance;
[DataMember(Name = "sexe")] [DataMember(Name = "sexe")]
public string Sexe public string Sexe
@ -71,7 +71,7 @@ namespace Model
private string sexe; private string sexe;
[DataMember(Name = "adoption")] [DataMember(Name = "adoption")]
public string DateAdoption public DateTime DateAdoption
{ {
get => dateAdoption; get => dateAdoption;
set set
@ -82,7 +82,7 @@ namespace Model
OnPropertyChanged(nameof(DateAdoption)); OnPropertyChanged(nameof(DateAdoption));
} }
} }
private string dateAdoption; private DateTime dateAdoption;
[DataMember(Name = "taille")] [DataMember(Name = "taille")]
public float? Taille public float? Taille
@ -238,12 +238,10 @@ namespace Model
} }
private string image; private string image;
public Animal(string nom = "", string dateNaissance = "Inconnue", string sexe = "Inconnu", string dateAdpotion = "Inconnue", float? taille = null, float? poids = null, string alimentation = "Inconnue") public Animal(string nom = "", string sexe = "Inconnu", float? taille = null, float? poids = null, string alimentation = "Inconnue")
{ {
Nom = nom; Nom = nom;
DateNaissance = dateNaissance;
Sexe = sexe; Sexe = sexe;
DateAdoption = dateAdpotion;
Taille = taille; Taille = taille;
Poids = poids; Poids = poids;
Alimentation = alimentation; Alimentation = alimentation;

@ -12,11 +12,11 @@ namespace Persistance
{ {
public class DataSerializer public class DataSerializer
{ {
public void Serializer() public static void Serializer(String path)
{ {
Theque theque = new Theque(); Theque theque = new Theque();
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory())); Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
string xmlFile = "theque.xml"; string xmlFile = "theque.xml";
var serializer = new DataContractSerializer(typeof(Theque)); var serializer = new DataContractSerializer(typeof(Theque));
@ -27,20 +27,25 @@ namespace Persistance
} }
} }
public Theque Deserializer() public static Theque Deserializer(String path)
{ {
string path = FileSystem. Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory()));
Directory.SetCurrentDirectory();
string xmlFile = "theque.xml"; string xmlFile = "theque.xml";
var serializer = new DataContractSerializer(typeof(Theque)); var serializer = new DataContractSerializer(typeof(Theque));
Theque theque = new Theque(); Theque theque = new Theque();
if(File.Exists(xmlFile))
{
using (Stream s = File.OpenRead(xmlFile)) using (Stream s = File.OpenRead(xmlFile))
{ {
theque = serializer.ReadObject(s) as Theque; theque = serializer.ReadObject(s) as Theque;
} }
}
else
{
theque = Stub.LoadTheque();
}
return theque; return theque;
} }
} }

@ -1,4 +1,5 @@
using Model; using Model;
using Persistance;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -6,8 +7,9 @@ namespace Views
{ {
public partial class App : Application, INotifyPropertyChanged public partial class App : Application, INotifyPropertyChanged
{ {
string path = FileSystem.Current.AppDataDirectory; public string SerializationPath = FileSystem.Current.AppDataDirectory;
public Theque Theque { get; set; } = Stub.LoadTheque(); static private string serializationPath = FileSystem.Current.AppDataDirectory;
public Theque Theque { get; set; } = DataSerializer.Deserializer(serializationPath);
public Animal AnimalSelectionner public Animal AnimalSelectionner
{ {
get => animalSelectionner; get => animalSelectionner;
@ -17,8 +19,9 @@ namespace Views
OnPropertyChanged(nameof(AnimalSelectionner)); OnPropertyChanged(nameof(AnimalSelectionner));
} }
} }
public New_DetailAnimal PageDeSaisie { get; set; }
private Animal animalSelectionner; private Animal animalSelectionner;
public New_DetailAnimal PageDeSaisie { get; set; }
public Espece EspeceSelectionner { get; set; } public Espece EspeceSelectionner { get; set; }
public Race RaceSelectionner { get; set; } public Race RaceSelectionner { get; set; }

@ -54,9 +54,10 @@
RowSpacing="8"> RowSpacing="8">
<Label FontAttributes="Bold" <Label FontAttributes="Bold"
Text="Date de naissance"/> Text="Date de naissance"/>
<Entry Grid.Column="1" <DatePicker Grid.Column="1"
MinimumDate="01/01/2000"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding DateNaissance}"/> Date="{Binding DateNaissance}"/>
<Label Grid.Row="1" <Label Grid.Row="1"
FontAttributes="Bold" FontAttributes="Bold"
Text="Sexe"/> Text="Sexe"/>
@ -67,10 +68,11 @@
<Label Grid.Row="2" <Label Grid.Row="2"
FontAttributes="Bold" FontAttributes="Bold"
Text="Date d'adoption"/> Text="Date d'adoption"/>
<Entry Grid.Column="1" <DatePicker Grid.Column="1"
Grid.Row="2" Grid.Row="2"
MinimumDate="01/01/2000"
HorizontalOptions="End" HorizontalOptions="End"
Text="{Binding DateAdoption}"/> Date="{Binding DateAdoption}"/>
<Label Grid.Row="3" <Label Grid.Row="3"
FontAttributes="Bold" FontAttributes="Bold"
Text="Taille"/> Text="Taille"/>

@ -1,4 +1,5 @@
using Model; using Model;
using Persistance;
using System.Dynamic; using System.Dynamic;
namespace Views; namespace Views;
@ -31,6 +32,7 @@ public partial class New_DetailAnimal : ContentPage
if ((App.Current as App).AnimalSelectionner.NomIsValid == true) if ((App.Current as App).AnimalSelectionner.NomIsValid == true)
{ {
await Shell.Current.GoToAsync("//Animaux"); await Shell.Current.GoToAsync("//Animaux");
DataSerializer.Serializer((App.Current as App).SerializationPath);
} }
} }

@ -55,6 +55,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Persistance\Persistance.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save