Пример #1
0
        private async void btnscan_Clicked(object sender, EventArgs e)
        {
            await btnscan.ScaleTo(1.1, 80);

            await btnscan.ScaleTo(1, 80, Easing.BounceOut);

            scanPage = new ZXingScannerPage();
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;

                var pop = new PopUp(BarCodeManager.getCorrectName(BarCodeManager.getBarNameDabas(result.Text)));

                App.Current.MainPage.Navigation.PushPopupAsync(pop, true);

                pop.OnDialogClosed += (s, arg) =>
                {
                    string productname = Regex.Replace(arg.ProductName, @"\s+", " ").Trim();

                    if (!string.IsNullOrWhiteSpace(productname) && !productname.Equals(""))
                    {
                        productname = char.ToUpper(productname[0]) + productname.Substring(1);
                        DateTime date       = arg.ExpirationDate;
                        var      ingredient = new Ingredient(productname, date);
                        db.InsertIntoTable(ingredient);
                        PersonalIngredientList.Add(ingredient);
                        Model.IngredientList.Add(ingredient);
                        PersonalIngredientList.Sort((a, b) => a.Date.CompareTo(b.Date));
                        Model          = new IngredientsViewModel(PersonalIngredientList);
                        BindingContext = Model;

                        CrossLocalNotifications.Current.Show("Utgående vara", "Din vara '" + ingredient.Name + "' går ut snart! Använd vår sökfunktion för att hitta passande recept:)", ingredient.ID, date.AddDays(-2).AddHours(16));
                    }
                };

                //Gör något med "result"
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopModalAsync();
                });
            };

            await Navigation.PushModalAsync(scanPage);
        }