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); } } }
private void btnEditComic_Click(object sender, EventArgs e) { //get and check each value string title = txtBxComicTitle.Text.Trim(); if (title.Length == 0) { MessageBox.Show("Comic Title cannot be empty.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } //no need to check subtitle/issue, they can be empty string subtitle = txtBxComicSubTitle.Text.Trim(); string issue = txtBxComicIssue.Text.Trim(); //check if date can be parsed, is valid string dateReleased = txtBxDateReleased.Text.Trim(); //parsed time must not contain an exact time (hours, mins, seconds) if (!DateTime.TryParse(dateReleased, out DateTime dateRel) && dateRel.TimeOfDay.TotalSeconds == 0) { MessageBox.Show("Invalid date inputted in Date Released entry.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } //no need to check synopsis, they can be empty string synopsis = richTxtBxSynopsis.Text; //authors must be correctly separated string[] authors = txtBxAuthors.Text.Split(','); authors = authors.Select(s => s.Trim()).ToArray(); if (authors.Where(author => author.Length == 0).Count() != 0) { MessageBox.Show("Null authors are not allowed.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } //genres must be correctly separated, it can be empty string[] genres = txtBxGenre.Text.Split(','); genres = genres.Select(s => s.Trim()).ToArray(); if (txtBxGenre.Text.Trim() != "" && genres.Any(author => author.Length == 0)) { MessageBox.Show("Null genres are not allowed.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } //no need to check publisher, they can be empty string publisher = txtBxPublisher.Text; //confirm username change DialogResult response = MessageBox.Show("Save changes made to comic book?", "Edit 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); //set new values selectedComic.ComicTitle = title; selectedComic.ComicSubTitle = subtitle; selectedComic.ComicIssue = issue; selectedComic.ComicDateReleased = dateRel; selectedComic.ComicSynopsis = synopsis; selectedComic.ComicAuthors = authors; selectedComic.ComicGenres = genres; selectedComic.Publisher = publisher; //write to file if (comicReader.UpdateComicBookRecord(selectedComic)) { MessageBox.Show("Successfully modified comic information!", "Edit Comic Book", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); ComicInfo_SetValues(selectedComic); } else { Trace.WriteLine("Comic book with archivePath: <" + selectedComic.GetArchivePath() + "> failed to be modified."); MessageBox.Show("Failed to modify comic book.", "Edit Comic Book", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } }