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