From 845c42ebfc7f3301688145fbf3740ca33b6087a7 Mon Sep 17 00:00:00 2001 From: luevard <lucas.EVARD@etu.uca.fr> Date: Tue, 15 Nov 2022 20:41:48 +0100 Subject: [PATCH] Selection banque --- Sources/Data/PersLinqToPgSQL.cs | 38 +++++++++++++++++++++++++-- Sources/IHM/Dashboard.xaml | 24 ++++++++++++----- Sources/IHM/Dashboard.xaml.cs | 18 +++++++++++-- Sources/IHM/ForgetPassword.xaml.cs | 1 - Sources/IHM/MainPage.xaml.cs | 5 ++-- Sources/IHM/Settings.xaml.cs | 2 +- Sources/Modele/IPersistanceManager.cs | 1 + Sources/Modele/Inscrit.cs | 4 +++ Sources/Modele/Manager.cs | 19 ++++++++++++-- 9 files changed, 94 insertions(+), 18 deletions(-) diff --git a/Sources/Data/PersLinqToPgSQL.cs b/Sources/Data/PersLinqToPgSQL.cs index e701759..00c61d3 100644 --- a/Sources/Data/PersLinqToPgSQL.cs +++ b/Sources/Data/PersLinqToPgSQL.cs @@ -46,7 +46,6 @@ namespace LinqToPgSQL dr.Close(); return "null";//a changer doit retester } - } public bool ExistEmail(string mail) @@ -237,7 +236,6 @@ namespace LinqToPgSQL using (var command1 = new NpgsqlCommand(requete, conn)) { command1.Parameters.AddWithValue("p", i.Id); - /*await command1.ExecuteNonQueryAsync();*/ } @@ -249,6 +247,42 @@ namespace LinqToPgSQL return ListeCompte; } + public IEnumerable<Banque> LoadBanqueId(string id) + { + //int idnombre = Int16.Parse(id); + // Debug.WriteLine(idnombre+"------------------------------------"); + List<Banque> ListeBanque = new List<Banque>(); + Debug.WriteLine(id); + var conn = new NpgsqlConnection(connexionBDD); + Console.Out.WriteLine("Ouverture de la connection"); + try + { + conn.Open(); + } + catch + { + conn.Close(); + Debug.WriteLine("Probl�me de connection � la base de donn�es. Apr�s fermeture, l'application se fermera automatiquement."); + Environment.Exit(-1); + } + + /* NpgsqlCommand cmd = new NpgsqlCommand("select * from banque b, inscrbanque ib, Inscrit i where ib.idinscrit =(@p) AND ib.nombanque = b.nom AND ib.idinscrit = i.id;", conn) + { + Parameters = + { + new NpgsqlParameter("p",id), + } + }; + NpgsqlDataReader dataReader = cmd.ExecuteReader(); + while (dataReader.Read()) + { + Debug.WriteLine(dataReader.GetString(0), dataReader.GetString(1), dataReader.GetString(2)); + ListeBanque.Add(new Banque(dataReader.GetString(0), dataReader.GetString(1), dataReader.GetString(2))); + } + dataReader.Close();*/ + return ListeBanque; + } + /*Suppression d'un inscrit dans la base de donn�es*/ public async void SupprimerInscritBdd(Inscrit i) { diff --git a/Sources/IHM/Dashboard.xaml b/Sources/IHM/Dashboard.xaml index 404607f..c2addf6 100644 --- a/Sources/IHM/Dashboard.xaml +++ b/Sources/IHM/Dashboard.xaml @@ -16,13 +16,15 @@ Margin="0,0,40,0" Clicked="OnClickedGestionBanque" /> - <Label - IsVisible="false" - WidthRequest="50" + <Button + IsVisible="true" + IsEnabled="False" + WidthRequest="175" HeightRequest="50" Margin="0,-50,0,0" x:Name="ImgBanqueActuelle" - BackgroundColor="Aqua" + BackgroundColor="AliceBlue" + Text="wow" /> <Button IsVisible="false" @@ -34,8 +36,16 @@ Margin="0,-50,40,0" Clicked="OnClickedRetour" /> - <HorizontalStackLayout> - - </HorizontalStackLayout> + <StackLayout IsVisible="false" x:Name="stackpannel"> + <CollectionView x:Name="listeBanque" ItemsSource="{Binding listeBanqueConnecte}" ItemsUpdatingScrollMode="KeepScrollOffset" Margin="22,0,22,0" ItemsLayout="HorizontalList"> + <CollectionView.ItemTemplate> + <DataTemplate> + <StackLayout Margin="0,35,0,0"> + <Button Clicked="OnClickedBanque" Text="{Binding Nom}" Margin="0,0,20,0"/> + </StackLayout> + </DataTemplate> + </CollectionView.ItemTemplate> + </CollectionView> + </StackLayout> </VerticalStackLayout> </ContentPage> \ No newline at end of file diff --git a/Sources/IHM/Dashboard.xaml.cs b/Sources/IHM/Dashboard.xaml.cs index c48aa47..f59e59d 100644 --- a/Sources/IHM/Dashboard.xaml.cs +++ b/Sources/IHM/Dashboard.xaml.cs @@ -1,6 +1,7 @@ using Model; using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific; +using System.Diagnostics; namespace IHM; @@ -10,15 +11,26 @@ public partial class DashBoard : ContentPage public DashBoard() { InitializeComponent(); + BindingContext = Mgr; //Routing.RegisterRoute(nameof(DashBoard), typeof(DashBoard)); - - if (Mgr.SelectedInscrit == null) { loadInscription(); } } + void OnClickedBanque(object sender, EventArgs args) + { + /* foreach(Button but in CollectionView) + { + + }*/ + Button btn = (Button)sender; + btn.IsEnabled = false; + ImgBanqueActuelle.Text = btn.Text; + } + + async void OnClickedGestionBanque(object sender, EventArgs args) { Bouton.IsEnabled = false; @@ -26,6 +38,7 @@ public partial class DashBoard : ContentPage await Bouton.TranslateTo(-130, 35, 50); await Bouton.ScaleXTo(7.5, 50); await Bouton.ScaleYTo(3, 50); + stackpannel.IsVisible = true; BoutonRetour.IsVisible = true; ImgBanqueActuelle.IsVisible = true; @@ -37,6 +50,7 @@ public partial class DashBoard : ContentPage await Bouton.ScaleXTo(1, 50); await Bouton.ScaleYTo(1, 50); ImgBanqueActuelle.IsVisible = false; + stackpannel.IsVisible = false; await Bouton.TranslateTo(0,0,50); BoutonRetour.IsVisible = false; Bouton.IsEnabled = true; diff --git a/Sources/IHM/ForgetPassword.xaml.cs b/Sources/IHM/ForgetPassword.xaml.cs index 37e1e20..d41267e 100644 --- a/Sources/IHM/ForgetPassword.xaml.cs +++ b/Sources/IHM/ForgetPassword.xaml.cs @@ -1,4 +1,3 @@ -using Android.Renderscripts; using Model; using Email = Model.Email; diff --git a/Sources/IHM/MainPage.xaml.cs b/Sources/IHM/MainPage.xaml.cs index 7056a7a..9a31ac9 100644 --- a/Sources/IHM/MainPage.xaml.cs +++ b/Sources/IHM/MainPage.xaml.cs @@ -1,6 +1,4 @@ - using Android.Bluetooth; -using AndroidX.Emoji2.Text.FlatBuffer; -using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls; using Model; using System.Windows.Input; @@ -43,6 +41,7 @@ namespace IHM private async void ConnexionValide() { + Mgr.LoadBanques(); await Navigation.PopModalAsync(); } diff --git a/Sources/IHM/Settings.xaml.cs b/Sources/IHM/Settings.xaml.cs index cd17c29..6f2e061 100644 --- a/Sources/IHM/Settings.xaml.cs +++ b/Sources/IHM/Settings.xaml.cs @@ -12,7 +12,7 @@ public partial class Settings : ContentPage } public void deconnexionOnClicked(object sender, EventArgs e) { - Mgr.SelectedInscrit = null; + Mgr.deconnexion(); NavigateTo(); } private async void NavigateTo() diff --git a/Sources/Modele/IPersistanceManager.cs b/Sources/Modele/IPersistanceManager.cs index 207b624..cef2b6e 100644 --- a/Sources/Modele/IPersistanceManager.cs +++ b/Sources/Modele/IPersistanceManager.cs @@ -17,5 +17,6 @@ namespace Model bool ExistEmail(string mail); void ChangePasswordBdd(string mail, string newMdp); string RecupMdpBdd(string mail); + IEnumerable<Banque> LoadBanqueId(string id); } } diff --git a/Sources/Modele/Inscrit.cs b/Sources/Modele/Inscrit.cs index 7e05712..458fd85 100644 --- a/Sources/Modele/Inscrit.cs +++ b/Sources/Modele/Inscrit.cs @@ -77,6 +77,10 @@ namespace Model LesBanques = lesbanques; } + public Inscrit(List<Banque> lesbanques) + { + LesBanques = lesbanques; + } public void ajouterBanque(Banque banque) diff --git a/Sources/Modele/Manager.cs b/Sources/Modele/Manager.cs index f771a24..47c4661 100644 --- a/Sources/Modele/Manager.cs +++ b/Sources/Modele/Manager.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Diagnostics; namespace Model { @@ -19,11 +20,12 @@ namespace Model if(selectedBanque != value) { selectedBanque = value; - OnPropertyChanged(nameof(selectedBanque)); + OnPropertyChanged(nameof(SelectedBanque)); } } } private Banque selectedBanque; + public IEnumerable<Banque> listeBanqueConnecte { get; private set; } void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); @@ -40,8 +42,14 @@ namespace Model public void LoadInscrit(string id, string mdp) { SelectedInscrit = Pers.LoadInscrit(id, mdp); + Debug.WriteLine(SelectedInscrit); } + public void LoadBanques() + { + listeBanqueConnecte = Pers.LoadBanqueId(SelectedInscrit); + } + public void supprimerToutesBanquesBdd(Inscrit inscrit) { Pers.SupprimerToutesBanquesBdd(inscrit); @@ -76,6 +84,13 @@ namespace Model { return hash.IsEqualHash(mdpBdd, mdpSent); } - } + public void deconnexion() + { + SelectedBanque= null; + SelectedInscrit = null; + listeBanqueConnecte = new List<Banque>(); + Debug.WriteLine(listeBanqueConnecte.Count()); + } + } }