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" xmlns:autre="clr-namespace:ParionsCuite.Views.Participations.Autre"
> >
<VerticalStackLayout> <Grid ColumnDefinitions="1*,10*">
<!-- Séparation de la page -->
<ScrollView> <!-- Première colonne -->
<Grid > <ScrollView >
<!-- Séparation de la page --> <StackLayout x:Name="ButtonStackLayout" BindingContext="{Binding mgr.Evenement}">
<Grid.ColumnDefinitions> <Button Text="+" BackgroundColor="Green" Grid.Column="0" HeightRequest="50" Clicked="Button_Clicked"/>
<ColumnDefinition Width="1*" /> </StackLayout>
<ColumnDefinition Width="10*" /> </ScrollView>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Grid.Column="0" Height="2*" />
<RowDefinition Grid.Column="0" Height="3*" />
</Grid.RowDefinitions>
<!-- 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 --> <!-- 2e ligne -->
<Grid Grid.Column="1"> <Grid Grid.Row="1" >
<!-- Création de 2 lignes --> <ContentView x:Name="changeButton">
<Grid.RowDefinitions> <views:Accueil/>
<RowDefinition Height="100"/> </ContentView>
<RowDefinition Height="1500"/> </Grid>
</Grid.RowDefinitions> </Grid>
<!-- 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>
</Grid>
<!-- 2e ligne -->
<Grid Grid.Row="1" >
<ContentView x:Name="changeButton">
<views:Accueil/>
</ContentView>
</Grid>
</Grid>
</Grid>
</ScrollView>
</VerticalStackLayout>
</ContentPage> </ContentPage>

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

@ -103,7 +103,7 @@ namespace ParionsCuite.Modeles
} }
public void Charge_Donnee() public void Charge_Donnee()
{ {
var donnees = Persistance.chargeDonnees(); var donnees = Persistance.chargeDonnees();
foreach (var donnee in donnees) foreach (var donnee in donnees)
{ {

@ -17,7 +17,7 @@ namespace ParionsCuite.Modeles
[DataMember] [DataMember]
public List<Boisson> Boissons { get; private set; } public List<Boisson> Boissons { get; private set; }
[DataMember] [DataMember]
public List<Nourriture> Nourriture { get; private set; } public List<Nourriture> Nourriture { get; private set; }
[DataMember] [DataMember]
public List<Autre> Autre { get; private set; } public List<Autre> Autre { get; private set; }
@ -27,6 +27,13 @@ namespace ParionsCuite.Modeles
Nourriture = nourriture; Nourriture = nourriture;
Autre = autre; Autre = autre;
} }
public Participation()
{
Boissons = new List<Boisson>();
Nourriture = new List<Nourriture>();
Autre = new List<Autre>();
}
/* Boisson */ /* Boisson */

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

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

@ -2,53 +2,35 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ParionsCuite.Views.Participations.Autre.Autres"> x:Class="ParionsCuite.Views.Participations.Autre.Autres">
<VerticalStackLayout> <VerticalStackLayout>
<!--Grid menu--> <Grid ColumnDefinitions="5*, 1*, 5*">
<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="*,*,*">
<!--Input des boissons et quantité--> <!--Input des nourritures et quantité-->
<StackLayout Grid.Column="0" > <StackLayout Grid.Column="0" >
<Entry Text="Entrer autre" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" /> <Entry Placeholder="Entrer l'objet" x:Name="AutreInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,0" />
<Entry Text="Entrer quantité" 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"/> <Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0" Clicked="AddAutrelist"/>
</StackLayout> </StackLayout>
<!--Grid quantité et boisson + output --> <!--Grid quantité et nourrite + output -->
<Grid Grid.Column="1" Margin="30"> <Grid Grid.Column="2" x:Name="GridAutre">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="1*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="3*" x:Name="sup"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!--Header Grille quantité+boisson--> <!--Header Grille quantité+nourritre-->
<Label Text="Quantité" Grid.Column="1" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/> <Label Text="Objet" Grid.Column="0" Grid.Row="0" BackgroundColor="LightGrey" FontSize="Large"/>
<Label Text="Autre" 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 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>
</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 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" <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ParionsCuite.Views.Participations.NewFolder1.Nourri"> x:Class="ParionsCuite.Views.Participations.NewFolder1.Nourri">
<VerticalStackLayout> <VerticalStackLayout>
<Grid ColumnDefinitions="5*, 1*, 5*"> <Grid ColumnDefinitions="5*, 1*, 5*">
<!--Input des nourritures et quantité--> <!--Input des nourritures et quantité-->
<StackLayout Grid.Column="0" > <StackLayout Grid.Column="0" >
<Entry Placeholder="Entrer nourriture" x:Name="FoodInput" HorizontalOptions="End" FontSize="Large" Margin="0,20,0,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"/> <Button Text="Ajouter" HorizontalOptions="Center" Margin="0,20,0,0" Clicked="AddFoodlist"/>
</StackLayout> </StackLayout>
<!--Grid quantité et nourrite + output --> <!--Grid quantité et nourrite + output -->
<Grid Grid.Column="2" Margin="30" x:Name="GridFood"> <Grid Grid.Column="2" x:Name="GridFood">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="3*" x:Name="sup"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!--Header Grille quantité+nourritre--> <!--Header Grille quantité+nourritre-->
<Label Text="Nourriture" Grid.Column="1" 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="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 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; this.EventSelect = EventSelect;
InitializeComponent(); InitializeComponent();
//restoreListInvite(EventSelect); restoreListFood(EventSelect);
BindingContext = this; BindingContext = this;
} }
public void restoreListInvite(Evenement EventSelect) public void restoreListFood(Evenement EventSelect)
{ {
var listFood = EventSelect.Participation.Nourriture; List<Modeles.Nourriture> listFood = EventSelect.Participation.Nourriture;
Debug.WriteLine(listFood); Debug.WriteLine("TEst " + listFood.Count());
int len = 1; int len = 1;
foreach (Modeles.Nourriture food in listFood) foreach (Modeles.Nourriture food in listFood)
{ {
@ -31,17 +31,18 @@ public partial class Nourri : ContentView
row.Height = new GridLength(45); row.Height = new GridLength(45);
GridFood.RowDefinitions.Add(row); GridFood.RowDefinitions.Add(row);
// AJout Prenom // AJout Nourriture
Label foodLabel = new Label(); Label foodLabel = new Label();
foodLabel.Text = food.Nom; foodLabel.Text = food.Nom.ToString();
Debug.WriteLine(foodLabel);
Grid.SetRow(foodLabel, len); Grid.SetRow(foodLabel, len);
Grid.SetColumn(foodLabel, 0); Grid.SetColumn(foodLabel, 0);
GridFood.Children.Add(foodLabel); GridFood.Children.Add(foodLabel);
// Ajout Nom // Ajout Quantite
Label qteLabel = new Label(); Label qteLabel = new Label();
food.Nom = food.Quantite.ToString(); qteLabel.Text = food.Quantite.ToString();
Grid.SetRow(qteLabel, len); Grid.SetRow(qteLabel, len);
Grid.SetColumn(qteLabel, 1); Grid.SetColumn(qteLabel, 1);
GridFood.Children.Add(qteLabel); GridFood.Children.Add(qteLabel);
@ -62,49 +63,57 @@ public partial class Nourri : ContentView
} }
private void AddFoodlist(object sender, EventArgs e) private async void AddFoodlist(object sender, EventArgs e)
{ {
//restoreListInvite(); //restoreListInvite();
string food = FoodInput.Text; string food = FoodInput.Text;
string qte = QteInput.Text; string qte = QteInput.Text;
if (food == null || qte == null) { return; } if (int.TryParse(qte, out int value))
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(); if (food == null || qte == null) { return; }
row.Height = new GridLength(45); Modeles.Nourriture food1 = new Modeles.Nourriture(food, Int32.Parse(qte));
GridFood.RowDefinitions.Add(row); EventSelect.Participation.Nourriture.Add(food1);
int len = 1;
// AJout Prenom //if (len == 0 ) { len = 1; }
Label foodLabel = new Label(); foreach (Modeles.Nourriture food2 in EventSelect.Participation.Nourriture)
foodLabel.Text = food2.Nom; {
Grid.SetRow(foodLabel, len); RowDefinition row = new RowDefinition();
Grid.SetColumn(foodLabel, 0); row.Height = new GridLength(45);
GridFood.Children.Add(foodLabel); GridFood.RowDefinitions.Add(row);
// AJout Nourriture
// Ajout Nom Label foodLabel = new Label();
Label qteLabel = new Label(); foodLabel.Text = food2.Nom;
food2.Nom = food2.Quantite.ToString(); Grid.SetRow(foodLabel, len);
Grid.SetRow(qteLabel, len); Grid.SetColumn(foodLabel, 0);
Grid.SetColumn(qteLabel, 1); GridFood.Children.Add(foodLabel);
GridFood.Children.Add(qteLabel);
// Ajout Bouton // Ajout Quantite
Label qteLabel = new Label();
Button buttonMoins = new Button(); qteLabel.Text = food2.Quantite.ToString();
buttonMoins.Text = "-"; Grid.SetRow(qteLabel, len);
buttonMoins.Clicked += BoutonSupprimer_Clicked; Grid.SetColumn(qteLabel, 1);
Grid.SetRow(buttonMoins, len); GridFood.Children.Add(qteLabel);
Grid.SetColumn(buttonMoins, 2);
GridFood.Children.Add(buttonMoins); // Ajout Bouton
len++; Button buttonMoins = new Button();
Debug.WriteLine("Test test"); 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;
} }
} }
@ -121,8 +130,8 @@ public partial class Nourri : ContentView
// Vérifier que l'indice rowIndex est valide // Vérifier que l'indice rowIndex est valide
Label prenomLabel = null; Label foodLabel = null;
Label nomLabel = null; Label qteLabel = null;
// Parcourir les enfants de la grille pour trouver les labels de la ligne // Parcourir les enfants de la grille pour trouver les labels de la ligne
foreach (View child in parentGrid.Children) foreach (View child in parentGrid.Children)
@ -132,29 +141,29 @@ public partial class Nourri : ContentView
if (childRowIndex == rowIndex) if (childRowIndex == rowIndex)
{ {
if (Grid.GetColumn(child) == 0) if (Grid.GetColumn(child) == 0)
prenomLabel = (Label)child; foodLabel = (Label)child;
else if (Grid.GetColumn(child) == 1) 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 // Récupérer le prénom et le nom de l'invité à supprimer
string prenom = prenomLabel.Text; string nom = foodLabel.Text;
string nom = nomLabel.Text; string qte = qteLabel.Text;
// Rechercher l'invité correspondant dans la liste // 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 // 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 // Supprimer les éléments de la ligne de la grille
parentGrid.Children.Remove(prenomLabel); parentGrid.Children.Remove(foodLabel);
parentGrid.Children.Remove(nomLabel); parentGrid.Children.Remove(qteLabel);
parentGrid.Children.Remove(button); parentGrid.Children.Remove(button);
parentGrid.RowDefinitions.RemoveAt(rowIndex); parentGrid.RowDefinitions.RemoveAt(rowIndex);
} }

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

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

Loading…
Cancel
Save