MyBookShopDAL/BookService.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyBookShop.Model;
using System.Data.SqlClient;

namespace MyBookShop.DAL
{
    public class BookService
    {
        /// <summary>
        /// 获得所有图书
        /// </summary>
        /// <returns>图书的集合</returns>
        public List<Books> GetAllBooks()
        {
            List<Books> list = new List<Books>();
            string sqlStr = "select * from Books";
            SqlDataReader reader = DBHelper.ExecuteGetReader(System.Data.CommandType.Text, sqlStr, null);
            while (reader.Read())
            {
                Books book = new Books();
                book.Id = reader.GetInt32(0);
                book.Title = reader.GetString(1);
                book.Author = reader.GetString(2);
                book.PublisherId = reader.GetInt32(3);
                book.PublishDate = reader.GetDateTime(4);
                book.ISBN = reader.GetString(5);
                book.UnitPrice = reader.GetDecimal(6);
                book.ContentDescription = reader.GetString(7);
                book.TOC = reader.GetString(8);
                book.CategoryId = reader.GetInt32(9);
                book.Clicks = reader.GetInt32(10);
                list.Add(book);
            }
            reader.Dispose();
            return list;
        }

        /// <summary>
        /// 分页得到图书
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页展示的数据条数</param>
        /// <returns>图书集合</returns>
        public List<Books> GetBooksByPage(int pageIndex, int pageSize)
        {
            List<Books> list = new List<Books>();
            SqlParameter[] paras=new SqlParameter[]{
                new SqlParameter("pageIndex",pageIndex),
                new SqlParameter("pageSize",pageSize)
            };
            SqlDataReader reader = DBHelper.ExecuteGetReader(System.Data.CommandType.StoredProcedure, "up_bookPager", paras);
            while (reader.Read())
            {
                Books book = new Books();
                book.Id = reader.GetInt32(0);
                book.Title = reader.GetString(1);
                book.Author = reader.GetString(2);
后面还有 69 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。