Compare commits
4 Commits
3a149b8b5e
...
76e4e68799
Author | SHA1 | Date | |
---|---|---|---|
76e4e68799 | |||
8168c8844d | |||
abad40c9f6 | |||
1cc7257f5f |
@ -66,8 +66,4 @@
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -13,7 +13,7 @@ public class Reservation
|
||||
|
||||
public string? DemandeSpecifique { get; set; }
|
||||
|
||||
public int NbPersonnes { get; set; }
|
||||
public int NbInvite { get; set; }
|
||||
|
||||
public int ClientId { get; set; }
|
||||
public int ChambreId { get; set; }
|
||||
|
@ -11,7 +11,7 @@
|
||||
HorizontalOptions="Center"
|
||||
Margin="0,10"/>
|
||||
|
||||
<ListView x:Name="ClientsListView" HasUnevenRows="True">
|
||||
<ListView x:Name="ClientsListView" HasUnevenRows="True" ItemTapped="OnClientTapped">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
@ -40,5 +40,7 @@
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
|
||||
</StackLayout>
|
||||
</ContentPage>
|
||||
|
@ -27,6 +27,7 @@ namespace HegreHotel.Views.Client
|
||||
Clients.Add(client);
|
||||
}
|
||||
ClientsListView.ItemsSource = Clients;
|
||||
|
||||
}
|
||||
|
||||
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
||||
@ -63,5 +64,20 @@ namespace HegreHotel.Views.Client
|
||||
{
|
||||
LoadClients();
|
||||
}
|
||||
|
||||
private async void OnClientTapped(object sender, ItemTappedEventArgs e)
|
||||
{
|
||||
if (e.Item != null)
|
||||
{
|
||||
// Désélectionne l'élément tappé
|
||||
((ListView)sender).SelectedItem = null;
|
||||
|
||||
// Récupère le client sélectionné
|
||||
var client = e.Item as Models.Client;
|
||||
|
||||
// Navigue vers la page de détails du client
|
||||
await Navigation.PushAsync(new DetailsClientPage(client));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
Views/Client/DetailsClientPage.xaml
Normal file
35
Views/Client/DetailsClientPage.xaml
Normal file
@ -0,0 +1,35 @@
|
||||
<?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.DetailsClientPage">
|
||||
<ContentPage.Content>
|
||||
<ScrollView>
|
||||
<StackLayout Padding="10" Spacing="5">
|
||||
<HorizontalStackLayout Spacing="5">
|
||||
<Label Text="{Binding Nom}" FontAttributes="Bold" FontSize="18"/>
|
||||
<Label Text="{Binding Prenom}" FontSize="18"/>
|
||||
</HorizontalStackLayout>
|
||||
<VerticalStackLayout>
|
||||
<Label Text="{Binding Email}"/>
|
||||
<Label Text="{Binding Telephone}"/>
|
||||
</VerticalStackLayout>
|
||||
<Label Text="Historique des réservations :" FontAttributes="Bold" FontSize="Large"/>
|
||||
<ListView x:Name="ListeReservations">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout Orientation="Horizontal" Padding="5" Spacing="10">
|
||||
<Label Text="{Binding DateDebut, StringFormat='{0:dd/MM/yyyy}'}"/>
|
||||
<Label Text="{Binding DateFin, StringFormat='{0:dd/MM/yyyy}'}"/>
|
||||
<Label Text="{Binding NbInvite}"/>
|
||||
<Label Text="{Binding ChambreNom}"/>
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
71
Views/Client/DetailsClientPage.xaml.cs
Normal file
71
Views/Client/DetailsClientPage.xaml.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HegreHotel.Views.Client;
|
||||
|
||||
public partial class DetailsClientPage : ContentPage
|
||||
{
|
||||
public Models.Client Client { get; set; }
|
||||
|
||||
public DetailsClientPage(Models.Client client)
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = client;
|
||||
Client = client;
|
||||
LoadReservations();
|
||||
}
|
||||
|
||||
private async void LoadReservations()
|
||||
{
|
||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||
var db = SingletonConnection.GetInstance(dbPath);
|
||||
List<Models.Reservation> reservationsList = await db.Table<Models.Reservation>().Where(x => x.ClientId == Client.Id).ToListAsync();
|
||||
List<Models.Chambre> cahmbresList = await db.Table<Models.Chambre>().ToListAsync();
|
||||
List<ReservationInfo> reservationInfoList = new List<ReservationInfo>();
|
||||
|
||||
if (reservationsList is null)
|
||||
{
|
||||
await DisplayAlert("Aucune réservation", "Le client n'a pas de réservations", "OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Models.Reservation reservation in reservationsList)
|
||||
{
|
||||
ReservationInfo reservationInfo = new ReservationInfo()
|
||||
{
|
||||
DateDebut = reservation.DateDebut,
|
||||
DateFin = reservation.DateFin,
|
||||
DemandeSpecifique = reservation.DemandeSpecifique,
|
||||
NbInvite = reservation.NbInvite
|
||||
};
|
||||
foreach (Models.Chambre chambre in cahmbresList)
|
||||
{
|
||||
if (reservation.ChambreId == chambre.Id)
|
||||
{
|
||||
reservationInfo.ChambreNom = chambre.Nom;
|
||||
}
|
||||
}
|
||||
reservationInfoList.Add(reservationInfo);
|
||||
}
|
||||
}
|
||||
|
||||
ListeReservations.ItemsSource = reservationInfoList;
|
||||
}
|
||||
|
||||
public class ReservationInfo
|
||||
{
|
||||
public DateTime DateDebut { get; set; }
|
||||
|
||||
public DateTime DateFin { get; set; }
|
||||
|
||||
public string? DemandeSpecifique { get; set; }
|
||||
|
||||
public int NbInvite { get; set; }
|
||||
|
||||
public string? ChambreNom { get; set; }
|
||||
}
|
||||
}
|
@ -5,13 +5,28 @@
|
||||
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"/>
|
||||
<Label Text="Sélectionnez la période" FontAttributes="Bold"/>
|
||||
<DatePicker x:Name="DatePickerDebut" />
|
||||
<DatePicker x:Name="DatePickerFin" />
|
||||
<Entry x:Name="EntryDemandeSpecifique" Placeholder="Demandes spécifiques"/>
|
||||
<Button Text="Enregistrer" Clicked="OnEnregistrerClicked" Margin="0,20"/>
|
||||
|
||||
<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>
|
||||
|
||||
|
@ -10,28 +10,55 @@ namespace HegreHotel.Views.Reservation
|
||||
public partial class AjouterReservationPage : ContentPage
|
||||
{
|
||||
private List<Models.Client> _clients;
|
||||
private List<Models.Chambre> _chambres;
|
||||
private List<Models.Chambre> _chambresDispo;
|
||||
private bool _datesValidees = false;
|
||||
|
||||
public AjouterReservationPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
LoadClientsAndChambres();
|
||||
}
|
||||
|
||||
private async void LoadClientsAndChambres()
|
||||
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);
|
||||
|
||||
_clients = await db.Table<Models.Client>().ToListAsync();
|
||||
_chambres = await db.Table<Models.Chambre>().ToListAsync();
|
||||
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 = _chambres.Select(ch => ch.Nom).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");
|
||||
@ -41,8 +68,8 @@ namespace HegreHotel.Views.Reservation
|
||||
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,
|
||||
ChambreId = _chambresDispo[PickerChambre.SelectedIndex].Id,
|
||||
NbInvite = int.TryParse(EntryNbInvite.Text, out int nb) ? nb : 0,
|
||||
DateDebut = DatePickerDebut.Date,
|
||||
DateFin = DatePickerFin.Date,
|
||||
DemandeSpecifique = EntryDemandeSpecifique.Text
|
||||
@ -51,6 +78,8 @@ namespace HegreHotel.Views.Reservation
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
<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"/>
|
||||
<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"/>
|
||||
|
@ -34,7 +34,7 @@ namespace HegreHotel.Views.Reservation
|
||||
PickerClient.SelectedIndex = _clients.FindIndex(c => c.Id == _reservation.ClientId);
|
||||
PickerChambre.SelectedIndex = _chambres.FindIndex(ch => ch.Id == _reservation.ChambreId);
|
||||
|
||||
EntryNbPersonne.Text = _reservation.NbPersonnes.ToString();
|
||||
EntryNbInvite.Text = _reservation.NbInvite.ToString();
|
||||
DatePickerDebut.Date = _reservation.DateDebut;
|
||||
DatePickerFin.Date = _reservation.DateFin;
|
||||
EntryDemandeSpecifique.Text = _reservation.DemandeSpecifique;
|
||||
@ -50,7 +50,7 @@ namespace HegreHotel.Views.Reservation
|
||||
|
||||
_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.NbInvite = int.TryParse(EntryNbInvite.Text, out int nb) ? nb : _reservation.NbInvite;
|
||||
_reservation.DateDebut = DatePickerDebut.Date;
|
||||
_reservation.DateFin = DatePickerFin.Date;
|
||||
_reservation.DemandeSpecifique = EntryDemandeSpecifique.Text;
|
||||
|
Loading…
x
Reference in New Issue
Block a user