Пример #1
0
        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            if (lstBooks.SelectedItem == null)
            {
                MessageBox.Show("Select a book to edit");
                return;
            }

            var selectedIndex = lstBooks.SelectedIndex;
            var selectedBook  = lstBooks.SelectedItem as Book;
            var upsertBook    = new UpsertBook(selectedBook);

            upsertBook.ShowDialog();

            if (upsertBook.IsCanceled)
            {
                return;
            }

            var book = upsertBook.NewOrUpdatedBook;

            book.CWID = cwid;
            var mode = upsertBook.Mode;

            BookFile.SaveBook(book, cwid, mode);

            lstBooks.Items.RemoveAt(selectedIndex);
            lstBooks.Items.Insert(selectedIndex, book);
            SelectItemInListBox(selectedIndex);
        }
Пример #2
0
        private void btnNew_Click(object sender, System.EventArgs e)
        {
            var upsertBook = new UpsertBook();

            upsertBook.ShowDialog();

            if (upsertBook.IsCanceled)
            {
                return;
            }

            var book = upsertBook.NewOrUpdatedBook;

            book.CWID = cwid;
            var mode = upsertBook.Mode;

            BookFile.SaveBook(book, cwid, mode);

            this.lstBooks.Items.Add(book);
        }