コード例 #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();
            }
        }
コード例 #2
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();
        }