58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|