Example #1
0
        public void AddBookWithAuthors(BookVM book)
        {
            var _book = new Book()
            {
                Title       = book.Title,
                Description = book.Description,
                IsRead      = book.IsRead,
                DateRead    = book.IsRead ? book.DateRead.Value : null,
                Rate        = book.IsRead ? book.Rate.Value : null,
                Genre       = book.Genre,
                CoverUrl    = book.CoverUrl,
                DateAdded   = DateTime.Now,
                PublisherId = book.PublisherId
            };

            _context.Books.Add(_book);
            _context.SaveChanges();

            foreach (var id in book.AuthorIds)
            {
                var _book_author = new Book_Authors()
                {
                    BookId   = _book.Id,
                    AuthorId = id
                };
                _context.Book_Authors.Add(_book_author);
                _context.SaveChanges();
            }
        }
Example #2
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();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Book_Authors book_Authors = db.Book_Authors.Find(id);

            db.Book_Authors.Remove(book_Authors);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #4
0
        public ActionResult DeleteRelation(long book_id, string fname, string lname)
        {
            long         id = db.Authors.Where(a => a.firstName == fname && a.lastName == lname).Select(a => a.id).First();
            Book_Authors ba = db.Book_Authors.Where(a => a.AuthorId == id && a.BookId == book_id).First();

            db.Book_Authors.Remove(ba);
            db.TrySaveChanges();
            return(RedirectToAction("Details", "Books", new { id = book_id }));
        }
Example #5
0
 public void SaveBooksAuthors(Book_Authors Book_AuthorsToSave)
 {
     using (SQLiteConnection con = new SQLiteConnection("data source=Knjiznica_projektt.db"))
     {
         con.Open();
         string        query = "INSERT INTO book_authors (author_id, book_id) VALUES((SELECT id_a FROM authors WHERE id_a='" + Book_AuthorsToSave.author_id + "'), '" + Book_AuthorsToSave.book_id + "');";
         SQLiteCommand com   = new SQLiteCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
Example #6
0
 public void DeleteBooksAuthors(Book_Authors Book_AuthorsToDelete)
 {
     using (SQLiteConnection con = new SQLiteConnection("data source=Knjiznica_projektt.db"))
     {
         con.Open();
         string        query = "DELETE FROM book_authors WHERE(book_id='" + Book_AuthorsToDelete.book_id + "' AND author_id='" + Book_AuthorsToDelete.author_id + "');";
         SQLiteCommand com   = new SQLiteCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
 public ActionResult Edit([Bind(Include = "Books_AuthorID,AuthorID,BookID")] Book_Authors book_Authors)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book_Authors).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "FirstName", book_Authors.AuthorID);
     ViewBag.BookID   = new SelectList(db.Books, "BookID", "Title", book_Authors.BookID);
     return(View(book_Authors));
 }
Example #8
0
 public void UpdateBooksAuthors(Book_Authors Book_AuthorsToUpdate)
 {
     using (SQLiteConnection con = new SQLiteConnection("data source=Knjiznica_projektt.db"))
     {
         con.Open();
         string        query = "UPDATE book_authors SET author_id='" + Book_AuthorsToUpdate.newid + "', book_id='" + Book_AuthorsToUpdate.book_id + "' WHERE id_ba='" + Book_AuthorsToUpdate.id_ba + "';";
         SQLiteCommand com   = new SQLiteCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
 public void UpdateBooksAuthors(Book_Authors Book_AuthorsToUpdate)
 {
     //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_authors SET author_id='" + Book_AuthorsToUpdate.author_id + "' WHERE book_id='" + Book_AuthorsToUpdate.book_id + "';";
         NpgsqlCommand com   = new NpgsqlCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
 public void SaveBooksAuthors(Book_Authors Book_AuthorsToSave)
 {
     // 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_authors (book_id, author_id) VALUES((SELECT id_b FROM books WHERE id_b='" + Book_AuthorsToSave.book_id + "'), (SELECT id_a FROM authors WHERE id_a='" + Book_AuthorsToSave.author_id + "'));";
         NpgsqlCommand com   = new NpgsqlCommand(query, con);
         com.ExecuteNonQuery();
         com.Dispose();
         con.Close();
     }
 }
        // GET: Book_Authors/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Book_Authors book_Authors = db.Book_Authors.Find(id);

            if (book_Authors == null)
            {
                return(HttpNotFound());
            }
            return(View(book_Authors));
        }
        // GET: Book_Authors/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Book_Authors book_Authors = db.Book_Authors.Find(id);

            if (book_Authors == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "FirstName", book_Authors.AuthorID);
            ViewBag.BookID   = new SelectList(db.Books, "BookID", "Title", book_Authors.BookID);
            return(View(book_Authors));
        }
Example #13
0
        public List <int> ReadAuthorsID(Book_Authors Book_AuthorsToGetID)
        {
            List <int> listOfAuthorsID = new List <int>();

            using (SQLiteConnection con = new SQLiteConnection("data source=Knjiznica_projektt.db"))
            {
                con.Open();
                string           query  = "SELECT author_id FROM book_authors WHERE book_id='" + Book_AuthorsToGetID.book_id + "';";
                SQLiteCommand    com    = new SQLiteCommand(query, con);
                SQLiteDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    int id = reader.GetInt32(0);

                    listOfAuthorsID.Add(id);
                }
                con.Close();
                return(listOfAuthorsID);
            }
        }
Example #14
0
        public List <int> idBookAuthors(Book_Authors ToReadIDs)
        {
            List <int> listOfIDs = new List <int>();

            using (SQLiteConnection con = new SQLiteConnection("data source=Knjiznica_projektt.db"))
            {
                con.Open();
                string           query  = "SELECT id_ba FROM book_authors WHERE (author_id=" + ToReadIDs.author_id + " AND book_id=" + ToReadIDs.book_id + ");";
                SQLiteCommand    com    = new SQLiteCommand(query, con);
                SQLiteDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    int id = reader.GetInt32(0);
                    listOfIDs.Add(id);
                }
                com.Dispose();
                con.Close();
                return(listOfIDs);
            }
        }
Example #15
0
        public ActionResult Create(long book_id, [Bind(Include = "id,firstName,lastName,birthDate,sex,birthPlace,BIO,photo")] Authors authors)
        {
            if (ModelState.IsValid)
            {
                long            author_id;
                BooksController bc = new BooksController();

                if (bc.IsInDatabase(authors.firstName, authors.lastName, 3) == false)
                {
                    db.Authors.Add(authors);

                    db.SaveChanges();

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

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

                    db.Book_Authors.Add(bk);

                    db.TrySaveChanges();
                }

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

            return(View(authors));
        }
Example #16
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();
        }
Example #17
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));
        }
Example #18
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();
        }
Example #19
0
        private void booksDeleteButton_Click(object sender, EventArgs e)
        {
            if (bookslistBox.SelectedItem == null)
            {
                MessageBox.Show("Nobena knjiga ni izbrana.");
            }
            else
            {
                databaseController dbc          = new databaseController();
                string             selectedBook = bookslistBox.SelectedItem.ToString();//exception needs to be handled
                selectedBook = selectedBook.Trim();
                string[] BookID = selectedBook.Split('|');
                int      id_b   = Convert.ToInt32(BookID[0].Trim());
                selectedBook = BookID[1].Trim();//title
                string author_name     = BookID[2].Trim();
                string author_surname  = BookID[3].Trim();
                int    lost            = Convert.ToInt32(BookID[4].Trim());
                string year            = BookID[5].Trim();
                string location_name   = BookID[6].Trim();
                string publisher_name  = BookID[7].Trim();
                string genre_genretype = BookID[8].Trim();
                int    id_g            = 0;

                Authors aid = new Authors(0, author_name, author_surname);
                dbc.idAuthors(aid);
                int author_id = 0;
                foreach (int k in dbc.idAuthors(aid))
                {
                    author_id = k;
                }

                Locations lid = new Locations(0, location_name, "");
                dbc.idLocations(lid);
                int location_id = 0;
                foreach (int k in dbc.idLocations(lid))
                {
                    location_id = k;
                }

                Publishers pid = new Publishers(0, publisher_name);
                dbc.idPublishers(pid);
                int publisher_id = 0;
                foreach (int k in dbc.idPublishers(pid))
                {
                    publisher_id = k;
                }

                Genres gid = new Genres(0, genre_genretype);
                dbc.idGenres(gid);
                int genre_id = 0;
                foreach (int k in dbc.idGenres(gid))
                {
                    genre_id = k;
                }


                Books b = new Books(id_b, selectedBook, "", year, lost, genre_id, publisher_id, location_id);
                #region author_id
                Book_Authors id = new Book_Authors(0, id_b);
                dbc.ReadAuthorsID(id);
                int id_a = 0;
                foreach (int k in dbc.ReadAuthorsID(id))
                {
                    id_a = k;
                }

                /*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();
                 * int id_a = Convert.ToInt32(AuthorID[0].Trim());*/
                #endregion



                Book_Authors ba = new Book_Authors(author_id, id_b);
                //MessageBox.Show("author"+Convert.ToString(author_id), "book" + Convert.ToString(id_b));
                dbc.DeleteBooksAuthors(ba);
                dbc.DeleteBooks(b);
                bookslistBox.Items.Clear();
                OutputBooks();
                userUnLendedBookslistBox.Items.Clear();
                userLendedBookslistBox.Items.Clear();
                //OutputBooksOnRents_Lended();
                OutputBooksOnRents_UnLended();
            }
        }
Example #20
0
        private void booksUpdateButton_Click(object sender, EventArgs e)
        {
            if (titleTextBox.Text == "" || yearTextBox.Text == "" || authorsBooksCombobox.SelectedItem == null || publishersBooksCombobox.SelectedItem == null || genreBooksCombobox.SelectedItem == null || locationBooksCombobox.SelectedItem == null)
            {
                MessageBox.Show("Preverite vnos. Eno izmed polij ni napolnjeno.");
            }
            else
            {
                databaseController dbc          = new databaseController();
                string             selectedBook = bookslistBox.SelectedItem.ToString();//exception needs to be handled
                selectedBook = selectedBook.Trim();
                string[] BookID = selectedBook.Split('|');
                int      id_b   = Convert.ToInt32(BookID[0].Trim());
                selectedBook = BookID[1].Trim();//title
                string author_name     = BookID[2].Trim();
                string author_surname  = BookID[3].Trim();
                int    lost            = Convert.ToInt32(BookID[4].Trim());
                string year            = BookID[5].Trim();
                string location_name   = BookID[6].Trim();
                string publisher_name  = BookID[7].Trim();
                string genre_genretype = BookID[8].Trim();
                int    id_g            = 0;
                string summary         = summaryTextBox.Text;

                #region genre_id
                string selectedGenre1 = genreBooksCombobox.SelectedItem.ToString();//exception needs to be handled
                selectedGenre1 = selectedGenre1.Trim();
                string[] GenreID1 = selectedGenre1.Split('|');
                selectedGenre1 = GenreID1[1].Trim();
                int genre_id = Convert.ToInt32(GenreID1[0].Trim());
                #endregion

                #region publisher_id
                string selectedPublisher = publishersBooksCombobox.SelectedItem.ToString();//exception needs to be handled
                selectedPublisher = selectedPublisher.Trim();
                string[] PublisherID = selectedPublisher.Split('|');
                selectedPublisher = PublisherID[1].Trim();
                int publisher_id = Convert.ToInt32(PublisherID[0].Trim());

                #endregion

                #region location_id
                string selectedLocation = locationBooksCombobox.SelectedItem.ToString();//exception needs to be handled
                selectedLocation = selectedLocation.Trim();
                string[] LocationID  = selectedLocation.Split('|');
                int      location_id = Convert.ToInt32(LocationID[0].Trim());
                #endregion

                #region author_id
                string selectedAuthor = authorsBooksCombobox.SelectedItem.ToString();//exception needs to be handled
                selectedAuthor = selectedAuthor.Trim();
                string[] AuthorID          = selectedAuthor.Split('|');
                int      author_id_waiting = Convert.ToInt32(AuthorID[0].Trim());//nov id
                #endregion

                Authors aid = new Authors(0, author_name, author_surname);//tastar id
                dbc.idAuthors(aid);
                int author_id = 0;
                foreach (int k in dbc.idAuthors(aid))
                {
                    author_id = k;
                }

                Book_Authors baid = new Book_Authors(author_id, id_b);//poiscem id v book authors z pomocjo ttih idejev
                dbc.idBookAuthors(baid);
                int book_authors_id = 0;
                foreach (int k in dbc.idBookAuthors(baid))
                {
                    book_authors_id = k;
                }

                Books        b  = new Books(id_b, selectedBook, summary, year, lost, genre_id, publisher_id, location_id);
                Book_Authors ba = new Book_Authors(author_id, id_b, book_authors_id, author_id_waiting);
                dbc.UpdateBooksAuthors(ba);
                dbc.UpdateBooks(b);
                bookslistBox.Items.Clear();
                OutputBooks();
                userUnLendedBookslistBox.Items.Clear();
                userLendedBookslistBox.Items.Clear();
                //OutputBooksOnRents_Lended();
                OutputBooksOnRents_UnLended();
            }
        }
Example #21
0
        private void booksAddButton_Click(object sender, EventArgs e)
        {
            if (titleTextBox.Text == "" || yearTextBox.Text == "" || authorsBooksCombobox.SelectedItem == null || publishersBooksCombobox.SelectedItem == null || genreBooksCombobox.SelectedItem == null || locationBooksCombobox.SelectedItem == null)
            {
                MessageBox.Show("Preverite vnos. Eno izmed polij ni napolnjeno.");
            }
            else
            {
                databaseController dbc = new databaseController();
                int    id_b            = 0;
                string title           = titleTextBox.Text;
                string summary         = Convert.ToString(summaryTextBox.Text);
                string year            = Convert.ToString(yearTextBox.Text);
                int    lost            = 0;
                string publish_date    = Convert.ToString(DateTime.Now.Date.ToString("MM/dd/yyyy"));
                if (lostBookCheckBox.Checked)
                {
                    lost = 1;
                }
                else
                {
                    lost = 0;
                }
                #region genre_id
                string selectedGenre1 = genreBooksCombobox.SelectedItem.ToString();//exception needs to be handled
                selectedGenre1 = selectedGenre1.Trim();
                string[] GenreID1 = selectedGenre1.Split('|');
                selectedGenre1 = GenreID1[1].Trim();

                int genre_id = Convert.ToInt32(GenreID1[0].Trim());
                #endregion
                #region publisher_id
                string selectedPublisher = publishersBooksCombobox.SelectedItem.ToString();//exception needs to be handled
                selectedPublisher = selectedPublisher.Trim();
                string[] PublisherID = selectedPublisher.Split('|');
                selectedPublisher = PublisherID[1].Trim();

                int publisher_id = Convert.ToInt32(PublisherID[0].Trim());
                selectedPublisher = publishersNameTextBox.Text;
                MessageBox.Show(Convert.ToString(publisher_id));
                #endregion
                #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    location_idd = Convert.ToInt32(LocationID[0].Trim());
                MessageBox.Show("locationid" + Convert.ToString(location_idd) + selectedLocation + postalcode);
                #endregion
                Books b = new Books(id_b, title, summary, year, lost, genre_id, publisher_id, location_idd);
                dbc.SaveBooks(b);

                dbc.idBooks(b);
                int book_id = 0;
                foreach (int k in dbc.idBooks(b))
                {
                    book_id = k;
                }
                //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();

                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();
                int    id_a    = Convert.ToInt32(AuthorID[0].Trim());
                #endregion
                //getting book_id

                Book_Authors ba = new Book_Authors(id_a, book_id);
                dbc.SaveBooksAuthors(ba);
                DateTime currentDateTime = DateTime.Now;
                Rents    rentss          = new Rents(0, 0, Convert.ToString(currentDateTime), book_id, 0);
                dbc.SaveBookRents(rentss);
                bookslistBox.Items.Clear();
                OutputBooks();
                userUnLendedBookslistBox.Items.Clear();
                userLendedBookslistBox.Items.Clear();
                //OutputBooksOnRents_Lended();
                OutputBooksOnRents_UnLended();
            }
        }