示例#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 void bookslistBox_DoubleClick(object sender, EventArgs e)
        {
            //SELECT b.id_b, b.title, a.name, a.surname, b.lost, b.year, l.name, p.name, g.genretype
            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 summary = BookID[2].Trim();

            int    lost = Convert.ToInt32(BookID[4].Trim());
            string year = BookID[5].Trim();

            //string genre_id = BookID[5].Trim();
            //int genre_id = Convert.ToInt32(BookID[5].Trim());
            //int publisher_id = Convert.ToInt32(BookID[6].Trim());
            titleTextBox.Text = selectedBook.ToString();
            //publish_date
            //summaryTextBox.Text = summary.ToString();
            yearTextBox.Text = year.ToString();

            if (lost == 1)
            {
                lostBookCheckBox.Checked = true;
            }
            else
            {
                lostBookCheckBox.Checked = false;
            }
        }
示例#3
0
 private void deleteUserButton_Click(object sender, EventArgs e)
 {
     if (userShowcomboBox.SelectedItem == null)
     {
         MessageBox.Show("Izbran ni noben uporabnik/član.");
     }
     else
     {
         //u.id_u, u.name, u.surname, u.tel, u.address, u.notes, l.name, l.postalcode
         databaseController dbc          = new databaseController();
         string             selectedUser = userShowcomboBox.SelectedItem.ToString();//exception needs to be handled
         selectedUser = selectedUser.Trim();
         string[] UserID = selectedUser.Split('|');
         int      id_u   = Convert.ToInt32(UserID[0].Trim());
         selectedUser = UserID[1].Trim();//user's name
         string surname             = UserID[2].Trim();
         string tel                 = UserID[3].Trim();
         string address             = UserID[4].Trim();
         string notes               = UserID[5].Trim();
         string location_name       = UserID[6].Trim();
         string location_postalcode = UserID[7].Trim();
         Users  u = new Users(id_u, selectedUser, surname, tel, address, "", "", "", notes);
         dbc.DeleteUsers(u);
         userShowcomboBox.Items.Clear();
         OutputUsers();
     }
 }
示例#4
0
        private void authorsDeleteButton_Click(object sender, EventArgs e)
        {
            databaseController dbc            = new databaseController();
            string             selectedAuthor = authorsListbox.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());

            selectedAuthor = authorsNameTextBox.Text;
            surname        = authorsSurnameTextBox.Text;
            middlename     = authorsMiddlenameTextBox.Text;
            MessageBox.Show(Convert.ToString(id_a));
            MessageBox.Show(selectedAuthor);
            MessageBox.Show(surname);
            MessageBox.Show(middlename);
            Authors aut = new Authors(id_a, selectedAuthor, surname);

            dbc.DeleteAuthors(aut);
            authorsListbox.Items.Clear();
            OutputAuthors();
        }
示例#5
0
        private void userShowcomboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            userLendedBookslistBox.Items.Clear();
            userUnLendedBookslistBox.Items.Clear();


            //SELECT u.id_u, u.name, u.surname, u.tel, u.address, u.notes, l.name, l.postalcode
            databaseController dbc          = new databaseController();
            string             selectedUser = userShowcomboBox.SelectedItem.ToString();//exception needs to be handled

            selectedUser = selectedUser.Trim();
            string[] UserID              = selectedUser.Split('|');
            int      id_u                = Convert.ToInt32(UserID[0].Trim());
            string   name                = UserID[1].Trim();//title
            string   surname             = UserID[2].Trim();
            string   tel                 = UserID[3].Trim();
            string   address             = UserID[3].Trim();
            string   location_name       = UserID[3].Trim();
            string   location_postalcode = UserID[3].Trim();

            Locations lid = new Locations(0, location_name, "");

            dbc.idLocations(lid);
            int location_id = 0;

            foreach (int k in dbc.idLocations(lid))
            {
                location_id = k;
            }
            Users uid = new Users(0, name, surname, "", "", "", "", 0);

            dbc.idUsers(uid);
            int user_id = 0;

            foreach (int k in dbc.idUsers(uid))
            {
                user_id = k;
            }
            Users u = new Users(id_u, name, surname, tel, address, "", "", location_id);
            Rents r = new Rents(0, 1, "", 0, id_u);

            dbc.ReadLendedBooks(r);
            foreach (string name1 in dbc.ReadLendedBooks(r))
            {
                userLendedBookslistBox.Items.Add(name1);
            }


            userUnLendedBookslistBox.Items.Clear();
            dbc.ReadUnlendedBooks();
            foreach (string name1 in dbc.ReadUnlendedBooks())
            {
                userUnLendedBookslistBox.Items.Add(name1);
            }
            userUnLendedBookslistBox.Items.Clear();
            //OutputBooksOnRents_Lended();
            OutputBooksOnRents_UnLended();
        }
示例#6
0
        private void publishersAddButton_Click(object sender, EventArgs e)
        {
            databaseController dbc = new databaseController();
            int        id_p        = 0;
            string     name1       = publishersNameTextBox.Text;
            Publishers pub         = new Publishers(id_p, name1);

            dbc.SavePublishers(pub);
            publishersListBox.Items.Clear();
            OutputPublishers();
        }
示例#7
0
        private void genresAddButton_Click(object sender, EventArgs e)
        {
            databaseController dbc = new databaseController();
            int    id_g            = 0;
            string name            = genresNametextBox.Text;
            Genres gen             = new Genres(id_g, name);

            dbc.SaveGenres(gen);
            genreslistBox.Items.Clear();
            OutputGenres();
        }
示例#8
0
        private void authorsAddButton_Click(object sender, EventArgs e)
        {
            databaseController dbc = new databaseController();
            int     id_a           = 0;
            string  name           = authorsNameTextBox.Text;
            string  surname        = authorsSurnameTextBox.Text;
            Authors aut            = new Authors(id_a, name, surname);

            dbc.SaveAuthors(aut);
            authorsListbox.Items.Clear();
            OutputAuthors();
        }
示例#9
0
        private void locationsAddButton_Click(object sender, EventArgs e)
        {
            databaseController dbc = new databaseController();
            int       id_l         = 0;
            string    name1        = locationsNameTextBox.Text;
            string    postal       = postalLocationsTextBox.Text;
            Locations loc          = new Locations(id_l, name1, postal);

            dbc.SaveLocations(loc);
            locationslistBox.Items.Clear();
            OutputLocations();
        }
示例#10
0
        private void genresDeleteButton_Click(object sender, EventArgs e)
        {
            databaseController dbc           = new databaseController();
            string             selectedGenre = genreslistBox.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;
            Genres gen = new Genres(id_g, selectedGenre);

            dbc.DeleteGenres(gen);
            genreslistBox.Items.Clear();
            OutputGenres();
        }
示例#11
0
        private void publishersDeleteButton_Click(object sender, EventArgs e)
        {
            databaseController dbc = new databaseController();
            string             selectedPublisher = publishersListBox.SelectedItem.ToString();//exception needs to be handled

            selectedPublisher = selectedPublisher.Trim();
            string[] PublisherID = selectedPublisher.Split('|');
            selectedPublisher = PublisherID[1].Trim();
            int id_p = Convert.ToInt32(PublisherID[0].Trim());

            selectedPublisher = publishersNameTextBox.Text;
            Publishers pub = new Publishers(id_p, selectedPublisher);

            dbc.DeletePublishers(pub);
            publishersListBox.Items.Clear();
            OutputPublishers();
        }
示例#12
0
        private void locationsDeleteButton_Click(object sender, EventArgs e)
        {
            databaseController dbc = new databaseController();
            string             selectedLocation = locationslistBox.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());
            string    name1      = locationsNameTextBox.Text;
            string    postal     = postalLocationsTextBox.Text;
            Locations loc        = new Locations(id_l, name1, postal);

            dbc.DeleteLocations(loc);
            locationslistBox.Items.Clear();
            OutputLocations();
        }
示例#13
0
        private void editUserButton_Click(object sender, EventArgs e)
        {
            //u.id_u, u.name, u.surname, u.tel, u.address, u.notes, l.name, l.postalcode
            userUpdateForm     a   = new userUpdateForm();
            databaseController dbc = new databaseController();

            /*string selectedUser = userShowcomboBox.SelectedItem.ToString();//exception needs to be handled
             * selectedUser = selectedUser.Trim();
             * string[] UserID1 = selectedUser.Split('|');
             * int id_u= Convert.ToInt32(UserID1[0].Trim());
             *
             *
             *
             * userShowcomboBox.Items.Clear();
             *  foreach (string name in dbc.ReadUsersForUpdate(u))
             *  {
             *      userShowcomboBox.Items.Add(name);
             *  }
             *
             *
             *
             *
             *
             * string[] UserID = selectedUser.Split('|');
             * user_id_u = Convert.ToInt32(UserID[0].Trim());
             * name = UserID[1].Trim();//user's name
             * surname = UserID[2].Trim();
             * tel = UserID[3].Trim();
             * address = UserID[4].Trim();
             * email= UserID[5].Trim();
             * username= UserID[6].Trim();
             * passwordV1 = UserID[7].Trim();
             * notes = UserID[8].Trim();
             * // location_name = UserID[9].Trim();
             * // location_postalcode = UserID[10].Trim();*/



            a.Show();
            userShowcomboBox.Items.Clear();
            OutputUsers();
        }
示例#14
0
        private void bookslistBox_DoubleClick(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();

            titleTextBox.Text   = selectedBook.ToString();
            numOfPages.Value    = total_pages;
            ratingNumeric.Value = rating;
            //publish_date

            summaryTextBox.Text = summary.ToString();
        }
示例#15
0
        private void rentABookButton_Click(object sender, EventArgs e)
        {
            if (userShowcomboBox.SelectedItem == null)
            {
                MessageBox.Show("Izberite člana.");
            }
            else
            {
                databaseController dbc          = new databaseController();
                string             selectedUser = userShowcomboBox.SelectedItem.ToString();//exception needs to be handled
                selectedUser = selectedUser.Trim();
                string[]  UserID              = selectedUser.Split('|');
                int       id_u                = Convert.ToInt32(UserID[0].Trim());
                string    name                = UserID[1].Trim();//title
                string    surname             = UserID[2].Trim();
                string    tel                 = UserID[3].Trim();
                string    address             = UserID[3].Trim();
                string    location_name       = UserID[3].Trim();
                string    location_postalcode = UserID[3].Trim();
                Locations lid                 = new Locations(0, location_name, "");
                dbc.idLocations(lid);
                int location_id = 0;
                foreach (int k in dbc.idLocations(lid))
                {
                    location_id = k;
                }
                Users uid = new Users(0, name, surname, "", "", "", "", 0);
                dbc.idUsers(uid);
                int user_id = 0;
                foreach (int k in dbc.idUsers(uid))
                {
                    user_id = k;
                }
                if (userUnLendedBookslistBox.SelectedItem == null)
                {
                    MessageBox.Show("Izberite knjigo.");
                }
                else
                {
                    string selectedBook = userUnLendedBookslistBox.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_book = 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_book = new Locations(0, location_name, "");
                    dbc.idLocations(lid);
                    int location_id_book = 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;
                    }
                    Rents rid = new Rents(0, 0, "", id_b, user_id);
                    dbc.idRents(rid);
                    int rent_id = 0;
                    foreach (int k in dbc.idRents(rid))
                    {
                        rent_id = k;
                    }

                    string rent_date  = Convert.ToString(DateTime.Now);
                    int    rent_state = 1;
                    Rents  rentss     = new Rents(rent_id, rent_state, rent_date, id_b, id_u);
                    dbc.UpdateRentsLend(rentss);
                    userUnLendedBookslistBox.Items.Clear();
                    OutputBooksOnRents_UnLended();
                }
            }
        }
示例#16
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();
        }
示例#17
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();
            }
        }
示例#18
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();
            }
        }
示例#19
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();
            }
        }
示例#20
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();
        }