/// <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> /// 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> /// 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); }