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(); } }
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(); }