Merge branch 'xaml-C#/data-binding' of codefirst.iut.uca.fr:antoine.perederii/Banquale into xaml-C#/data-binding

pull/46/head^2
Titouan LOUVET 2 years ago
commit dd89de6a97

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

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

@ -49,7 +49,6 @@
<None Remove="Resources\Images\helpIcon.svg" /> <None Remove="Resources\Images\helpIcon.svg" />
<None Remove="Stub\" /> <None Remove="Stub\" />
<None Remove="DataContractPersistance\" /> <None Remove="DataContractPersistance\" />
<None Remove="Views\Balance\" />
<None Remove="Views\Category\" /> <None Remove="Views\Category\" />
<None Remove="Test\" /> <None Remove="Test\" />
</ItemGroup> </ItemGroup>
@ -64,7 +63,6 @@
<Folder Include="Persistances\" /> <Folder Include="Persistances\" />
<Folder Include="Stub\" /> <Folder Include="Stub\" />
<Folder Include="DataContractPersistance\" /> <Folder Include="DataContractPersistance\" />
<Folder Include="Views\Balance\" />
<Folder Include="Views\Category\" /> <Folder Include="Views\Category\" />
<Folder Include="Test\" /> <Folder Include="Test\" />
</ItemGroup> </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; } = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/datbase.xml";
public string FilePath { get; set; } = FileSystem.Current.AppDataDirectory; 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))) if (File.Exists(Path.Combine(FilePath, FileName))) // Vérifiez si le fichier existe
{ {
CustomersList = serializer.ReadObject(s) as List<Customer>; using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName)))
} {
return CustomersList; 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>)); var serializer = new DataContractSerializer(typeof(DataToPersist));
if(!Directory.Exists(FilePath)) if (!Directory.Exists(FilePath))
{ {
Debug.WriteLine("Directory created"); Debug.WriteLine("Directory doesn't exist.");
Debug.WriteLine(FilePath); Directory.CreateDirectory(FilePath);
Directory.CreateDirectory(FilePath); }
}
var settings = new XmlWriterSettings() { Indent = true }; DataToPersist data = new DataToPersist();
using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName))) data.customer = cu;
{ data.consultant = co;
using (XmlWriter writer = XmlWriter.Create(tw, settings))
{ var settings = new XmlWriterSettings() { Indent = true };
serializer.WriteObject(writer, c); 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 class DataToPersist
{ {
public List<Customer> customer { get; set; } = new List<Customer>(); public List<Customer> customer { get; set; } = new List<Customer>();
public List<Transactions> transactions { get; set; } = new List<Transactions>(); public Consultant consultant { get; set; } = null;
} }
} }

@ -116,13 +116,14 @@ namespace Banquale.Model
// Console.WriteLine("Help button pressed !"); // 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.Text);
Debug.WriteLine(subject); Debug.WriteLine(description.Text);
Debug.WriteLine(message);
Debug.WriteLine("Help button pressed !"); Debug.WriteLine("Help button pressed !");
//throw new NotImplementedException(); //throw new NotImplementedException();
Message message = new Message(subject.Text, description.Text);
return message;
} }
internal static void DoRequest(Entry name, Entry iBAN, Entry sum) internal static void DoRequest(Entry name, Entry iBAN, Entry sum)

@ -0,0 +1,14 @@
using System;
namespace Banquale.Model
{
public class Consultant : Person
{
public List<Message> MessagesList = new List<Message>();
public Consultant(string name, string firstName, uint id, string password) : base(name, firstName, id, password)
{
}
}
}

@ -8,8 +8,8 @@ namespace Banquale.Model
{ {
public interface IPersistenceManager 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 public class Manager
{ {
[DataMember] [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 Consultant Consultant { get; private set; } // 1 SEUL consultant
public List<Account> AccountList { get; private set; }
public Customer SelectedCustomer public Customer SelectedCustomer
{ {
@ -48,18 +46,15 @@ namespace Banquale.Model
public IPersistenceManager Persistence { get; set; } public IPersistenceManager Persistence { get; set; }
public Manager(IPersistenceManager persistence) { public Manager(IPersistenceManager persistence)
{
TransactionsList = new List<Transactions>();
CustomersList = new List<Customer>(); CustomersList = new List<Customer>();
Persistence = persistence; Persistence = persistence;
} }
public Manager() public Manager()
{ {
CustomersList = new List<Customer>(); CustomersList = new List<Customer>();
TransactionsList = new List<Transactions>();
} }
public bool AddCustomer(Customer MyCustomer) public bool AddCustomer(Customer MyCustomer)
@ -74,24 +69,21 @@ namespace Banquale.Model
public void DataSave() public void DataSave()
{ {
Persistence.DataSave(CustomersList); Persistence.DataSave(CustomersList, Consultant);
} }
public void DataLoad() public void DataLoad()
{ {
var data = Persistence.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); CustomersList.Add(j);
} }
/*
foreach (var i in data.Item2) Consultant = data.Item2;
{
TransactionsList.Add(i);
}*/
} }
} }

@ -0,0 +1,19 @@
using System;
namespace Banquale.Model
{
public class Message
{
public string Subject { get; private set; }
public string Description { get; private set; }
public Message(string subject, string description)
{
Subject = subject;
Description = description;
}
}
}

@ -24,7 +24,15 @@ namespace Banquale.Model
{ {
Name = name; Name = name;
FirstName = firstName; 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; Password = password;
} }

@ -7,8 +7,10 @@ namespace Banquale.Stub
public class Stub : IPersistenceManager 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 Customer1 = new Customer("Jacques", "Morice", "J'aimeLesFrites");
Customer Customer2 = new Customer("Francis", "Begore", "J'aimeLes"); Customer Customer2 = new Customer("Francis", "Begore", "J'aimeLes");
Customer Customer3 = new Customer("Michel", "Boudout", "MonMdP"); Customer Customer3 = new Customer("Michel", "Boudout", "MonMdP");
@ -37,44 +39,8 @@ namespace Banquale.Stub
Account1.TransactionsList.Add(Transactions2); Account1.TransactionsList.Add(Transactions2);
Account1.TransactionsList.Add(Transactions3); 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); Account2.TransactionsList.Add(Transactions2);
//AccountsList.Add(Account1);
//AccountsList.Add(Account2);
//AccountsList.Add(Account3);
Customer1.AccountsList.Add(Account1); Customer1.AccountsList.Add(Account1);
Customer1.AccountsList.Add(Account2); Customer1.AccountsList.Add(Account2);
@ -83,10 +49,10 @@ namespace Banquale.Stub
CustomersList.Add(Customer1); CustomersList.Add(Customer1);
CustomersList.Add(Customer2); CustomersList.Add(Customer2);
CustomersList.Add(Customer3); 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(); 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" ?> <?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:Banquale.Views.Balance" xmlns:local="clr-namespace:Banquale.Views"
xmlns:model="clr-namespace:Banquale.Model" xmlns:model="clr-namespace:Banquale.Model"
x:Class="Banquale.Views.Balance.BalancePage" x:Class="Banquale.Views.BalancePage"
Title="BalancePage" Title="BalancePage"
Shell.NavBarIsVisible="False"> Shell.NavBarIsVisible="False">
@ -84,7 +84,7 @@
Grid.Column="0" Grid.Column="0"
MaximumHeightRequest="30"/> MaximumHeightRequest="30"/>
<Label <Label
Text="{Binding Date, StringFormat='{0:f}'}" Text="{Binding Date, StringFormat='{0:ddd dd MMM yyyy}'}"
Grid.Column="1" Grid.Column="1"
VerticalOptions="Center" VerticalOptions="Center"
Margin="10, 0, 0, 0"/> Margin="10, 0, 0, 0"/>

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

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

@ -6,18 +6,6 @@
<VerticalStackLayout VerticalOptions="Center"> <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" <Frame CornerRadius="10"
HeightRequest="40" HeightRequest="40"
WidthRequest="300" WidthRequest="300"

@ -3,6 +3,7 @@ namespace Banquale.Views;
public partial class HelpPage : ContentPage public partial class HelpPage : ContentPage
{ {
public Manager Mgr => (App.Current as App).MyManager;
public HelpPage() public HelpPage()
{ {
InitializeComponent(); InitializeComponent();
@ -10,7 +11,8 @@ public partial class HelpPage : ContentPage
public async void Send_Clicked(Object sender, EventArgs e) 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"); await Shell.Current.GoToAsync("//balance");
} }

@ -7,13 +7,12 @@
Shell.NavBarIsVisible="False"> Shell.NavBarIsVisible="False">
<StackLayout <VerticalStackLayout
VerticalOptions="Center" VerticalOptions="Center">
HorizontalOptions="Center">
<ListView
<ListView ItemsSource="{Binding AccountsList}" ItemsSource="{Binding AccountsList}"
SelectionMode="None" Grid.Row="1"> SelectionMode="None">
<ListView.ItemTemplate> <ListView.ItemTemplate>
@ -21,15 +20,15 @@
<ViewCell> <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> </VerticalStackLayout>
</ViewCell> </ViewCell>
@ -45,10 +44,10 @@
HorizontalOptions="Fill" HorizontalOptions="Fill"
MinimumHeightRequest="100" MinimumHeightRequest="100"
MinimumWidthRequest="375" MinimumWidthRequest="375"
Margin="0,65,0,0" Margin="10"
FontSize="Large" FontSize="Large"
Clicked="DisconnectionClicked"/> Clicked="DisconnectionClicked"/>
</StackLayout> </VerticalStackLayout>
</ContentPage> </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