示例#1
0
        /// <summary>
        /// loads the information of a book from an online source
        /// </summary>
        public Book AutoLoadDNB(string isbn)
        {
            Book book = new Book();

            book.BookIsbn = isbn;
            if (IsbnValidated(isbn))
            {
                htmlData = Regex.Replace(htmlData, @"\t|\n|\r", "");
                htmlData = Regex.Replace(htmlData, "<a href=.*?>", "");
                var genreName = GetGenreNeu().Replace("[", "(").Replace("]", ")");
                if (!genreName.Equals(""))
                {
                    GenreHelper helper = new GenreHelper();
                    Genre       genre  = new Genre();
                    if (helper.FindIdByName(genreName) < 0)
                    {
                        genre.GenreName = genreName;
                        genre.Add();
                    }
                    genre          = new Genre(helper.FindIdByName(genreName));
                    book.BookGenre = genre;
                }

                var titel = GetTitelNeu().Replace("[", "(").Replace("]", ")");
                if (!titel.Equals(""))
                {
                    book.BookTitle = titel;
                }

                var authors = GetAutorNeu();
                foreach (string s in authors)
                {
                    Author       author = new Author();
                    AuthorHelper helper = new AuthorHelper();
                    if (helper.FindIdByName(s) < 0)
                    {
                        author.AuthorName = s;
                        author.Add();
                    }
                    author = new Author(helper.FindIdByName(s));
                    book.BookAuthors.Add(author);
                }

                var ausgabe = GetAusgabeNeu().Replace("[", "(").Replace("]", ")");
                if (!ausgabe.Equals(""))
                {
                    book.BookEdition = ausgabe;
                }

                var publisherName = GetVerlagNeu().Replace("[", "(").Replace("]", ")");
                if (!publisherName.Equals(""))
                {
                    PublisherHelper helper    = new PublisherHelper();
                    Publisher       publisher = new Publisher();
                    if (helper.FindIdByName(publisherName) < 0)
                    {
                        publisher.PublisherName = publisherName;
                        publisher.Add();
                    }
                    publisher          = new Publisher(helper.FindIdByName(publisherName));
                    book.BookPublisher = publisher;
                }

                var jahr = GetDatumNeu();
                if (!jahr.Equals(""))
                {
                    try
                    {
                        DateTime date = new DateTime(int.Parse(jahr), 1, 1);
                        book.BookDatePublication = date;
                    }
                    catch
                    {
                        book.BookDatePublication = DateTime.UtcNow;
                    }
                }

                var preis = GetPreisNeu().Replace('.', ',');
                if (!preis.Equals(""))
                {
                    book.BookPrice = decimal.Parse(preis);
                }

                var languageName = GetSpracheNeu().Replace("[", "(").Replace("]", ")");
                if (!languageName.Equals(""))
                {
                    LanguageHelper helper   = new LanguageHelper();
                    Language       language = new Language();
                    if (helper.FindIdByName(languageName) < 0)
                    {
                        language.LanguageName = languageName;
                        language.Add();
                    }
                    language          = new Language(helper.FindIdByName(languageName));
                    book.BookLanguage = language;
                }

                var image = GetPictureNeu(isbn);
                if (image != null)
                {
                    book.BookImage = image;
                }
                return(book);
                //MetroMessageBox.Show(this, "Das Buch \"" + tb_Titel.Text + "\" wurde erfolgreich geladen!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                return(book);
                //AutoLoadBuecherNachISBN();
            }
        }