private void btnRate_Click(object sender, EventArgs e) { if (lstBxSavedComics.SelectedItem != null) { string fileName = lstBxSavedComics.SelectedItem.ToString(); string cbzCompleteDir = Path.Combine(Directory.GetCurrentDirectory(), cbResourceDirectory, fileName); //rate loggedInUser.MyComicLibrary.RateComicBook(cbzCompleteDir, setRating); //also the public one var pubCb = comicManager.GetComicBook(cbzCompleteDir); pubCb.RateComicBook(setRating); //write changes accountManager.WriteComicLibrary(loggedInUser.Id, loggedInUser.MyComicLibrary); comicManager.UpdateComicBookRecord(pubCb); } }
private void lstBxComics_DoubleClick(object sender, EventArgs e) { if (lstBxComics.SelectedItem != null) { //get selected item string fileName = lstBxComics.SelectedItem.ToString(); string fullPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), cbResourceDirectory, fileName)); //increment view count loggedInUser.MyComicLibrary.GetComicBook(fullPath); var publicCb = comicManager.GetComicBook(fullPath); publicCb.ViewCount++; //write changes comicManager.UpdateComicBookRecord(publicCb); accountManager.WriteComicLibrary(loggedInUser.Id, loggedInUser.MyComicLibrary); //open new comicView window ComicView ui_view = new ComicView(fullPath, loggedInUser); ui_view.ShowDialog(); } }
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); } } }
/// <summary> /// edits the existing comic book /// </summary> /// <param name="modifiedComicBook"></param> /// <returns> /// true if successful, false if invalid comic book supplied /// </returns> public bool EditComicBook(ComicBook modifiedComicBook) { return(comicManager.UpdateComicBookRecord(modifiedComicBook)); }