parent
837dd38642
commit
fb5da57e19
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="ParionsCuite.Views.Participations.NewFolder1.Nourri">
|
||||||
|
<VerticalStackLayout>
|
||||||
|
<Grid ColumnDefinitions="5*, 1*, 5*">
|
||||||
|
|
||||||
|
<!--Input des nourritures et quantité-->
|
||||||
|
<StackLayout Grid.Column="0" >
|
||||||
|
<Entry Placeholder="Entrer nourriture" x:Name="FoodInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
|
||||||
|
<Entry Placeholder="Entrer quantité" x:Name="QteInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
|
||||||
|
<Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0" Clicked="AddFoodlist"/>
|
||||||
|
</StackLayout>
|
||||||
|
|
||||||
|
<!--Grid quantité et nourrite + output -->
|
||||||
|
<Grid Grid.Column="2" Margin="30" x:Name="GridFood">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="2*" />
|
||||||
|
<ColumnDefinition Width="2*" />
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!--Header Grille quantité+nourritre-->
|
||||||
|
<Label Text="Nourriture" Grid.Column="1" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
|
||||||
|
<Label Text="Quantité" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
|
||||||
|
<Label Grid.Column="2" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</VerticalStackLayout>
|
||||||
|
</ContentView>
|
@ -0,0 +1,163 @@
|
|||||||
|
using ParionsCuite.Modeles;
|
||||||
|
using ParionsCuite.Views.Participations;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace ParionsCuite.Views.Participations.NewFolder1;
|
||||||
|
|
||||||
|
public partial class Nourri : ContentView
|
||||||
|
{
|
||||||
|
readonly Evenement EventSelect;
|
||||||
|
|
||||||
|
public Manageur mgr => (App.Current as App).MyManager;
|
||||||
|
|
||||||
|
public Nourri(Evenement EventSelect)
|
||||||
|
{
|
||||||
|
this.EventSelect = EventSelect;
|
||||||
|
InitializeComponent();
|
||||||
|
//restoreListInvite(EventSelect);
|
||||||
|
BindingContext = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void restoreListInvite(Evenement EventSelect)
|
||||||
|
{
|
||||||
|
|
||||||
|
var listFood = EventSelect.Participation.Nourriture;
|
||||||
|
Debug.WriteLine(listFood);
|
||||||
|
int len = 1;
|
||||||
|
foreach (Modeles.Nourriture food in listFood)
|
||||||
|
{
|
||||||
|
RowDefinition row = new RowDefinition();
|
||||||
|
row.Height = new GridLength(45);
|
||||||
|
GridFood.RowDefinitions.Add(row);
|
||||||
|
|
||||||
|
// AJout Prenom
|
||||||
|
Label foodLabel = new Label();
|
||||||
|
foodLabel.Text = food.Nom;
|
||||||
|
Grid.SetRow(foodLabel, len);
|
||||||
|
Grid.SetColumn(foodLabel, 0);
|
||||||
|
GridFood.Children.Add(foodLabel);
|
||||||
|
|
||||||
|
|
||||||
|
// Ajout Nom
|
||||||
|
Label qteLabel = new Label();
|
||||||
|
food.Nom = food.Quantite.ToString();
|
||||||
|
Grid.SetRow(qteLabel, len);
|
||||||
|
Grid.SetColumn(qteLabel, 1);
|
||||||
|
GridFood.Children.Add(qteLabel);
|
||||||
|
|
||||||
|
// Ajout Bouton
|
||||||
|
|
||||||
|
Button buttonMoins = new Button();
|
||||||
|
buttonMoins.Text = "-";
|
||||||
|
buttonMoins.Clicked += BoutonSupprimer_Clicked;
|
||||||
|
Grid.SetRow(buttonMoins, len);
|
||||||
|
Grid.SetColumn(buttonMoins, 2);
|
||||||
|
GridFood.Children.Add(buttonMoins);
|
||||||
|
|
||||||
|
len++;
|
||||||
|
Debug.WriteLine("Test test");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddFoodlist(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//restoreListInvite();
|
||||||
|
string food = FoodInput.Text;
|
||||||
|
string qte = QteInput.Text;
|
||||||
|
if (food == null || qte == null) { return; }
|
||||||
|
Modeles.Nourriture food1 = new Modeles.Nourriture(food, Int32.Parse(qte));
|
||||||
|
EventSelect.Participation.Nourriture.Add(food1);
|
||||||
|
int len = 1;
|
||||||
|
//if (len == 0 ) { len = 1; }
|
||||||
|
foreach (Modeles.Nourriture food2 in EventSelect.Participation.Nourriture)
|
||||||
|
{
|
||||||
|
RowDefinition row = new RowDefinition();
|
||||||
|
row.Height = new GridLength(45);
|
||||||
|
GridFood.RowDefinitions.Add(row);
|
||||||
|
|
||||||
|
// AJout Prenom
|
||||||
|
Label foodLabel = new Label();
|
||||||
|
foodLabel.Text = food2.Nom;
|
||||||
|
Grid.SetRow(foodLabel, len);
|
||||||
|
Grid.SetColumn(foodLabel, 0);
|
||||||
|
GridFood.Children.Add(foodLabel);
|
||||||
|
|
||||||
|
|
||||||
|
// Ajout Nom
|
||||||
|
Label qteLabel = new Label();
|
||||||
|
food2.Nom = food2.Quantite.ToString();
|
||||||
|
Grid.SetRow(qteLabel, len);
|
||||||
|
Grid.SetColumn(qteLabel, 1);
|
||||||
|
GridFood.Children.Add(qteLabel);
|
||||||
|
|
||||||
|
// Ajout Bouton
|
||||||
|
|
||||||
|
Button buttonMoins = new Button();
|
||||||
|
buttonMoins.Text = "-";
|
||||||
|
buttonMoins.Clicked += BoutonSupprimer_Clicked;
|
||||||
|
Grid.SetRow(buttonMoins, len);
|
||||||
|
Grid.SetColumn(buttonMoins, 2);
|
||||||
|
GridFood.Children.Add(buttonMoins);
|
||||||
|
|
||||||
|
len++;
|
||||||
|
Debug.WriteLine("Test test");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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 = EventSelect.ListInviter.FirstOrDefault(i => i.Prenom == prenom && i.Nom == nom);
|
||||||
|
|
||||||
|
if (inviter != null)
|
||||||
|
{
|
||||||
|
// Supprimer l'invité de la liste
|
||||||
|
EventSelect.ListInviter.Remove(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…
Reference in new issue