/// <summary> /// Shows all book titles by single author loop. /// </summary> public void ShowAllBookTitlesBySingleAuthorLoop() { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; var coll1 = new BookDataCollection(); var coll2 = new BookTitlesCollection(); for (var i = 0; i < coll1.GetItemsCount(); i++) { var s1 = coll1.GetItemAt(i); if (!this._valid.ValidateStringIsNotNull(s1)) { return; } s1 = s1.Trim(); if (!this._valid.ValidateStringHasLength(s1)) { return; } coll2.AddItem(s1); } }
/// <summary> /// Books the titles search loop. /// </summary> private void BookTitlesSearchLoop() { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; if (!this._valid.ValidateStringIsNotNull(BookDataProperties.SetBookTitleSearchString)) { return; } if (!this._valid.ValidateStringHasLength(BookDataProperties.SetBookTitleSearchString.Trim())) { return; } var searchStr = BookDataProperties.SetBookTitleSearchString.Trim().ToLower(); var coll1 = new BookDataCollection(); var coll2 = new BookTitlesCollection(); for (var i = 0; i < coll1.GetItemsCount(); i++) { var s1 = coll1.GetItemAt(i); s1 = s1.ToLower(); if (s1.Contains(searchStr)) { coll2.AddItem(s1); } } }
/// <summary> /// Searches the book title by single author. /// </summary> public void SearchBookTitleBySingleAuthor() { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; var dirAuthors = BookListPathsProperties.PathAuthorsDirectory; var cls1 = new CombinePathsClass(); var filePath = cls1.CombineDirectoryPathWithFileName(dirAuthors, BookListPathsProperties.CurrentWorkingFileName); var coll = new BookDataCollection(); coll.ClearCollection(); var titles = new BookTitlesCollection(); titles.ClearCollection(); var cls2 = new InputClass(); cls2.ReadTitlesFromFileLoop(filePath); this.FindTitlesInString(); if (titles.GetItemsCount() < 1) { titles.AddItem("No titles with this search criteria were found."); } }
/// <summary>Called when [ok button clicked].</summary> /// <param name="sender">The source of the event</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void OnOKButton_Clicked(object sender, EventArgs e) { var coll = new BookDataCollection(); BookListPathsProperties.AuthorsNameCurrent = lblAuthor.Text; var clsComb = new CombinePathsClass(); var filePath = clsComb.CombineDirectoryPathWithFileName(BookListPathsProperties.PathAuthorsDirectory, BookListPathsProperties.AuthorsNameCurrent); var valid = new ValidationClass(); var msgBox = new MyMessageBoxClass(); if (!valid.ValidateStringHasLength(filePath)) { msgBox.Msg = "Unable to complete the operation."; msgBox.ShowErrorMessageBox(); return; } BookListPathsProperties.PathOfCurrentWorkingFile = filePath; coll.ClearCollection(); Close(); }
/// <summary> /// Create a backup of all unformatted data. This will allow the user to /// roll back changes. /// </summary> public static void AddToBackUpList() { var coll = new DataBackUpCollection(); var collData = new BookDataCollection(); for (var index = 0; index < collData.GetItemsCount(); index++) { coll.AddItem(collData.GetItemAt(index)); } }
/// <summary> /// Read the book title from file add to <see cref="BookDataCollection"/> /// collection. /// </summary> /// <param name="filePath">The path to the authors file. <see cref="String" /> .</param> public void ReadTitlesFromFileLoop(string filePath) { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { var coll = new BookDataCollection(); if (!this._validate.ValidateStringIsNotNull(filePath)) { return; } if (!this._validate.ValidateStringHasLength(filePath)) { return; } if (!this._validate.ValidateFileExists(filePath, true)) { return; } using (var sr = new StreamReader(filePath)) { string line; while ((line = sr.ReadLine()) != null) { coll.AddItem(line); } } } catch (OutOfMemoryException ex) { this._msgBox.Msg = "Not enough memory to continue. Try closing other windows."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } }
/// <summary> /// Searches the book title all authors. /// </summary> public void SearchBookAuthorAllTitles() { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; var cls1 = new FileClass(); cls1.GetAllAuthorFilePathsContainedInAuthorDirectory(); var coll1 = new BookDataCollection(); coll1.ClearCollection(); this.AuthorNamesSearchLoop(); var coll2 = new BookTitlesCollection(); if (coll2.GetItemsCount() < 1) { coll2.AddItem("No titles with this search criteria were found."); } }
/// <summary> /// Called when [show all titles for author button clicked]. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void OnShowAllTitlesSingleAuthorButton_Clicked(object sender, EventArgs e) { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; var dirAuthors = BookListPathsProperties.PathAuthorsDirectory; var cls1 = new CombinePathsClass(); var filePath = cls1.CombineDirectoryPathWithFileName(dirAuthors, BookListPathsProperties.CurrentWorkingFileName); var cls2 = new BookDataCollection(); cls2.ClearCollection(); var cls3 = new InputClass(); cls3.ReadTitlesFromFileLoop(filePath); var cls4 = new AuthorOperationsClass(); cls4.ShowAllBookTitlesBySingleAuthorLoop(); this.lstTiltes.Items.Clear(); }
/// <summary> /// writes book info to the authors file. If Not book series then writes /// book title name. if Series writes book title, series name, volume /// number. /// </summary> /// <param name="filePath">.</param> /// <param name="bookInfo">.</param> public bool WriteBookTitleSeriesVolumeNamesToAuthorsFile(string filePath) { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { if (string.IsNullOrEmpty(filePath)) { return(false); } if (!File.Exists(filePath)) { return(false); } var coll = new BookDataCollection(); using (var writer = new StreamWriter(filePath, true)) { for (var i = 0; i < coll.GetItemsCount(); i++) { writer.WriteLine(coll.GetItemAt(i)); } } return(true); } catch (UnauthorizedAccessException ex) { this._msgBox.Msg = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); return(false); } catch (ArgumentNullException ex) { this._msgBox.Msg = $"The path variable contains a null string. {filePath}"; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { this._msgBox.Msg = $"The file path value is a null string. {filePath}"; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { this._msgBox.Msg = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); return(false); } catch (PathTooLongException ex) { this._msgBox.Msg = "the file path is to long."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { this._msgBox.Msg = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { this._msgBox.Msg = $"File path has invalid characters in it. {filePath}"; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); return(false); } }
/// <summary> /// If adding new user then write there name to the Art2MSpell user /// names file. /// </summary> /// <param name="filePath">The filePath <see cref="string" /> .</param> /// <returns> /// True if write successful else false. /// </returns> public bool WriteAuthorsTitlesToFile(string filePath) { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { var coll = new BookDataCollection(); var validate = new ValidationClass(); // Append line to the file. using (var writer = new StreamWriter(filePath, false)) { var count = coll.GetItemsCount(); for (var index = 0; index < coll.GetItemsCount(); index++) { writer.WriteLine(coll.GetItemAt(index)); } return(true); } } catch (UnauthorizedAccessException ex) { this._msgBox.Msg = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { this._msgBox.Msg = $"The path variable contains a null string. {filePath}"; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } catch (ArgumentException ex) { this._msgBox.Msg = $"The file path value is a null string. {filePath}"; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { this._msgBox.Msg = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } catch (PathTooLongException ex) { this._msgBox.Msg = "the file path is to long."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } catch (SecurityException ex) { this._msgBox.Msg = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); } catch (IOException ex) { this._msgBox.Msg = $"File path has invalid characters in it. {filePath}"; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } return(false); }