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); }
private void BtnRent_Click(object sender, EventArgs e) { BookClass myBook = (BookClass)lstBooks.SelectedItem; myBook.copies--; BookFile.SaveBook(myBook, cwid, "edit"); LoadList(); }
private void btnReturn_Click(object sender, EventArgs e) { Book myBook = (Book)lstBooks.SelectedItem; myBook.copies++; BookFile.SaveBook(myBook, cwid, "edit"); LoadList(); }
private void button1_Click(object sender, EventArgs e) { Book myBook = (Book)lstBooks.SelectedItem; myBook.copies--; BookFile.SaveBook(myBook, cwid, "edit"); loadList(); }
private void btnRent_Click(object sender, EventArgs e) { Book myBook = (Book)lstBooks.SelectedItem; int temp = lstBooks.SelectedIndex; myBook.copies--; BookFile.SaveBook(myBook, cwid, "edit"); LoadList(); lstBooks.SelectedIndex = temp; }
private void btnDelete_Click(object sender, EventArgs e) { Book myBook = (Book)listBooks.SelectedItem; DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this", "Delete", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { BookFile.DeleteBook(myBook, cwid); LoadList(); } }
private void btnDelete_Click(object sender, EventArgs e) { try { var book = (Book)lbBooks.SelectedItem; BookFile.DeleteBook(book, cwid); LoadBooks(); } catch (Exception exc) { } }
private void LoadBooks() { var books = BookFile.GetAllBooks(cwid); foreach (var book in books) { lstBooks.Items.Add(book); } if (books.Count > 0) { lstBooks.SelectedIndex = 0; } }
private void button1_Click(object sender, EventArgs e) { myBook.title = txtTitleData.Text; myBook.author = txtAuthorData.Text; myBook.genre = txtGenreData.Text; myBook.copies = int.Parse(txtCopiesData.Text); myBook.isbn = txtIbsnData.Text; myBook.cover = txtCoverData.Text; myBook.length = int.Parse(txtCopiesData.Text); myBook.cwid = cwid; BookFile.SaveBook(myBook, cwid, mode); MessageBox.Show("Content was saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
private void btnReturn_Click(object sender, EventArgs e) { try { var book = (Book)lbBooks.SelectedItem; book.copies++; BookFile.SaveBook(book, cwid, "edit"); LoadBooks(); } catch (Exception exc) { } }
private void btnSave_Click(object sender, EventArgs e) { myBook.title = txtTitleData.Text; myBook.author = txtAuthorData.Text; myBook.genre = txtGeneData.Text; myBook.copies = int.Parse(txtCopiesData.Text); //number of copies is and int so you have to use a ToString myBook.isbn = txtISBNData.Text; myBook.cover = txtCoverData.Text; myBook.length = int.Parse(txtLengthData.Text); //number of copies is and int so you have to use a ToString myBook.cwid = cwid; BookFile.SaveBook(myBook, cwid, mode); MessageBox.Show("Content was saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
//saves the edit private void btnSave_Click(object sender, EventArgs e) { myBook.title = txtTitleData.Text; myBook.author = txtAuthorData.Text; myBook.genre = txtGenreData.Text; myBook.copies = int.Parse(txtCopiesData.Text); myBook.isbn = txtIsbnData.Text; myBook.cover = txtCoverData.Text; myBook.length = int.Parse(txtLengthData.Text); myBook.cwid = cwid; BookFile.SaveBook(myBook, cwid, mode); //displays a message box showing the user that their book was saved MessageBox.Show("The Book Was Saved!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
private void btnEdit_Click(object sender, EventArgs e) { try { var book = (Book)lbBooks.SelectedItem; frmEdit editForm = new frmEdit(book, cwid); if (editForm.ShowDialog() == DialogResult.OK) { var editedBook = (Book)editForm.Tag; BookFile.SaveBook(editedBook, cwid, "edit"); LoadBooks(); } } catch (Exception exc) { } }
private void btnNew_Click(object sender, EventArgs e) { try { var book = new Book(); frmEdit newForm = new frmEdit(book, cwid); if (newForm.ShowDialog() == DialogResult.OK) { var editedBook = (Book)newForm.Tag; BookFile.SaveBook(editedBook, cwid, ""); LoadBooks(); } } catch (Exception exc) { } }
//rents a book private void btnRent_Click(object sender, EventArgs e) { Book myBook = (Book)lstBooks.SelectedItem; //the user cannot rent books if their are 0 copies if (myBook.copies <= 0) { MessageBox.Show("Sorry, this book is currently unavailable.", "Unavailable", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { myBook.copies--; BookFile.SaveBook(myBook, cwid, "edit"); } LoadList(); }
private void BtnSave_Click(object sender, EventArgs e) //closes the form, saving all data that was changed { myBook.title = txtTitleData.Text; myBook.author = txtAuthorData.Text; myBook.genre = txtGenreData.Text; myBook.copies = int.Parse(txtCopiesData.Text); myBook.isbn = txtIsbnData.Text; myBook.length = int.Parse(txtLengthData.Text); myBook.cover = txtCoverData.Text; //Console.WriteLine(cwid); //Console.ReadKey(); myBook.cwid = cwid; BookFile.SaveBook(myBook, cwid, mode); MessageBox.Show("Content was saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); //saved message this.Close(); }
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); }
private void btnDelete_Click(object sender, System.EventArgs e) { if (lstBooks.SelectedItem == null) { MessageBox.Show("Select a book to edit"); return; } var selectedBook = lstBooks.SelectedItem as Book; var message = MessageBox.Show($"Are you sure you want to delete\n'{selectedBook.Title}'", "Delete Movie", MessageBoxButtons.YesNo); if (message == DialogResult.No) { return; } BookFile.DeleteBook(selectedBook, cwid); lstBooks.Items.Remove(selectedBook); }
private void LoadList() //method to keep the list up to date { myBooks = BookFile.GetAllBooks(cwid); lstBooks.DataSource = myBooks; }
public void LoadList() { myBooks = BookFile.GetAllBooks(cwid); listBooks.DataSource = myBooks; }
private void LoadList() { myBooks = BookFile.GetAllBooks(cwid); lstBooks.DataSource = myBooks; }
private void LoadBooks() { // Load books from API myBooks = BookFile.GetAllBooks(cwid); lbBooks.DataSource = myBooks; }