示例#1
0
        public static List <Book> listBooks()
        {
            List <Book> books = new List <Book>();

            String          sql = "select * from books order by author_id";
            MySqlConnection cnn = new MySqlConnection(SystemClasses.connString);
            MySqlCommand    cmd = new MySqlCommand(sql, cnn);

            cnn.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            int             i      = 1;

            while (reader.Read())
            {
                Book b = new Book();
                b.bookId        = int.Parse(reader["book_id"].ToString());
                b.bookName      = reader["book_name"].ToString();
                b.authorId      = int.Parse(reader["author_id"].ToString());
                b.authorName    = Author.getAuthorName(b.authorId);
                b.bookIsbn      = reader["book_isbn"].ToString();
                b.publisherId   = int.Parse(reader["publisher_id"].ToString());
                b.publisherName = Publisher.getPublisherName(b.publisherId);
                b.bookIndex     = reader["book_index"].ToString();
                b.bookNotes     = reader["book_notes"].ToString();
                b.isDigitized   = int.Parse(reader["is_digitized"].ToString());
                b.orderNumber   = i++;
                books.Add(b);
            }
            cnn.Close();

            return(books);
        }
示例#2
0
        public static Book getBook(int bookId)
        {
            Book            b   = new Book();
            String          sql = "select * from books where book_id = @bookId";
            MySqlConnection cnn = new MySqlConnection(SystemClasses.connString);
            MySqlCommand    cmd = new MySqlCommand(sql, cnn);

            cmd.Parameters.AddWithValue("@bookId", bookId);
            cnn.Open();
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                b.bookName      = reader["book_name"].ToString();
                b.authorId      = int.Parse(reader["author_id"].ToString());
                b.authorName    = Author.getAuthorName(b.authorId);
                b.bookIsbn      = reader["book_isbn"].ToString();
                b.publisherId   = int.Parse(reader["publisher_id"].ToString());
                b.publisherName = Publisher.getPublisherName(b.publisherId);
                b.bookIndex     = reader["book_index"].ToString();
                b.bookNotes     = reader["book_notes"].ToString();
                b.isDigitized   = int.Parse(reader["is_digitized"].ToString());
            }
            cnn.Close();
            return(b);
        }