remake datacontractpers with consultant but a error occured

pull/46/head
Antoine PEREDERII 2 years ago
parent 69a2945a16
commit 0f90e0c938

@ -16,11 +16,11 @@ public partial class App : Application
MyManager.DataLoad();
MyManager.Persistence = new DataContractPersistance.DataContractPers();
//MyManager.DataSave();
InitializeComponent();
InitializeComponent();
MainPage = new AppShell();
//MyManager.DataSave();
}

@ -4,7 +4,6 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Banquale.Views"
xmlns:balance="clr-namespace:Banquale.Views.Balance"
xmlns:transfer="clr-namespace:Banquale.Views.Transfer"
Shell.FlyoutBehavior="Disabled">
@ -16,7 +15,7 @@
<ShellContent
Title="Solde"
ContentTemplate="{DataTemplate balance:BalancePage}"
ContentTemplate="{DataTemplate views:BalancePage}"
Route="balance"
Icon="home.png"/>

@ -49,7 +49,6 @@
<None Remove="Resources\Images\helpIcon.svg" />
<None Remove="Stub\" />
<None Remove="DataContractPersistance\" />
<None Remove="Views\Balance\" />
<None Remove="Views\Category\" />
<None Remove="Test\" />
</ItemGroup>
@ -64,7 +63,6 @@
<Folder Include="Persistances\" />
<Folder Include="Stub\" />
<Folder Include="DataContractPersistance\" />
<Folder Include="Views\Balance\" />
<Folder Include="Views\Category\" />
<Folder Include="Test\" />
</ItemGroup>

@ -13,40 +13,93 @@ namespace Banquale.DataContractPersistance
//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; } = "CustomerList.xml";
public string FileName { get; set; } = "DataSave.xml";
public List<Customer> DataLoad()
public (List<Customer>, Consultant) DataLoad()
{
var serializer = new DataContractSerializer(typeof(List<Customer>));
var serializer = new DataContractSerializer(typeof(DataToPersist));
List<Customer> CustomersList;
DataToPersist data;
using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName)))
{
CustomersList = serializer.ReadObject(s) as List<Customer>;
}
return CustomersList;
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> c)
public void DataSave(List<Customer> cu, Consultant co)
{
var serializer = new DataContractSerializer(typeof(List<Customer>));
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, FileName)))
{
using (XmlWriter writer = XmlWriter.Create(tw, settings))
{
serializer.WriteObject(writer, c);
}
}
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);
// }
// }
}
}
}

@ -5,8 +5,8 @@ namespace Banquale.DataContractPersistance
{
public class DataToPersist
{
public List<Customer> customer { get; set; } = new List<Customer>();
public List<Transactions> transactions { get; set; } = new List<Transactions>();
public List<Customer> customer { get; set; } = new List<Customer>();
public Consultant consultant { get; set; } = null;
}
}

@ -103,13 +103,14 @@ namespace Banquale.Model
// Console.WriteLine("Help button pressed !");
//}
internal static void AskForHelp(Entry request, Entry subject, Editor message)
internal static Message AskForHelp(Entry subject, Editor description)
{
Debug.WriteLine(request.Text);
Debug.WriteLine(subject);
Debug.WriteLine(message);
Debug.WriteLine(subject.Text);
Debug.WriteLine(description.Text);
Debug.WriteLine("Help button pressed !");
//throw new NotImplementedException();
Message message = new Message(subject.Text, description.Text);
return message;
}
internal static void DoRequest(Entry name, Entry iBAN, Entry sum)

@ -8,8 +8,8 @@ namespace Banquale.Model
{
public interface IPersistenceManager
{
public List<Customer> DataLoad();
public (List<Customer>, Consultant) DataLoad();
void DataSave(List<Customer> c /* , List<Transactions> t, List<Account> c2*/);
void DataSave(List<Customer> cu, Consultant co);
}
}

@ -7,11 +7,9 @@ namespace Banquale.Model
public class Manager
{
[DataMember]
public List<Customer> CustomersList { get; private set; }
public List<Customer> CustomersList { get; private set; } // devient un set
public List<Transactions> TransactionsList { get; private set; }
public List<Account> AccountList { get; private set; }
public Consultant Consultant { get; private set; } // 1 SEUL consultant
public Customer SelectedCustomer
{
@ -37,18 +35,15 @@ namespace Banquale.Model
public IPersistenceManager Persistence { get; set; }
public Manager(IPersistenceManager persistence) {
TransactionsList = new List<Transactions>();
public Manager(IPersistenceManager persistence)
{
CustomersList = new List<Customer>();
Persistence = persistence;
}
public Manager()
{
CustomersList = new List<Customer>();
TransactionsList = new List<Transactions>();
}
public bool AddCustomer(Customer MyCustomer)
@ -63,24 +58,21 @@ namespace Banquale.Model
public void DataSave()
{
Persistence.DataSave(CustomersList);
Persistence.DataSave(CustomersList, Consultant);
}
public void DataLoad()
{
var data = Persistence.DataLoad();
CustomersList.AddRange(data);
CustomersList.AddRange(data.Item1);
foreach (var j in data)
foreach (var j in data.Item1)
{
CustomersList.Add(j);
}
/*
foreach (var i in data.Item2)
{
TransactionsList.Add(i);
}*/
Consultant = data.Item2;
}
}

@ -24,7 +24,15 @@ namespace Banquale.Model
{
Name = name;
FirstName = firstName;
Id = 0;
Id = 1;
Password = password;
}
public Person(string name, string firstName, uint id, string password)
{
Name = name;
FirstName = firstName;
Id = id;
Password = password;
}

@ -7,8 +7,10 @@ namespace Banquale.Stub
public class Stub : IPersistenceManager
{
public List<Customer> /*List<Transactions>, List<Account>*/ DataLoad()
public (List<Customer>, Consultant) DataLoad()
{
Consultant Consultant = new Consultant("Consultant", "Consultant", 0, "Consultant");
Customer Customer1 = new Customer("Jacques", "Morice", "J'aimeLesFrites");
Customer Customer2 = new Customer("Francis", "Begore", "J'aimeLes");
Customer Customer3 = new Customer("Michel", "Boudout", "MonMdP");
@ -37,44 +39,8 @@ namespace Banquale.Stub
Account1.TransactionsList.Add(Transactions2);
Account1.TransactionsList.Add(Transactions3);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions1);
//Account1.TransactionsList.Add(Transactions12);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions2);
//Account1.TransactionsList.Add(Transactions3);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions1);
//Account1.TransactionsList.Add(Transactions12);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions2);
//Account1.TransactionsList.Add(Transactions3);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
//Account1.TransactionsList.Add(Transactions13);
Account2.TransactionsList.Add(Transactions2);
//AccountsList.Add(Account1);
//AccountsList.Add(Account2);
//AccountsList.Add(Account3);
Customer1.AccountsList.Add(Account1);
Customer1.AccountsList.Add(Account2);
@ -83,10 +49,10 @@ namespace Banquale.Stub
CustomersList.Add(Customer1);
CustomersList.Add(Customer2);
CustomersList.Add(Customer3);
return CustomersList; // TransactionsList /*, AccountsList*/);
return (CustomersList, Consultant);
}
public void DataSave(List<Customer> c)
public void DataSave(List<Customer> c, Consultant consultant)
{
throw new NotImplementedException();
}

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Banquale.Views.Balance.BalanceView">
<ListView ItemsSource="{Binding CustomersList[0].AccountsList[0].TransactionsList}"
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
ColumnDefinitions="40, 3*, *"
Margin="20, 5, 20, 5"
HorizontalOptions="Fill">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Tapped="Transaction_Clicked"
NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
<Image Source="dotnet_bot.png"
Grid.Column="0"
MaximumHeightRequest="30"/>
<Label
Text="{Binding Date, StringFormat='{0:f}'}"
Grid.Column="1"
VerticalOptions="Center"
Margin="10, 0, 0, 0"/>
<Label
Text="{Binding Sum, StringFormat='{0} €'}"
Grid.Column="2"
VerticalOptions="Center"
HorizontalOptions="End"
Margin="0, 0, 20, 0"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentView>

@ -1,20 +0,0 @@
using Banquale.Model;
using Banquale.Views.Category;
namespace Banquale.Views.Balance;
public partial class BalanceView : ContentView
{
public Manager Mgr => (App.Current as App).MyManager;
public BalanceView()
{
InitializeComponent();
BindingContext = Mgr;
}
public async void Transaction_Clicked(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e)
{
await Shell.Current.Navigation.PushAsync(new TransactionsPage());
}
}

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Banquale.Views.Balance"
xmlns:local="clr-namespace:Banquale.Views"
xmlns:model="clr-namespace:Banquale.Model"
x:Class="Banquale.Views.Balance.BalancePage"
x:Class="Banquale.Views.BalancePage"
Title="BalancePage"
Shell.NavBarIsVisible="False">
@ -84,7 +84,7 @@
Grid.Column="0"
MaximumHeightRequest="30"/>
<Label
Text="{Binding Date, StringFormat='{0:f}'}"
Text="{Binding Date, StringFormat='{0:ddd dd MMM yyyy}'}"
Grid.Column="1"
VerticalOptions="Center"
Margin="10, 0, 0, 0"/>

@ -1,6 +1,6 @@
using Banquale.Model;
namespace Banquale.Views.Balance;
namespace Banquale.Views;
public partial class BalancePage : ContentPage

@ -1,4 +1,4 @@
using Banquale.Views.Balance;
using Banquale.Views;
namespace Banquale.Views;
public partial class ConsultantIdPage : ContentPage

@ -6,18 +6,6 @@
<VerticalStackLayout VerticalOptions="Center">
<Frame CornerRadius="10"
HeightRequest="40"
WidthRequest="300"
Padding="3">
<Entry Placeholder="Quel est votre demande ?"
HorizontalOptions="Center"
WidthRequest="280"
x:Name="Request"/>
</Frame>
<Frame CornerRadius="10"
HeightRequest="40"
WidthRequest="300"

@ -3,6 +3,7 @@ namespace Banquale.Views;
public partial class HelpPage : ContentPage
{
public Manager Mgr => (App.Current as App).MyManager;
public HelpPage()
{
InitializeComponent();
@ -10,7 +11,8 @@ public partial class HelpPage : ContentPage
public async void Send_Clicked(Object sender, EventArgs e)
{
Account.AskForHelp(Request, Subject, Message);
Message message = Account.AskForHelp(Subject, Message);
Mgr.Consultant.MessagesList.Add(message);
await Shell.Current.GoToAsync("//balance");
}

@ -7,13 +7,12 @@
Shell.NavBarIsVisible="False">
<StackLayout
VerticalOptions="Center"
HorizontalOptions="Center">
<VerticalStackLayout
VerticalOptions="Center">
<ListView ItemsSource="{Binding AccountsList}"
SelectionMode="None" Grid.Row="1">
<ListView
ItemsSource="{Binding AccountsList}"
SelectionMode="None">
<ListView.ItemTemplate>
@ -21,15 +20,15 @@
<ViewCell>
<VerticalStackLayout>
<VerticalStackLayout
HeightRequest="84">
<Button
Text="{Binding Name, StringFormat=' Compte Personnel &#10; {0}'}"
Clicked="Transfer_Clicked"
FontSize="Large"
Margin="20"/>
<Button Text="{Binding Name, StringFormat=' Compte Personnel \n {0}'}"
Clicked="Transfer_Clicked"
MinimumHeightRequest="165"
MinimumWidthRequest="100"
FontSize="Large"
Margin="0, 10, 0, 10"
VerticalOptions="Center"/>
</VerticalStackLayout>
</ViewCell>
@ -45,10 +44,10 @@
HorizontalOptions="Fill"
MinimumHeightRequest="100"
MinimumWidthRequest="375"
Margin="0,65,0,0"
Margin="10"
FontSize="Large"
Clicked="DisconnectionClicked"/>
</StackLayout>
</VerticalStackLayout>
</ContentPage>

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Banquale.Views.SwitchAccountView">
<VerticalStackLayout>
<Button Text=" Compte Personnel &#x0a; Mme Tatouille "
Clicked="Transfer_Clicked"
MinimumHeightRequest="65"
FontSize="Large"
Margin="0, 10, 0, 10"/>
<!-- &#x0a; sert à faire un retour à la ligne-->
</VerticalStackLayout>
</ContentView>

@ -1,15 +0,0 @@
namespace Banquale.Views;
public partial class SwitchAccountView : ContentView
{
public SwitchAccountView()
{
InitializeComponent();
}
public async void Transfer_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//balance");
}
}
Loading…
Cancel
Save