Compare commits
7 Commits
ad9727beec
...
9eb0330f33
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9eb0330f33 | ||
8168c8844d | |||
abad40c9f6 | |||
1cc7257f5f | |||
3a149b8b5e | |||
cab1fcacbf | |||
f9a764e550 |
10
App.xaml.cs
10
App.xaml.cs
@ -1,4 +1,6 @@
|
|||||||
namespace HegreHotel;
|
using HegreHotel.Views;
|
||||||
|
|
||||||
|
namespace HegreHotel;
|
||||||
|
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
@ -6,6 +8,8 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
MainPage = new AppShell();
|
Task.Run(async () => await Database.CreateDatabaseAsync()).Wait();
|
||||||
|
|
||||||
|
MainPage = new NavigationPage(new MainPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
Database.cs
Normal file
29
Database.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using HegreHotel.Models;
|
||||||
|
|
||||||
|
namespace HegreHotel
|
||||||
|
{
|
||||||
|
public class Database
|
||||||
|
{
|
||||||
|
public static async Task CreateDatabaseAsync()
|
||||||
|
{
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
|
||||||
|
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" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -57,9 +57,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="EntityFramework" Version="6.5.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
|
||||||
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
|
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
|
||||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
|
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
|
||||||
|
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,36 +1,25 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<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.MainPage">
|
x:Class="HegreHotel.MainPage"
|
||||||
|
Title="HegreHotel">
|
||||||
|
<StackLayout Padding="20" VerticalOptions="Center">
|
||||||
|
<Label Text="Bienvenue à HegreHotel"
|
||||||
|
FontSize="24"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0,20"/>
|
||||||
|
|
||||||
<ScrollView>
|
<Button Text="Gérer les Clients"
|
||||||
<VerticalStackLayout
|
Clicked="OnClientsClicked"
|
||||||
Padding="30,0"
|
Margin="0,10"/>
|
||||||
Spacing="25">
|
|
||||||
<Image
|
|
||||||
Source="dotnet_bot.png"
|
|
||||||
HeightRequest="185"
|
|
||||||
Aspect="AspectFit"
|
|
||||||
SemanticProperties.Description="dot net bot in a race car number eight" />
|
|
||||||
|
|
||||||
<Label
|
<Button Text="Gérer les Chambres"
|
||||||
Text="Hello, World!"
|
Clicked="OnChambresClicked"
|
||||||
Style="{StaticResource Headline}"
|
Margin="0,10"/>
|
||||||
SemanticProperties.HeadingLevel="Level1" />
|
|
||||||
|
|
||||||
<Label
|
|
||||||
Text="Welcome to .NET Multi-platform App UI"
|
|
||||||
Style="{StaticResource SubHeadline}"
|
|
||||||
SemanticProperties.HeadingLevel="Level2"
|
|
||||||
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
x:Name="CounterBtn"
|
|
||||||
Text="Click me"
|
|
||||||
SemanticProperties.Hint="Counts the number of times you click"
|
|
||||||
Clicked="OnCounterClicked"
|
|
||||||
HorizontalOptions="Fill" />
|
|
||||||
</VerticalStackLayout>
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
|
<Button Text="Gérer les Réservations"
|
||||||
|
Clicked="OnReservationsClicked"
|
||||||
|
Margin="0,10"/>
|
||||||
|
</StackLayout>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
|
@ -1,23 +1,31 @@
|
|||||||
namespace HegreHotel;
|
using HegreHotel.Views;
|
||||||
|
using HegreHotel.Views.Chambre;
|
||||||
|
using HegreHotel.Views.Client;
|
||||||
|
using HegreHotel.Views.Reservation;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
|
||||||
public partial class MainPage : ContentPage
|
namespace HegreHotel
|
||||||
{
|
{
|
||||||
int count = 0;
|
public partial class MainPage : ContentPage
|
||||||
|
|
||||||
public MainPage()
|
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
public MainPage()
|
||||||
}
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnCounterClicked(object sender, EventArgs e)
|
private async void OnClientsClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
count++;
|
await Navigation.PushAsync(new ClientsPage());
|
||||||
|
}
|
||||||
|
|
||||||
if (count == 1)
|
private async void OnChambresClicked(object sender, EventArgs e)
|
||||||
CounterBtn.Text = $"Clicked {count} time";
|
{
|
||||||
else
|
await Navigation.PushAsync(new ChambresPage());
|
||||||
CounterBtn.Text = $"Clicked {count} times";
|
}
|
||||||
|
|
||||||
SemanticScreenReader.Announce(CounterBtn.Text);
|
private async void OnReservationsClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new ReservationsPage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
24
Models/Chambre.cs
Normal file
24
Models/Chambre.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
namespace HegreHotel.Models;
|
||||||
|
|
||||||
|
using SQLite;
|
||||||
|
|
||||||
|
public class Chambre
|
||||||
|
{
|
||||||
|
[PrimaryKey, AutoIncrement]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(50)]
|
||||||
|
public string? Nom { get; set; }
|
||||||
|
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public decimal Tarif { get; set; }
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
23
Models/Client.cs
Normal file
23
Models/Client.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace HegreHotel.Models;
|
||||||
|
|
||||||
|
using SQLite;
|
||||||
|
|
||||||
|
public class Client
|
||||||
|
{
|
||||||
|
[PrimaryKey, AutoIncrement]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(100)]
|
||||||
|
public string? Nom { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(100)]
|
||||||
|
public string? Prenom { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(150), Unique]
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(15), Unique]
|
||||||
|
public string? Telephone { get; set; }
|
||||||
|
|
||||||
|
public override string ToString() => $"{Nom} {Prenom}";
|
||||||
|
}
|
21
Models/Reservation.cs
Normal file
21
Models/Reservation.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace HegreHotel.Models;
|
||||||
|
|
||||||
|
using SQLite;
|
||||||
|
|
||||||
|
public class Reservation
|
||||||
|
{
|
||||||
|
[PrimaryKey, AutoIncrement]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public DateTime DateDebut { get; set; }
|
||||||
|
|
||||||
|
public DateTime DateFin { get; set; }
|
||||||
|
|
||||||
|
public string? DemandeSpecifique { get; set; }
|
||||||
|
|
||||||
|
public int NbInvite { get; set; }
|
||||||
|
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
public int ChambreId { get; set; }
|
||||||
|
|
||||||
|
}
|
11
Models/Status.cs
Normal file
11
Models/Status.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace HegreHotel.Models;
|
||||||
|
|
||||||
|
using SQLite;
|
||||||
|
|
||||||
|
public class Status
|
||||||
|
{
|
||||||
|
[PrimaryKey, AutoIncrement]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string? Libelle { get; set; }
|
||||||
|
}
|
24
SingletonConnection.cs
Normal file
24
SingletonConnection.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using SQLite;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel
|
||||||
|
{
|
||||||
|
public class SingletonConnection : SQLiteAsyncConnection
|
||||||
|
{
|
||||||
|
private static SingletonConnection instance;
|
||||||
|
|
||||||
|
private SingletonConnection(string dbPath) : base(dbPath)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SingletonConnection GetInstance(string dbPath)
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new SingletonConnection(dbPath);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Views/Chambre/AjouterChambrePage.xaml
Normal file
14
Views/Chambre/AjouterChambrePage.xaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?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.AjouterChambrePage"
|
||||||
|
Title="Ajouter une Chambre">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Entry x:Name="EntryNom" Placeholder="Nom de la chambre"/>
|
||||||
|
<Entry x:Name="EntryDescription" Placeholder="Description"/>
|
||||||
|
<Entry x:Name="EntryTarif" Placeholder="Tarif" Keyboard="Numeric"/>
|
||||||
|
<Entry x:Name="EntryNbPersonne" Placeholder="Nombre de personnes" Keyboard="Numeric"/>
|
||||||
|
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
32
Views/Chambre/AjouterChambrePage.xaml.cs
Normal file
32
Views/Chambre/AjouterChambrePage.xaml.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Chambre
|
||||||
|
{
|
||||||
|
public partial class AjouterChambrePage : ContentPage
|
||||||
|
{
|
||||||
|
public AjouterChambrePage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var chambre = new Models.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,
|
||||||
|
StatusId = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.InsertAsync(chambre);
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
Views/Chambre/ChambresPage.xaml
Normal file
53
Views/Chambre/ChambresPage.xaml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?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"
|
||||||
|
Clicked="OnAjouterChambreClicked"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0,10"/>
|
||||||
|
|
||||||
|
<ListView x:Name="ChambresListView" HasUnevenRows="True">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ViewCell>
|
||||||
|
<StackLayout Orientation="Horizontal" Padding="5" Spacing="10">
|
||||||
|
<!-- Nom de la chambre -->
|
||||||
|
<Label Text="{Binding Nom}"
|
||||||
|
FontAttributes="Bold"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="120"/> <!-- Ajusté pour laisser de la place -->
|
||||||
|
|
||||||
|
<!-- Statut de la chambre -->
|
||||||
|
<Label Text="{Binding Status.Libelle}"
|
||||||
|
FontAttributes="Italic"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="100"/>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
138
Views/Chambre/ChambresPage.xaml.cs
Normal file
138
Views/Chambre/ChambresPage.xaml.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Chambre
|
||||||
|
{
|
||||||
|
public partial class ChambresPage : ContentPage
|
||||||
|
{
|
||||||
|
private ObservableCollection<Models.Chambre> _toutesLesChambres = new();
|
||||||
|
private List<Status> _statuts;
|
||||||
|
|
||||||
|
public ChambresPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
LoadChambresEtStatuts();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_toutesLesChambres.Add(chambre);
|
||||||
|
}
|
||||||
|
|
||||||
|
FiltrerChambres();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFiltreChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FiltrerChambres();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FiltrerChambres()
|
||||||
|
{
|
||||||
|
if (PickerFiltreStatus.SelectedIndex <= 0)
|
||||||
|
{
|
||||||
|
ChambresListView.ItemsSource = _toutesLesChambres;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnAjouterChambreClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new AjouterChambrePage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnModifierChambreClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Chambre chambre)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new ModifierChambrePage(chambre));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnSupprimerChambreClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.DeleteAsync(chambre);
|
||||||
|
LoadChambresEtStatuts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChambresPage_OnAppearing(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadChambresEtStatuts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Views/Chambre/ModifierChambrePage.xaml
Normal file
14
Views/Chambre/ModifierChambrePage.xaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?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.ModifierChambrePage"
|
||||||
|
Title="Modifier la Chambre">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Entry x:Name="EntryNom" Placeholder="Nom de la chambre"/>
|
||||||
|
<Entry x:Name="EntryDescription" Placeholder="Description"/>
|
||||||
|
<Entry x:Name="EntryTarif" Placeholder="Tarif" Keyboard="Numeric"/>
|
||||||
|
<Entry x:Name="EntryNbPersonne" Placeholder="Nombre de personnes" Keyboard="Numeric"/>
|
||||||
|
<Button Text="Enregistrer les modifications" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
35
Views/Chambre/ModifierChambrePage.xaml.cs
Normal file
35
Views/Chambre/ModifierChambrePage.xaml.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Chambre
|
||||||
|
{
|
||||||
|
public partial class ModifierChambrePage : ContentPage
|
||||||
|
{
|
||||||
|
Models.Chambre _chambre;
|
||||||
|
public ModifierChambrePage(Models.Chambre chambre)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_chambre = chambre;
|
||||||
|
|
||||||
|
EntryNom.Text = _chambre.Nom;
|
||||||
|
EntryDescription.Text = _chambre.Description;
|
||||||
|
EntryTarif.Text = _chambre.Tarif.ToString();
|
||||||
|
EntryNbPersonne.Text = _chambre.NbPersonne.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_chambre.Nom = EntryNom.Text;
|
||||||
|
_chambre.Description = EntryDescription.Text;
|
||||||
|
_chambre.Tarif = decimal.TryParse(EntryTarif.Text, out decimal tarif) ? tarif : _chambre.Tarif;
|
||||||
|
_chambre.NbPersonne = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : _chambre.NbPersonne;
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.UpdateAsync(_chambre);
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Views/Client/AjouterClientPage.xaml
Normal file
14
Views/Client/AjouterClientPage.xaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?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.AjouterClientPage"
|
||||||
|
Title="Ajouter un Client">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
|
||||||
|
<Entry x:Name="EntryPrenom" Placeholder="Prenom"/>
|
||||||
|
<Entry x:Name="EntryEmail" Placeholder="Email" />
|
||||||
|
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
|
||||||
|
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
31
Views/Client/AjouterClientPage.xaml.cs
Normal file
31
Views/Client/AjouterClientPage.xaml.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Client
|
||||||
|
{
|
||||||
|
public partial class AjouterClientPage : ContentPage
|
||||||
|
{
|
||||||
|
public AjouterClientPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var client = new Models.Client()
|
||||||
|
{
|
||||||
|
Nom = EntryNom.Text,
|
||||||
|
Prenom = EntryPrenom.Text,
|
||||||
|
Email = EntryEmail.Text,
|
||||||
|
Telephone = EntryTelephone.Text,
|
||||||
|
};
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.InsertAsync(client);
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
Views/Client/ClientsPage.xaml
Normal file
45
Views/Client/ClientsPage.xaml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?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"
|
||||||
|
Title="Gestion des Clients"
|
||||||
|
Appearing="ClientsPage_OnAppearing">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Button Text="Ajouter Client"
|
||||||
|
Clicked="OnAjouterClientClicked"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0,10"/>
|
||||||
|
|
||||||
|
<ListView x:Name="ClientsListView" HasUnevenRows="True">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ViewCell>
|
||||||
|
<StackLayout Orientation="Horizontal" Padding="5" Spacing="10">
|
||||||
|
<Label Text="{Binding Nom}"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
FontAttributes="Bold"
|
||||||
|
WidthRequest="100"/>
|
||||||
|
<Label Text="{Binding Prenom}"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="100"/>
|
||||||
|
<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>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
67
Views/Client/ClientsPage.xaml.cs
Normal file
67
Views/Client/ClientsPage.xaml.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Client
|
||||||
|
{
|
||||||
|
public partial class ClientsPage : ContentPage
|
||||||
|
{
|
||||||
|
public ObservableCollection<Models.Client> Clients { get; set; } = new ObservableCollection<Models.Client>();
|
||||||
|
|
||||||
|
public ClientsPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
LoadClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LoadClients()
|
||||||
|
{
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
var clientsList = await db.Table<Models.Client>().ToListAsync();
|
||||||
|
Clients.Clear();
|
||||||
|
foreach (var client in clientsList)
|
||||||
|
{
|
||||||
|
Clients.Add(client);
|
||||||
|
}
|
||||||
|
ClientsListView.ItemsSource = Clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new AjouterClientPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnModifierClientClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.DeleteAsync(client);
|
||||||
|
LoadClients();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ClientsPage_OnAppearing(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadClients();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Views/Client/ModifierClientPage.xaml
Normal file
14
Views/Client/ModifierClientPage.xaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?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.ModifierClientPage"
|
||||||
|
Title="Modifier le Client">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Entry x:Name="EntryNom" Placeholder="Nom du client"/>
|
||||||
|
<Entry x:Name="EntryPrenom" Placeholder="Prenom"/>
|
||||||
|
<Entry x:Name="EntryEmail" Placeholder="Email" />
|
||||||
|
<Entry x:Name="EntryTelephone" Placeholder="Téléphone" Keyboard="Numeric"/>
|
||||||
|
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
35
Views/Client/ModifierClientPage.xaml.cs
Normal file
35
Views/Client/ModifierClientPage.xaml.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Client
|
||||||
|
{
|
||||||
|
public partial class ModifierClientPage : ContentPage
|
||||||
|
{
|
||||||
|
Models.Client _client;
|
||||||
|
public ModifierClientPage(Models.Client client)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_client = client;
|
||||||
|
|
||||||
|
EntryNom.Text = _client.Nom;
|
||||||
|
EntryPrenom.Text = _client.Prenom;
|
||||||
|
EntryEmail.Text = _client.Email;
|
||||||
|
EntryTelephone.Text = _client.Telephone;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_client.Nom = EntryNom.Text;
|
||||||
|
_client.Prenom = EntryPrenom.Text;
|
||||||
|
_client.Email = EntryEmail.Text;
|
||||||
|
_client.Telephone = EntryTelephone.Text;
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.UpdateAsync(_client);
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
Views/Reservation/AjouterReservationPage.xaml
Normal file
32
Views/Reservation/AjouterReservationPage.xaml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?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.AjouterReservationPage"
|
||||||
|
Title="Ajouter une Réservation">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Label Text="Sélectionnez la période" FontAttributes="Bold"/>
|
||||||
|
<DatePicker x:Name="DatePickerDebut" />
|
||||||
|
<DatePicker x:Name="DatePickerFin" />
|
||||||
|
|
||||||
|
<Button Text="Vérifier Disponibilité"
|
||||||
|
Clicked="OnVerifierDisponibiliteClicked"
|
||||||
|
Margin="10,0"/>
|
||||||
|
|
||||||
|
<StackLayout x:Name="SelectionSection" IsVisible="False">
|
||||||
|
|
||||||
|
<Label Text="Sélectionnez un client" FontAttributes="Bold"/>
|
||||||
|
<Picker x:Name="PickerClient" Title="Sélectionner un client"/>
|
||||||
|
|
||||||
|
<Label Text="Sélectionnez une chambre disponible" FontAttributes="Bold"/>
|
||||||
|
<Picker x:Name="PickerChambre" Title="Sélectionner une chambre"/>
|
||||||
|
|
||||||
|
<Entry x:Name="EntryNbInvite" Placeholder="Nombre de personnes" Keyboard="Numeric"/>
|
||||||
|
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
||||||
|
|
||||||
|
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
|
</StackLayout>
|
||||||
|
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
||||||
|
|
86
Views/Reservation/AjouterReservationPage.xaml.cs
Normal file
86
Views/Reservation/AjouterReservationPage.xaml.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
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> _chambresDispo;
|
||||||
|
private bool _datesValidees = false;
|
||||||
|
|
||||||
|
public AjouterReservationPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnVerifierDisponibiliteClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (DatePickerDebut.Date > DatePickerFin.Date)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "La date de début doit être avant la date de fin.", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
|
||||||
|
var reservations = await db.Table<Models.Reservation>().ToListAsync();
|
||||||
|
var chambresReservees = reservations
|
||||||
|
.Where(r => !(DatePickerFin.Date <= r.DateDebut || DatePickerDebut.Date >= r.DateFin))
|
||||||
|
.Select(r => r.ChambreId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_chambresDispo = await db.Table<Models.Chambre>().Where(c => !chambresReservees.Contains(c.Id)).ToListAsync();
|
||||||
|
|
||||||
|
if (_chambresDispo.Count == 0)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Aucune chambre disponible", "Aucune chambre n'est disponible pour cette période.", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_clients = await db.Table<Models.Client>().ToListAsync();
|
||||||
|
PickerClient.ItemsSource = _clients.Select(c => $"{c.Nom} {c.Prenom}").ToList();
|
||||||
|
PickerChambre.ItemsSource = _chambresDispo.Select(ch => ch.Nom).ToList();
|
||||||
|
|
||||||
|
SelectionSection.IsVisible = true;
|
||||||
|
_datesValidees = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnEnregistrerClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!_datesValidees)
|
||||||
|
{
|
||||||
|
await DisplayAlert("Erreur", "Veuillez d'abord vérifier la disponibilité des chambres.", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
ClientId = _clients[PickerClient.SelectedIndex].Id,
|
||||||
|
ChambreId = _chambresDispo[PickerChambre.SelectedIndex].Id,
|
||||||
|
NbInvite = int.TryParse(EntryNbInvite.Text, out int nb) ? nb : 0,
|
||||||
|
DateDebut = DatePickerDebut.Date,
|
||||||
|
DateFin = DatePickerFin.Date,
|
||||||
|
DemandeSpecifique = EntryDemandeSpecifique.Text
|
||||||
|
};
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.InsertAsync(reservation);
|
||||||
|
|
||||||
|
await DisplayAlert("Succès", "Réservation ajoutée avec succès.", "OK");
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
Views/Reservation/ModifierReservationPage.xaml
Normal file
17
Views/Reservation/ModifierReservationPage.xaml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?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.ModifierReservationPage"
|
||||||
|
Title="Modifier la Réservation">
|
||||||
|
<StackLayout Padding="10">
|
||||||
|
<Picker x:Name="PickerClient" Title="Sélectionner un client"/>
|
||||||
|
<Picker x:Name="PickerChambre" Title="Sélectionner une chambre"/>
|
||||||
|
|
||||||
|
<Entry x:Name="EntryNbInvite" Placeholder="Nombre d'invités" Keyboard="Numeric"/>
|
||||||
|
<DatePicker x:Name="DatePickerDebut" />
|
||||||
|
<DatePicker x:Name="DatePickerFin" />
|
||||||
|
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
||||||
|
<Button Text="Enregistrer les modifications" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
64
Views/Reservation/ModifierReservationPage.xaml.cs
Normal file
64
Views/Reservation/ModifierReservationPage.xaml.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
private Models.Reservation _reservation;
|
||||||
|
private List<Models.Client> _clients;
|
||||||
|
private List<Models.Chambre> _chambres;
|
||||||
|
|
||||||
|
public ModifierReservationPage(Models.Reservation reservation)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_reservation = reservation;
|
||||||
|
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);
|
||||||
|
|
||||||
|
EntryNbInvite.Text = _reservation.NbInvite.ToString();
|
||||||
|
DatePickerDebut.Date = _reservation.DateDebut;
|
||||||
|
DatePickerFin.Date = _reservation.DateFin;
|
||||||
|
EntryDemandeSpecifique.Text = _reservation.DemandeSpecifique;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
_reservation.ClientId = _clients[PickerClient.SelectedIndex].Id;
|
||||||
|
_reservation.ChambreId = _chambres[PickerChambre.SelectedIndex].Id;
|
||||||
|
_reservation.NbInvite = int.TryParse(EntryNbInvite.Text, out int nb) ? nb : _reservation.NbInvite;
|
||||||
|
_reservation.DateDebut = DatePickerDebut.Date;
|
||||||
|
_reservation.DateFin = DatePickerFin.Date;
|
||||||
|
_reservation.DemandeSpecifique = EntryDemandeSpecifique.Text;
|
||||||
|
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.UpdateAsync(_reservation);
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
Views/Reservation/ReservationsPage.xaml
Normal file
48
Views/Reservation/ReservationsPage.xaml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?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" Spacing="10">
|
||||||
|
<Label Text="{Binding NbInvite}"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="50"/>
|
||||||
|
<Label Text="{Binding DateDebut, StringFormat='{0:dd/MM/yyyy}'}"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="100"/>
|
||||||
|
<Label Text="{Binding DateFin, StringFormat='{0:dd/MM/yyyy}'}"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="100"/>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
65
Views/Reservation/ReservationsPage.xaml.cs
Normal file
65
Views/Reservation/ReservationsPage.xaml.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using HegreHotel.Models;
|
||||||
|
using Microsoft.Maui.Controls;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Maui.Storage;
|
||||||
|
|
||||||
|
namespace HegreHotel.Views.Reservation
|
||||||
|
{
|
||||||
|
public partial class ReservationsPage : ContentPage
|
||||||
|
{
|
||||||
|
public ObservableCollection<Models.Reservation> Reservations { get; set; } = new ObservableCollection<Models.Reservation>();
|
||||||
|
|
||||||
|
public ReservationsPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
LoadReservations();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LoadReservations()
|
||||||
|
{
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
var reservationsList = await db.Table<Models.Reservation>().ToListAsync();
|
||||||
|
Reservations.Clear();
|
||||||
|
foreach (var reservation in reservationsList)
|
||||||
|
{
|
||||||
|
Reservations.Add(reservation);
|
||||||
|
}
|
||||||
|
ReservationsListView.ItemsSource = Reservations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnAjouterReservationClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new AjouterReservationPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnModifierReservationClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Reservation reservation)
|
||||||
|
{
|
||||||
|
await Navigation.PushAsync(new ModifierReservationPage(reservation));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnSupprimerReservationClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
|
await db.DeleteAsync(reservation);
|
||||||
|
LoadReservations();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReservationsPage_OnAppearing(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadReservations();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user