status fixed pour les chambres

This commit is contained in:
allavenavr 2025-03-27 16:36:40 +01:00
parent 1920b8a164
commit 53ebad6fe5
4 changed files with 29 additions and 4 deletions

View File

@ -18,7 +18,6 @@ public class Chambre
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; }
}

View File

@ -9,6 +9,10 @@
<Entry x:Name="EntryDescription" Placeholder="Description"/>
<Entry x:Name="EntryTarif" Placeholder="Tarif" Keyboard="Numeric"/>
<Entry x:Name="EntryNbPersonne" Placeholder="Nombre de personnes" Keyboard="Numeric"/>
<Label Text="Modifier le Statut" Margin="10,0,0,0"/>
<Picker x:Name="PickerStatut" Title=""/>
<Button Text="Enregistrer les modifications" Clicked="OnEnregistrerClicked" Margin="0,20"/>
</StackLayout>
</ContentPage>

View File

@ -8,6 +8,8 @@ namespace HegreHotel.Views.Chambre
public partial class ModifierChambrePage : ContentPage
{
Models.Chambre _chambre;
private List<Status> _statuts;
public ModifierChambrePage(Models.Chambre chambre)
{
InitializeComponent();
@ -17,17 +19,40 @@ namespace HegreHotel.Views.Chambre
EntryDescription.Text = _chambre.Description;
EntryTarif.Text = _chambre.Tarif.ToString();
EntryNbPersonne.Text = _chambre.NbPersonne.ToString();
LoadStatuts();
}
private async void LoadStatuts()
{
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
_statuts = await db.Table<Status>().ToListAsync();
PickerStatut.ItemsSource = _statuts.Select(s => s.Libelle).ToList();
PickerStatut.SelectedIndex = _statuts.FindIndex(s => s.Id == _chambre.StatusId);
}
private async void OnEnregistrerClicked(object sender, EventArgs e)
{
if (PickerStatut.SelectedIndex == -1)
{
await DisplayAlert("Erreur", "Veuillez sélectionner un statut", "OK");
return;
}
_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;
_chambre.StatusId = _statuts[PickerStatut.SelectedIndex].Id;
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
Console.WriteLine(_chambre.StatusId);
await db.UpdateAsync(_chambre);
await Navigation.PopAsync();
}

View File

@ -69,13 +69,10 @@ namespace HegreHotel.Views.Client
{
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));
}
}