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 _clients; private List _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().ToListAsync(); _chambres = await db.Table().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(); } } }