public ExpenseForm(MainForm parent, Expense selected, string accept) { InitializeComponent(); this.parent = parent; this.acceptButton.Text = accept; this.categoriesComboBox.Items.Clear(); foreach(string s in parent.portfel.categories) this.categoriesComboBox.Items.Add(s); this.categoriesComboBox.Items.Remove("stałe"); this.categoriesComboBox.SelectedItem = this.categoriesComboBox.Items[0]; if(selected != null) { this.groupBox.Text = "Edytuj"; this.dateTimePicker.Value = selected.date; this.categoriesComboBox.Text = selected.category; foreach(object item in this.categoriesComboBox.Items) if(item as string == selected.category) { this.categoriesComboBox.SelectedItem = item; break; } if(selected.value < 0) { this.valueTextBox.Text = (selected.value * -1).ToString(); this.outcopmRadioButton.Checked = true; } else { this.valueTextBox.Text = selected.value.ToString(); this.incomeRadioButton.Checked = true; } this.descTextBox.Text = selected.description; } else { this.groupBox.Text = "Dodaj"; this.acceptButton.Enabled = false; } this.to_edit = selected; this.valueTextBox.Focus(); }
/// <summary>Usuwa element z ListView.</summary> /// <param name="elem">Element do usunięcia.</param> private void RemoveFromListView(Expense elem) { Func<object, object> filter = o => (o as ListViewItem).GetExpense() == elem ? o : null; ListViewItem item = (ListViewItem)this.listView.Items.GetItem(filter); if(item != null) this.listView.Items.Remove(item); }
/// <summary>Usunięcie wydatku.</summary> /// <param name="elem">Element reprezentujacy wydatek do usuniecia.</param> private void RemoveExpense(Expense elem) { this.portfel.RemoveExpense(elem); this.RemoveFromListView(elem); this.UpdateForm(); if(this.ProfileChanged != null) this.ProfileChanged(); this.removeButton.Enabled = false; this.RemoveFromDateList(elem.date); }
/// <summary>Edycja wydatku.</summary> /// <remarks>Pobiera zaznaczony wydatek z ListView i towrzy instancję ExpenseForm. /// Metoda nie jest odporna na brak zaznaczenia na ListView.</remarks> private void EditExpenseClick(Expense to_edit) { if(to_edit.category == "stałe") { string text = "Wydatki z kategorii 'stałe' można edytować tylko z menu Stałe."; MainForm.MessageBoxWrapper(text, MessageType.WOK); } else { ExpenseForm form = new ExpenseForm(this, to_edit, "Edytuj"); form.EditEvent += this.EditExpense; form.ShowDialog(this); } }
/// <summary>Edycja wydatku.</summary> /// <param name="to_edit">Wydatek edytowany.</param> /// <param name="changes">Wydatek reprezentujący zmiany.</param> private void EditExpense(Expense to_edit, Expense changes) { this.portfel.EditExpense(to_edit, changes); this.UpdateForm(); if(this.ProfileChanged != null) this.ProfileChanged(); this.RemoveFromDateList(to_edit.date); this.AddToDateList(changes.date); ListViewItem to_update = null; Func<object, object> filter = item => (item as ListViewItem).GetExpense() == to_edit ? item : null; to_update = this.listView.Items.GetItem(filter) as ListViewItem; to_update.SubItems[0].Text = changes.date.ToString("dd-MM-yyyy"); to_update.SubItems[1].Text = changes.value.ToString("#,##0.00zł;-#,##0.00zł;0.00zł"); to_update.SubItems[2].Text = changes.category; to_update.SubItems[3].Text = changes.description; }
/// <summary>Dodaje element do ListView.</summary> /// <param name="elem">Element do dodania.</param> /// <remarks>Nie dodaje wpisu, jeśli istnieje identyczny.</remarks> private void AddToListView(Expense elem) { Func<object, object> filter = i => (i as ListViewItem).GetExpense() == elem ? elem : null; object o = this.listView.Items.GetItem(filter); //jesli w kolekcji elem juz jest if(o != null) return; string[] list = new string[4] { elem.date.ToString("dd-MM-yyyy"), elem.value.ToString("#,##0.00zł;-#,##0.00zł;0.00zł"), elem.category, elem.description }; ListViewItem item = new ListViewItem(list); item.SetExpense(elem); int index; for(index = 0; index < this.listView.Items.Count; index++) { ListViewItem i = this.listView.Items[index]; if(i.GetExpense().date.CompareTo(item.GetExpense().date) > 0) break; } this.listView.Items.Insert(index, item); }
/// <summary>Dodanie wydatku.</summary> /// <param name="elem">Element reprezentujacy nowy wydatek.</param> private void AddExpense(Expense elem) { this.portfel.AddExpense(elem); this.AddToListView(elem); this.UpdateForm(); if(this.ProfileChanged != null) this.ProfileChanged(); this.AddToDateList(elem.date); this.listView.Items[this.listView.Items.Count - 1].EnsureVisible(); }
/// <summary>Dodaje nowy wydatek.</summary> /// <param name="elem">Element dodawany do listy wydatków.</param> /// <remarks>Dodaje element do listy i ustala now¹ wartoœæ salda.</remarks> public void AddExpense(Expense elem) { this.hist.Add(elem); this.Balance = elem.value; }
/// <summary>Usuwa wydatek.</summary> /// <param name="elem">Element usuwany z listy wydatków.</param> /// <remarks>Usuwa element z listy i ustala now¹ wartoœæ salda.</remarks> public void RemoveExpense(Expense elem) { this.Balance = -elem.value; this.hist.Remove(elem); }
/// <summary>Wczytuje profil z pliku.</summary> /// depracated!!!!! /// <param name="tr">Strumieñ z którego bêd¹ czytane dane.</param> /// <remarks>Wczytuje Wallet.profile, Wallet.hist i Wallet.categories.</remarks> public void Read(TextReader tr) { this.Reset(); this.profile = tr.ReadLine(); int elem_amount = Convert.ToInt32(tr.ReadLine()); int category_amount = Convert.ToInt32(tr.ReadLine()); while(category_amount > 0) { this.categories.Add(tr.ReadLine()); category_amount--; } while(elem_amount > 0) { double val = Convert.ToDouble(tr.ReadLine()); string desc = tr.ReadLine(); string cat = tr.ReadLine(); int d = Convert.ToInt32(tr.ReadLine()); int m = Convert.ToInt32(tr.ReadLine()); int y = Convert.ToInt32(tr.ReadLine()); Expense e = new Expense(val, desc, cat, new DateTime(y, m, d)); elem_amount--; this.AddExpense(e); } }
/// <summary>Edytuje wydatek.</summary> /// <param name="to_edit">Wydatek to edycji.</param> /// <param name="changes">Element reprezentuj¹cy zmiany.</param> /// <remarks>Wprowadza zmiany i ustala saldo.</remarks> public void EditExpense(Expense to_edit, Expense change) { this.Balance = -to_edit.value; this.Balance = change.value; to_edit.value = change.value; to_edit.category = change.category; to_edit.date = change.date; to_edit.description = change.description; }
public static void SetExpense(this ListViewItem item, Expense expense) { item.Tag = expense; }
private void okButton_Click(object sender, EventArgs e) { string text; this.date = this.dateTimePicker.Value.Date; this.desc = this.descTextBox.Text; if(this.value == 0) { text = "Czy na pewno chcesz dodać wydatek z zerową kwotą?"; DialogResult result = MainForm.MessageBoxWrapper(text, MessageType.QYesNo); if(result != DialogResult.Yes) { this.valueTextBox.Text = ""; return; } } if(this.categoriesComboBox.SelectedItem != null) { this.cat = this.categoriesComboBox.SelectedItem.ToString(); } if(this.outcopmRadioButton.Checked) this.value = this.value * -1; Expense e2 = new Expense(this.value, this.desc, this.cat, this.date); if(this.EditEvent != null) this.EditEvent(this.to_edit, e2); if(this.AddEvent != null) this.AddEvent(e2); if(this.to_edit != null) this.Close(); this.valueTextBox.Text = ""; this.descTextBox.Text = ""; this.valueTextBox.Focus(); }