Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (addexpense rr = new addexpense())
     {
         rr.ShowDialog();
     }
 }
Esempio n. 2
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                ActiveIn.IsRunning = true;

                //    var jsoncategoryArray = JsonConvert.SerializeObject(Expenses);
                if (CrossConnectivity.Current.IsConnected)
                {
                    addexpense expense = new addexpense
                    {
                        date      = DatePicker.Date.ToShortDateString(),
                        statement = Statmententry.Text,
                        user_id   = 3,
                        amount    = double.Parse(amountentry.Text)
                    };
                    var nsAPI = RestService.For <IUpdateService>("https://ittezanmobilepos.com");
                    try
                    {
                        var data = await nsAPI.addexpense(expense);

                        if (data.success == true)
                        {
                            ActiveIn.IsRunning = false;
                            await DisplayAlert(AppResources.Alert, AppResources.ExpnseAdded, AppResources.Ok);

                            await Navigation.PopAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        ActiveIn.IsRunning = false;
                        await DisplayAlert(AppResources.Alert, AppResources.ConnectionNotAvailable, AppResources.Ok);

                        //     var data = await nsAPI.AddClientError(client);
                        // await Navigation.PushPopupAsync(new ClientAdded(data));
                        //  Emailentry.Focus();
                    }
                }
                else
                {
                    addexpense expense = new addexpense
                    {
                        date      = DatePicker.Date.ToShortDateString(),
                        statement = Statmententry.Text,
                        user_id   = 3,
                        amount    = double.Parse(amountentry.Text)
                    };
                    var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyDb.db");
                    var db     = new SQLiteConnection(dbpath);
                    var info   = db.GetTableInfo("addexpense");
                    if (!info.Any())
                    {
                        db.CreateTable <addexpense>();
                    }
                    db.Insert(expense);
                    await DisplayAlert(AppResources.Alert, AppResources.ExpnseAdded, AppResources.Ok);

                    var info2 = db.GetTableInfo("Box");
                    if (!info.Any())
                    {
                        db.CreateTable <Box>();
                    }

                    ActiveIn.IsRunning = false;
                    var boxs = (db.Table <Box>().ToList());


                    if (boxs.Count != 0)
                    {
                        box = db.Get <Box>(0);
                        var disc_expenses = Preferences.Get("disc_expenses", 0);
                        if (disc_expenses == 1)
                        {
                            box.balance = (Convert.ToDouble(box.balance) - expense.amount).ToString("0.00");
                        }
                        db.Update(box);
                    }
                }
            }
            catch (ValidationApiException validationException)
            {
                ActiveIn.IsRunning = false;
                await DisplayAlert(AppResources.Alert, AppResources.ConnectionNotAvailable, AppResources.Ok);

                // handle validation here by using validationException.Content,
                // which is type of ProblemDetails according to RFC 7807
            }
            catch (ApiException exception)
            {
                ActiveIn.IsRunning = false;
                await DisplayAlert(AppResources.Alert, AppResources.ConnectionNotAvailable, AppResources.Ok);

                // other exception handling
            }
        }