Beispiel #1
0
 private void btnNew_Click(object sender, EventArgs e)
 {
     using (var form = new NewForm("New"))
     {
         var result = form.ShowDialog();
         if(result == DialogResult.OK)
         {
             var entry = form.Entry;
             _listFinances.Add(entry);
             UIHelper.LoadItem(lstItems, entry);
             _currData[entry.Category] += entry.Amount;
             Recalculate();
         }
     }
 }
Beispiel #2
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (lstItems.SelectedItems.Count == 1)
            {
                using (var form = new NewForm("Edit"))
                {
                    var row = lstItems.SelectedItems[0];
                    var entry = _listFinances.Find(item => item.ID == Convert.ToInt32(row.SubItems[0].Text));
                    var index = _listFinances.IndexOf(entry);
                    _currData[entry.Category] -= entry.Amount;
                    form.Entry = entry;
                    var result = form.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        _listFinances[index] = form.Entry;
                        row.SubItems[1].Text = Categories.Get(form.Entry.Category);
                        row.SubItems[2].Text = form.Entry.Amount.ToString(Formats.MoneyFormat);
                        row.SubItems[3].Text = form.Entry.Place;
                        row.SubItems[4].Text = form.Entry.Description;

                        _currData[form.Entry.Category] += form.Entry.Amount;
                        Recalculate();
                    }
                    lstItems.SelectedItems[0].Selected = false;
                }
            }
            else if (lstItems.SelectedItems.Count > 1)
            {
                MessageBox.Show("Please select only 1 entry to edit","Edit Error");
                foreach (ListViewItem row in lstItems.SelectedItems)
                    row.Selected = false;
            }
            else
                MessageBox.Show("Please select an entry to edit", "Edit Error");
        }