From 1f994eb49d759c6be17f359d0d90ac98a0e3d974 Mon Sep 17 00:00:00 2001 From: anperederi Date: Wed, 7 Jun 2023 15:54:14 +0200 Subject: [PATCH] add collection --- src/Banquale/Banquale/AppShell.xaml | 3 +- src/Banquale/Banquale/Banquale.csproj | 2 + .../Views/{ => Balance}/BalancePage.xaml | 62 ++----------------- .../Views/Balance/BalancePage.xaml.cs | 29 +++++++++ .../Banquale/Views/Balance/BalanceView.xaml | 59 ++++++++++++++++++ .../Views/Balance/BalanceView.xaml.cs | 41 ++++++++++++ .../Banquale/Views/BalancePage.xaml.cs | 53 ---------------- .../Banquale/Views/Category/CategoryView.xaml | 60 ++++++++++++++---- .../Banquale/Views/ConsultantIdPage.xaml.cs | 46 ++++++++++++-- .../Banquale/Views/SwitchAccountPage.xaml.cs | 24 +++++-- src/Banquale/Model/Account.cs | 3 +- src/Banquale/Model/Manager.cs | 2 + 12 files changed, 252 insertions(+), 132 deletions(-) rename src/Banquale/Banquale/Views/{ => Balance}/BalancePage.xaml (53%) create mode 100644 src/Banquale/Banquale/Views/Balance/BalancePage.xaml.cs create mode 100644 src/Banquale/Banquale/Views/Balance/BalanceView.xaml create mode 100644 src/Banquale/Banquale/Views/Balance/BalanceView.xaml.cs delete mode 100644 src/Banquale/Banquale/Views/BalancePage.xaml.cs diff --git a/src/Banquale/Banquale/AppShell.xaml b/src/Banquale/Banquale/AppShell.xaml index 68c2ba6..f3a2300 100644 --- a/src/Banquale/Banquale/AppShell.xaml +++ b/src/Banquale/Banquale/AppShell.xaml @@ -4,6 +4,7 @@ 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"> @@ -15,7 +16,7 @@ diff --git a/src/Banquale/Banquale/Banquale.csproj b/src/Banquale/Banquale/Banquale.csproj index 44d300a..6ef5ed2 100644 --- a/src/Banquale/Banquale/Banquale.csproj +++ b/src/Banquale/Banquale/Banquale.csproj @@ -60,6 +60,7 @@ + @@ -71,6 +72,7 @@ + diff --git a/src/Banquale/Banquale/Views/BalancePage.xaml b/src/Banquale/Banquale/Views/Balance/BalancePage.xaml similarity index 53% rename from src/Banquale/Banquale/Views/BalancePage.xaml rename to src/Banquale/Banquale/Views/Balance/BalancePage.xaml index 0ef8203..cda652a 100644 --- a/src/Banquale/Banquale/Views/BalancePage.xaml +++ b/src/Banquale/Banquale/Views/Balance/BalancePage.xaml @@ -1,11 +1,12 @@  - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/Banquale/Banquale/Views/Balance/BalancePage.xaml.cs b/src/Banquale/Banquale/Views/Balance/BalancePage.xaml.cs new file mode 100644 index 0000000..c294f20 --- /dev/null +++ b/src/Banquale/Banquale/Views/Balance/BalancePage.xaml.cs @@ -0,0 +1,29 @@ +using Model; + +namespace Banquale.Views.Balance; + + +public partial class BalancePage : ContentPage +{ + public Manager Mgr => (App.Current as App).MyManager; + + public BalancePage() + { + InitializeComponent(); + BindingContext = Mgr.SelectedAccount; + if(Mgr.IsConsultant == true) + { + //Label lext = new Label { Text = "Hello" }; + //Grid.Add(lext); + Image backArrow = new Image { HeightRequest = 100 }; + backArrow.SetBinding(Image.SourceProperty, "backArrowIcon"); + Grid.Add(backArrow); + } + } + + public async void Balance_Clicked(object sender, EventArgs e) + { + await Shell.Current.Navigation.PushAsync(new NewPage1()); + } + +} diff --git a/src/Banquale/Banquale/Views/Balance/BalanceView.xaml b/src/Banquale/Banquale/Views/Balance/BalanceView.xaml new file mode 100644 index 0000000..913bbe3 --- /dev/null +++ b/src/Banquale/Banquale/Views/Balance/BalanceView.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Banquale/Banquale/Views/Balance/BalanceView.xaml.cs b/src/Banquale/Banquale/Views/Balance/BalanceView.xaml.cs new file mode 100644 index 0000000..c24ef72 --- /dev/null +++ b/src/Banquale/Banquale/Views/Balance/BalanceView.xaml.cs @@ -0,0 +1,41 @@ +using System.Diagnostics; +using Model; + +namespace Banquale.Views.Balance; + +public partial class BalanceView : ContentView +{ + + public Manager Mgr => (App.Current as App).MyManager; + + public BalanceView() + { + InitializeComponent(); + BindingContext = Mgr.SelectedAccount; + } + + public async void Transaction_Clicked(Object sender, EventArgs e) + { + //uint TransactionId = Convert.ToUInt32(transactionId.Text); + + //if (string.IsNullOrWhiteSpace(idLabel.Text)) + //{ + // //await DisplayAlert("Erreur", "Aucune transaction présente", "OK"); + // Debug.WriteLine("Erreur1"); + // return; + //} + + //Transaction transaction = Mgr.SelectedAccount.TransactionsList.FirstOrDefault(u => u.Id == TransactionId); + //if (transaction == null) + //{ + // Debug.WriteLine("Erreur2"); + // //await DisplayAlert("Erreur", "La transaction n'éxiste pas !", "OK"); + // return; + //} + + //Mgr.SelectedTransaction = transaction; + + + await Navigation.PushModalAsync(new TransactionsPage()); + } +} diff --git a/src/Banquale/Banquale/Views/BalancePage.xaml.cs b/src/Banquale/Banquale/Views/BalancePage.xaml.cs deleted file mode 100644 index 33a525b..0000000 --- a/src/Banquale/Banquale/Views/BalancePage.xaml.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Model; - -namespace Banquale.Views; - - -public partial class BalancePage : ContentPage -{ - public Manager Mgr => (App.Current as App).MyManager; - - public BalancePage() - { - InitializeComponent(); - BindingContext = Mgr.SelectedAccount; - //BindingContext = new Account(999, "Tatouille", "FR76 9161 9581 6296 8415 2361 004"); - } - - - public async void Transactions_Clicked(System.Object sender, Microsoft.Maui.Controls.TappedEventArgs e) - { - Mgr.SelectedTransaction = Mgr.SelectedAccount.TransactionsList[0]; - //Mgr.SelectedTransaction = Mgr.PropertyChanged; - await Shell.Current.Navigation.PushAsync(new TransactionsPage()); - } - - public async void Balance_Clicked(object sender, EventArgs e) - { - await Shell.Current.Navigation.PushAsync(new NewPage1()); - } - - public async void Transaction_Clicked(Object sender, EventArgs e) - { - uint TransactionId = Convert.ToUInt32(idLabel.Text); - - if (string.IsNullOrWhiteSpace(idLabel.Text)) - { - await DisplayAlert("Erreur", "Aucune transaction présente", "OK"); - return; - } - - Transaction transaction = Mgr.SelectedAccount.TransactionsList.FirstOrDefault(u => u.Id == TransactionId); - if (transaction == null) - { - await DisplayAlert("Erreur", "La transaction n'éxiste pas !", "OK"); - return; - } - - Mgr.SelectedTransaction = transaction; - - - await Navigation.PushModalAsync(new TransactionsPage()); - } - -} diff --git a/src/Banquale/Banquale/Views/Category/CategoryView.xaml b/src/Banquale/Banquale/Views/Category/CategoryView.xaml index 21166d5..937491d 100644 --- a/src/Banquale/Banquale/Views/Category/CategoryView.xaml +++ b/src/Banquale/Banquale/Views/Category/CategoryView.xaml @@ -5,17 +5,55 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Banquale/Banquale/Views/ConsultantIdPage.xaml.cs b/src/Banquale/Banquale/Views/ConsultantIdPage.xaml.cs index 8d54a38..040f54e 100644 --- a/src/Banquale/Banquale/Views/ConsultantIdPage.xaml.cs +++ b/src/Banquale/Banquale/Views/ConsultantIdPage.xaml.cs @@ -1,24 +1,60 @@ +using System.Diagnostics; using Banquale.Views; +using Model; + namespace Banquale.Views; public partial class ConsultantIdPage : ContentPage { - public ConsultantIdPage() + public Manager Mgr => (App.Current as App).MyManager; + + public ConsultantIdPage() { InitializeComponent(); } + //public async void Connection_Clicked(Object sender, EventArgs e) + //{ + // string id = ident.Text; + + // if (string.IsNullOrWhiteSpace(id)) + // { + // await DisplayAlert("Erreur", "l'id ne doit pas être nulle", "OK"); + // return; + // } + + // await Navigation.PushModalAsync(new Balance.BalancePage()); + //} + public async void Connection_Clicked(Object sender, EventArgs e) { - string id = ident.Text; + uint currentId = Convert.ToUInt32(ident.Text); + + if (string.IsNullOrWhiteSpace(ident.Text)) + { + await DisplayAlert("Erreur", "Il faut rentrer un ID", "OK"); + return; + } + + if (currentId == 0) + { + await DisplayAlert("Erreur", "Ce compte est innaccessible", "OK"); + return; + } - if (string.IsNullOrWhiteSpace(id)) + Customer customer = Mgr.CustomersList.FirstOrDefault(u => u.Id == currentId); + if (customer == null) { - await DisplayAlert("Erreur", "l'id ne doit pas être nulle", "OK"); + await DisplayAlert("Erreur", "L'id entré est incorrect ou n'existe pas.", "OK"); return; } - await Navigation.PushModalAsync(new BalancePage()); + Mgr.SelectedCustomer = customer; + + Debug.WriteLine(Mgr.IsConsultant); + + + await Navigation.PushModalAsync(new SwitchAccountPage()); } } \ No newline at end of file diff --git a/src/Banquale/Banquale/Views/SwitchAccountPage.xaml.cs b/src/Banquale/Banquale/Views/SwitchAccountPage.xaml.cs index 589824b..0854e47 100644 --- a/src/Banquale/Banquale/Views/SwitchAccountPage.xaml.cs +++ b/src/Banquale/Banquale/Views/SwitchAccountPage.xaml.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Model; namespace Banquale.Views; @@ -15,12 +16,27 @@ public partial class SwitchAccountPage : ContentPage public async void Transfer_Clicked(object sender, EventArgs e) { Mgr.SelectedAccount = Mgr.SelectedCustomer.AccountsList[0]; // 0 � changer - - await Shell.Current.GoToAsync("//balance"); + if(Mgr.IsConsultant == true) + { + await Shell.Current.Navigation.PushAsync(new Balance.BalancePage()); + } + else + { + await Shell.Current.GoToAsync("//balance"); + } } - async void DisconnectionClicked(System.Object sender, System.EventArgs e) + + async void DisconnectionClicked(object sender, EventArgs e) { - await Shell.Current.GoToAsync("///connection"); + if(Mgr.IsConsultant == true) + { + //await Shell.Current.GoToAsync(; + Debug.WriteLine("Hello"); + } + else + { + await Shell.Current.GoToAsync("///connection"); + } } } \ No newline at end of file diff --git a/src/Banquale/Model/Account.cs b/src/Banquale/Model/Account.cs index 400ccde..3649cd0 100644 --- a/src/Banquale/Model/Account.cs +++ b/src/Banquale/Model/Account.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; @@ -108,7 +109,7 @@ namespace Model /// Obtient ou définit la liste des transactions effectuées sur le compte. /// [DataMember(Order = 5)] - public List TransactionsList { get; set; } = new List(); + public ObservableCollection TransactionsList { get; set; } = new ObservableCollection(); /// /// Effectue une transaction entre le compte courant et un compte tiers. diff --git a/src/Banquale/Model/Manager.cs b/src/Banquale/Model/Manager.cs index 61d5862..af8856b 100644 --- a/src/Banquale/Model/Manager.cs +++ b/src/Banquale/Model/Manager.cs @@ -27,6 +27,8 @@ namespace Model [DataMember] public List CustomersList { get; private set; } // devient un set + public List CategoryList { get; private set; } = new List {"Automobile", "Santé", "Abonnement", "Logement", "Impôts et taxes", "Courses", "Loisirs et sorties", "Enfant(s)"}; + /// /// Consultant assigné au gestionnaire. ///