crash fixed listview replaced
This commit is contained in:
parent
7f05f4f634
commit
ff39425766
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="HegreHotel.Views.Client.ClientsPage"
|
x:Class="HegreHotel.Views.Client.ClientsPage"
|
||||||
@ -6,8 +6,6 @@
|
|||||||
Appearing="ClientsPage_OnAppearing">
|
Appearing="ClientsPage_OnAppearing">
|
||||||
|
|
||||||
<StackLayout Padding="15" Spacing="10">
|
<StackLayout Padding="15" Spacing="10">
|
||||||
|
|
||||||
<!-- Bouton Ajouter Client -->
|
|
||||||
<Button Text="Ajouter Client"
|
<Button Text="Ajouter Client"
|
||||||
Clicked="OnAjouterClientClicked"
|
Clicked="OnAjouterClientClicked"
|
||||||
HorizontalOptions="Center"
|
HorizontalOptions="Center"
|
||||||
@ -16,46 +14,56 @@
|
|||||||
CornerRadius="10"
|
CornerRadius="10"
|
||||||
Padding="10"
|
Padding="10"
|
||||||
FontAttributes="Bold"
|
FontAttributes="Bold"
|
||||||
WidthRequest="200"/>
|
WidthRequest="200" />
|
||||||
|
|
||||||
<!-- Liste des clients -->
|
<CollectionView x:Name="ClientsCollectionView"
|
||||||
<ListView x:Name="ClientsListView" HasUnevenRows="True" ItemTapped="OnClientTapped">
|
SelectionMode="None">
|
||||||
<ListView.ItemTemplate>
|
<CollectionView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ViewCell>
|
<Frame Padding="10"
|
||||||
<Frame Padding="10" CornerRadius="10" BackgroundColor="White" BorderColor="#E5E7EB" Margin="0,5">
|
CornerRadius="10"
|
||||||
<StackLayout Orientation="Horizontal" Spacing="15">
|
BackgroundColor="White"
|
||||||
<!-- Icône ou Avatar -->
|
BorderColor="#E5E7EB"
|
||||||
<Image Source="user_icon.png" WidthRequest="40" HeightRequest="40"/>
|
Margin="0,5"
|
||||||
|
BindingContext="{Binding .}">
|
||||||
|
<Frame.GestureRecognizers>
|
||||||
|
<TapGestureRecognizer Tapped="OnClientTapped" />
|
||||||
|
</Frame.GestureRecognizers>
|
||||||
|
|
||||||
<!-- Infos du client -->
|
<StackLayout Orientation="Horizontal" Spacing="15">
|
||||||
<VerticalStackLayout>
|
<Image Source="user_icon.png"
|
||||||
<Label Text="{Binding Nom}" FontAttributes="Bold" FontSize="16"/>
|
WidthRequest="40"
|
||||||
<Label Text="{Binding Prenom}" FontSize="14" TextColor="Gray"/>
|
HeightRequest="40" />
|
||||||
</VerticalStackLayout>
|
|
||||||
|
|
||||||
<!-- Actions Modifier / Supprimer -->
|
<VerticalStackLayout>
|
||||||
<StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" Spacing="5">
|
<Label Text="{Binding Nom}"
|
||||||
<ImageButton Source="edit_icon.png"
|
FontAttributes="Bold"
|
||||||
Clicked="OnModifierClientClicked"
|
FontSize="16" />
|
||||||
CommandParameter="{Binding .}"
|
<Label Text="{Binding Prenom}"
|
||||||
HeightRequest="30"
|
FontSize="14"
|
||||||
WidthRequest="30"
|
TextColor="Gray" />
|
||||||
BackgroundColor="Transparent"/>
|
</VerticalStackLayout>
|
||||||
<ImageButton Source="delete_icon.png"
|
|
||||||
Clicked="OnSupprimerClientClicked"
|
<StackLayout Orientation="Horizontal"
|
||||||
CommandParameter="{Binding .}"
|
HorizontalOptions="EndAndExpand"
|
||||||
HeightRequest="30"
|
Spacing="5">
|
||||||
WidthRequest="30"
|
<ImageButton Source="edit_icon.png"
|
||||||
BackgroundColor="Transparent"/>
|
Clicked="OnModifierClientClicked"
|
||||||
</StackLayout>
|
CommandParameter="{Binding .}"
|
||||||
|
HeightRequest="30"
|
||||||
|
WidthRequest="30"
|
||||||
|
BackgroundColor="Transparent" />
|
||||||
|
<ImageButton Source="delete_icon.png"
|
||||||
|
Clicked="OnSupprimerClientClicked"
|
||||||
|
CommandParameter="{Binding .}"
|
||||||
|
HeightRequest="30"
|
||||||
|
WidthRequest="30"
|
||||||
|
BackgroundColor="Transparent" />
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</Frame>
|
</StackLayout>
|
||||||
</ViewCell>
|
</Frame>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
</ListView>
|
</CollectionView>
|
||||||
|
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
||||||
</ContentPage>
|
</ContentPage>
|
@ -18,16 +18,25 @@ namespace HegreHotel.Views.Client
|
|||||||
|
|
||||||
private async void LoadClients()
|
private async void LoadClients()
|
||||||
{
|
{
|
||||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
try
|
||||||
var db = SingletonConnection.GetInstance(dbPath);
|
|
||||||
var clientsList = await db.Table<Models.Client>().ToListAsync();
|
|
||||||
Clients.Clear();
|
|
||||||
foreach (var client in clientsList)
|
|
||||||
{
|
{
|
||||||
Clients.Add(client);
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
}
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
ClientsListView.ItemsSource = Clients;
|
var clientsList = await db.Table<Models.Client>().ToListAsync();
|
||||||
|
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
Clients.Clear();
|
||||||
|
foreach (var client in clientsList)
|
||||||
|
Clients.Add(client);
|
||||||
|
|
||||||
|
ClientsCollectionView.ItemsSource = Clients;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Erreur lors du chargement des clients : {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
||||||
@ -43,7 +52,6 @@ namespace HegreHotel.Views.Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async void OnSupprimerClientClicked(object sender, EventArgs e)
|
private async void OnSupprimerClientClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Client client)
|
if (sender is ImageButton imageButton && imageButton.CommandParameter is Models.Client client)
|
||||||
@ -54,25 +62,24 @@ namespace HegreHotel.Views.Client
|
|||||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||||
var db = SingletonConnection.GetInstance(dbPath);
|
var db = SingletonConnection.GetInstance(dbPath);
|
||||||
await db.DeleteAsync(client);
|
await db.DeleteAsync(client);
|
||||||
LoadClients();
|
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
Clients.Remove(client);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ClientsPage_OnAppearing(object sender, EventArgs e)
|
||||||
private void ClientsPage_OnAppearing(object? sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
LoadClients();
|
LoadClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnClientTapped(object sender, ItemTappedEventArgs e)
|
private async void OnClientTapped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Item != null)
|
if (sender is Frame frame && frame.BindingContext is Models.Client client)
|
||||||
{
|
{
|
||||||
((ListView)sender).SelectedItem = null;
|
|
||||||
|
|
||||||
var client = e.Item as Models.Client;
|
|
||||||
|
|
||||||
await Navigation.PushAsync(new DetailsClientPage(client));
|
await Navigation.PushAsync(new DetailsClientPage(client));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user