예제 #1
0
        private async void Apply_Clicked(object sender, EventArgs e)
        {
            bool result = false;

            if (codiceAndroid.Text != "" || codiceAndroid.Text != null || codiceiOS.Text != "" || codiceiOS.Text != null)
            {
                switch (Device.RuntimePlatform)
                {
                case Device.Android:
                    result = await ControlloCodice.checkBeforeAction(codiceAndroid.Text);

                    break;

                case Device.iOS:

                    result = await ControlloCodice.checkBeforeAction(codiceiOS.Text);

                    break;
                }
                if (result)
                {
                    switch (mod)
                    {
                    case "mangia":
                        SnackServiceManager a        = new SnackServiceManager();
                        SnackDataDTO        elemento = (SnackDataDTO)index;
                        var scelta = await DisplayAlert("Fondomerende", "Sicuro di voler mangiare " + elemento.friendly_name + "?", "Si", "No");

                        if (scelta)
                        {
                            var risposta = await a.EatAsync(elemento.id, 1);

                            if (risposta.success)
                            {
                                await DisplayAlert("Fondomerende", "Snack mangiato", "Ok");
                            }
                            else
                            {
                                await DisplayAlert("Fondomerende", "Snack non mangiato", "Ok");
                            }
                            await PopupNavigation.Instance.PopAsync();
                        }
                        else
                        {
                            await PopupNavigation.Instance.PopAsync();
                        }
                        break;

                    //////////////////////////////////////////////////////////
                    case "deposita":
                        DepositServiceManager d = new DepositServiceManager();

                        string app       = (string)index;
                        var    resultDep = await d.DepositAsync(app);

                        if (resultDep != null)
                        {
                            if (resultDep.success)
                            {
                                await DisplayAlert("Fondomerende", "Soldi depositati con successo", "Ok");

                                if (Device.RuntimePlatform == Device.iOS)
                                {
                                    DependencyService.Get <HapticFeedbackGen>().HapticFeedbackGenSuccessAsync();
                                }

                                else
                                {
                                    Vibration.Vibrate(40);
                                    await Task.Delay(100);

                                    Vibration.Vibrate(40);
                                }
                                await PopupNavigation.Instance.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Fondomerende", "I soldi non sono stati depositati", "Ok");
                            };
                        }
                        else
                        {
                            await PopupNavigation.Instance.PopAsync();
                        }
                        break;

                    /////////////////////////////////////////////////
                    case "compra":
                        int  id               = (int)index;
                        int  quantita         = (int)aggiunta;
                        bool swap             = (bool)aggiunta4;
                        SnackServiceManager x = new SnackServiceManager();
                        if (!swap)
                        {
                            var risp = await x.BuySnackAsync(id, quantita);

                            if (risp != null)
                            {
                                if (risp.success)
                                {
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGetSnacks");
                                    Vibration.Vibrate(40);
                                    await Task.Delay(100);

                                    Vibration.Vibrate(40);
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGriglia");
                                    await DisplayAlert("Fondo Merende", "Lo snack è stato comprato", "Ok");

                                    await PopupNavigation.Instance.PopAsync();
                                }
                                else
                                {
                                    await DisplayAlert("Fondo Merende", risp.message, "Ok");
                                }
                            }
                        }
                        else
                        {
                            string prezzo   = (string)aggiunta2;
                            string scadenza = (string)aggiunta3;
                            var    risp     = await x.BuySnackAsync2(id, quantita, prezzo, scadenza);

                            if (risp != null)
                            {
                                if (risp.success)
                                {
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGetSnacks");
                                    Vibration.Vibrate(40);
                                    await Task.Delay(100);

                                    Vibration.Vibrate(40);
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGriglia");
                                    await DisplayAlert("Fondo Merende", "Lo snack è stato comprato", "Ok");

                                    await PopupNavigation.Instance.PopAsync();
                                }
                                else
                                {
                                    await DisplayAlert("Fondo Merende", risp.message, "Ok");
                                }
                            }
                        }

                        break;

                        ///////////////////////////////////////////
                    }
                }
                else
                {
                    await DisplayAlert("Fondomerende", "Codice non presente", "Ok");
                }
            }
            else
            {
                await DisplayAlert("Fondomerende", "Inserire il codice", "Ok");
            }
            ControlloCodice.fineAzioni();
        }
예제 #2
0
        private async void Apply_ClickedAndroid(object sender, EventArgs e)
        {
            SnackServiceManager snackService = new SnackServiceManager();

            if (swap == false)
            {
                if (lineAndroid.Text == null || lineAndroid.Text == "")
                {
                    await DisplayAlert("Fondo Merende", "Inserisci la quantità", "OK");
                }
                else
                {
                    if (lineAndroid.Text.Contains(","))
                    {
                        int aiuto = lineAndroid.Text.IndexOf(",");
                        lineAndroid.Text = lineAndroid.Text.Substring(0, aiuto);
                    }
                    if (TabletManager.Instance.tablet)
                    {
                        await Navigation.PushPopupAsync(new CodicePopup((BuySnackListPage.SelectedSnackID), "compra", Convert.ToInt32(lineAndroid.Text), swap));
                    }
                    else
                    {
                        var result = await snackService.BuySnackAsync(BuySnackListPage.SelectedSnackID, Convert.ToInt32(lineAndroid.Text));

                        if (result != null)
                        {
                            if (result.success)
                            {
                                MessagingCenter.Send(new AllSnacksPage()
                                {
                                }, "RefreshGetSnacks");
                                Vibration.Vibrate(40);
                                await Task.Delay(100);

                                Vibration.Vibrate(40);
                                MessagingCenter.Send(new AllSnacksPage()
                                {
                                }, "RefreshGriglia");
                                await DisplayAlert("Fondo Merende", "Lo snack è stato comprato", "Ok");

                                await PopupNavigation.Instance.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Fondo Merende", result.message, "Ok");
                            }
                        }
                    }
                }
            }
            if (swap == true)
            {
                if (lineAndroid.Text == null || lineAndroid.Text == "")
                {
                    await DisplayAlert("Fondo Merende", "Inserisci la quantità", "OK");
                }
                if (prezzoAndroid.Text == null || prezzoAndroid.Text == "")
                {
                    await DisplayAlert("Fondo Merende", "Inserisci il prezzo", "OK");
                }
                if (scadenzaAndroid.Text == null || scadenzaAndroid.Text == "")
                {
                    await DisplayAlert("Fondo Merende", "Inserisci i giorni di scadenza", "OK");
                }
                else
                {
                    if (lineAndroid.Text.Contains(","))
                    {
                        int aiuto = lineAndroid.Text.IndexOf(",");
                        lineAndroid.Text = lineAndroid.Text.Substring(0, aiuto);
                    }
                    if (TabletManager.Instance.tablet)
                    {
                        await Navigation.PushPopupAsync(new CodicePopup(BuySnackListPage.SelectedSnackID, "compra", Int32.Parse(lineAndroid.Text), prezzoAndroid.Text, scadenzaAndroid.Text, true));
                    }
                    else
                    {
                        var result = await snackService.BuySnackAsync2(BuySnackListPage.SelectedSnackID, Int32.Parse(lineAndroid.Text), prezzoAndroid.Text, scadenzaAndroid.Text);

                        if (result != null)
                        {
                            if (result.success)
                            {
                                MessagingCenter.Send(new AllSnacksPage()
                                {
                                }, "RefreshGetSnacks");
                                Vibration.Vibrate(40);
                                await Task.Delay(100);

                                Vibration.Vibrate(40);
                                MessagingCenter.Send(new AllSnacksPage()
                                {
                                }, "RefreshGriglia");
                                await PopupNavigation.Instance.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Fondo Merende", result.message, "Ok");
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        private async void Apply_ClickediOs(object sender, EventArgs e)
        {
            try
            {
                SnackServiceManager snackService = new SnackServiceManager();
                if (swap == false)
                {
                    if (lineiOs.Text.Contains(","))
                    {
                        int aiuto = lineiOs.Text.IndexOf(",");
                        lineiOs.Text = lineiOs.Text.Substring(0, aiuto);
                    }

                    else
                    {
                        if (TabletManager.Instance.tablet)
                        {
                            await Navigation.PushPopupAsync(new CodicePopup((BuySnackListPage.SelectedSnackID), "compra", Convert.ToInt32(lineiOs.Text), null, null, swap));
                        }
                        else
                        {
                            var result = await snackService.BuySnackAsync(BuySnackListPage.SelectedSnackID, Convert.ToInt32(lineiOs.Text));

                            if (result != null)
                            {
                                if (result.success)
                                {
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGetSnacks");
                                    DependencyService.Get <HapticFeedbackGen>().HapticFeedbackGenSuccessAsync();
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGriglia");
                                    await PopupNavigation.Instance.PopAsync();
                                }
                                else
                                {
                                    await DisplayAlert("Fondo Merende", result.message, "Ok");
                                }
                            }
                        }
                    }
                }
                if (swap == true)
                {
                    if (lineiOs.Text.Contains(","))
                    {
                        int aiuto = lineiOs.Text.IndexOf(",");
                        lineiOs.Text = lineiOs.Text.Substring(0, aiuto);
                    }
                    else
                    {
                        if (TabletManager.Instance.tablet)
                        {
                            await Navigation.PushPopupAsync(new CodicePopup(BuySnackListPage.SelectedSnackID, "compra", Int32.Parse(lineiOs.Text), prezzoiOs.Text, scadenzaiOs.Text, true));
                        }
                        else
                        {
                            var result = await snackService.BuySnackAsync2(BuySnackListPage.SelectedSnackID, Int32.Parse(lineiOs.Text), prezzoiOs.Text, scadenzaiOs.Text);

                            if (result != null)
                            {
                                if (result.success)
                                {
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGetSnacks");
                                    DependencyService.Get <HapticFeedbackGen>().HapticFeedbackGenSuccessAsync();
                                    MessagingCenter.Send(new AllSnacksPage()
                                    {
                                    }, "RefreshGriglia");
                                    await PopupNavigation.Instance.PopAsync();
                                }
                                else
                                {
                                    await DisplayAlert("Fondo Merende", result.message, "Ok");
                                }
                            }
                        }
                    }
                }
            }catch (Exception ex)
            {
                await DisplayAlert("Fondo Merende", "Riempire tutti i campi", "Ok");
            }
        }
예제 #4
0
        //per applicare le modifiche//
        private async void Apply_Clicked(object sender, EventArgs e)
        {
            SnackServiceManager snackService = new SnackServiceManager();

            if (NomeSnack.Text == null || PrezzoSnack.Text == null || SnackPerBox.Text == null || ExpInDays.Text == null)
            {
                await DisplayAlert("Fondo Merende", "Compila tutti i campi", "OK");
            }
            else
            {
                var ans = await DisplayAlert("Fondo Merende", "Lo Snack è contabile?", "Si", "No");

                if (ans)
                {
                    var result = await snackService.AddSnackAsync(NomeSnack.Text, double.Parse(PrezzoSnack.Text), int.Parse(SnackPerBox.Text), int.Parse(ExpInDays.Text), true);

                    if (result != null)
                    {
                        if (result.success)
                        {
                            await DisplayAlert("Fondo Merende", "Lo snack è stato aggiunto", "Ok");

                            if (Device.RuntimePlatform == Device.iOS)
                            {
                                DependencyService.Get <HapticFeedbackGen>().HapticFeedbackGenSuccessAsync();
                            }

                            else
                            {
                                Vibration.Vibrate(40);
                                await Task.Delay(100);

                                Vibration.Vibrate(40);
                            }
                            await Navigation.PopPopupAsync();
                        }
                        else
                        {
                            await DisplayAlert("Fondo Merende", "Snack già presente", "Ok");
                        }
                    }
                    else
                    {
                        await PopupNavigation.Instance.PopAsync();
                    }
                }
                else
                {
                    var result = await snackService.AddSnackAsync(NomeSnack.Text, double.Parse(PrezzoSnack.Text), int.Parse(SnackPerBox.Text), int.Parse(ExpInDays.Text), false);

                    if (result != null)
                    {
                        if (result.success)
                        {
                            await DisplayAlert("Fondo Merende", "SnackID: " + result.data.id, "Ok");

                            await Navigation.PopPopupAsync();
                        }
                        else
                        {
                            await DisplayAlert("Fondo Merende", result.message, "Ok");
                        }
                    }
                    else
                    {
                        await PopupNavigation.Instance.PopAsync();
                    }
                }
            }
        }