Beispiel #1
0
        /// <summary>
        /// Displays the message after search.
        /// </summary>
        /// <param name="str">The string.</param>
        private void DisplayMessageAfterSearch(string str)
        {
            if (lstSearch.Items.Count < 1)
            {
                _msgBox.Msg = "Author not located in list.";
                _msgBox.ShowInformationMessageBox();

                txtSearch.Text = string.Empty;

                return;
            }

            txtSearch.Text = string.Empty;

            lblSearch.Text = $"List of authors found. Using search criteria {str}";
        }
        /// <summary>
        ///     The OnSaveBookRecordButton_Clicked
        ///     If not series save book title.
        ///     If series save book title, book series name, book volume number.
        /// </summary>
        /// <param name="sender">The source of the event.<see cref="object" />The source of the event.</param>
        /// <param name="e">The e<see cref="System.EventArgs" />Instance containing the event data.</param>
        private void OnSaveBookRecordButton_Clicked(object sender, EventArgs e)
        {
            _msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            var clsOutput = new OutputClass();

            var filePath = BookListPathsProperties.PathOfCurrentWorkingFile;

            if (!chkSeries.Checked)
            {
                clsOutput.WriteAuthorsTitlesToFile(filePath);
                return;
            }

            var seriesOp = new SeriesOperationsClass();

            var bookInfo = seriesOp.FormatBookSeriesData(txtSeries.Text, txtTitle.Text, txtVolume.Text);


            var bookTitle = txtTitle.Text.Trim();
            var retVal    = CheckThatAuthorsFileDoesNotContainThisBookTitle(filePath, bookTitle);


            if (retVal)
            {
                _msgBox.Msg = "This book title is all ready contained in the authors file.";
                _msgBox.ShowInformationMessageBox();
                return;
            }

            if (clsOutput.WriteAuthorsTitlesSeriesToFile(filePath, bookInfo))
            {
                _msgBox.Msg = "The book title and series information have been successfully saved. ";
                _msgBox.ShowInformationMessageBox();
            }
        }
        /// <summary>
        ///     The OnSaveRecordButton_Clicked.
        /// </summary>
        /// <param name="sender">
        ///     The source of the event. <see cref="Object" /> The source of the
        ///     event.
        /// </param>
        /// <param name="e">
        ///     The e <see cref="EventArgs" /> Instance containing the event data.
        /// </param>
        private void OnSaveRecordButton_Clicked(object sender, EventArgs e)
        {
            _msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            var dirFileOp = new FileClass();

            var dirAuthors = BookListPathsProperties.PathAuthorsDirectory;

            var authorOp = new AuthorOperationsClass();

            if (!_valid.ValidateStringIsNotNull(dirAuthors))
            {
                return;
            }
            if (!_valid.ValidateStringHasLength(dirAuthors))
            {
                return;
            }
            if (!_valid.ValidateStringHasLength(txtAuthor.Text.Trim()))
            {
                return;
            }
            if (!_valid.ValidateDirectoryExists(dirAuthors))
            {
                return;
            }


            var fileName = authorOp.AddDashBetweenAuthorsFirstMiddleLastName(txtAuthor.Text);

            if (!_valid.ValidateStringHasLength(fileName))
            {
                return;
            }

            var cls      = new CombinePathsClass();
            var filePath = cls.CombineDirectoryPathWithFileName(dirAuthors, fileName);

            if (!_valid.ValidateStringHasLength(filePath))
            {
                return;
            }

            if (_valid.ValidateFileExists(filePath, false))
            {
                _msgBox.Msg = "This file all ready exists.";
                _msgBox.ShowInformationMessageBox();
                return;
            }

            if (dirFileOp.CreateNewFile(filePath))
            {
                _msgBox.Msg = "Author file created successfully.";
                _msgBox.ShowInformationMessageBox();
                BookListPathsProperties.AuthorsNameCurrent       = fileName;
                BookListPathsProperties.PathOfCurrentWorkingFile = filePath;

                AddNewAuthorFileNameToAuthorsList(fileName);

                return;
            }

            BookListPathsProperties.AuthorsNameCurrent       = string.Empty;
            BookListPathsProperties.PathOfCurrentWorkingFile = string.Empty;

            _msgBox.Msg = "Failed to create the file for this author.";
            _msgBox.ShowErrorMessageBox();
        }