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