BInding Boisson / Autre + Gestion de la responsivité des pages

C#
thomas muzard 2 years ago
commit de00e2679d

@ -13,64 +13,41 @@
xmlns:autre="clr-namespace:ParionsCuite.Views.Participations.Autre"
>
<VerticalStackLayout>
<Grid ColumnDefinitions="1*,10*">
<!-- Séparation de la page -->
<ScrollView>
<Grid >
<!-- Séparation de la page -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Grid.Column="0" Height="2*" />
<RowDefinition Grid.Column="0" Height="3*" />
</Grid.RowDefinitions>
<!-- Première colonne -->
<ScrollView >
<StackLayout x:Name="ButtonStackLayout" BindingContext="{Binding mgr.Evenement}">
<Button Text="+" BackgroundColor="Green" Grid.Column="0" HeightRequest="50" Clicked="Button_Clicked"/>
</StackLayout>
</ScrollView>
<!-- Deuxième colonne -->
<Grid Grid.Column="1" RowDefinitions="1*,8*">
<!-- 1er ligne -->
<!--Grid menu-->
<Grid Grid.Row="0" Margin="20" ColumnDefinitions="*,*,*,*" MinimumHeightRequest="30" MaximumHeightRequest="50">
<Button Text="Invité" Clicked="InviteView" />
<Button Text="Participant" Grid.Column="1" Clicked="ParticipantView"/>
<Button Text="Pari" Grid.Column="2" BackgroundColor="Grey" Clicked="PariView"/>
<Button Text="Information" Grid.Column="3" Clicked="InfoView" />
</Grid>
<!-- Première colonne -->
<ScrollView >
<StackLayout x:Name="ButtonStackLayout" BindingContext="{Binding mgr.Evenement}">
<Button Text="+" BackgroundColor="Green" Grid.Column="0" Grid.Row="1" HeightRequest="5 0" Clicked="Button_Clicked"/>
</StackLayout>
</ScrollView>
<!-- Deuxième colonne -->
<Grid Grid.Column="1">
<!-- Création de 2 lignes -->
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="1500"/>
</Grid.RowDefinitions>
<!-- 1er ligne -->
<!--Grid menu-->
<Grid Grid.Row="0" Margin="20" ColumnDefinitions="*,*,*,*">
<Button Text="Invité" Clicked="InviteView" />
<Button Text="Participant" Grid.Column="1" Clicked="ParticipantView"/>
<Button Text="Pari" Grid.Column="2" BackgroundColor="Grey" Clicked="PariView"/>
<Button Text="Information" Grid.Column="3" Clicked="InfoView" />
</Grid>
<!-- 2e ligne -->
<Grid Grid.Row="1" >
<ContentView x:Name="changeButton">
<views:Accueil/>
</ContentView>
</Grid>
<!-- 2e ligne -->
<Grid Grid.Row="1" >
<ContentView x:Name="changeButton">
<views:Accueil/>
</ContentView>
</Grid>
</Grid>
</Grid>
</Grid>
</ScrollView>
</VerticalStackLayout>
</ContentPage>

@ -44,6 +44,7 @@ namespace ParionsCuite.Modeles
Heure = heure;
ListInviter = new List<Inviter>();
ListParier = new List<Parier>();
Participation = new Participation();
}
public Evenement(string nom, string date, string lieu, string heure, Participation participation)
{

@ -28,6 +28,13 @@ namespace ParionsCuite.Modeles
Autre = autre;
}
public Participation()
{
Boissons = new List<Boisson>();
Nourriture = new List<Nourriture>();
Autre = new List<Autre>();
}
/* Boisson */
public bool Ajout_Boissons(Boisson boisson)

@ -71,6 +71,9 @@
<MauiXaml Update="Views\Pari\Parier.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\Participations\Boisson\Drink.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\Participations\NewFolder1\Nourri.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
@ -94,7 +97,6 @@
<ItemGroup>
<Folder Include="Views\Ajout_Paris\" />
<Folder Include="Views\Participations\Autre\" />
<Folder Include="Views\Participations\Boisson\" />
<Folder Include="Modeles\" />
<Folder Include="Stub\" />
</ItemGroup>

@ -18,5 +18,6 @@ public partial class Parier : ContentView
private void AjoutPariView(object sender, EventArgs e)
{
}
}

@ -2,53 +2,35 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ParionsCuite.Views.Participations.Autre.Autres">
<VerticalStackLayout>
<!--Grid menu-->
<Grid Margin="20" ColumnDefinitions="*,*,*,*">
<Button Text="Invité" />
<Button Text="Participant" Grid.Column="1"/>
<Button Text="Pari" Grid.Column="2" BackgroundColor="Grey"/>
<Button Text="Information" Grid.Column="3" />
</Grid>
<!--Grid Participation-->
<Grid ColumnDefinitions="*,*,*">
<Button Text="Nourriture" />
<Button Text="Boisson" Grid.Column="1" />
<Button Text="Autre" Grid.Column="2" BackgroundColor="Grey" />
</Grid>
<!--Grid Pincipale-->
<Grid ColumnDefinitions="*,*,*">
<VerticalStackLayout>
<Grid ColumnDefinitions="5*, 1*, 5*">
<!--Input des boissons et quantité-->
<!--Input des nourritures et quantité-->
<StackLayout Grid.Column="0" >
<Entry Text="Entrer autre" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Entry Text="Entrer quantité" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0"/>
<Entry Placeholder="Entrer l'objet" x:Name="AutreInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Entry Placeholder="Entrer quantité" Keyboard="Numeric" x:Name="QteInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0" Clicked="AddAutrelist"/>
</StackLayout>
<!--Grid quantité et boisson + output -->
<Grid Grid.Column="1" Margin="30">
<!--Grid quantité et nourrite + output -->
<Grid Grid.Column="2" x:Name="GridAutre">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="3*" x:Name="sup"/>
</Grid.RowDefinitions>
<!--Header Grille quantité+boisson-->
<Label Text="Quantité" Grid.Column="1" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="Autre" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<!--Header Grille quantité+nourritre-->
<Label Text="Objet" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="Quantité" Grid.Column="1" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Grid.Column="2" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<!--Content Grille quantité+boisson-->
<Label Text="Tire bouchon" Grid.Row="1" FontSize="Large" HorizontalOptions="Center"/>
<Label Text="1" Grid.Column="1" Grid.Row="1" FontSize="Large" HorizontalOptions="Center"/>
<Button Text="-" Grid.Row="1" Grid.Column="2"/>
</Grid>
</Grid>

@ -1,9 +1,173 @@
namespace ParionsCuite.Views.Participations.Autre;
using ParionsCuite.Modeles;
using ParionsCuite.Views.Participations;
using System.Diagnostics;
namespace ParionsCuite.Views.Participations.Autre;
public partial class Autres : ContentView
{
public Autres()
readonly Evenement EventSelect;
public Manageur mgr => (App.Current as App).MyManager;
public Autres(Evenement EventSelect)
{
InitializeComponent();
}
this.EventSelect = EventSelect;
InitializeComponent();
restoreListAutre(EventSelect);
BindingContext = this;
}
public void restoreListAutre(Evenement EventSelect)
{
List<Modeles.Autre> listAutre = EventSelect.Participation.Autre;
Debug.WriteLine("TEst " + listAutre.Count());
int len = 1;
foreach (Modeles.Autre food in listAutre)
{
RowDefinition row = new RowDefinition();
row.Height = new GridLength(45);
GridAutre.RowDefinitions.Add(row);
// AJout Nourriture
Label AutreLabel = new Label();
AutreLabel.Text = food.Nom.ToString();
Debug.WriteLine(AutreLabel);
Grid.SetRow(AutreLabel, len);
Grid.SetColumn(AutreLabel, 0);
GridAutre.Children.Add(AutreLabel);
// Ajout Quantite
Label qteLabel = new Label();
qteLabel.Text = food.Quantite.ToString();
Grid.SetRow(qteLabel, len);
Grid.SetColumn(qteLabel, 1);
GridAutre.Children.Add(qteLabel);
// Ajout Bouton
Button buttonMoins = new Button();
buttonMoins.Text = "-";
buttonMoins.Clicked += BoutonSupprimer_Clicked;
Grid.SetRow(buttonMoins, len);
Grid.SetColumn(buttonMoins, 2);
GridAutre.Children.Add(buttonMoins);
len++;
Debug.WriteLine("Test test");
}
}
private async void AddAutrelist(object sender, EventArgs e)
{
//restoreListInvite();
string autre = AutreInput.Text;
string qte = QteInput.Text;
if (int.TryParse(qte, out int value))
{
if (autre == null || qte == null) { return; }
Modeles.Autre autre1 = new Modeles.Autre(autre, Int32.Parse(qte));
EventSelect.Participation.Autre.Add(autre1);
int len = 1;
//if (len == 0 ) { len = 1; }
foreach (Modeles.Autre autre2 in EventSelect.Participation.Autre)
{
RowDefinition row = new RowDefinition();
row.Height = new GridLength(45);
GridAutre.RowDefinitions.Add(row);
// AJout Nourriture
Label AutreLabel = new Label();
AutreLabel.Text = autre2.Nom;
Grid.SetRow(AutreLabel, len);
Grid.SetColumn(AutreLabel, 0);
GridAutre.Children.Add(AutreLabel);
// Ajout Quantite
Label qteLabel = new Label();
qteLabel.Text = autre2.Quantite.ToString();
Grid.SetRow(qteLabel, len);
Grid.SetColumn(qteLabel, 1);
GridAutre.Children.Add(qteLabel);
// Ajout Bouton
Button buttonMoins = new Button();
buttonMoins.Text = "-";
buttonMoins.Clicked += BoutonSupprimer_Clicked;
Grid.SetRow(buttonMoins, len);
Grid.SetColumn(buttonMoins, 2);
GridAutre.Children.Add(buttonMoins);
len++;
Debug.WriteLine("Test test");
}
}
else
{
//await DisplayAlert("esv", "efds", "OK");
return;
}
}
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 AutreLabel = null;
Label qteLabel = 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)
AutreLabel = (Label)child;
else if (Grid.GetColumn(child) == 1)
qteLabel = (Label)child;
}
}
if (AutreLabel != null && qteLabel != null)
{
// Récupérer le prénom et le nom de l'invité à supprimer
string nom = AutreLabel.Text;
string qte = qteLabel.Text;
// Rechercher l'invité correspondant dans la liste
Modeles.Autre autre = EventSelect.Participation.Autre.FirstOrDefault(i => i.Nom == nom && i.Quantite.ToString() == qte);
if (autre != null)
{
// Supprimer l'invité de la liste
EventSelect.Participation.Autre.Remove(autre);
// Supprimer les éléments de la ligne de la grille
parentGrid.Children.Remove(AutreLabel);
parentGrid.Children.Remove(qteLabel);
parentGrid.Children.Remove(button);
parentGrid.RowDefinitions.RemoveAt(rowIndex);
}
}
}
}

@ -1,50 +0,0 @@
<?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.Boisson.Boissons">
<VerticalStackLayout>
<!--Grid Participation-->
<Grid ColumnDefinitions="*,*,*">
<Button Text="Nourriture" />
<Button Text="Boisson" Grid.Column="1" BackgroundColor="Grey"/>
<Button Text="Autre" Grid.Column="2" />
</Grid>
<!--Grid Pincipale-->
<Grid ColumnDefinitions="*,*,*">
<!--Input des boissons et quantité-->
<StackLayout Grid.Column="0" >
<Entry Placeholder="Entrer boisson" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Entry Placeholder="Entrer quantité" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0"/>
</StackLayout>
<!--Grid quantité et boisson + output -->
<Grid Grid.Column="2" Margin="30">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--Header Grille quantité+boisson-->
<Label Text="Boisson" 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"/>
<!--Content Grille quantité+boisson-->
<Label Text="Vodka" Grid.Row="1" FontSize="Large" HorizontalOptions="Center"/>
<Label Text="2" Grid.Column="1" Grid.Row="1" FontSize="Large" HorizontalOptions="Center"/>
<Button Text="-" Grid.Row="1" Grid.Column="2"/>
</Grid>
</Grid>
</VerticalStackLayout>
</ContentView>

@ -1,9 +0,0 @@
namespace ParionsCuite.Views.Participations.Boisson;
public partial class Boissons : ContentView
{
public Boissons()
{
InitializeComponent();
}
}

@ -0,0 +1,38 @@
<?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.Boisson.Drink">
<VerticalStackLayout>
<Grid ColumnDefinitions="5*, 1*, 5*">
<!--Input des nourritures et quantité-->
<StackLayout Grid.Column="0" >
<Entry Placeholder="Entrer Boisson" x:Name="DrinkInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Entry Placeholder="Entrer quantité" Keyboard="Numeric" x:Name="QteInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0" Clicked="AddDrinklist"/>
</StackLayout>
<!--Grid quantité et nourrite + output -->
<Grid Grid.Column="2" x:Name="GridDrink">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="3*" x:Name="sup"/>
</Grid.RowDefinitions>
<!--Header Grille quantité+nourritre-->
<Label Text="Boisson" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="Quantité" Grid.Column="1" 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,173 @@
using ParionsCuite.Modeles;
using ParionsCuite.Views.Participations;
using System.Diagnostics;
namespace ParionsCuite.Views.Participations.Boisson;
public partial class Drink : ContentView
{
readonly Evenement EventSelect;
public Manageur mgr => (App.Current as App).MyManager;
public Drink(Evenement EventSelect)
{
this.EventSelect = EventSelect;
InitializeComponent();
restoreListBoisson(EventSelect);
BindingContext = this;
}
public void restoreListBoisson(Evenement EventSelect)
{
List<Modeles.Boisson> listDrink = EventSelect.Participation.Boissons;
Debug.WriteLine("TEst " + listDrink.Count());
int len = 1;
foreach (Modeles.Boisson food in listDrink)
{
RowDefinition row = new RowDefinition();
row.Height = new GridLength(45);
GridDrink.RowDefinitions.Add(row);
// AJout Nourriture
Label DrinkLabel = new Label();
DrinkLabel.Text = food.Nom.ToString();
Debug.WriteLine(DrinkLabel);
Grid.SetRow(DrinkLabel, len);
Grid.SetColumn(DrinkLabel, 0);
GridDrink.Children.Add(DrinkLabel);
// Ajout Quantite
Label qteLabel = new Label();
qteLabel.Text = food.Quantite.ToString();
Grid.SetRow(qteLabel, len);
Grid.SetColumn(qteLabel, 1);
GridDrink.Children.Add(qteLabel);
// Ajout Bouton
Button buttonMoins = new Button();
buttonMoins.Text = "-";
buttonMoins.Clicked += BoutonSupprimer_Clicked;
Grid.SetRow(buttonMoins, len);
Grid.SetColumn(buttonMoins, 2);
GridDrink.Children.Add(buttonMoins);
len++;
Debug.WriteLine("Test test");
}
}
private async void AddDrinklist(object sender, EventArgs e)
{
//restoreListInvite();
string drink = DrinkInput.Text;
string qte = QteInput.Text;
if (int.TryParse(qte, out int value))
{
if (drink == null || qte == null) { return; }
Modeles.Boisson drink1 = new Modeles.Boisson(drink, Int32.Parse(qte));
EventSelect.Participation.Boissons.Add(drink1);
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);
GridDrink.RowDefinitions.Add(row);
// AJout Nourriture
Label DrinkLabel = new Label();
DrinkLabel.Text = food2.Nom;
Grid.SetRow(DrinkLabel, len);
Grid.SetColumn(DrinkLabel, 0);
GridDrink.Children.Add(DrinkLabel);
// Ajout Quantite
Label qteLabel = new Label();
qteLabel.Text = food2.Quantite.ToString();
Grid.SetRow(qteLabel, len);
Grid.SetColumn(qteLabel, 1);
GridDrink.Children.Add(qteLabel);
// Ajout Bouton
Button buttonMoins = new Button();
buttonMoins.Text = "-";
buttonMoins.Clicked += BoutonSupprimer_Clicked;
Grid.SetRow(buttonMoins, len);
Grid.SetColumn(buttonMoins, 2);
GridDrink.Children.Add(buttonMoins);
len++;
Debug.WriteLine("Test test");
}
}
else
{
//await DisplayAlert("esv", "efds", "OK");
return;
}
}
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 DrinkLabel = null;
Label qteLabel = 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)
DrinkLabel = (Label)child;
else if (Grid.GetColumn(child) == 1)
qteLabel = (Label)child;
}
}
if (DrinkLabel != null && qteLabel != null)
{
// Récupérer le prénom et le nom de l'invité à supprimer
string nom = DrinkLabel.Text;
string qte = qteLabel.Text;
// Rechercher l'invité correspondant dans la liste
Modeles.Boisson drink = EventSelect.Participation.Boissons.FirstOrDefault(i => i.Nom == nom && i.Quantite.ToString() == qte);
if (drink != null)
{
// Supprimer l'invité de la liste
EventSelect.Participation.Boissons.Remove(drink);
// Supprimer les éléments de la ligne de la grille
parentGrid.Children.Remove(DrinkLabel);
parentGrid.Children.Remove(qteLabel);
parentGrid.Children.Remove(button);
parentGrid.RowDefinitions.RemoveAt(rowIndex);
}
}
}
}

@ -2,32 +2,35 @@
<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" />
<Entry Placeholder="Entrer quantité" Keyboard="Numeric" 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 Grid.Column="2" x:Name="GridFood">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="3*" x:Name="sup"/>
</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 Text="Nourriture" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="Quantité" Grid.Column="1" 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 Quantite}" Grid.Row="1" FontSize="Large"/>

@ -14,16 +14,16 @@ public partial class Nourri : ContentView
{
this.EventSelect = EventSelect;
InitializeComponent();
//restoreListInvite(EventSelect);
restoreListFood(EventSelect);
BindingContext = this;
}
public void restoreListInvite(Evenement EventSelect)
public void restoreListFood(Evenement EventSelect)
{
var listFood = EventSelect.Participation.Nourriture;
Debug.WriteLine(listFood);
List<Modeles.Nourriture> listFood = EventSelect.Participation.Nourriture;
Debug.WriteLine("TEst " + listFood.Count());
int len = 1;
foreach (Modeles.Nourriture food in listFood)
{
@ -31,17 +31,18 @@ public partial class Nourri : ContentView
row.Height = new GridLength(45);
GridFood.RowDefinitions.Add(row);
// AJout Prenom
// AJout Nourriture
Label foodLabel = new Label();
foodLabel.Text = food.Nom;
foodLabel.Text = food.Nom.ToString();
Debug.WriteLine(foodLabel);
Grid.SetRow(foodLabel, len);
Grid.SetColumn(foodLabel, 0);
GridFood.Children.Add(foodLabel);
// Ajout Nom
// Ajout Quantite
Label qteLabel = new Label();
food.Nom = food.Quantite.ToString();
qteLabel.Text = food.Quantite.ToString();
Grid.SetRow(qteLabel, len);
Grid.SetColumn(qteLabel, 1);
GridFood.Children.Add(qteLabel);
@ -62,50 +63,58 @@ public partial class Nourri : ContentView
}
private void AddFoodlist(object sender, EventArgs e)
private async 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)
if (int.TryParse(qte, out int value))
{
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");
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 Nourriture
Label foodLabel = new Label();
foodLabel.Text = food2.Nom;
Grid.SetRow(foodLabel, len);
Grid.SetColumn(foodLabel, 0);
GridFood.Children.Add(foodLabel);
// Ajout Quantite
Label qteLabel = new Label();
qteLabel.Text = 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");
}
}
else {
//await DisplayAlert("esv", "efds", "OK");
return;
}
}
private void BoutonSupprimer_Clicked(object sender, EventArgs e)
@ -121,8 +130,8 @@ public partial class Nourri : ContentView
// Vérifier que l'indice rowIndex est valide
Label prenomLabel = null;
Label nomLabel = null;
Label foodLabel = null;
Label qteLabel = null;
// Parcourir les enfants de la grille pour trouver les labels de la ligne
foreach (View child in parentGrid.Children)
@ -132,29 +141,29 @@ public partial class Nourri : ContentView
if (childRowIndex == rowIndex)
{
if (Grid.GetColumn(child) == 0)
prenomLabel = (Label)child;
foodLabel = (Label)child;
else if (Grid.GetColumn(child) == 1)
nomLabel = (Label)child;
qteLabel = (Label)child;
}
}
if (prenomLabel != null && nomLabel != null)
if (foodLabel != null && qteLabel != null)
{
// Récupérer le prénom et le nom de l'invité à supprimer
string prenom = prenomLabel.Text;
string nom = nomLabel.Text;
string nom = foodLabel.Text;
string qte = qteLabel.Text;
// Rechercher l'invité correspondant dans la liste
Modeles.Inviter inviter = EventSelect.ListInviter.FirstOrDefault(i => i.Prenom == prenom && i.Nom == nom);
Modeles.Nourriture nourriture = EventSelect.Participation.Nourriture.FirstOrDefault(i => i.Nom == nom && i.Quantite.ToString() == qte);
if (inviter != null)
if (nourriture != null)
{
// Supprimer l'invité de la liste
EventSelect.ListInviter.Remove(inviter);
EventSelect.Participation.Nourriture.Remove(nourriture);
// Supprimer les éléments de la ligne de la grille
parentGrid.Children.Remove(prenomLabel);
parentGrid.Children.Remove(nomLabel);
parentGrid.Children.Remove(foodLabel);
parentGrid.Children.Remove(qteLabel);
parentGrid.Children.Remove(button);
parentGrid.RowDefinitions.RemoveAt(rowIndex);
}

@ -8,20 +8,38 @@
<VerticalStackLayout>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="300"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Text="Nourriture" BackgroundColor="Grey" Clicked="NourritureView" />
<Button Text="Boisson" Grid.Column="1" Clicked="BoissonView"/>
<Button Text="Autre" Grid.Column="2" Clicked="AutreView" />
</Grid>
<!--Grid Participation-->
<Grid ColumnDefinitions="*,*,*" RowDefinitions="*,*" HeightRequest="100" VerticalOptions="Center" BackgroundColor="AliceBlue">
<Button Text="Nourriture" BackgroundColor="Grey" Clicked="NourritureView" />
<Button Text="Boisson" Grid.Column="1" Clicked="BoissonView"/>
<Button Text="Autre" Grid.Column="2" Clicked="AutreView" />
<ContentView x:Name="changeButton" Grid.Row="1" BackgroundColor="AliceBlue" >
</ContentView>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentView x:Name="changeButton" >
</ContentView>
</Grid>
</Grid>
</VerticalStackLayout>
</ContentView>

@ -27,7 +27,7 @@ public partial class Nourriture : ContentView
{
if (EventSelect == null) { return; }
var newPage = new Views.Participations.NewFolder1.Nourri(EventSelect);
var newPage = new Views.Participations.Boisson.Drink(EventSelect);
changeButton.Content = newPage;
}
@ -36,7 +36,7 @@ public partial class Nourriture : ContentView
{
if (EventSelect == null) { return; }
var newPage = new Views.Participations.NewFolder1.Nourri(EventSelect);
var newPage = new Views.Participations.Autre.Autres(EventSelect);
changeButton.Content = newPage;
}

Loading…
Cancel
Save