/// <summary> /// Handles navigating to the <see cref="Views.ExpenseEdit"/> /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">Event arguments</param> public static void EditButtonClicked(object sender, EventArgs e) { if (ExpenseEdit == null) { ExpenseEdit = new ExpenseEdit(); ExpenseEdit.FormClosed += ExpenseEditViewOnFormClosed; } var selectedListItems = ExpenseView.ExpenseListView.SelectedItems; if (selectedListItems.Count > 0) { var selectedItem = selectedListItems[0]; var expenseId = Guid.Parse(selectedItem.SubItems[0].Text); var expense = ListAccessHelper.FindExpense(expenseId); EditExpense = expense; } else { EditExpense = null; } ExpenseEdit.Show(ExpenseView); ExpenseView.Hide(); }
/// <summary> /// Handles the deletion of an <see cref="Expense"/> /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">Event arguments</param> public static void DeleteExpense(object sender, EventArgs e) { try { var selectedListItems = ExpenseView.ExpenseListView.SelectedItems; if (selectedListItems.Count > 0) { var selectedItem = selectedListItems[0]; var expenseId = Guid.Parse(selectedItem.SubItems[0].Text); var expense = ListAccessHelper.FindExpense(expenseId); ListAccessHelper.ExpenseList.Remove(expense); XmlDA.SaveXml(); DA.DeleteExpense(expenseId); PopulateListView(); } } catch (Exception ex) { ErrorHelper.SendError(ex); } }