コード例 #1
0
        private void booksDeleteButton_Click(object sender, EventArgs e)
        {
            databaseController dbc          = new databaseController();
            string             selectedBook = bookslistBox.SelectedItem.ToString();//exception needs to be handled

            selectedBook = selectedBook.Trim();
            string[] BookID = selectedBook.Split('|');
            selectedBook = BookID[1].Trim();
            int    total_pages  = Convert.ToInt32(BookID[2].Trim());
            int    id_b         = Convert.ToInt32(BookID[0].Trim());
            string publish_date = BookID[4].Trim();
            int    rating       = Convert.ToInt32(BookID[3].Trim());
            string summary      = BookID[5].Trim();

            int publisher_id = Convert.ToInt32(BookID[6].Trim());
            int location_id  = Convert.ToInt32(BookID[7].Trim());


            int id_g = 0;

            Books       b  = new Books(id_b, selectedBook, summary, year, lost, genre_id);
            Book_Genres bg = new Book_Genres(id_b, id_g);

            dbc.DeleteBooksGenres(bg);

            Book_Authors ba = new Book_Authors(id_b, id_g);

            dbc.DeleteBooksAuthors(ba);

            dbc.DeleteBooks(b);
            bookslistBox.Items.Clear();
            OutputBooks();
        }
コード例 #2
0
        private async void btn_Created(object sender, RoutedEventArgs e)
        {
            string genre = txt_Create_Genre.Text.Trim();

            if (genre == "")
            {
                MessageBox.Show("Запоните это поле!!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (_libdb.Book_Genres.Any(bg => bg.Genre_Name == genre))
            {
                MessageBox.Show("Такое тип уже имеется!!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Book_Genres book_Genre = new Book_Genres
            {
                Genre_Name = genre
            };

            _libdb.Book_Genres.Add(book_Genre);
            await _libdb.SaveChangesAsync();

            MessageBox.Show("Данный тип успешно добавлен!!!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);

            txt_Create_Genre.Text = "";
        }
コード例 #3
0
        public ActionResult DeleteRelation(long book_id, string genre)
        {
            long        id = db.Genres.Where(g => g.genre == genre).Select(g => g.id).First();
            Book_Genres bg = db.Book_Genres.Where(b => b.GenreId == id && b.BookId == book_id).First();

            db.Book_Genres.Remove(bg);
            db.TrySaveChanges();
            return(RedirectToAction("Details", "Books", new { id = book_id }));
        }
コード例 #4
0
        private async void btn_Delete_Click(object sender, RoutedEventArgs e)
        {
            int id = ((Cb_Genres)cb_Delete.SelectedItem).ID;

            Book_Genres genre = _libdb.Book_Genres.Find(id);

            genre.Is_Deleted = true;
            await _libdb.SaveChangesAsync();

            MessageBox.Show("Данный тип успешно удален!!!", "Deleted", MessageBoxButton.OK, MessageBoxImage.Information);
            cb_Delete.Text = "";
        }
コード例 #5
0
 public void UpdateBooksGenres(Book_Genres Book_GenresToUpdate)
 {
     //List<string> listOfLocations = new List<string>();
     using (NpgsqlConnection con = new NpgsqlConnection("Server=hattie.db.elephantsql.com; User Id=oxbcwgvz;" + "Password=igpiilcYjHtSKKDcs3wuGd15RtjskDzP; Database=oxbcwgvz;"))
     {
         con.Open();
         string        query = "UPDATE book_genres SET genre_id='" + Book_GenresToUpdate.genre_id + "'WHERE book_id='" + Book_GenresToUpdate.book_id + "';";
         NpgsqlCommand com   = new NpgsqlCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
コード例 #6
0
 public void SaveBooksGenres(Book_Genres Book_GenresToSave)
 {
     // List<string> listOfLocations = new List<string>();
     using (NpgsqlConnection con = new NpgsqlConnection("Server=hattie.db.elephantsql.com; User Id=oxbcwgvz;" + "Password=igpiilcYjHtSKKDcs3wuGd15RtjskDzP; Database=oxbcwgvz;"))
     {
         con.Open();
         string        query = "INSERT INTO book_genres (book_id, genre_id) VALUES((SELECT id_b FROM books WHERE id_b='" + Book_GenresToSave.book_id + "'), (SELECT id_g FROM genres WHERE id_g='" + Book_GenresToSave.genre_id + "'));";
         NpgsqlCommand com   = new NpgsqlCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
コード例 #7
0
        public ActionResult Create(long book_id, [Bind(Include = "id,genre")] Genres genres)
        {
            if (ModelState.IsValid)
            {
                long            genre_id;
                BooksController bc = new BooksController();

                if (bc.IsInDatabase(genres.genre, null, 1) == false)
                {
                    db.Genres.Add(genres);

                    db.SaveChanges();

                    genre_id = genres.id;
                }
                else
                {
                    genre_id = db.Genres.Where(g => g.genre == genres.genre).Select(g => g.id).First();
                }

                if (book_id != 0)
                {
                    Book_Genres bg = new Book_Genres()
                    {
                        BookId  = book_id,
                        GenreId = genre_id
                    };

                    db.Book_Genres.Add(bg);

                    db.TrySaveChanges();
                }

                return(RedirectToAction("Details", "Books", new { id = book_id }));
            }

            return(View(genres));
        }
コード例 #8
0
        private void booksUpdateButton_Click(object sender, EventArgs e)
        {
            databaseController dbc          = new databaseController();
            string             selectedBook = bookslistBox.SelectedItem.ToString();//exception needs to be handled

            MessageBox.Show(selectedBook);
            selectedBook = selectedBook.Trim();
            string[] BookID = selectedBook.Split('|');
            selectedBook = BookID[1].Trim();

            int id_b = Convert.ToInt32(BookID[0].Trim());


            string title        = titleTextBox.Text;
            int    total_pages  = Convert.ToInt32(numOfPages.Value);
            int    rating       = Convert.ToInt32(ratingNumeric.Value);
            string publish_date = Convert.ToString(DateTime.Now.Date.ToString("MM/dd/yyyy"));
            string summary      = Convert.ToString(summaryTextBox.Text);


            //getting location id in bookstab
            #region location_id
            string selectedLocation = locationBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedLocation = selectedLocation.Trim();
            string[] LocationID = selectedLocation.Split('|');
            selectedLocation = LocationID[1].Trim();
            string postalcode = LocationID[2].Trim();
            int    id_l       = Convert.ToInt32(LocationID[0].Trim());
            #endregion

            //getting publisher id in books tab
            #region publisher_id
            string selectedPublisher = publishersBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedPublisher = selectedPublisher.Trim();
            string[] PublisherID = selectedPublisher.Split('|');
            selectedPublisher = PublisherID[1].Trim();
            string description = PublisherID[2].Trim();
            int    id_p        = Convert.ToInt32(PublisherID[0].Trim());
            selectedPublisher = publishersNameTextBox.Text;
            description       = publishersDescriptionRichTextBox.Text;
            #endregion

            //getting genre id
            #region genre_id
            string selectedGenre = genreBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedGenre = selectedGenre.Trim();
            string[] GenreID = selectedGenre.Split('|');
            selectedGenre = GenreID[1].Trim();
            string description_genre = GenreID[2].Trim();
            int    id_g  = Convert.ToInt32(GenreID[0].Trim());
            int    id_aa = 0;
            #endregion

            #region author_id
            string selectedAuthor = authorsBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedAuthor = selectedAuthor.Trim();
            string[] AuthorID = selectedAuthor.Split('|');
            selectedAuthor = AuthorID[1].Trim();
            string surname    = AuthorID[2].Trim();
            string middlename = AuthorID[3].Trim();
            int    id_a       = Convert.ToInt32(AuthorID[0].Trim());
            #endregion

            Book_Authors ba = new Book_Authors(id_b, id_a);
            dbc.UpdateBooksAuthors(ba);

            Book_Genres bg = new Book_Genres(id_b, id_g);
            dbc.UpdateBooksGenres(bg);


            Books b = new Books(id_b, title, summary, year, lost, genre_id);
            dbc.UpdateBooks(b);
            bookslistBox.Items.Clear();
            OutputBooks();
        }
コード例 #9
0
        private void booksAddButton_Click(object sender, EventArgs e)
        {
            ratingNumeric.Minimum = 1;
            ratingNumeric.Maximum = 10;
            databaseController dbc = new databaseController();

            int    id_b         = 0;
            string title        = titleTextBox.Text;
            int    total_pages  = Convert.ToInt32(numOfPages.Value);
            int    rating       = Convert.ToInt32(ratingNumeric.Value);
            string publish_date = Convert.ToString(DateTime.Now.Date.ToString("MM/dd/yyyy"));
            string summary      = Convert.ToString(summaryTextBox.Text);

            //getting location id in bookstab
            #region location_id
            string selectedLocation = locationBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedLocation = selectedLocation.Trim();
            string[] LocationID = selectedLocation.Split('|');
            selectedLocation = LocationID[1].Trim();
            string postalcode = LocationID[2].Trim();
            int    id_l       = Convert.ToInt32(LocationID[0].Trim());
            #endregion

            //getting publisher id in books tab
            #region publisher_id
            string selectedPublisher = publishersBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedPublisher = selectedPublisher.Trim();
            string[] PublisherID = selectedPublisher.Split('|');
            selectedPublisher = PublisherID[1].Trim();
            string description = PublisherID[2].Trim();
            int    id_p        = Convert.ToInt32(PublisherID[0].Trim());
            selectedPublisher = publishersNameTextBox.Text;
            description       = publishersDescriptionRichTextBox.Text;
            #endregion

            Books b = new Books(id_b, title, summary, year, lost, genre_id);
            dbc.SaveBooks(b);


            //getting genre id
            #region genre_id
            string selectedGenre = genreBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedGenre = selectedGenre.Trim();
            string[] GenreID = selectedGenre.Split('|');
            selectedGenre = GenreID[1].Trim();
            string g_description = GenreID[2].Trim();
            int    id_g          = Convert.ToInt32(GenreID[0].Trim());
            //selectedGenre = genresNametextBox.Text;
            //g_description = genresDescriptionrichTextBox.Text;
            #endregion

            //getting author id
            #region author_id
            string selectedAuthor = authorsBooksCombobox.SelectedItem.ToString();//exception needs to be handled
            selectedAuthor = selectedAuthor.Trim();
            string[] AuthorID = selectedAuthor.Split('|');
            selectedAuthor = AuthorID[1].Trim();
            string surname    = AuthorID[2].Trim();
            string middlename = AuthorID[3].Trim();
            int    id_a       = Convert.ToInt32(AuthorID[0].Trim());
            #endregion

            //getting book_id
            #region book_id

            List <string> listOfBookss = new List <string>();
            using (NpgsqlConnection con = new NpgsqlConnection("Server=hattie.db.elephantsql.com; User Id=oxbcwgvz;" + "Password=igpiilcYjHtSKKDcs3wuGd15RtjskDzP; Database=oxbcwgvz;"))
            {
                con.Open();
                string           query  = "SELECT id_b FROM books WHERE(title='" + title + "' AND total_pages='" + total_pages + "' AND rating='" + rating + "' AND publisher_id='" + id_p + "' AND location_id='" + id_l + "')";
                NpgsqlCommand    com    = new NpgsqlCommand(query, con);
                NpgsqlDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    int id_bb = reader.GetInt32(0);
                    listOfBookss.Add(id_bb + "");
                }
                con.Close();
            }
            string prvi = listOfBookss.ElementAt(0);
            int    idbb = Convert.ToInt32(prvi);
            #endregion

            Book_Authors ba = new Book_Authors(idbb, id_a);
            dbc.SaveBooksAuthors(ba);
            Book_Genres bg = new Book_Genres(idbb, id_g);
            dbc.SaveBooksGenres(bg);
            bookslistBox.Items.Clear();
            OutputBooks();
        }
コード例 #10
0
        public ActionResult Create(CombinedDataModels newBook)
        {
            if (ModelState.IsValid)
            {
                long book_id;
                long author_id;
                long genre_id;
                long series_id;
                //***************************check if title, author, genre and series are in database************************
                if (IsInDatabase(newBook.Books.title, null, 0) == false)
                {
                    Books book;
                    if (newBook.cover == null)
                    {
                        book = new Books()
                        {
                            title       = newBook.Books.title,
                            year        = newBook.Books.year,
                            description = newBook.Books.description,
                            cover       = null
                        }
                    }
                    ;
                    else
                    {
                        book = new Books()
                        {
                            title       = newBook.Books.title,
                            year        = newBook.Books.year,
                            description = newBook.Books.description,
                            cover       = newBook.cover.FileName
                        };

                        newBook.cover.SaveAs(HttpContext.Server.MapPath(ConfigurationManager.AppSettings["bookCovers"]) + book.cover);
                    }

                    db.Books.Add(book);

                    db.TrySaveChanges();

                    book_id = book.id;
                }
                else
                {
                    book_id = db.Books.Where(b => b.title == newBook.Books.title).Select(b => b.id).First();
                }

                if (IsInDatabase(newBook.Authors.firstName, newBook.Authors.lastName, 3) == false)
                {
                    Authors author;
                    if (newBook.photo == null)
                    {
                        author = new Authors()
                        {
                            firstName  = newBook.Authors.firstName,
                            lastName   = newBook.Authors.lastName,
                            birthDate  = newBook.Authors.birthDate,
                            birthPlace = newBook.Authors.birthPlace,
                            BIO        = newBook.Authors.BIO,
                            photo      = null,
                            sex        = newBook.Authors.sex
                        }
                    }
                    ;
                    else
                    {
                        author = new Authors()
                        {
                            firstName  = newBook.Authors.firstName,
                            lastName   = newBook.Authors.lastName,
                            birthDate  = newBook.Authors.birthDate,
                            birthPlace = newBook.Authors.birthPlace,
                            BIO        = newBook.Authors.BIO,
                            photo      = newBook.photo.FileName,
                            sex        = newBook.Authors.sex
                        };

                        newBook.photo.SaveAs(HttpContext.Server.MapPath(ConfigurationManager.AppSettings["authorPhotos"]) + author.photo);
                    }

                    db.Authors.Add(author);

                    db.TrySaveChanges();

                    author_id = author.id;
                }
                else
                {
                    author_id = db.Authors.Where(a => a.firstName == newBook.Authors.firstName && a.lastName == newBook.Authors.lastName).Select(a => a.id).First();
                }

                if (BookIsBounded(book_id, author_id, 0) == false)
                {
                    Book_Authors bk = new Book_Authors()
                    {
                        BookId   = book_id,
                        AuthorId = author_id
                    };

                    db.Book_Authors.Add(bk);
                }


                if (IsInDatabase(newBook.Genres.genre, null, 1) == false)
                {
                    Genres genre = new Genres()
                    {
                        genre = newBook.Genres.genre
                    };

                    db.Genres.Add(genre);

                    db.TrySaveChanges();

                    genre_id = genre.id;
                }
                else
                {
                    genre_id = db.Genres.Where(g => g.genre == newBook.Genres.genre).Select(g => g.id).First();
                }

                if (IsInDatabase(newBook.Series.series, null, 2) == false)
                {
                    Series series = new Series()
                    {
                        series = newBook.Series.series
                    };

                    db.Series.Add(series);

                    db.TrySaveChanges();

                    series_id = series.id;
                }
                else
                {
                    series_id = db.Series.Where(s => s.series == newBook.Series.series).Select(s => s.id).First();
                }

                if (BookIsBounded(book_id, genre_id, 1) == false)
                {
                    Book_Genres bg = new Book_Genres()
                    {
                        BookId  = book_id,
                        GenreId = genre_id
                    };

                    db.Book_Genres.Add(bg);
                }

                if (BookIsBounded(book_id, series_id, 2) == false)
                {
                    Book_Series bs = new Book_Series()
                    {
                        BookId   = book_id,
                        SeriesId = series_id
                    };

                    db.Book_Series.Add(bs);
                }

                db.TrySaveChanges();

                return(RedirectToAction("Index", "Books"));
            }
            return(View(newBook));
        }