/// <summary> /// Handles a new <see cref="Views.PayersEdit"/> form being opened from a <see cref="Views.PayerView"/> form /// </summary> /// <param name="sender">The sender object</param> /// <param name="e">Event arguments</param> public static void EditPayerClicked(object sender, EventArgs e) { if (PayersEdit == null) { PayersEdit = new PayersEdit(); PayersEdit.FormClosed += PayerEditViewOnFormClosed; } var selectedItems = PayerView.PayerListView.SelectedItems; if (selectedItems.Count > 0) { var selectedItem = selectedItems[0]; var payerId = Guid.Parse(selectedItem.SubItems[0].Text); var payer = ListAccessHelper.FindPayer(payerId); EditedPayer = payer; } else { EditedPayer = null; } PayersEdit.Show(PayerView); PayerView.Hide(); }
/// <summary> /// Handles retrieving all <see cref="Income"/> records from the database /// </summary> /// <returns>A list of <see cref="Income"/> objects</returns> public async Task <List <Income> > GetIncomes() { try { using (Conn) using (var comm = Conn.CreateCommand()) { await Conn.OpenAsync(); comm.CommandText = "SELECT * FROM income"; var incomes = new List <Income>(); var reader = comm.ExecuteReader(); while (reader.ReadAsync().Result) { var income = new Income { Id = reader.GetGuid(0), Payer = ListAccessHelper.FindPayer(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) }; incomes.Add(income); } await Conn.CloseAsync(); return(incomes); } } catch (Exception ex) { throw new Exception("An error occurred retrieving incomes from the database", ex); } }
/// <summary> /// Handles deleting a <see cref="Payer"/> record /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void DeletePayer(object sender, EventArgs e) { try { var selectedListItems = PayerView.PayerListView.SelectedItems; if (selectedListItems.Count > 0) { var selectedItem = selectedListItems[0]; var payerId = Guid.Parse(selectedItem.SubItems[0].Text); var payer = ListAccessHelper.FindPayer(payerId); ListAccessHelper.PayerList.Remove(payer); XmlDA.SaveXml(); DA.DeletePayer(payerId); PopulateListView(); } } catch (Exception ex) { ErrorHelper.SendError(ex); } }