From 76e4e687990fec0e73ab23cc3fce2af53e9b844f Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 20 Mar 2025 17:17:25 +0100 Subject: [PATCH] client page par id --- Views/Client/ClientsPage.xaml | 4 +- Views/Client/ClientsPage.xaml.cs | 16 ++++++ Views/Client/DetailsClientPage.xaml | 35 +++++++++++++ Views/Client/DetailsClientPage.xaml.cs | 71 ++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 Views/Client/DetailsClientPage.xaml create mode 100644 Views/Client/DetailsClientPage.xaml.cs diff --git a/Views/Client/ClientsPage.xaml b/Views/Client/ClientsPage.xaml index 3344e40..ff78046 100644 --- a/Views/Client/ClientsPage.xaml +++ b/Views/Client/ClientsPage.xaml @@ -11,7 +11,7 @@ HorizontalOptions="Center" Margin="0,10"/> - + @@ -40,5 +40,7 @@ + + diff --git a/Views/Client/ClientsPage.xaml.cs b/Views/Client/ClientsPage.xaml.cs index d97e04f..c2cc533 100644 --- a/Views/Client/ClientsPage.xaml.cs +++ b/Views/Client/ClientsPage.xaml.cs @@ -27,6 +27,7 @@ namespace HegreHotel.Views.Client Clients.Add(client); } ClientsListView.ItemsSource = Clients; + } private async void OnAjouterClientClicked(object sender, EventArgs e) @@ -63,5 +64,20 @@ namespace HegreHotel.Views.Client { LoadClients(); } + + private async void OnClientTapped(object sender, ItemTappedEventArgs e) + { + if (e.Item != null) + { + // Désélectionne l'élément tappé + ((ListView)sender).SelectedItem = null; + + // Récupère le client sélectionné + var client = e.Item as Models.Client; + + // Navigue vers la page de détails du client + await Navigation.PushAsync(new DetailsClientPage(client)); + } + } } } diff --git a/Views/Client/DetailsClientPage.xaml b/Views/Client/DetailsClientPage.xaml new file mode 100644 index 0000000..78066aa --- /dev/null +++ b/Views/Client/DetailsClientPage.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Views/Client/DetailsClientPage.xaml.cs b/Views/Client/DetailsClientPage.xaml.cs new file mode 100644 index 0000000..50cb0bf --- /dev/null +++ b/Views/Client/DetailsClientPage.xaml.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HegreHotel.Views.Client; + +public partial class DetailsClientPage : ContentPage +{ + public Models.Client Client { get; set; } + + public DetailsClientPage(Models.Client client) + { + InitializeComponent(); + BindingContext = client; + Client = client; + LoadReservations(); + } + + private async void LoadReservations() + { + string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3"); + var db = SingletonConnection.GetInstance(dbPath); + List reservationsList = await db.Table().Where(x => x.ClientId == Client.Id).ToListAsync(); + List cahmbresList = await db.Table().ToListAsync(); + List reservationInfoList = new List(); + + if (reservationsList is null) + { + await DisplayAlert("Aucune réservation", "Le client n'a pas de réservations", "OK"); + } + else + { + foreach (Models.Reservation reservation in reservationsList) + { + ReservationInfo reservationInfo = new ReservationInfo() + { + DateDebut = reservation.DateDebut, + DateFin = reservation.DateFin, + DemandeSpecifique = reservation.DemandeSpecifique, + NbInvite = reservation.NbInvite + }; + foreach (Models.Chambre chambre in cahmbresList) + { + if (reservation.ChambreId == chambre.Id) + { + reservationInfo.ChambreNom = chambre.Nom; + } + } + reservationInfoList.Add(reservationInfo); + } + } + + ListeReservations.ItemsSource = reservationInfoList; + } + + public class ReservationInfo + { + public DateTime DateDebut { get; set; } + + public DateTime DateFin { get; set; } + + public string? DemandeSpecifique { get; set; } + + public int NbInvite { get; set; } + + public string? ChambreNom { get; set; } + } +} \ No newline at end of file