Exemplo n.º 1
0
        private void AddDeposit_Clicked(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(EnteredDeposit.Text) == true)
            {
                DisplayAlert("Error", "Please Enter A Valid Amount", "Retry");
            }

            else
            {
                Nullable <double> amountDep = Convert.ToDouble(EnteredDeposit.Text);
                amountDep = Math.Round(amountDep.Value, 2);
                TransactionTable transaction = new TransactionTable()
                {
                    amount   = Convert.ToDouble(amountDep),
                    type     = "Deposit",
                    category = "",
                    UserID   = user.Id,
                };
                transaction.shit = "Type: " + transaction.type; //"        Category: " + transaction.category;
                using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <TransactionTable>();
                    conn.Insert(transaction);
                    Account acc = conn.FindWithQuery <Account>("Select* From Account Where uId=?", user.Id);
                    acc.dep += Convert.ToDouble(amountDep);
                    acc.bal += Convert.ToDouble(amountDep);
                    conn.Update(acc);
                }

                DisplayAlert("Deposited", "$" + amountDep.ToString(), "Okay");
                Navigation.PushAsync(new Navigation(user.Id));
            }
        }
Exemplo n.º 2
0
        private void AddExpense_Clicked(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(EnteredExpense.Text) == true)
            {
                DisplayAlert("Error", "Please Enter A Valid Amount and Selected Category", "Retry");
            }

            else
            {
                Nullable <double> amountEx = Convert.ToDouble(EnteredExpense.Text);
                Nullable <double> category = Convert.ToDouble(CategoryPicker.SelectedIndex);
                if (category < -.01 || category > 4.1)
                {
                    DisplayAlert("Error", "Please Enter A Valid Amount and Selected Category", "Retry");
                }

                else
                {
                    amountEx = Math.Round(amountEx.Value, 2);
                    var selected = CategoryPicker.SelectedItem;
                    var value    = selected.ToString();
                    TransactionTable transaction = new TransactionTable()
                    {
                        amount   = Convert.ToDouble(amountEx),
                        type     = "Expense",
                        category = value,
                        UserID   = user.Id,
                    };
                    transaction.shit = "Type: " + transaction.type + "        Category: " + transaction.category;
                    Account acc;
                    using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
                    {
                        conn.CreateTable <TransactionTable>();
                        conn.Insert(transaction);
                        acc        = conn.FindWithQuery <Account>("Select* From Account Where uId=?", user.Id);
                        acc.spent += Convert.ToDouble(amountEx);
                        acc.bal   -= Convert.ToDouble(amountEx);
                        if (value == "Food")
                        {
                            acc.foodSpent += Convert.ToDouble(amountEx);
                        }

                        else if (value == "Entertainment")
                        {
                            acc.entSpent += Convert.ToDouble(amountEx);
                        }

                        else if (value == "Transportation")
                        {
                            acc.tranSpent += Convert.ToDouble(amountEx);
                        }

                        else if (value == "Bills")
                        {
                            acc.billSpent += Convert.ToDouble(amountEx);
                        }

                        else
                        {
                            acc.otherSpent += Convert.ToDouble(amountEx);
                        }
                        conn.Update(acc);
                    }

                    DisplayAlert("Added Expense", "$" + amountEx.ToString(), "Okay");
                    Navigation.PushAsync(new Navigation(user.Id));
                }
            }
        }