void DeleteClicked(Object Sender, EventArgs E) { if (!ConfirmMode) { ReloadExpenses(ConvertOrderSelect(OrderSelect.Items[OrderSelect.SelectedIndex]), ConvertContentSelect(ContentSelect.Items[ContentSelect.SelectedIndex]), ReloadMode.delete); Delete_btn.Text = "Confirm"; Add_btn.Text = "Cancel"; ConfirmMode = true; } else { // this will handle the confirmation of the deleted items for (int i = 0; i < TopTenTable.Count(); i++) { TopTenItem current = (TopTenItem)TopTenTable.ElementAt(i); if (current.ToBeDeleted) { ExpenseDataBase.DeleteItem(current.This_expense.Id); } } Delete_btn.Text = "Delete"; Add_btn.Text = "Add"; ReloadExpenses(ConvertOrderSelect(OrderSelect.Items[OrderSelect.SelectedIndex]), ConvertContentSelect(ContentSelect.Items[ContentSelect.SelectedIndex]), ReloadMode.display); ConfirmMode = false; } }
//public static DatabaseController<Expenditure> ExpenseDataBase //{ // get // { // if (ExpenseDataBase == null) // { // ExpenseDataBase = new DatabaseController<Expenditure>(DependencyService.Get<ISQLHelper>().getLocalFilePath("LifeBudget_moneyDB.db3")); // } // return ExpenseDataBase; // } //} private void ReloadExpenses(ReloadType type, ContentType content, ReloadMode mode) { // This function will take the last 10 expenses (if available) and place them in the 'TopTenExpenses' stack layout // First, I need to clear out the table TopTenTable.Clear(); // Second, I need to get the whole list of expenses switch (mode) { case ReloadMode.display: switch (content) { case ContentType.Spending: switch (type) { case ReloadType.most_recent: for (int i = 1; i <= 10; i++) { try { TopTenTable.Add(new TopTenItem(ExpenseDataBase.GetItem(ExpenseDataBase.CountItems() - i), ReloadMode.display)); } catch { break; } // this will kick out of the for loop whenever an exception is raised } break; } break; } break; case ReloadMode.delete: switch (content) { case ContentType.Spending: switch (type) { case ReloadType.most_recent: for (int i = ExpenseDataBase.CountItems() - 1; i >= 0; i--) { try { TopTenTable.Add(new TopTenItem(ExpenseDataBase.GetItem(i), ReloadMode.delete)); } catch { break; } // this will kick out of the for loop whenever an exception is raised } break; } break; } break; } ResizeTable(); }