|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|