Added DataContractJSON And update DataContractXML

pull/50/head^2
Titouan LOUVET 2 years ago
parent 947597cdc8
commit b8d5fbca78

@ -7,7 +7,7 @@ namespace Banquale;
public partial class App : Application public partial class App : Application
{ {
public Manager MyManager { get; private set; } = new Manager(new Stub.Stub() /*DataContractPersistance.DataContractPers()*/); public Manager MyManager { get; private set; } = new Manager(new Stub.Stub() /*DataContractPersistance.DataContractPersXML()*/);
@ -15,7 +15,7 @@ public partial class App : Application
{ {
MyManager.DataLoad(); MyManager.DataLoad();
MyManager.Persistence = new DataContractPersistance.DataContractPers(); MyManager.Persistence = new DataContractPersistance.DataContractPersXML();
MyManager.DataSave(); MyManager.DataSave();
InitializeComponent(); InitializeComponent();

@ -71,7 +71,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Stub\" /> <Folder Include="Stub\" />
<Folder Include="DataContractPersistance\" />
<Folder Include="Views\Category\" /> <Folder Include="Views\Category\" />
<Folder Include="Test\" /> <Folder Include="Test\" />
</ItemGroup> </ItemGroup>

@ -1,106 +0,0 @@
using Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Xml;
namespace Banquale.DataContractPersistance
{
public class DataContractPers : IPersistenceManager
{
//public string FilePath { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/datbase.xml";
public string FilePath { get; set; } = FileSystem.Current.AppDataDirectory;
public string FileName { get; set; } = "DataSave.xml";
public (List<Customer>, Consultant) DataLoad()
{
var serializer = new DataContractSerializer(typeof(DataToPersist));
DataToPersist data;
if (File.Exists(Path.Combine(FilePath, FileName))) // Vérifiez si le fichier existe
{
using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName)))
{
data = serializer.ReadObject(s) as DataToPersist;
}
}
else
{
data = new DataToPersist(); // Si le fichier n'existe pas, créez une nouvelle liste
}
// List<Customer> CustomersList;
//Consultant Consultant;
//using (Stream s = File.OpenRead(Path.Combine(FilePath, FileNameCustomer)))
//{
// CustomersList = serializer.ReadObject(s) as List<Customer>;
// }
// using (Stream s = File.OpenRead(Path.Combine(FilePath, FileNameConsultant)))
// {
// Consultant = serializer2.ReadObject(s) as Consultant;
// }
return (data.customer, data.consultant);
}
public void DataSave(List<Customer> cu, Consultant co)
{
var serializer = new DataContractSerializer(typeof(DataToPersist));
if (!Directory.Exists(FilePath))
{
Debug.WriteLine("Directory doesn't exist.");
Directory.CreateDirectory(FilePath);
}
DataToPersist data = new DataToPersist();
data.customer = cu;
data.consultant = co;
var settings = new XmlWriterSettings() { Indent = true };
using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName)))
{
using (XmlWriter w = XmlWriter.Create(tw, settings))
{
serializer.WriteObject(w, data);
}
}
// var serializer = new DataContractSerializer(typeof(List<Customer>));
// var serializer2 = new DataContractSerializer(typeof(Consultant));
// if (!Directory.Exists(FilePath))
//{
// Debug.WriteLine("Directory created");
// Debug.WriteLine(FilePath);
// Directory.CreateDirectory(FilePath);
//}
//var settings = new XmlWriterSettings() { Indent = true };
// using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileNameCustomer)))
//{
// using (XmlWriter writer = XmlWriter.Create(tw, settings))
// {
// serializer.WriteObject(writer, cu);
// }
//}
// using (TextWriter tw2 = File.CreateText(Path.Combine(FilePath, FileNameConsultant)))
// {
// using (XmlWriter writer2 = XmlWriter.Create(tw2, settings))
// {
// serializer.WriteObject(writer2, co);
// }
// }
}
}
}

@ -20,7 +20,7 @@ namespace Banquale.Stub
Customer Customer2 = new Customer("Francis", "Begore", "Halo"); Customer Customer2 = new Customer("Francis", "Begore", "Halo");
Customer Customer3 = new Customer("Michel", "Boudout", "Hola"); Customer Customer3 = new Customer("Michel", "Boudout", "Hola");
Account Account1 = new Account(999, "Tatouille", "FR76 9161 9581 6296 8415 2361 004"); Account Account1 = new Account(999, "Tatouille", "FR7691619581629684152361004");
Account Account2 = new Account(9510, "Despoints", "FR7647858569691441525263003"); Account Account2 = new Account(9510, "Despoints", "FR7647858569691441525263003");
Account Account3 = new Account(3519, "Perotte", "FR7663522541416969585847002"); Account Account3 = new Account(3519, "Perotte", "FR7663522541416969585847002");

@ -69,12 +69,13 @@
Grid.Row="1" Grid.Row="1"
HeightRequest="1"/> HeightRequest="1"/>
<Label Text="{Binding TransactionsList.Id}" <Label Text="{Binding TransactionsList[0].Id}"
x:Name="idLabel" /> x:Name="idLabel" />
<ListView ItemsSource="{Binding TransactionsList}" <ListView ItemsSource="{Binding TransactionsList}"
Grid.Row="2" Grid.Row="2"
SelectionMode="None"> SelectionMode="None">
<!--ItemSelected="Transactions_Clicked"-->
<ListView.ItemTemplate> <ListView.ItemTemplate>

@ -33,7 +33,7 @@ public partial class BalancePage : ContentPage
if (string.IsNullOrWhiteSpace(idLabel.Text)) if (string.IsNullOrWhiteSpace(idLabel.Text))
{ {
await DisplayAlert("Erreur", "aucune transaction présente", "OK"); await DisplayAlert("Erreur", "Aucune transaction présente", "OK");
return; return;
} }

@ -10,17 +10,17 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
[DataContract] [DataContract]
public class Account : INotifyPropertyChanged, IEquatable<Account> public class Account : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged(string propertyName) void OnPropertyChanged(string propertyName)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
[DataMember] [DataMember(Order = 3)]
public Double Balance public double Balance
{ {
get => balance; get => balance;
set set
@ -32,10 +32,10 @@ namespace Model
} }
} }
[DataMember] [DataMember]
private Double balance; private double balance;
[DataMember] [DataMember(Order = 1)]
public string Name public string Name
{ {
get => name; get => name;
@ -51,7 +51,7 @@ namespace Model
private string name; private string name;
[DataMember] [DataMember(Order = 2)]
public string IBAN public string IBAN
{ {
get => iban; get => iban;
@ -66,7 +66,7 @@ namespace Model
[DataMember] [DataMember]
private string iban; private string iban;
[DataMember] [DataMember(Order = 4)]
public string IBANHide public string IBANHide
{ {
get => ibanHide; get => ibanHide;
@ -81,10 +81,10 @@ namespace Model
[DataMember] [DataMember]
private string ibanHide; private string ibanHide;
[DataMember] [DataMember(Order = 5)]
public List<Transactions> TransactionsList { get; set; } = new List<Transactions>(); public List<Transactions> TransactionsList { get; set; } = new List<Transactions>();
public void DoTransactions(Account involvedAccount, Double sum, bool type, int nb) public void DoTransactions(Account involvedAccount, double sum, bool type, int nb)
{ {
if (type) // si le type est True => c'est un débit, on doit donc ajouter la transaction pour l'autre compte if (type) // si le type est True => c'est un débit, on doit donc ajouter la transaction pour l'autre compte
{ {
@ -101,7 +101,7 @@ namespace Model
} }
public Account(Double balance, string name, string iban) public Account(double balance, string name, string iban)
{ {
Balance = balance; Balance = balance;
Name = name; Name = name;
@ -155,15 +155,6 @@ namespace Model
return new string(res); return new string(res);
} }
public bool Equals(Account other)
{
if(other == null) return false;
else return other.IBAN.Equals(IBAN);
}
public override int GetHashCode()
{
return IBAN.GetHashCode();
}
} }
} }

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
[DataContract] [DataContract]
public class Customer : Person public class Customer : Person, IEquatable<Customer>//, IComparable<Customer>
{ {
[DataMember] [DataMember]
public List<Account> AccountsList { get; private set; } = new List<Account>(); public List<Account> AccountsList { get; private set; } = new List<Account>();
@ -21,8 +21,16 @@ namespace Model
{} {}
public bool Equals(Customer? other)
{
if (other == null) return false;
else return other.Id.Equals(Id);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
} }
} }

@ -8,9 +8,9 @@ namespace Model
[DataContract] [DataContract]
public class Manager : INotifyPropertyChanged public class Manager : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = null) void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
[DataMember] [DataMember]

@ -11,10 +11,10 @@ namespace Model
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
[DataMember] [DataMember(Order = 1)]
public int Id { get; private set; } public int Id { get; private set; }
[DataMember] [DataMember(Order = 2)]
public bool Type public bool Type
{ {
get => type; get => type;
@ -30,8 +30,8 @@ namespace Model
private bool type; private bool type;
[DataMember] [DataMember(Order = 3)]
public Double Sum public double Sum
{ {
get => sum; get => sum;
set set
@ -43,9 +43,9 @@ namespace Model
} }
} }
[DataMember] [DataMember]
private Double sum; private double sum;
[DataMember] [DataMember(Order = 4)]
public Account InvolvedAccounts public Account InvolvedAccounts
{ {
get => involvedAccounts; get => involvedAccounts;
@ -60,7 +60,7 @@ namespace Model
[DataMember] [DataMember]
private Account involvedAccounts; private Account involvedAccounts;
[DataMember] [DataMember(Order = 5)]
public string Category public string Category
{ {
get => category; get => category;
@ -73,9 +73,9 @@ namespace Model
} }
} }
[DataMember] [DataMember]
private string category; private string? category;
[DataMember] [DataMember(Order = 6)]
public DateTime Date public DateTime Date
{ {
get => date; get => date;
@ -90,7 +90,7 @@ namespace Model
[DataMember] [DataMember]
private DateTime date; private DateTime date;
public Transactions(bool type, Double sum, Account involvedAccounts/*, string category*/, int id, DateTime date) public Transactions(bool type, double sum, Account involvedAccounts/*, string category*/, int id, DateTime date)
{ {
Type = type; Type = type;
Sum = sum; Sum = sum;
@ -100,7 +100,11 @@ namespace Model
Date = date; Date = date;
} }
public void ChangeCategory(string newCateg)
{
Category = newCateg;
}
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
} }
} }

Loading…
Cancel
Save