// TODO: extract common code from HandleBookEditedEvent and AddBookViewItem methods private void HandleBookEditedEvent(object sender, BookEventArgs args) { Book book = args.Book; ListViewItem bookViewItem = FindBookViewItem(args.Book); if (bookViewItem != null) { if (filter(book)) { bookViewItem.SubItems[0].Text = book.Title; bookViewItem.SubItems[1].Text = book.Author; bookViewItem.SubItems[2].Text = book.Category; bookViewItem.SubItems[3].Text = book.Date.ToShortDateString(); } else { listViewForm.Items.Remove(bookViewItem); this.CountLabel.Text = this.listViewForm.Items.Count.ToString(); } } else if (filter(book)) { AddBookViewItem(book); } }
private void HandleBookAddedEvent(object sender, BookEventArgs args) { Book book = args.Book; if (filter(book)) { AddBookViewItem(book); } }
private void HandleBookRemovedEvent(object sender, BookEventArgs args) { ListViewItem bookViewItem = FindBookViewItem(args.Book); if (bookViewItem != null) { listViewForm.Items.Remove(bookViewItem); this.CountLabel.Text = this.listViewForm.Items.Count.ToString(); } }