protected override void OnAppearing()
        {
            var Expenses = ExpenseManager.GetExpenses();

            ExpenseManager.SaveBudget(500);
            Budget.Text          = budget.ToString();
            RemainingAmount.Text = ExpenseManager.RemainingBudget().ToString();
            if (budget > 0)
            {
                AddNewExpense.IsEnabled = true;
            }
            foreach (var expense in Expenses)
            {
                expenses.Add(expense);
            }
            ExpenseRecords.ItemsSource = expenses.OrderBy(n => n.Date).ToList();
        }
Beispiel #2
0
        private void ItemSelectedFromPicker(object sender, EventArgs e)
        {
            //Getting the selected item from the picker
            var SelectedMonth = mainpicker.Items[mainpicker.SelectedIndex];

            selectedMonth    = SelectedMonth;
            mainpicker.Title = selectedMonth;
            //checking if the item is AllMonths. if yes, clearing the observable collection and adding all expenses to it
            if (SelectedMonth == "AllMonths")
            {
                EditBudget.IsEnabled = false;
                Enum.TryParse(SelectedMonth, out Month month);
                Budget.Text          = ExpenseManager.ReadBudget(month).BudgetAmount.ToString();
                RemainingAmount.Text = ExpenseManager.RemainingBudget(month).ToString();
                var ExpensesFromFile = ExpenseManager.GetExpenses();
                expenses.Clear();
                foreach (var expense in ExpensesFromFile)
                {
                    expenses.Add(expense);
                }
                var orderedExpenses = expenses.OrderBy(n => n.Date).ToList();
                expenses.Clear();
                foreach (var expense in orderedExpenses)
                {
                    expenses.Add(expense);
                }
            }
            else
            {
                EditBudget.IsEnabled = true;
                Enum.TryParse(SelectedMonth, out Month month);
                budget               = ExpenseManager.ReadBudget(month);
                Budget.Text          = budget.BudgetAmount.ToString();
                remainingBudget      = ExpenseManager.RemainingBudget(month);
                RemainingAmount.Text = remainingBudget.ToString();
                var expensesList = ExpenseManager.GetExpensesByMonth(month);
                //Clearing the observable collection.
                expenses.Clear();
                foreach (var expense in expensesList)
                {
                    expenses.Add(expense);
                }
            }
        }
Beispiel #3
0
        protected async override void OnAppearing()
        {
            //ExpenseManager.DeleteAllExpenses();
            //ExpenseManager.DeleteBudget();
            var allExpenses = ExpenseManager.GetExpenses();

            foreach (var expense in allExpenses)
            {
                expenses.Add(expense);
            }
            budget = ExpenseManager.ReadBudget((Month)DateTime.Now.Month);
            if (budget.BudgetAmount <= 0)
            {
                await Navigation.PushModalAsync(new SaveBudgetPage
                {
                    BindingContext = null
                });
            }
            Budget.Text          = budget.BudgetAmount.ToString();
            RemainingAmount.Text = ExpenseManager.RemainingBudget((Month)DateTime.Now.Month).ToString();
            if (budget.BudgetAmount > 0)
            {
                AddNewExpense.IsEnabled = true;
            }
            //clearing the observableCollection list to get the new observableCollection list
            expenses.Clear();
            var expensesByMonth = ExpenseManager.GetExpensesByMonth((Month)DateTime.Now.Month);

            foreach (var expense in expensesByMonth)
            {
                expenses.Add(expense);
            }

            var orderedExpenses = expenses.OrderBy(n => n.Date).ToList();

            expenses.Clear();
            foreach (var expense in orderedExpenses)
            {
                expenses.Add(expense);
            }
            ExpenseRecords.ItemsSource = expenses;
        }