Beispiel #1
0
        /// <summary>
        /// Goes through all rows in Book table and creates a list of Books
        /// </summary>
        /// <param name="authors">List of all Authors</param>
        /// <returns>List of all Books</returns>
        public List <Book> getBooks(List <Author> authors)
        {
            List <Book> books = new List <Book>();

            foreach (BookRow row in _bookAdapter.GetData().Rows)
            {
                int bookId = row.BookId;

                Author bookAuthor = null;
                foreach (Author author in authors)
                {
                    if (author.Id == row.AuthorId)
                    {
                        bookAuthor = author;
                        break;
                    }
                }

                GenreDAO genreDAO = new GenreDAO();

                books.Add(
                    new Book(bookId, row.Title, bookAuthor, row.Year.Year, genreDAO.GetBookGenres(bookId))
                    );
            }

            return(books);
        }
        private void RefreshGridView()
        {
            tblBook = adpBook.GetData();    // get the datatable

            grdBook.DataSource = tblBook;
            grdBook.DataBind();

            tblAuthor = adpAuthor.GetData();
            tblCat    = adpCat.GetData();
            tblPub    = adpPub.GetData();

            lstAuthor.DataSource     = tblAuthor;
            lstAuthor.DataTextField  = tblAuthor.AuthorNameColumn.ToString();
            lstAuthor.DataValueField = tblAuthor.AuthorIdColumn.ToString();
            lstAuthor.DataBind();
            lstAuthor.Items.Insert(0, new ListItem("Add Author", "-1"));
            //lstAuthor.SelectedIndex = 1;

            lstPub.DataSource     = tblPub;
            lstPub.DataTextField  = tblPub.PublisherNameColumn.ToString();
            lstPub.DataValueField = tblPub.PublisherIdColumn.ToString();
            lstPub.DataBind();
            lstPub.Items.Insert(0, new ListItem("Add Publisher", "-1"));
            //lstPub.SelectedIndex = 1;

            lstCat.DataSource     = tblCat;
            lstCat.DataTextField  = tblCat.CategoryNameColumn.ToString();
            lstCat.DataValueField = tblCat.CategoryIdColumn.ToString();
            lstCat.DataBind();
            lstCat.Items.Insert(0, new ListItem("Add Category", "-1"));
            //lstCat.SelectedIndex = 1;
        }