Gestion statut chambre et image edit/delete

This commit is contained in:
bourgoino 2025-03-20 17:41:05 +01:00
parent 8168c8844d
commit 9eb0330f33
7 changed files with 116 additions and 65 deletions

View File

@ -17,4 +17,8 @@ public class Chambre
public int NbPersonne { get; set; }
public int StatusId { get; set; }
}
// Propriété de navigation pour associer l'objet Status (non stockée en base)
[Ignore]
public Status Status { get; set; }
}

View File

@ -1,12 +1,10 @@
<?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"
x:Class="HegreHotel.Views.Chambre.ChambresPage"
Title="Gestion des Chambres"
Appearing="ChambresPage_OnAppearing">
<StackLayout Padding="10">
<Picker x:Name="PickerFiltreStatus" Title="Filtrer par statut" SelectedIndexChanged="OnFiltreChanged"/>
<Button Text="Ajouter Chambre"
@ -18,26 +16,34 @@
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<StackLayout Orientation="Horizontal" Padding="5" Spacing="10">
<!-- Nom de la chambre -->
<Label Text="{Binding Nom}"
FontAttributes="Bold"
WidthRequest="100"/>
<Label Text="{Binding Description}"
WidthRequest="150"/>
<Label Text="{Binding Status.Libelle}"
TextColor="Gray"/>
VerticalOptions="Center"
WidthRequest="120"/> <!-- Ajusté pour laisser de la place -->
<Button Text="Modifier"
CommandParameter="{Binding .}"
Clicked="OnModifierChambreClicked"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<!-- Statut de la chambre -->
<Label Text="{Binding Status.Libelle}"
FontAttributes="Italic"
VerticalOptions="Center"
WidthRequest="100"/>
<Button Text="Supprimer"
CommandParameter="{Binding .}"
Clicked="OnSupprimerChambreClicked"
HorizontalOptions="End"
Margin="5,0"/>
<!-- Icônes Modifier / Supprimer -->
<StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" Spacing="5">
<ImageButton Source="edit_icon.png"
Clicked="OnModifierChambreClicked"
CommandParameter="{Binding .}"
HeightRequest="30"
WidthRequest="30"
BackgroundColor="Transparent"/>
<ImageButton Source="delete_icon.png"
Clicked="OnSupprimerChambreClicked"
CommandParameter="{Binding .}"
HeightRequest="30"
WidthRequest="30"
BackgroundColor="Transparent"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>

View File

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Microsoft.Maui.Storage;
using System.Collections.Generic;
namespace HegreHotel.Views.Chambre
{
@ -24,12 +25,47 @@ namespace HegreHotel.Views.Chambre
var db = SingletonConnection.GetInstance(dbPath);
_statuts = await db.Table<Status>().ToListAsync();
var statutsAvecTous = new List<string> { "Tous" };
statutsAvecTous.AddRange(_statuts.Select(s => s.Libelle));
PickerFiltreStatus.ItemsSource = statutsAvecTous;
var chambresList = await db.Table<Models.Chambre>().ToListAsync();
var reservationsList = await db.Table<Models.Reservation>().ToListAsync();
DateTime today = DateTime.Today;
foreach (var chambre in chambresList)
{
var chambreReservee = reservationsList
.Where(r => r.ChambreId == chambre.Id && r.DateDebut <= today && r.DateFin >= today)
.OrderByDescending(r => r.DateFin)
.FirstOrDefault();
if (chambreReservee != null)
{
chambre.StatusId = 2;
}
else
{
var chambreFinieRecemment = reservationsList
.Where(r => r.ChambreId == chambre.Id && r.DateFin >= today.AddDays(-2) && r.DateFin < today)
.OrderByDescending(r => r.DateFin)
.FirstOrDefault();
if (chambreFinieRecemment != null)
{
chambre.StatusId = 3;
}
else
{
chambre.StatusId = 1;
}
}
chambre.Status = _statuts.FirstOrDefault(s => s.Id == chambre.StatusId);
await db.UpdateAsync(chambre);
}
_toutesLesChambres.Clear();
foreach (var chambre in chambresList)
{
@ -38,7 +74,7 @@ namespace HegreHotel.Views.Chambre
FiltrerChambres();
}
private void OnFiltreChanged(object sender, EventArgs e)
{
FiltrerChambres();
@ -52,8 +88,17 @@ namespace HegreHotel.Views.Chambre
}
else
{
var statutSelectionne = _statuts[PickerFiltreStatus.SelectedIndex - 1].Id;
ChambresListView.ItemsSource = _toutesLesChambres.Where(c => c.StatusId == statutSelectionne).ToList();
string statutSelectionne = PickerFiltreStatus.SelectedItem.ToString();
var statut = _statuts.FirstOrDefault(s => s.Libelle == statutSelectionne);
if (statut != null)
{
ChambresListView.ItemsSource = _toutesLesChambres.Where(c => c.StatusId == statut.Id).ToList();
}
else
{
Console.WriteLine($"⚠ Filtrage impossible : statut '{statutSelectionne}' introuvable.");
}
}
}
@ -64,8 +109,7 @@ namespace HegreHotel.Views.Chambre
private async void OnModifierChambreClicked(object sender, EventArgs e)
{
var chambre = ((Button)sender).CommandParameter as Models.Chambre;
if (chambre != null)
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Chambre chambre)
{
await Navigation.PushAsync(new ModifierChambrePage(chambre));
}
@ -73,8 +117,7 @@ namespace HegreHotel.Views.Chambre
private async void OnSupprimerChambreClicked(object sender, EventArgs e)
{
var chambre = ((Button)sender).CommandParameter as Models.Chambre;
if (chambre != null)
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Chambre chambre)
{
bool confirmation = await DisplayAlert("Suppression", "Voulez-vous vraiment supprimer cette chambre ?", "Oui", "Non");
if (confirmation)

View File

@ -1,5 +1,4 @@
<?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"
x:Class="HegreHotel.Views.Client.ClientsPage"
@ -15,7 +14,7 @@
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<StackLayout Orientation="Horizontal" Padding="5" Spacing="10">
<Label Text="{Binding Nom}"
VerticalOptions="Center"
FontAttributes="Bold"
@ -23,18 +22,20 @@
<Label Text="{Binding Prenom}"
VerticalOptions="Center"
WidthRequest="100"/>
<Button Text="Modifier"
Clicked="OnModifierClientClicked"
CommandParameter="{Binding .}"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<Button Text="Supprimer"
Clicked="OnSupprimerClientClicked"
CommandParameter="{Binding .}"
HorizontalOptions="End"
Margin="5,0"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" Spacing="5">
<ImageButton Source="edit_icon.png"
Clicked="OnModifierClientClicked"
CommandParameter="{Binding .}"
HeightRequest="30"
WidthRequest="30"
BackgroundColor="Transparent"/>
<ImageButton Source="delete_icon.png"
Clicked="OnSupprimerClientClicked"
CommandParameter="{Binding .}"
HeightRequest="30"
WidthRequest="30"
BackgroundColor="Transparent"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>

View File

@ -36,17 +36,16 @@ namespace HegreHotel.Views.Client
private async void OnModifierClientClicked(object sender, EventArgs e)
{
var client = ((Button)sender).CommandParameter as Models.Client;
if (client != null)
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Client client)
{
await Navigation.PushAsync(new ModifierClientPage(client));
}
}
private async void OnSupprimerClientClicked(object sender, EventArgs e)
{
var client = ((Button)sender).CommandParameter as Models.Client;
if (client != null)
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Client client)
{
bool confirmation = await DisplayAlert("Suppression", "Voulez-vous vraiment supprimer ce client ?", "Oui", "Non");
if (confirmation)
@ -59,6 +58,7 @@ namespace HegreHotel.Views.Client
}
}
private void ClientsPage_OnAppearing(object? sender, EventArgs e)
{
LoadClients();

View File

@ -1,24 +1,20 @@
<?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"
x:Class="HegreHotel.Views.Reservation.ReservationsPage"
Title="Gestion des Réservations"
Appearing="ReservationsPage_OnAppearing">
<StackLayout Padding="10">
<Button Text="Ajouter Réservation"
Clicked="OnAjouterReservationClicked"
HorizontalOptions="Center"
Margin="0,10"/>
<ListView x:Name="ReservationsListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<StackLayout Orientation="Horizontal" Padding="5" Spacing="10">
<Label Text="{Binding NbInvite}"
VerticalOptions="Center"
WidthRequest="50"/>
@ -29,17 +25,20 @@
VerticalOptions="Center"
WidthRequest="100"/>
<Button Text="Modifier"
CommandParameter="{Binding .}"
Clicked="OnModifierReservationClicked"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<Button Text="Supprimer"
CommandParameter="{Binding .}"
Clicked="OnSupprimerReservationClicked"
HorizontalOptions="End"
Margin="5,0"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" Spacing="5">
<ImageButton Source="edit_icon.png"
Clicked="OnModifierReservationClicked"
CommandParameter="{Binding .}"
HeightRequest="30"
WidthRequest="30"
BackgroundColor="Transparent"/>
<ImageButton Source="delete_icon.png"
Clicked="OnSupprimerReservationClicked"
CommandParameter="{Binding .}"
HeightRequest="30"
WidthRequest="30"
BackgroundColor="Transparent"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>

View File

@ -36,8 +36,7 @@ namespace HegreHotel.Views.Reservation
private async void OnModifierReservationClicked(object sender, EventArgs e)
{
var reservation = ((Button)sender).CommandParameter as Models.Reservation;
if (reservation != null)
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Reservation reservation)
{
await Navigation.PushAsync(new ModifierReservationPage(reservation));
}
@ -45,8 +44,7 @@ namespace HegreHotel.Views.Reservation
private async void OnSupprimerReservationClicked(object sender, EventArgs e)
{
var reservation = ((Button)sender).CommandParameter as Models.Reservation;
if (reservation != null)
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Reservation reservation)
{
bool confirmation = await DisplayAlert("Suppression", "Voulez-vous vraiment supprimer cette réservation ?", "Oui", "Non");
if (confirmation)