Implementation Nourriture

C#
Tony Fages 2 years ago
parent a7d041db0d
commit 9727948f3d

@ -19,12 +19,12 @@
<Grid > <Grid >
<!-- Séparation de la page --> <!-- Séparation de la page -->
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" /> <ColumnDefinition Width="100" />
<ColumnDefinition Width="10*" /> <ColumnDefinition Width="1500" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Grid.Column="0" Height="2*" /> <RowDefinition Grid.Column="0" Height="1500" />
<RowDefinition Grid.Column="0" Height="3*" /> <RowDefinition Grid.Column="0" Height="1300" />
</Grid.RowDefinitions> </Grid.RowDefinitions>

@ -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)
{ {

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

@ -8,25 +8,25 @@
<!--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" WidthRequest="300" x:Name="GridFood">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="auto" />
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="auto" />
<ColumnDefinition Width="*"/> <ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="auto"/>
<RowDefinition Height="*"/> <RowDefinition Height="auto" 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"/>

@ -14,7 +14,7 @@ public partial class Nourri : ContentView
{ {
this.EventSelect = EventSelect; this.EventSelect = EventSelect;
InitializeComponent(); InitializeComponent();
//restoreListInvite(EventSelect); restoreListInvite(EventSelect);
BindingContext = this; BindingContext = this;
} }
@ -22,8 +22,8 @@ public partial class Nourri : ContentView
public void restoreListInvite(Evenement EventSelect) public void restoreListInvite(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,11 +63,13 @@ 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 (int.TryParse(qte, out int value))
{
if (food == null || qte == null) { return; } if (food == null || qte == null) { return; }
Modeles.Nourriture food1 = new Modeles.Nourriture(food, Int32.Parse(qte)); Modeles.Nourriture food1 = new Modeles.Nourriture(food, Int32.Parse(qte));
EventSelect.Participation.Nourriture.Add(food1); EventSelect.Participation.Nourriture.Add(food1);
@ -78,7 +81,7 @@ 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 = food2.Nom; foodLabel.Text = food2.Nom;
Grid.SetRow(foodLabel, len); Grid.SetRow(foodLabel, len);
@ -86,9 +89,9 @@ public partial class Nourri : ContentView
GridFood.Children.Add(foodLabel); GridFood.Children.Add(foodLabel);
// Ajout Nom // Ajout Quantite
Label qteLabel = new Label(); Label qteLabel = new Label();
food2.Nom = food2.Quantite.ToString(); qteLabel.Text = food2.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);
@ -105,6 +108,12 @@ public partial class Nourri : ContentView
len++; len++;
Debug.WriteLine("Test test"); 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>
<!--Grid Participation-->
<Grid ColumnDefinitions="*,*,*" RowDefinitions="*,*" HeightRequest="100" VerticalOptions="Center" BackgroundColor="AliceBlue">
<Button Text="Nourriture" BackgroundColor="Grey" Clicked="NourritureView" /> <Button Text="Nourriture" BackgroundColor="Grey" Clicked="NourritureView" />
<Button Text="Boisson" Grid.Column="1" Clicked="BoissonView"/> <Button Text="Boisson" Grid.Column="1" Clicked="BoissonView"/>
<Button Text="Autre" Grid.Column="2" Clicked="AutreView" /> <Button Text="Autre" Grid.Column="2" Clicked="AutreView" />
</Grid>
<!--Grid Participation-->
<ContentView x:Name="changeButton" Grid.Row="1" BackgroundColor="AliceBlue" > <Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentView x:Name="changeButton" >
</ContentView> </ContentView>
</Grid>
</Grid> </Grid>
</VerticalStackLayout> </VerticalStackLayout>
</ContentView> </ContentView>

Loading…
Cancel
Save