93 lines
3.1 KiB
C#
93 lines
3.1 KiB
C#
|
using MauiApp1.Model;
|
|||
|
|
|||
|
namespace MauiApp1.Views;
|
|||
|
|
|||
|
public partial class FournisseurPage : ContentPage
|
|||
|
{
|
|||
|
public FournisseurPage()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
LoadFournisseurs();
|
|||
|
}
|
|||
|
|
|||
|
private async Task LoadFournisseurs()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var fournisseurs = await App.Database.GetFournisseursAsync();
|
|||
|
FournisseursList.ItemsSource = fournisseurs;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
await DisplayAlert("Erreur", "Impossible de charger les fournisseurs: " + ex.Message, "OK");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private async void OnAddFournisseurClicked(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var fournisseur = new Fournisseur
|
|||
|
{
|
|||
|
Name = await DisplayPromptAsync("Nouveau fournisseur", "Nom:"),
|
|||
|
Email = await DisplayPromptAsync("Email", "Email:"),
|
|||
|
Telephone = await DisplayPromptAsync("Téléphone", "Numéro:"),
|
|||
|
Address = await DisplayPromptAsync("Adresse", "Adresse:")
|
|||
|
};
|
|||
|
|
|||
|
if (string.IsNullOrWhiteSpace(fournisseur.Name)) return;
|
|||
|
|
|||
|
await App.Database.SaveFournisseurAsync(fournisseur);
|
|||
|
await LoadFournisseurs();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
await DisplayAlert("Erreur", "Impossible d'ajouter le fournisseur: " + ex.Message, "OK");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private async void OnEditFournisseur(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var swipeItem = sender as SwipeItem;
|
|||
|
var fournisseur = swipeItem?.BindingContext as Fournisseur;
|
|||
|
if (fournisseur == null) return;
|
|||
|
|
|||
|
fournisseur.Name = await DisplayPromptAsync("Modifier", "Nom:", initialValue: fournisseur.Name);
|
|||
|
fournisseur.Email = await DisplayPromptAsync("Modifier", "Email:", initialValue: fournisseur.Email);
|
|||
|
fournisseur.Telephone = await DisplayPromptAsync("Modifier", "Téléphone:", initialValue: fournisseur.Telephone);
|
|||
|
fournisseur.Address = await DisplayPromptAsync("Modifier", "Adresse:", initialValue: fournisseur.Address);
|
|||
|
|
|||
|
await App.Database.SaveFournisseurAsync(fournisseur);
|
|||
|
await LoadFournisseurs();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
await DisplayAlert("Erreur", "Impossible de modifier le fournisseur: " + ex.Message, "OK");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private async void OnDeleteFournisseur(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var swipeItem = sender as SwipeItem;
|
|||
|
var fournisseur = swipeItem?.BindingContext as Fournisseur;
|
|||
|
if (fournisseur == null) return;
|
|||
|
|
|||
|
bool answer = await DisplayAlert("Confirmation",
|
|||
|
"Voulez-vous vraiment supprimer ce fournisseur ?", "Oui", "Non");
|
|||
|
|
|||
|
if (answer)
|
|||
|
{
|
|||
|
await App.Database.DeleteFournisseurAsync(fournisseur);
|
|||
|
await LoadFournisseurs();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
await DisplayAlert("Erreur", "Impossible de supprimer le fournisseur: " + ex.Message, "OK");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|