Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
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();
            }
        }