/// <summary> /// Handles opening a <see cref="Views.PayeeEdit"/> form being opened from a <see cref="PayeeViewForm"/> forms /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">Event arguments</param> public static void EditPayeeClick(object sender, EventArgs e) { if (PayeeEdit == null) { PayeeEdit = new PayeeEdit(); PayeeEdit.FormClosed += PayeeEditViewOnFormClosed; } var selectedItems = PayeeView.payeeListView.SelectedItems; if (selectedItems.Count > 0) { var selecteditem = selectedItems[0]; var payeeId = Guid.Parse(selecteditem.SubItems[0].Text); var payee = ListAccessHelper.FindPayee(payeeId); EditPayee = payee; } else { EditPayee = null; } PayeeEdit.Show(PayeeView); PayeeView.Hide(); }
/// <summary> /// Handles retrieving all <see cref="Expense"/> records from the database /// </summary> /// <returns>A list of <see cref="Expense"/> objects</returns> public async Task <List <Expense> > GetExpenses() { try { using (Conn) using (var comm = Conn.CreateCommand()) { await Conn.OpenAsync(); comm.CommandText = "SELECT * FROM expense"; var expenses = new List <Expense>(); var reader = comm.ExecuteReader(); while (reader.ReadAsync().Result) { var expense = new Expense { Id = reader.GetGuid(0), Payee = ListAccessHelper.FindPayee(reader.GetGuid(1)), Ref = reader.GetString(2), Amount = reader.GetDecimal(3), IsRecurring = reader.GetBoolean(4), Interval = reader.GetInt32(5), InitialPaidDate = reader.GetDateTime(6), LastPaidDate = reader.GetDateTime(7) }; expenses.Add(expense); } await Conn.CloseAsync(); return(expenses); } } catch (Exception ex) { throw new Exception("An error occurred retrieving expenses from the database", ex); } }
/// <summary> /// Handles deleting a <see cref="Payee"/> item /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">Event arguments</param> public static void DeletePayee(object sender, EventArgs e) { try { var selectedListItems = PayeeView.payeeListView.SelectedItems; if (selectedListItems.Count > 0) { var selectedItem = selectedListItems[0]; var payeeId = Guid.Parse(selectedItem.SubItems[0].Text); var payee = ListAccessHelper.FindPayee(payeeId); ListAccessHelper.PayeeList.Remove(payee); XmlDA.SaveXml(); DA.DeletePayee(payeeId); PopulateListView(); } } catch (Exception ex) { ErrorHelper.SendError(ex); } }