Status added and crash resolved

This commit is contained in:
allavenavr 2025-03-18 09:00:39 +01:00
parent cab1fcacbf
commit 3a149b8b5e
21 changed files with 149 additions and 66 deletions

View File

@ -9,17 +9,21 @@ namespace HegreHotel
{
public static async Task CreateDatabaseAsync()
{
// Construction du chemin de la BDD dans le dossier AppData
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
// Récupération de l'instance unique du Singleton
var db = SingletonConnection.GetInstance(dbPath);
// Création des tables
await db.CreateTableAsync<Client>();
await db.CreateTableAsync<Reservation>();
await db.CreateTableAsync<Chambre>();
await db.CreateTableAsync<Status>();
var statuts = await db.Table<Status>().ToListAsync();
if (statuts.Count == 0)
{
await db.InsertAsync(new Status { Libelle = "Disponible" });
await db.InsertAsync(new Status { Libelle = "Occupée" });
await db.InsertAsync(new Status { Libelle = "Indisponible" });
}
}
}
}

View File

@ -1,5 +1,6 @@
using HegreHotel.Views;
using HegreHotel.Views.Chambre;
using HegreHotel.Views.Client;
using HegreHotel.Views.Reservation;
using Microsoft.Maui.Controls;

View File

@ -15,4 +15,6 @@ public class Chambre
public decimal Tarif { get; set; }
public int NbPersonne { get; set; }
public int StatusId { get; set; }
}

View File

@ -15,4 +15,7 @@ public class Reservation
public int NbPersonnes { get; set; }
public int ClientId { get; set; }
public int ChambreId { get; set; }
}

View File

@ -6,7 +6,6 @@ public class Status
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[MaxLength(50), Unique]
public string? Libelle { get; set; }
}

View File

@ -6,15 +6,12 @@ namespace HegreHotel
{
public class SingletonConnection : SQLiteAsyncConnection
{
// Instance unique de la connexion
private static SingletonConnection instance;
// Constructeur privé qui appelle le constructeur parent avec le chemin de la BDD
private SingletonConnection(string dbPath) : base(dbPath)
{
}
// Point d'accès global à l'instance
public static SingletonConnection GetInstance(string dbPath)
{
if (instance == null)

View File

@ -19,7 +19,8 @@ namespace HegreHotel.Views.Chambre
Nom = EntryNom.Text,
Description = EntryDescription.Text,
Tarif = decimal.TryParse(EntryTarif.Text, out decimal tarif) ? tarif : 0,
NbPersonne = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : 0
NbPersonne = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : 0,
StatusId = 1
};
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");

View File

@ -6,35 +6,33 @@
Title="Gestion des Chambres"
Appearing="ChambresPage_OnAppearing">
<StackLayout Padding="10">
<!-- Bouton pour ajouter une chambre -->
<Picker x:Name="PickerFiltreStatus" Title="Filtrer par statut" SelectedIndexChanged="OnFiltreChanged"/>
<Button Text="Ajouter Chambre"
Clicked="OnAjouterChambreClicked"
HorizontalOptions="Center"
Margin="0,10"/>
<!-- Liste des chambres -->
<ListView x:Name="ChambresListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<!-- Affichage des informations de la chambre -->
<Label Text="{Binding Nom}"
VerticalOptions="Center"
FontAttributes="Bold"
WidthRequest="100"/>
<Label Text="{Binding Description}"
VerticalOptions="Center"
WidthRequest="150"/>
<!-- Bouton Modifier -->
<Label Text="{Binding Status.Libelle}"
TextColor="Gray"/>
<Button Text="Modifier"
CommandParameter="{Binding .}"
Clicked="OnModifierChambreClicked"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<!-- Bouton Supprimer -->
<Button Text="Supprimer"
CommandParameter="{Binding .}"
Clicked="OnSupprimerChambreClicked"

View File

@ -2,31 +2,59 @@ using HegreHotel.Models;
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views.Chambre
{
public partial class ChambresPage : ContentPage
{
public ObservableCollection<Models.Chambre> Chambres { get; set; } = new ObservableCollection<Models.Chambre>();
private ObservableCollection<Models.Chambre> _toutesLesChambres = new();
private List<Status> _statuts;
public ChambresPage()
{
InitializeComponent();
LoadChambres();
LoadChambresEtStatuts();
}
private async void LoadChambres()
private async void LoadChambresEtStatuts()
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
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();
Chambres.Clear();
_toutesLesChambres.Clear();
foreach (var chambre in chambresList)
{
Chambres.Add(chambre);
_toutesLesChambres.Add(chambre);
}
FiltrerChambres();
}
private void OnFiltreChanged(object sender, EventArgs e)
{
FiltrerChambres();
}
private void FiltrerChambres()
{
if (PickerFiltreStatus.SelectedIndex <= 0)
{
ChambresListView.ItemsSource = _toutesLesChambres;
}
else
{
var statutSelectionne = _statuts[PickerFiltreStatus.SelectedIndex - 1].Id;
ChambresListView.ItemsSource = _toutesLesChambres.Where(c => c.StatusId == statutSelectionne).ToList();
}
ChambresListView.ItemsSource = Chambres;
}
private async void OnAjouterChambreClicked(object sender, EventArgs e)
@ -54,14 +82,14 @@ namespace HegreHotel.Views.Chambre
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
await db.DeleteAsync(chambre);
LoadChambres();
LoadChambresEtStatuts();
}
}
}
private void ChambresPage_OnAppearing(object? sender, EventArgs e)
{
LoadChambres();
LoadChambresEtStatuts();
}
}
}

View File

@ -12,7 +12,7 @@ namespace HegreHotel.Views.Chambre
{
InitializeComponent();
_chambre = chambre;
// Préremplissage des champs
EntryNom.Text = _chambre.Nom;
EntryDescription.Text = _chambre.Description;
EntryTarif.Text = _chambre.Tarif.ToString();

View File

@ -2,7 +2,7 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HegreHotel.Views.AjouterClientPage"
x:Class="HegreHotel.Views.Client.AjouterClientPage"
Title="Ajouter un Client">
<StackLayout Padding="10">
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
@ -11,4 +11,4 @@
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
</StackLayout>
</ContentPage>
</ContentPage>

View File

@ -3,7 +3,7 @@ using Microsoft.Maui.Controls;
using System.IO;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views
namespace HegreHotel.Views.Client
{
public partial class AjouterClientPage : ContentPage
{
@ -14,7 +14,7 @@ namespace HegreHotel.Views
private async void OnEnregistrerClicked(object sender, EventArgs e)
{
var client = new Client()
var client = new Models.Client()
{
Nom = EntryNom.Text,
Prenom = EntryPrenom.Text,

View File

@ -2,23 +2,20 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HegreHotel.Views.ClientsPage"
x:Class="HegreHotel.Views.Client.ClientsPage"
Title="Gestion des Clients"
Appearing="ClientsPage_OnAppearing">
<StackLayout Padding="10">
<!-- Bouton pour ajouter un client -->
<Button Text="Ajouter Client"
Clicked="OnAjouterClientClicked"
HorizontalOptions="Center"
Margin="0,10"/>
<!-- Liste des clients -->
<ListView x:Name="ClientsListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<!-- Affichage des infos du client -->
<Label Text="{Binding Nom}"
VerticalOptions="Center"
FontAttributes="Bold"
@ -27,14 +24,12 @@
VerticalOptions="Center"
WidthRequest="100"/>
<!-- Bouton Modifier -->
<Button Text="Modifier"
Clicked="OnModifierClientClicked"
CommandParameter="{Binding .}"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<!-- Bouton Supprimer -->
<Button Text="Supprimer"
Clicked="OnSupprimerClientClicked"
CommandParameter="{Binding .}"

View File

@ -4,11 +4,11 @@ using System.Collections.ObjectModel;
using System.IO;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views
namespace HegreHotel.Views.Client
{
public partial class ClientsPage : ContentPage
{
public ObservableCollection<Client> Clients { get; set; } = new ObservableCollection<Client>();
public ObservableCollection<Models.Client> Clients { get; set; } = new ObservableCollection<Models.Client>();
public ClientsPage()
{
@ -16,12 +16,11 @@ namespace HegreHotel.Views
LoadClients();
}
// Chargement des clients depuis la BDD
private async void LoadClients()
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
var clientsList = await db.Table<Client>().ToListAsync();
var clientsList = await db.Table<Models.Client>().ToListAsync();
Clients.Clear();
foreach (var client in clientsList)
{
@ -30,26 +29,23 @@ namespace HegreHotel.Views
ClientsListView.ItemsSource = Clients;
}
// Redirige vers la page d'ajout de client
private async void OnAjouterClientClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new AjouterClientPage());
}
// Redirige vers la page de modification du client sélectionné
private async void OnModifierClientClicked(object sender, EventArgs e)
{
var client = ((Button)sender).CommandParameter as Client;
var client = ((Button)sender).CommandParameter as Models.Client;
if (client != null)
{
await Navigation.PushAsync(new ModifierClientPage(client));
}
}
// Suppression du client après confirmation
private async void OnSupprimerClientClicked(object sender, EventArgs e)
{
var client = ((Button)sender).CommandParameter as Client;
var client = ((Button)sender).CommandParameter as Models.Client;
if (client != null)
{
bool confirmation = await DisplayAlert("Suppression", "Voulez-vous vraiment supprimer ce client ?", "Oui", "Non");

View File

@ -2,7 +2,7 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HegreHotel.Views.ModifierClientPage"
x:Class="HegreHotel.Views.Client.ModifierClientPage"
Title="Modifier le Client">
<StackLayout Padding="10">
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
@ -11,4 +11,4 @@
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
</StackLayout>
</ContentPage>
</ContentPage>

View File

@ -3,16 +3,16 @@ using Microsoft.Maui.Controls;
using System.IO;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views
namespace HegreHotel.Views.Client
{
public partial class ModifierClientPage : ContentPage
{
Client _client;
public ModifierClientPage(Client client)
Models.Client _client;
public ModifierClientPage(Models.Client client)
{
InitializeComponent();
_client = client;
// Préremplissage des champs
EntryNom.Text = _client.Nom;
EntryPrenom.Text = _client.Prenom;
EntryEmail.Text = _client.Email;

View File

@ -5,7 +5,10 @@
x:Class="HegreHotel.Views.Reservation.AjouterReservationPage"
Title="Ajouter une Réservation">
<StackLayout Padding="10">
<Entry x:Name="EntryNbInvite" Placeholder="Nombre d'invités" Keyboard="Numeric"/>
<Picker x:Name="PickerClient" Title="Sélectionner un client"/>
<Picker x:Name="PickerChambre" Title="Sélectionner une chambre"/>
<Entry x:Name="EntryNbPersonne" Placeholder="Nombre d'invités" Keyboard="Numeric"/>
<DatePicker x:Name="DatePickerDebut" />
<DatePicker x:Name="DatePickerFin" />
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>

View File

@ -1,22 +1,48 @@
using HegreHotel.Models;
using Microsoft.Maui.Controls;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views.Reservation
{
public partial class AjouterReservationPage : ContentPage
{
private List<Models.Client> _clients;
private List<Models.Chambre> _chambres;
public AjouterReservationPage()
{
InitializeComponent();
LoadClientsAndChambres();
}
private async void LoadClientsAndChambres()
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
_clients = await db.Table<Models.Client>().ToListAsync();
_chambres = await db.Table<Models.Chambre>().ToListAsync();
PickerClient.ItemsSource = _clients.Select(c => $"{c.Nom} {c.Prenom}").ToList();
PickerChambre.ItemsSource = _chambres.Select(ch => ch.Nom).ToList();
}
private async void OnEnregistrerClicked(object sender, EventArgs e)
{
if (PickerClient.SelectedIndex == -1 || PickerChambre.SelectedIndex == -1)
{
await DisplayAlert("Erreur", "Veuillez sélectionner un client et une chambre", "OK");
return;
}
var reservation = new Models.Reservation
{
NbPersonnes = int.TryParse(EntryNbInvite.Text, out int nb) ? nb : 0,
ClientId = _clients[PickerClient.SelectedIndex].Id,
ChambreId = _chambres[PickerChambre.SelectedIndex].Id,
NbPersonnes = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : 0,
DateDebut = DatePickerDebut.Date,
DateFin = DatePickerFin.Date,
DemandeSpecifique = EntryDemandeSpecifique.Text
@ -28,4 +54,4 @@ namespace HegreHotel.Views.Reservation
await Navigation.PopAsync();
}
}
}
}

View File

@ -5,7 +5,10 @@
x:Class="HegreHotel.Views.Reservation.ModifierReservationPage"
Title="Modifier la Réservation">
<StackLayout Padding="10">
<Entry x:Name="EntryNbInvite" Placeholder="Nombre d'invités" Keyboard="Numeric"/>
<Picker x:Name="PickerClient" Title="Sélectionner un client"/>
<Picker x:Name="PickerChambre" Title="Sélectionner une chambre"/>
<Entry x:Name="EntryNbPersonne" Placeholder="Nombre d'invités" Keyboard="Numeric"/>
<DatePicker x:Name="DatePickerDebut" />
<DatePicker x:Name="DatePickerFin" />
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>

View File

@ -1,19 +1,40 @@
using HegreHotel.Models;
using Microsoft.Maui.Controls;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views.Reservation
{
public partial class ModifierReservationPage : ContentPage
{
Models.Reservation _reservation;
private Models.Reservation _reservation;
private List<Models.Client> _clients;
private List<Models.Chambre> _chambres;
public ModifierReservationPage(Models.Reservation reservation)
{
InitializeComponent();
_reservation = reservation;
// Préremplir les champs
EntryNbInvite.Text = _reservation.NbPersonnes.ToString();
LoadClientsAndChambres();
}
private async void LoadClientsAndChambres()
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
_clients = await db.Table<Models.Client>().ToListAsync();
_chambres = await db.Table<Models.Chambre>().ToListAsync();
PickerClient.ItemsSource = _clients.Select(c => $"{c.Nom} {c.Prenom}").ToList();
PickerChambre.ItemsSource = _chambres.Select(ch => ch.Nom).ToList();
PickerClient.SelectedIndex = _clients.FindIndex(c => c.Id == _reservation.ClientId);
PickerChambre.SelectedIndex = _chambres.FindIndex(ch => ch.Id == _reservation.ChambreId);
EntryNbPersonne.Text = _reservation.NbPersonnes.ToString();
DatePickerDebut.Date = _reservation.DateDebut;
DatePickerFin.Date = _reservation.DateFin;
EntryDemandeSpecifique.Text = _reservation.DemandeSpecifique;
@ -21,7 +42,15 @@ namespace HegreHotel.Views.Reservation
private async void OnEnregistrerClicked(object sender, EventArgs e)
{
_reservation.NbPersonnes = int.TryParse(EntryNbInvite.Text, out int nb) ? nb : _reservation.NbPersonnes;
if (PickerClient.SelectedIndex == -1 || PickerChambre.SelectedIndex == -1)
{
await DisplayAlert("Erreur", "Veuillez sélectionner un client et une chambre", "OK");
return;
}
_reservation.ClientId = _clients[PickerClient.SelectedIndex].Id;
_reservation.ChambreId = _chambres[PickerChambre.SelectedIndex].Id;
_reservation.NbPersonnes = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : _reservation.NbPersonnes;
_reservation.DateDebut = DatePickerDebut.Date;
_reservation.DateFin = DatePickerFin.Date;
_reservation.DemandeSpecifique = EntryDemandeSpecifique.Text;
@ -32,4 +61,4 @@ namespace HegreHotel.Views.Reservation
await Navigation.PopAsync();
}
}
}
}

View File

@ -6,19 +6,19 @@
Title="Gestion des Réservations"
Appearing="ReservationsPage_OnAppearing">
<StackLayout Padding="10">
<!-- Bouton pour ajouter une réservation -->
<Button Text="Ajouter Réservation"
Clicked="OnAjouterReservationClicked"
HorizontalOptions="Center"
Margin="0,10"/>
<!-- Liste des réservations -->
<ListView x:Name="ReservationsListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<!-- Affichage des infos de la réservation -->
<Label Text="{Binding NbInvite}"
VerticalOptions="Center"
WidthRequest="50"/>
@ -29,14 +29,12 @@
VerticalOptions="Center"
WidthRequest="100"/>
<!-- Bouton Modifier -->
<Button Text="Modifier"
CommandParameter="{Binding .}"
Clicked="OnModifierReservationClicked"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<!-- Bouton Supprimer -->
<Button Text="Supprimer"
CommandParameter="{Binding .}"
Clicked="OnSupprimerReservationClicked"