public static void ReadTitlesFromFile(string filePath)
        {
            try
            {
                if (!File.Exists(filePath))
                {
                    return;
                }

                using (var sr = new StreamReader(filePath))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        TitleNamesCollection.AddItem(line);
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (ArgumentException ex)
            {
                MyMessagesClass.ErrorMessage = "The file path value is an empty string.";

                Debug.WriteLine(ex.ToString());
                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (FileNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = "Unable to locate the directory.";

                Debug.WriteLine(ex.ToString());
                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (IOException ex)
            {
                MyMessagesClass.ErrorMessage = "File path has invalid characters in it.";

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
            }
        }
        public static void ReadTitlesFromFile(string filePath)
        {
            try
            {
                if (!File.Exists(filePath))
                {
                    return;
                }

                using (var sr = new StreamReader(filePath))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        TitleNamesCollection.AddItem(line);
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                MyMessagesClass.ErrorMessage = V6 + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (ArgumentException ex)
            {
                MyMessagesClass.ErrorMessage = V7;

                Debug.WriteLine(ex.ToString());
                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (FileNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = V8 + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = V9;

                Debug.WriteLine(ex.ToString());
                MyMessagesClass.ShowErrorMessageBox();
            }
            catch (IOException ex)
            {
                MyMessagesClass.ErrorMessage = V10;

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
            }
        }
        /// <summary>
        ///Backup AuthorsFileNamesCollection So if becomes corrupt while making changes to it.
        /// or the user changes there mind it can be restored.
        /// </summary>
        /// <param name="bkUpList">The backup list.</param>
        /// <returns>Empty backup list if AuthorsFileNamesCollection is empty.
        /// else returns copy of authorsFileNamesCollection.</returns>
        public static List <string> AddToBackUpList(List <string> bkUpList)
        {
            for (var index = 0; index < TitleNamesCollection.ItemsCount(); index++)
            {
                bkUpList.Add(TitleNamesCollection.GetItemAt(index));
            }

            return(bkUpList);
        }
        private void FindTitlesInString()
        {
            this.txtAuthorName.Text = this.txtAuthorName.Text.Trim();

            if (string.IsNullOrEmpty(this.txtAuthorName.Text))
            {
                return;
            }

            for (var i = 0; i < TitleNamesCollection.ItemsCount(); i++)
            {
            }
        }
예제 #5
0
        private void FindTitlesInString()
        {
            var s2 = this.txtAuthorName.Text.Trim();

            if (string.IsNullOrEmpty(s2)) return;

            for (var i = 0; i < TitleNamesCollection.ItemsCount(); i++)
            {
                var s1 = TitleNamesCollection.GetItemAt(i);

                if (s1.Contains(s2))
                {
                    this.lstTiltes.Items.Add(s1);
                }
            }
        }
        private void SearchBookTitlesBySingleAuthor()
        {
            var dirAuthors = AuthorsDirectoryFilesClass.GetPathToAuthorsDirectory();

            var filePath = DirectoryFileOperationsClass.CombineDirectoryPathWithFileName(dirAuthors,
                                                                                         BookListPropertiesClass.CurrentWorkingFileName);

            TitleNamesCollection.ClearCollection();

            FileInputClass.ReadTitlesFromFile(filePath);

            this.FindTitlesInString();

            if (this.lstTiltes.Items.Count < 1)
            {
                this.lstTiltes.Items.Add("No titles with this search criteria were found.");
            }
        }
        private void OnTitleSearchButtonClicked(object sender, EventArgs e)
        {
            var dirAuthors = AuthorsDirectoryFilesClass.GetPathToAuthorsDirectory();

            var filePath = DirectoryFileOperationsClass.CombineDirectoryPathWithFileName(dirAuthors,
                BookListPropertiesClass.CurrentWorkingFileName);

            TitleNamesCollection.ClearCollection();

            FileInputClass.ReadTitlesFromFile(filePath);

            this.FindTitlesInString();

            if (this.lstTiltes.Items.Count < 1)
            {
                this.lstTiltes.Items.Add( "No titles wit
            }
        }
        private void SearchBookTitlesAllAuthors()
        {
            AuthorsDirectoryFilesClass.GetAllAuthorFilePathsContainedInAuthorDirectory();

            TitleNamesCollection.ClearCollection();
            this.lstTiltes.

            for (var i = 0; i < AuthorsFileNamesCollection.ItemsCount(); i++)
            {
                var fileName   = AuthorsFileNamesCollection.GetItemAt(i);
                var dirAuthors = AuthorsDirectoryFilesClass.GetPathToAuthorsDirectory();
                var filePath   = DirectoryFileOperationsClass.CombineDirectoryPathWithFileName(dirAuthors,
                                                                                               fileName);
                this.txtAuthorName.Text = fileName;

                FileInputClass.ReadTitlesFromFile(filePath);
                this.FindTitlesInString();
            }
        }