async private void Sauvegarder_Clicked(System.Object sender, System.EventArgs e) { int Desc; if (!InternetGetConnectedState(out Desc, 0)) { SortieApi.Text = "You are not connected to the Internet"; } else { var col = Database.db.GetCollection <FrigoBaseDeDonnée>("FrigoBaseDeDonnée"); if (EntréeCodeBarre.Text == null || EntréeCodeBarre.Text == "") { if (SiPasCodeBarre.Text != null) { FrigoBaseDeDonnée.InsertProduct(null, SiPasCodeBarre.Text, -1, -1, -1, null, null, null, -1, null, peremption.Date, null, null); create(); } } else { var nutriInfo = await InfoResponseApi.LoadInfo((EntréeCodeBarre.Text)); if (nutriInfo == null) { SortieApi.Text = "Invalid Barcode"; } else { if (nutriInfo.Ingredients_text != null) { FrigoBaseDeDonnée.InsertProduct(EntréeCodeBarre.Text, nutriInfo.Product_name_fr, nutriInfo.Nutriments.Sugars_100g, nutriInfo.Nutriments.Salt_100g, nutriInfo.Nutriments.Fat_100g, nutriInfo.Nutrient_levels.Salt, nutriInfo.Nutrient_levels.Sugars, nutriInfo.Nutrient_levels.Fat, nutriInfo.Nutriments.Proteins_100g, nutriInfo.Ingredients_text, peremption.Date, nutriInfo.Nutrition_grades, nutriInfo.Quantity); SortieApi.Text = "The product has been added with succes to your pantry"; create(); } else { SortieApi.Text = "Invalid Barcode"; } } } } }
public PageProduct(FrigoBaseDeDonnée produit) { Content = grid; prod = produit; grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }); //grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.BackgroundColor = Color.White; StackLayout stackTop = new StackLayout(); stackTop.HorizontalOptions = LayoutOptions.Center; Titre.Text = produit.Name; Titre.HorizontalTextAlignment = TextAlignment.Center; Titre.FontSize = 25; // Grid.SetColumnSpan(stackTop, 2); ImageButton Close = new ImageButton(); Close.Source = "Assets/croix.png"; Close.HeightRequest = 50; Close.Scale = 0.5; Close.VerticalOptions = LayoutOptions.Start; Close.Clicked += (sender, e) => { Navigation.PopAsync(); }; stackTop.Children.Add(Close); stackTop.Children.Add(Titre); grid.Children.Add(stackTop, 0, 0); ImageButton nutriscore = new ImageButton(); nutriscore.WidthRequest = 140; stackTop.Children.Add(nutriscore); switch (produit.Nutriscore) { case "a": nutriscore.Source = "Assets/A.png"; break; case "b": nutriscore.Source = "Assets/B.png"; break; case "c": nutriscore.Source = "Assets/C.png"; break; case "d": nutriscore.Source = "Assets/D.png"; break; case "e": nutriscore.Source = "Assets/E.png"; break; default: Label isnot = new Label { Text = "The nutriscore is not set for this product" }; stackTop.Children.Add(isnot); break; } quantity.Text = produit.Quantity; stackTop.Children.Add(quantity); Label espace2 = new Label { HeightRequest = 70 }; grid.Children.Add(baspage, 0, 1); Label pour100g = new Label { Text = "Repères nutritionnels pour 100 g/100 mL", FontAttributes = FontAttributes.Bold, FontSize = 30, HorizontalTextAlignment = TextAlignment.Center }; baspage.Children.Add(pour100g); baspage.Children.Add(espace2); comparatif(produit.GommetesSucre, produit.Sucre, "Sugar"); comparatif(produit.GommetesSel, produit.Sel, "Salt"); comparatif(produit.GommetesMG, produit.Matiere_grasse, "Fat"); comparatif("", produit.Proteine, "Protein"); ingredient.Text = "Ingrédients: " + prod.Ingrédients; baspage.Children.Add(espace); if (produit.Ingrédients == null || produit.Ingrédients == "") { ImageButton save = new ImageButton { Source = "Assets/save.png", HeightRequest = 40, HorizontalOptions = LayoutOptions.Center, ClassId = produit.Name }; save.Clicked += Save_Clicked; baspage.Children.Add(ajoutdescription); baspage.Children.Add(save); } else { baspage.Children.Add(ingredient); } }