//adds a copy available back to the book you are returning private void btnReturn_Click(object sender, EventArgs e) { Book myBook = (Book)lstBooks.SelectedItem; //adds a copy myBook.copies++; //saves book BookFile.SaveBook(myBook, cwid, "edit"); //reloads list and displays new data LoadList(); }
//removes a book from the main form all together private void btnDelete_Click(object sender, EventArgs e) { Book myBook = (Book)lstBooks.SelectedItem; //makes sure the user really wants to delete a book DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete?", "Delete", MessageBoxButtons.YesNo); //if they chose to delete it, remove it from the list if (dialogResult == DialogResult.Yes) { BookFile.DeleteBook(myBook, cwid); LoadList(); } }
//updating objects and saving it to a database private void btnSave_Click(object sender, EventArgs e) { //updating object 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; //saving record to data base BookFile.SaveBook(myBook, cwid, mode); //message box letting them know the book has been saved MessageBox.Show("Content was saved.", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); //close the edit form this.Close(); }
//loads all book data private void LoadList() { myBooks = BookFile.GetAllBooks(cwid); lstBooks.DataSource = myBooks; }