Status added and crash resolved
This commit is contained in:
parent
cab1fcacbf
commit
3a149b8b5e
12
Database.cs
12
Database.cs
@ -9,17 +9,21 @@ namespace HegreHotel
|
|||||||
{
|
{
|
||||||
public static async Task CreateDatabaseAsync()
|
public static async Task CreateDatabaseAsync()
|
||||||
{
|
{
|
||||||
// Construction du chemin de la BDD dans le dossier AppData
|
|
||||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
|
||||||
// Récupération de l'instance unique du Singleton
|
|
||||||
var db = SingletonConnection.GetInstance(dbPath);
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
|
||||||
// Création des tables
|
|
||||||
await db.CreateTableAsync<Client>();
|
await db.CreateTableAsync<Client>();
|
||||||
await db.CreateTableAsync<Reservation>();
|
await db.CreateTableAsync<Reservation>();
|
||||||
await db.CreateTableAsync<Chambre>();
|
await db.CreateTableAsync<Chambre>();
|
||||||
await db.CreateTableAsync<Status>();
|
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" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using HegreHotel.Views;
|
using HegreHotel.Views;
|
||||||
using HegreHotel.Views.Chambre;
|
using HegreHotel.Views.Chambre;
|
||||||
|
using HegreHotel.Views.Client;
|
||||||
using HegreHotel.Views.Reservation;
|
using HegreHotel.Views.Reservation;
|
||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
|
|
||||||
|
@ -15,4 +15,6 @@ public class Chambre
|
|||||||
public decimal Tarif { get; set; }
|
public decimal Tarif { get; set; }
|
||||||
|
|
||||||
public int NbPersonne { get; set; }
|
public int NbPersonne { get; set; }
|
||||||
|
|
||||||
|
public int StatusId { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,7 @@ public class Reservation
|
|||||||
|
|
||||||
public int NbPersonnes { get; set; }
|
public int NbPersonnes { get; set; }
|
||||||
|
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
public int ChambreId { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ public class Status
|
|||||||
{
|
{
|
||||||
[PrimaryKey, AutoIncrement]
|
[PrimaryKey, AutoIncrement]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[MaxLength(50), Unique]
|
|
||||||
public string? Libelle { get; set; }
|
public string? Libelle { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,12 @@ namespace HegreHotel
|
|||||||
{
|
{
|
||||||
public class SingletonConnection : SQLiteAsyncConnection
|
public class SingletonConnection : SQLiteAsyncConnection
|
||||||
{
|
{
|
||||||
// Instance unique de la connexion
|
|
||||||
private static SingletonConnection instance;
|
private static SingletonConnection instance;
|
||||||
|
|
||||||
// Constructeur privé qui appelle le constructeur parent avec le chemin de la BDD
|
|
||||||
private SingletonConnection(string dbPath) : base(dbPath)
|
private SingletonConnection(string dbPath) : base(dbPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Point d'accès global à l'instance
|
|
||||||
public static SingletonConnection GetInstance(string dbPath)
|
public static SingletonConnection GetInstance(string dbPath)
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
|
@ -19,7 +19,8 @@ namespace HegreHotel.Views.Chambre
|
|||||||
Nom = EntryNom.Text,
|
Nom = EntryNom.Text,
|
||||||
Description = EntryDescription.Text,
|
Description = EntryDescription.Text,
|
||||||
Tarif = decimal.TryParse(EntryTarif.Text, out decimal tarif) ? tarif : 0,
|
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");
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
@ -6,35 +6,33 @@
|
|||||||
Title="Gestion des Chambres"
|
Title="Gestion des Chambres"
|
||||||
Appearing="ChambresPage_OnAppearing">
|
Appearing="ChambresPage_OnAppearing">
|
||||||
<StackLayout Padding="10">
|
<StackLayout Padding="10">
|
||||||
<!-- Bouton pour ajouter une chambre -->
|
|
||||||
|
<Picker x:Name="PickerFiltreStatus" Title="Filtrer par statut" SelectedIndexChanged="OnFiltreChanged"/>
|
||||||
|
|
||||||
<Button Text="Ajouter Chambre"
|
<Button Text="Ajouter Chambre"
|
||||||
Clicked="OnAjouterChambreClicked"
|
Clicked="OnAjouterChambreClicked"
|
||||||
HorizontalOptions="Center"
|
HorizontalOptions="Center"
|
||||||
Margin="0,10"/>
|
Margin="0,10"/>
|
||||||
|
|
||||||
<!-- Liste des chambres -->
|
|
||||||
<ListView x:Name="ChambresListView" HasUnevenRows="True">
|
<ListView x:Name="ChambresListView" HasUnevenRows="True">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
<StackLayout Orientation="Horizontal" Padding="5">
|
<StackLayout Orientation="Horizontal" Padding="5">
|
||||||
<!-- Affichage des informations de la chambre -->
|
|
||||||
<Label Text="{Binding Nom}"
|
<Label Text="{Binding Nom}"
|
||||||
VerticalOptions="Center"
|
|
||||||
FontAttributes="Bold"
|
FontAttributes="Bold"
|
||||||
WidthRequest="100"/>
|
WidthRequest="100"/>
|
||||||
<Label Text="{Binding Description}"
|
<Label Text="{Binding Description}"
|
||||||
VerticalOptions="Center"
|
|
||||||
WidthRequest="150"/>
|
WidthRequest="150"/>
|
||||||
|
<Label Text="{Binding Status.Libelle}"
|
||||||
<!-- Bouton Modifier -->
|
TextColor="Gray"/>
|
||||||
|
|
||||||
<Button Text="Modifier"
|
<Button Text="Modifier"
|
||||||
CommandParameter="{Binding .}"
|
CommandParameter="{Binding .}"
|
||||||
Clicked="OnModifierChambreClicked"
|
Clicked="OnModifierChambreClicked"
|
||||||
HorizontalOptions="EndAndExpand"
|
HorizontalOptions="EndAndExpand"
|
||||||
Margin="5,0"/>
|
Margin="5,0"/>
|
||||||
|
|
||||||
<!-- Bouton Supprimer -->
|
|
||||||
<Button Text="Supprimer"
|
<Button Text="Supprimer"
|
||||||
CommandParameter="{Binding .}"
|
CommandParameter="{Binding .}"
|
||||||
Clicked="OnSupprimerChambreClicked"
|
Clicked="OnSupprimerChambreClicked"
|
||||||
|
@ -2,31 +2,59 @@ using HegreHotel.Models;
|
|||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Maui.Storage;
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace HegreHotel.Views.Chambre
|
namespace HegreHotel.Views.Chambre
|
||||||
{
|
{
|
||||||
public partial class ChambresPage : ContentPage
|
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()
|
public ChambresPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
LoadChambres();
|
LoadChambresEtStatuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void LoadChambres()
|
private async void LoadChambresEtStatuts()
|
||||||
{
|
{
|
||||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
var db = SingletonConnection.GetInstance(dbPath);
|
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 chambresList = await db.Table<Models.Chambre>().ToListAsync();
|
||||||
Chambres.Clear();
|
_toutesLesChambres.Clear();
|
||||||
foreach (var chambre in chambresList)
|
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)
|
private async void OnAjouterChambreClicked(object sender, EventArgs e)
|
||||||
@ -54,14 +82,14 @@ namespace HegreHotel.Views.Chambre
|
|||||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
var db = SingletonConnection.GetInstance(dbPath);
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
await db.DeleteAsync(chambre);
|
await db.DeleteAsync(chambre);
|
||||||
LoadChambres();
|
LoadChambresEtStatuts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChambresPage_OnAppearing(object? sender, EventArgs e)
|
private void ChambresPage_OnAppearing(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadChambres();
|
LoadChambresEtStatuts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace HegreHotel.Views.Chambre
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_chambre = chambre;
|
_chambre = chambre;
|
||||||
// Préremplissage des champs
|
|
||||||
EntryNom.Text = _chambre.Nom;
|
EntryNom.Text = _chambre.Nom;
|
||||||
EntryDescription.Text = _chambre.Description;
|
EntryDescription.Text = _chambre.Description;
|
||||||
EntryTarif.Text = _chambre.Tarif.ToString();
|
EntryTarif.Text = _chambre.Tarif.ToString();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="HegreHotel.Views.AjouterClientPage"
|
x:Class="HegreHotel.Views.Client.AjouterClientPage"
|
||||||
Title="Ajouter un Client">
|
Title="Ajouter un Client">
|
||||||
<StackLayout Padding="10">
|
<StackLayout Padding="10">
|
||||||
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
|
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
|
||||||
@ -11,4 +11,4 @@
|
|||||||
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
|
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
|
||||||
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage>
|
</ContentPage>
|
@ -3,7 +3,7 @@ using Microsoft.Maui.Controls;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.Maui.Storage;
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace HegreHotel.Views
|
namespace HegreHotel.Views.Client
|
||||||
{
|
{
|
||||||
public partial class AjouterClientPage : ContentPage
|
public partial class AjouterClientPage : ContentPage
|
||||||
{
|
{
|
||||||
@ -14,7 +14,7 @@ namespace HegreHotel.Views
|
|||||||
|
|
||||||
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var client = new Client()
|
var client = new Models.Client()
|
||||||
{
|
{
|
||||||
Nom = EntryNom.Text,
|
Nom = EntryNom.Text,
|
||||||
Prenom = EntryPrenom.Text,
|
Prenom = EntryPrenom.Text,
|
@ -2,23 +2,20 @@
|
|||||||
|
|
||||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="HegreHotel.Views.ClientsPage"
|
x:Class="HegreHotel.Views.Client.ClientsPage"
|
||||||
Title="Gestion des Clients"
|
Title="Gestion des Clients"
|
||||||
Appearing="ClientsPage_OnAppearing">
|
Appearing="ClientsPage_OnAppearing">
|
||||||
<StackLayout Padding="10">
|
<StackLayout Padding="10">
|
||||||
<!-- Bouton pour ajouter un client -->
|
|
||||||
<Button Text="Ajouter Client"
|
<Button Text="Ajouter Client"
|
||||||
Clicked="OnAjouterClientClicked"
|
Clicked="OnAjouterClientClicked"
|
||||||
HorizontalOptions="Center"
|
HorizontalOptions="Center"
|
||||||
Margin="0,10"/>
|
Margin="0,10"/>
|
||||||
|
|
||||||
<!-- Liste des clients -->
|
|
||||||
<ListView x:Name="ClientsListView" HasUnevenRows="True">
|
<ListView x:Name="ClientsListView" HasUnevenRows="True">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
<StackLayout Orientation="Horizontal" Padding="5">
|
<StackLayout Orientation="Horizontal" Padding="5">
|
||||||
<!-- Affichage des infos du client -->
|
|
||||||
<Label Text="{Binding Nom}"
|
<Label Text="{Binding Nom}"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
FontAttributes="Bold"
|
FontAttributes="Bold"
|
||||||
@ -27,14 +24,12 @@
|
|||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
WidthRequest="100"/>
|
WidthRequest="100"/>
|
||||||
|
|
||||||
<!-- Bouton Modifier -->
|
|
||||||
<Button Text="Modifier"
|
<Button Text="Modifier"
|
||||||
Clicked="OnModifierClientClicked"
|
Clicked="OnModifierClientClicked"
|
||||||
CommandParameter="{Binding .}"
|
CommandParameter="{Binding .}"
|
||||||
HorizontalOptions="EndAndExpand"
|
HorizontalOptions="EndAndExpand"
|
||||||
Margin="5,0"/>
|
Margin="5,0"/>
|
||||||
|
|
||||||
<!-- Bouton Supprimer -->
|
|
||||||
<Button Text="Supprimer"
|
<Button Text="Supprimer"
|
||||||
Clicked="OnSupprimerClientClicked"
|
Clicked="OnSupprimerClientClicked"
|
||||||
CommandParameter="{Binding .}"
|
CommandParameter="{Binding .}"
|
@ -4,11 +4,11 @@ using System.Collections.ObjectModel;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.Maui.Storage;
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace HegreHotel.Views
|
namespace HegreHotel.Views.Client
|
||||||
{
|
{
|
||||||
public partial class ClientsPage : ContentPage
|
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()
|
public ClientsPage()
|
||||||
{
|
{
|
||||||
@ -16,12 +16,11 @@ namespace HegreHotel.Views
|
|||||||
LoadClients();
|
LoadClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chargement des clients depuis la BDD
|
|
||||||
private async void LoadClients()
|
private async void LoadClients()
|
||||||
{
|
{
|
||||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
var db = SingletonConnection.GetInstance(dbPath);
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
var clientsList = await db.Table<Client>().ToListAsync();
|
var clientsList = await db.Table<Models.Client>().ToListAsync();
|
||||||
Clients.Clear();
|
Clients.Clear();
|
||||||
foreach (var client in clientsList)
|
foreach (var client in clientsList)
|
||||||
{
|
{
|
||||||
@ -30,26 +29,23 @@ namespace HegreHotel.Views
|
|||||||
ClientsListView.ItemsSource = Clients;
|
ClientsListView.ItemsSource = Clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirige vers la page d'ajout de client
|
|
||||||
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Navigation.PushAsync(new AjouterClientPage());
|
await Navigation.PushAsync(new AjouterClientPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirige vers la page de modification du client sélectionné
|
|
||||||
private async void OnModifierClientClicked(object sender, EventArgs e)
|
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)
|
if (client != null)
|
||||||
{
|
{
|
||||||
await Navigation.PushAsync(new ModifierClientPage(client));
|
await Navigation.PushAsync(new ModifierClientPage(client));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppression du client après confirmation
|
|
||||||
private async void OnSupprimerClientClicked(object sender, EventArgs e)
|
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)
|
if (client != null)
|
||||||
{
|
{
|
||||||
bool confirmation = await DisplayAlert("Suppression", "Voulez-vous vraiment supprimer ce client ?", "Oui", "Non");
|
bool confirmation = await DisplayAlert("Suppression", "Voulez-vous vraiment supprimer ce client ?", "Oui", "Non");
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="HegreHotel.Views.ModifierClientPage"
|
x:Class="HegreHotel.Views.Client.ModifierClientPage"
|
||||||
Title="Modifier le Client">
|
Title="Modifier le Client">
|
||||||
<StackLayout Padding="10">
|
<StackLayout Padding="10">
|
||||||
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
|
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
|
||||||
@ -11,4 +11,4 @@
|
|||||||
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
|
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
|
||||||
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage>
|
</ContentPage>
|
@ -3,16 +3,16 @@ using Microsoft.Maui.Controls;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.Maui.Storage;
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace HegreHotel.Views
|
namespace HegreHotel.Views.Client
|
||||||
{
|
{
|
||||||
public partial class ModifierClientPage : ContentPage
|
public partial class ModifierClientPage : ContentPage
|
||||||
{
|
{
|
||||||
Client _client;
|
Models.Client _client;
|
||||||
public ModifierClientPage(Client client)
|
public ModifierClientPage(Models.Client client)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_client = client;
|
_client = client;
|
||||||
// Préremplissage des champs
|
|
||||||
EntryNom.Text = _client.Nom;
|
EntryNom.Text = _client.Nom;
|
||||||
EntryPrenom.Text = _client.Prenom;
|
EntryPrenom.Text = _client.Prenom;
|
||||||
EntryEmail.Text = _client.Email;
|
EntryEmail.Text = _client.Email;
|
@ -5,7 +5,10 @@
|
|||||||
x:Class="HegreHotel.Views.Reservation.AjouterReservationPage"
|
x:Class="HegreHotel.Views.Reservation.AjouterReservationPage"
|
||||||
Title="Ajouter une Réservation">
|
Title="Ajouter une Réservation">
|
||||||
<StackLayout Padding="10">
|
<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="DatePickerDebut" />
|
||||||
<DatePicker x:Name="DatePickerFin" />
|
<DatePicker x:Name="DatePickerFin" />
|
||||||
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
||||||
|
@ -1,22 +1,48 @@
|
|||||||
using HegreHotel.Models;
|
using HegreHotel.Models;
|
||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Maui.Storage;
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace HegreHotel.Views.Reservation
|
namespace HegreHotel.Views.Reservation
|
||||||
{
|
{
|
||||||
public partial class AjouterReservationPage : ContentPage
|
public partial class AjouterReservationPage : ContentPage
|
||||||
{
|
{
|
||||||
|
private List<Models.Client> _clients;
|
||||||
|
private List<Models.Chambre> _chambres;
|
||||||
|
|
||||||
public AjouterReservationPage()
|
public AjouterReservationPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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)
|
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
|
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,
|
DateDebut = DatePickerDebut.Date,
|
||||||
DateFin = DatePickerFin.Date,
|
DateFin = DatePickerFin.Date,
|
||||||
DemandeSpecifique = EntryDemandeSpecifique.Text
|
DemandeSpecifique = EntryDemandeSpecifique.Text
|
||||||
@ -28,4 +54,4 @@ namespace HegreHotel.Views.Reservation
|
|||||||
await Navigation.PopAsync();
|
await Navigation.PopAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
x:Class="HegreHotel.Views.Reservation.ModifierReservationPage"
|
x:Class="HegreHotel.Views.Reservation.ModifierReservationPage"
|
||||||
Title="Modifier la Réservation">
|
Title="Modifier la Réservation">
|
||||||
<StackLayout Padding="10">
|
<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="DatePickerDebut" />
|
||||||
<DatePicker x:Name="DatePickerFin" />
|
<DatePicker x:Name="DatePickerFin" />
|
||||||
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
||||||
|
@ -1,19 +1,40 @@
|
|||||||
using HegreHotel.Models;
|
using HegreHotel.Models;
|
||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.Maui.Storage;
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
namespace HegreHotel.Views.Reservation
|
namespace HegreHotel.Views.Reservation
|
||||||
{
|
{
|
||||||
public partial class ModifierReservationPage : ContentPage
|
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)
|
public ModifierReservationPage(Models.Reservation reservation)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_reservation = reservation;
|
_reservation = reservation;
|
||||||
// Préremplir les champs
|
LoadClientsAndChambres();
|
||||||
EntryNbInvite.Text = _reservation.NbPersonnes.ToString();
|
}
|
||||||
|
|
||||||
|
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;
|
DatePickerDebut.Date = _reservation.DateDebut;
|
||||||
DatePickerFin.Date = _reservation.DateFin;
|
DatePickerFin.Date = _reservation.DateFin;
|
||||||
EntryDemandeSpecifique.Text = _reservation.DemandeSpecifique;
|
EntryDemandeSpecifique.Text = _reservation.DemandeSpecifique;
|
||||||
@ -21,7 +42,15 @@ namespace HegreHotel.Views.Reservation
|
|||||||
|
|
||||||
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
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.DateDebut = DatePickerDebut.Date;
|
||||||
_reservation.DateFin = DatePickerFin.Date;
|
_reservation.DateFin = DatePickerFin.Date;
|
||||||
_reservation.DemandeSpecifique = EntryDemandeSpecifique.Text;
|
_reservation.DemandeSpecifique = EntryDemandeSpecifique.Text;
|
||||||
@ -32,4 +61,4 @@ namespace HegreHotel.Views.Reservation
|
|||||||
await Navigation.PopAsync();
|
await Navigation.PopAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,19 @@
|
|||||||
Title="Gestion des Réservations"
|
Title="Gestion des Réservations"
|
||||||
Appearing="ReservationsPage_OnAppearing">
|
Appearing="ReservationsPage_OnAppearing">
|
||||||
<StackLayout Padding="10">
|
<StackLayout Padding="10">
|
||||||
<!-- Bouton pour ajouter une réservation -->
|
|
||||||
<Button Text="Ajouter Réservation"
|
<Button Text="Ajouter Réservation"
|
||||||
Clicked="OnAjouterReservationClicked"
|
Clicked="OnAjouterReservationClicked"
|
||||||
HorizontalOptions="Center"
|
HorizontalOptions="Center"
|
||||||
Margin="0,10"/>
|
Margin="0,10"/>
|
||||||
|
|
||||||
<!-- Liste des réservations -->
|
|
||||||
<ListView x:Name="ReservationsListView" HasUnevenRows="True">
|
<ListView x:Name="ReservationsListView" HasUnevenRows="True">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<ViewCell>
|
||||||
<StackLayout Orientation="Horizontal" Padding="5">
|
<StackLayout Orientation="Horizontal" Padding="5">
|
||||||
<!-- Affichage des infos de la réservation -->
|
|
||||||
<Label Text="{Binding NbInvite}"
|
<Label Text="{Binding NbInvite}"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
WidthRequest="50"/>
|
WidthRequest="50"/>
|
||||||
@ -29,14 +29,12 @@
|
|||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
WidthRequest="100"/>
|
WidthRequest="100"/>
|
||||||
|
|
||||||
<!-- Bouton Modifier -->
|
|
||||||
<Button Text="Modifier"
|
<Button Text="Modifier"
|
||||||
CommandParameter="{Binding .}"
|
CommandParameter="{Binding .}"
|
||||||
Clicked="OnModifierReservationClicked"
|
Clicked="OnModifierReservationClicked"
|
||||||
HorizontalOptions="EndAndExpand"
|
HorizontalOptions="EndAndExpand"
|
||||||
Margin="5,0"/>
|
Margin="5,0"/>
|
||||||
|
|
||||||
<!-- Bouton Supprimer -->
|
|
||||||
<Button Text="Supprimer"
|
<Button Text="Supprimer"
|
||||||
CommandParameter="{Binding .}"
|
CommandParameter="{Binding .}"
|
||||||
Clicked="OnSupprimerReservationClicked"
|
Clicked="OnSupprimerReservationClicked"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user