Binding page Invi + bouton supprimer

Test_Binding
Tony Fages 2 years ago
parent 9398caf21e
commit 4522d32316

@ -41,6 +41,11 @@ namespace ParionsCuite.Modeles
Participation = participation;
ListInviter = new List<Inviter>();
ListParier = new List<Parier>();
}
public Evenement(List<Inviter> inviters, List<Participation> participations, List<Parier> pariers)
{
}
/* Méthode Inviter */

@ -16,6 +16,7 @@ namespace ParionsCuite.Modeles
public IPersistanceManager Persistance { get; set; }
public Manageur(IPersistanceManager Pers) {
Invites = new List<Inviter>();
Evenement = new List<Evenement>();
Persistance = Pers;
}
@ -58,12 +59,18 @@ namespace ParionsCuite.Modeles
Persistance.sauvegardeDonnees(Evenement);
}
internal List<Inviter> AddInvite(Inviter invite1)
public List<Inviter> AddInvite(Inviter invite1)
{
Invites.Add(invite1);
return Invites;
}
public List<Inviter> RemoveInviter(Inviter invite1)
{
Invites.Remove(invite1);
return Invites;
}
public int LenListInvite(List<Inviter> list)
{
int len = 0;
@ -73,5 +80,10 @@ namespace ParionsCuite.Modeles
}
return len;
}
public List<Inviter> ReturnListInvite()
{
return Invites;
}
}
}

@ -8,10 +8,10 @@
<TableView RowHeight="70">
<TableRoot >
<TableSection Title="Informations">
<TableSection Title="Informations" x:Name="tableInfo">
<TextCell Text="Nom de l'événement" Detail ="Nom"/>
<TextCell Text="Date de l'événement" Detail ="Date"/>
<TextCell Text="Nombres d'invité" Detail ="Nombre"/>
<TextCell Text="Nombres d'invité" Detail ="{Binding NbInvite}"/>
<TextCell Text="Nombres de paris" Detail ="Nombre"/>
<TextCell Text="Adresse" Detail ="Adresse"/>
<TextCell Text="Horaire" Detail ="Horaire"/>

@ -1,3 +1,6 @@
using ParionsCuite.Modeles;
using System.Diagnostics;
namespace ParionsCuite.Views.Information;
public partial class Info : ContentView
@ -5,5 +8,18 @@ public partial class Info : ContentView
public Info()
{
InitializeComponent();
MiseAJourInfo();
BindingContext = this;
}
public Manageur m = new Manageur();
public void MiseAJourInfo()
{
int NbInvite = m.LenListInvite(m.Invites);
Debug.WriteLine(NbInvite);
}
}

@ -29,9 +29,8 @@
<Label Text="Prenom" Grid.Column="1" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="Nom" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Grid.Column="2" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="{Binding Nom}" Grid.Column="1" Grid.Row="1" FontSize="Large"/>
<Label Text="{Binding Modeles.Inviter.Nom}" Grid.Column="1" Grid.Row="1" FontSize="Large"/>
<Label Text="{Binding Prenom}" Grid.Row="1" FontSize="Large"/>
<Button Text="-" Grid.Row="1" Grid.Column="2"/>
</Grid>

@ -1,4 +1,6 @@
using ParionsCuite.Modeles;
using System.Diagnostics;
using System.Windows;
namespace ParionsCuite.Views.Invite;
public partial class Inviter : ContentView
@ -9,19 +11,62 @@ public partial class Inviter : ContentView
public Inviter()
{
InitializeComponent();
this.BindingContext = this;
restoreListInvite();
BindingContext = this;
}
void ColumnDefinition_SizeChanged(System.Object sender, System.EventArgs e)
{
}
public void restoreListInvite()
{
List<Modeles.Inviter> listInvite = m.ReturnListInvite();
Debug.WriteLine(listInvite);
int len = listInvite.Count;
foreach (Modeles.Inviter inviter in listInvite) {
RowDefinition row = new RowDefinition();
row.Height = new GridLength(45);
GrilleInvite.RowDefinitions.Add(row);
// AJout Prenom
Label prenomLabel = new Label();
prenomLabel.Text = inviter.Prenom;
Grid.SetRow(prenomLabel, len);
Grid.SetColumn(prenomLabel, 0);
GrilleInvite.Children.Add(prenomLabel);
// Ajout Nom
Label nomLabel = new Label();
nomLabel.Text = inviter.Nom;
Grid.SetRow(nomLabel, len);
Grid.SetColumn(nomLabel, 1);
GrilleInvite.Children.Add(nomLabel);
// Ajout Bouton
Button buttonMoins = new Button();
buttonMoins.Text = "-";
Grid.SetRow(buttonMoins, len);
Grid.SetColumn(buttonMoins, 2);
GrilleInvite.Children.Add(buttonMoins);
len++;
}
}
private void AddInvitelist(object sender, EventArgs e)
{
//restoreListInvite();
string nom = nomEditor.Text;
string prenom = prenomEditor.Text;
if (nom == null || prenom == null) { return; }
Modeles.Inviter invite1 = new Modeles.Inviter(nom, prenom);
List<Modeles.Inviter> invites = m.AddInvite(invite1);
int len = 1;
int len = 1;//m.LenListInvite(invites);
//if (len == 0 ) { len = 1; }
Debug.WriteLine("LA taille de la liste est de " + m.LenListInvite(invites));
foreach (Modeles.Inviter inviter in invites)
{
RowDefinition row = new RowDefinition();
@ -47,6 +92,7 @@ public partial class Inviter : ContentView
Button buttonMoins = new Button();
buttonMoins.Text = "-";
buttonMoins.Clicked += BoutonSupprimer_Clicked;
Grid.SetRow(buttonMoins, len);
Grid.SetColumn(buttonMoins , 2);
GrilleInvite.Children.Add(buttonMoins );
@ -56,6 +102,60 @@ public partial class Inviter : ContentView
}
}
private void BoutonSupprimer_Clicked(object sender, EventArgs e)
{
// Récupérer le bouton cliqué
Button button = (Button)sender;
// Récupérer la grille parente du bouton
Grid parentGrid = (Grid)button.Parent;
// Récupérer la ligne parente du bouton
int rowIndex = Grid.GetRow(button);
// Vérifier que l'indice rowIndex est valide
if (rowIndex >= 0 && rowIndex < parentGrid.RowDefinitions.Count)
{
// Récupérer les labels correspondants à la ligne
Label prenomLabel = null;
Label nomLabel = null;
// Parcourir les enfants de la grille pour trouver les labels de la ligne
foreach (View child in parentGrid.Children)
{
int childRowIndex = Grid.GetRow(child);
if (childRowIndex == rowIndex)
{
if (Grid.GetColumn(child) == 0)
prenomLabel = (Label)child;
else if (Grid.GetColumn(child) == 1)
nomLabel = (Label)child;
}
}
if (prenomLabel != null && nomLabel != null)
{
// Récupérer le prénom et le nom de l'invité à supprimer
string prenom = prenomLabel.Text;
string nom = nomLabel.Text;
// Rechercher l'invité correspondant dans la liste
Modeles.Inviter inviter = m.ReturnListInvite().FirstOrDefault(i => i.Prenom == prenom && i.Nom == nom);
if (inviter != null)
{
// Supprimer l'invité de la liste
m.RemoveInviter(inviter);
// Supprimer les éléments de la ligne de la grille
parentGrid.Children.Remove(prenomLabel);
parentGrid.Children.Remove(nomLabel);
parentGrid.Children.Remove(button);
parentGrid.RowDefinitions.RemoveAt(rowIndex);
}
}
}
}
}
Loading…
Cancel
Save