Compare commits

...

3 Commits

Author SHA1 Message Date
3a149b8b5e Status added and crash resolved 2025-03-18 09:00:39 +01:00
cab1fcacbf Big commit 2025-03-13 17:49:25 +01:00
f9a764e550 ajout entités et premiere page 2025-01-16 17:50:56 +01:00
28 changed files with 898 additions and 48 deletions

View File

@ -1,4 +1,6 @@
namespace HegreHotel;
using HegreHotel.Views;
namespace HegreHotel;
public partial class App : Application
{
@ -6,6 +8,8 @@ public partial class App : Application
{
InitializeComponent();
MainPage = new AppShell();
Task.Run(async () => await Database.CreateDatabaseAsync()).Wait();
MainPage = new NavigationPage(new MainPage());
}
}
}

29
Database.cs Normal file
View 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" });
}
}
}
}

View File

@ -57,9 +57,17 @@
</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.Compatibility" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project>

View File

@ -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"
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>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Image
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />
<Button Text="Gérer les Clients"
Clicked="OnClientsClicked"
Margin="0,10"/>
<Label
Text="Hello, World!"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label
Text="Welcome to &#10;.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 Chambres"
Clicked="OnChambresClicked"
Margin="0,10"/>
<Button Text="Gérer les Réservations"
Clicked="OnReservationsClicked"
Margin="0,10"/>
</StackLayout>
</ContentPage>

View File

@ -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 MainPage()
public partial class MainPage : ContentPage
{
InitializeComponent();
}
public MainPage()
{
InitializeComponent();
}
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
private async void OnClientsClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new ClientsPage());
}
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
private async void OnChambresClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new ChambresPage());
}
SemanticScreenReader.Announce(CounterBtn.Text);
private async void OnReservationsClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new ReservationsPage());
}
}
}

20
Models/Chambre.cs Normal file
View File

@ -0,0 +1,20 @@
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; }
}

23
Models/Client.cs Normal file
View 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
View 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 NbPersonnes { get; set; }
public int ClientId { get; set; }
public int ChambreId { get; set; }
}

11
Models/Status.cs Normal file
View 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
View 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;
}
}
}

View 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>

View 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();
}
}
}

View File

@ -0,0 +1,47 @@
<?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">
<Label Text="{Binding Nom}"
FontAttributes="Bold"
WidthRequest="100"/>
<Label Text="{Binding Description}"
WidthRequest="150"/>
<Label Text="{Binding Status.Libelle}"
TextColor="Gray"/>
<Button Text="Modifier"
CommandParameter="{Binding .}"
Clicked="OnModifierChambreClicked"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<Button Text="Supprimer"
CommandParameter="{Binding .}"
Clicked="OnSupprimerChambreClicked"
HorizontalOptions="End"
Margin="5,0"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

View File

@ -0,0 +1,95 @@
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
{
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();
_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
{
var statutSelectionne = _statuts[PickerFiltreStatus.SelectedIndex - 1].Id;
ChambresListView.ItemsSource = _toutesLesChambres.Where(c => c.StatusId == statutSelectionne).ToList();
}
}
private async void OnAjouterChambreClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new AjouterChambrePage());
}
private async void OnModifierChambreClicked(object sender, EventArgs e)
{
var chambre = ((Button)sender).CommandParameter as Models.Chambre;
if (chambre != null)
{
await Navigation.PushAsync(new ModifierChambrePage(chambre));
}
}
private async void OnSupprimerChambreClicked(object sender, EventArgs e)
{
var chambre = ((Button)sender).CommandParameter as Models.Chambre;
if (chambre != null)
{
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();
}
}
}

View 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>

View 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();
}
}
}

View 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>

View 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();
}
}
}

View File

@ -0,0 +1,44 @@
<?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">
<Label Text="{Binding Nom}"
VerticalOptions="Center"
FontAttributes="Bold"
WidthRequest="100"/>
<Label Text="{Binding Prenom}"
VerticalOptions="Center"
WidthRequest="100"/>
<Button Text="Modifier"
Clicked="OnModifierClientClicked"
CommandParameter="{Binding .}"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<Button Text="Supprimer"
Clicked="OnSupprimerClientClicked"
CommandParameter="{Binding .}"
HorizontalOptions="End"
Margin="5,0"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

View 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)
{
var client = ((Button)sender).CommandParameter as Models.Client;
if (client != null)
{
await Navigation.PushAsync(new ModifierClientPage(client));
}
}
private async void OnSupprimerClientClicked(object sender, EventArgs e)
{
var client = ((Button)sender).CommandParameter as Models.Client;
if (client != null)
{
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();
}
}
}

View 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>

View 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();
}
}
}

View 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.AjouterReservationPage"
Title="Ajouter une 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="EntryNbPersonne" 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" Clicked="OnEnregistrerClicked" Margin="0,20"/>
</StackLayout>
</ContentPage>

View File

@ -0,0 +1,57 @@
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
{
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
};
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
await db.InsertAsync(reservation);
await Navigation.PopAsync();
}
}
}

View 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="EntryNbPersonne" 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>

View 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);
EntryNbPersonne.Text = _reservation.NbPersonnes.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.NbPersonnes = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : _reservation.NbPersonnes;
_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();
}
}
}

View File

@ -0,0 +1,49 @@
<?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">
<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"/>
<Button Text="Modifier"
CommandParameter="{Binding .}"
Clicked="OnModifierReservationClicked"
HorizontalOptions="EndAndExpand"
Margin="5,0"/>
<Button Text="Supprimer"
CommandParameter="{Binding .}"
Clicked="OnSupprimerReservationClicked"
HorizontalOptions="End"
Margin="5,0"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

View 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.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)
{
var reservation = ((Button)sender).CommandParameter as Models.Reservation;
if (reservation != null)
{
await Navigation.PushAsync(new ModifierReservationPage(reservation));
}
}
private async void OnSupprimerReservationClicked(object sender, EventArgs e)
{
var reservation = ((Button)sender).CommandParameter as Models.Reservation;
if (reservation != null)
{
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();
}
}
}