crash fixed listview replaced
This commit is contained in:
parent
7f05f4f634
commit
ff39425766
@ -6,8 +6,6 @@
|
||||
Appearing="ClientsPage_OnAppearing">
|
||||
|
||||
<StackLayout Padding="15" Spacing="10">
|
||||
|
||||
<!-- Bouton Ajouter Client -->
|
||||
<Button Text="Ajouter Client"
|
||||
Clicked="OnAjouterClientClicked"
|
||||
HorizontalOptions="Center"
|
||||
@ -18,24 +16,37 @@
|
||||
FontAttributes="Bold"
|
||||
WidthRequest="200" />
|
||||
|
||||
<!-- Liste des clients -->
|
||||
<ListView x:Name="ClientsListView" HasUnevenRows="True" ItemTapped="OnClientTapped">
|
||||
<ListView.ItemTemplate>
|
||||
<CollectionView x:Name="ClientsCollectionView"
|
||||
SelectionMode="None">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<Frame Padding="10" CornerRadius="10" BackgroundColor="White" BorderColor="#E5E7EB" Margin="0,5">
|
||||
<StackLayout Orientation="Horizontal" Spacing="15">
|
||||
<!-- Icône ou Avatar -->
|
||||
<Image Source="user_icon.png" WidthRequest="40" HeightRequest="40"/>
|
||||
<Frame Padding="10"
|
||||
CornerRadius="10"
|
||||
BackgroundColor="White"
|
||||
BorderColor="#E5E7EB"
|
||||
Margin="0,5"
|
||||
BindingContext="{Binding .}">
|
||||
<Frame.GestureRecognizers>
|
||||
<TapGestureRecognizer Tapped="OnClientTapped" />
|
||||
</Frame.GestureRecognizers>
|
||||
|
||||
<StackLayout Orientation="Horizontal" Spacing="15">
|
||||
<Image Source="user_icon.png"
|
||||
WidthRequest="40"
|
||||
HeightRequest="40" />
|
||||
|
||||
<!-- Infos du client -->
|
||||
<VerticalStackLayout>
|
||||
<Label Text="{Binding Nom}" FontAttributes="Bold" FontSize="16"/>
|
||||
<Label Text="{Binding Prenom}" FontSize="14" TextColor="Gray"/>
|
||||
<Label Text="{Binding Nom}"
|
||||
FontAttributes="Bold"
|
||||
FontSize="16" />
|
||||
<Label Text="{Binding Prenom}"
|
||||
FontSize="14"
|
||||
TextColor="Gray" />
|
||||
</VerticalStackLayout>
|
||||
|
||||
<!-- Actions Modifier / Supprimer -->
|
||||
<StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" Spacing="5">
|
||||
<StackLayout Orientation="Horizontal"
|
||||
HorizontalOptions="EndAndExpand"
|
||||
Spacing="5">
|
||||
<ImageButton Source="edit_icon.png"
|
||||
Clicked="OnModifierClientClicked"
|
||||
CommandParameter="{Binding .}"
|
||||
@ -51,11 +62,8 @@
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</StackLayout>
|
||||
|
||||
</ContentPage>
|
@ -17,17 +17,26 @@ namespace HegreHotel.Views.Client
|
||||
}
|
||||
|
||||
private async void LoadClients()
|
||||
{
|
||||
try
|
||||
{
|
||||
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
|
||||
var db = SingletonConnection.GetInstance(dbPath);
|
||||
var clientsList = await db.Table<Models.Client>().ToListAsync();
|
||||
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Clients.Clear();
|
||||
foreach (var client in clientsList)
|
||||
{
|
||||
Clients.Add(client);
|
||||
}
|
||||
ClientsListView.ItemsSource = Clients;
|
||||
|
||||
ClientsCollectionView.ItemsSource = Clients;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Erreur lors du chargement des clients : {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnAjouterClientClicked(object sender, EventArgs e)
|
||||
@ -43,7 +52,6 @@ namespace HegreHotel.Views.Client
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async void OnSupprimerClientClicked(object sender, EventArgs e)
|
||||
{
|
||||
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");
|
||||
var db = SingletonConnection.GetInstance(dbPath);
|
||||
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();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user