private void btnDeleteComic_Click(object sender, EventArgs e) { //confirm username change DialogResult response = MessageBox.Show("Delete selected comic book?", "Delete Comic Book", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2); if (response == DialogResult.Yes) { //get comic book selected and update int selectedIndex = lstViewAvailableComics.SelectedIndices[0]; string selectedItem = lstViewAvailableComics.Items[selectedIndex].Text; string cbFullPath = Path.GetFullPath(Path.Combine(@"Resources", @"comicbooks", selectedItem)); //get comicbook instance Business_Logic.ComicBook selectedComic = comicReader.GetComicBook(cbFullPath); //delete if (comicReader.RemoveComicBookRecord(selectedComic.GetArchivePath())) { MessageBox.Show("Successfully deleted comic book!", "Delete Comic Book", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); //delete archive in Resources/comicbook directory File.Delete(selectedComic.GetArchivePath()); //refresh values lstViewAvailableComics_Refresh(); ComicInfo_Enabled(false); } else { Trace.WriteLine("Comic book with archivePath: <" + selectedComic.GetArchivePath() + "> failed to be deleted."); MessageBox.Show("Failed to delete comic book.", "Delete Comic Book", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } }
/// <summary> /// deletes the existing comic book /// </summary> /// <param name="comicBookToDelete"></param> /// <returns></returns> public bool DeleteComicBook(ComicBook comicBookToDelete) { return(comicManager.RemoveComicBookRecord(comicBookToDelete.GetArchivePath())); }