⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookmanager.cs

📁 asp.net 做的个人图书站点应用
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO ;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
/// <summary>
/// BookManager 图书及图书类别业务锭逻辑层
/// </summary>
public class BookManager
{
    public BookManager()
    {


    }
   //获得类别列表
    public static List<BookCategory> GetCategory()
    
    {
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand("GetCategory", connection))
           {
               command.CommandType = CommandType.StoredProcedure;
               connection.Open();
               List<BookCategory> list = new List<BookCategory>();
               using (SqlDataReader reader = command.ExecuteReader())
               {
                   while (reader.Read())
                   {
                       BookCategory temp = new BookCategory((int)reader["CategoryID"], (string)reader["CategoryName"], (string)reader["CategoryRemark"], (int)reader["NumbersofBooks"]);
                       list.Add(temp);
                   }
               }

               return list;
            }
        }
    }
    //获得图书列表通过类别名和用户名  ,注:管理自己图书时调用
    public static List<Book> GetBookbyCategoryAndName(int CategoryID)
    {
        MembershipUser user = Membership.GetUser();
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand("GetBookbyCategoryAndName", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@CategoryID", CategoryID));
                command.Parameters.Add(new SqlParameter("@UserID", user.UserName.ToString()));
                List<Book> list = new List<Book>();                                 
                connection.Open();
                using (SqlDataReader reader = command .ExecuteReader ())
                {
                    while (reader.Read())
                    { Book temp = new Book((int)reader["BookID"], (string)reader["BookName"], (int)reader["CategoryID"], (string)reader["ISBN"], (string)reader["UserID"], (string)reader["BookTips"], (DateTime)reader["AddDateTime"],-1);
                    list.Add(temp);
                    }
                }
                return list;
            }
        }
    }
    //获得图书列表通过类别名 ,注:呈现图书时调用
    public static List<Book> GetBookbyCategory(int CategoryID)
    {
      //  MembershipUser user = Membership.GetUser();
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand("GetBookbyCategory", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("CategoryID", CategoryID));
                 List<Book> list = new List<Book>();
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Book temp = new Book((int)reader["BookID"], (string)reader["BookName"], (int)reader["CategoryID"], (string)reader["ISBN"], (string)reader["UserID"], (string)reader["BookTips"], (DateTime)reader["AddDateTime"],-1);
                        list.Add(temp);
                    }
                }
                return list;
            }
        }
    }
    //产生首页随机图书的方法。
    public static List<Book> GetBooks()
    {
       return  GetBookbyCategory(GetRandomCategory());
    }
    //获得一个随机非空类别ID
    public static int GetRandomCategory()
    {
        using(SqlConnection  connection = new SqlConnection (ConfigurationManager .ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand ("GetNotEmptyCategory",connection ))
            {
                command.CommandType=CommandType.StoredProcedure;
                connection .Open ();
                List<BookCategory> list= new List<BookCategory> ();
                SqlDataReader reader = command .ExecuteReader();
                while(reader .Read ())
                {
                    BookCategory temp = new BookCategory (Convert.ToInt32(reader["CategoryID"]),"","",0);
                    list.Add(temp);
                }
                try
                { Random ran = new Random() ;
                return list[ran.Next(list.Count)].CategoryID;
                }
                catch
                {
                    return -1;
                }
            }
        }
    }
//通过BookID获得图书信息
    public static Book GetBookbyBookID(int BookID)
    {
        Book book = null;

        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand("GetBookbyBookID", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("BookID", BookID));
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        book  = new Book((int)reader["BookID"], (string)reader["BookName"], (int)reader["CategoryID"], (string)reader["ISBN"], (string)reader["UserID"], (string)reader["BookTips"], (DateTime)reader["AddDateTime"],-1);
                       
                    }
                }
                return book;
            }
        }
    }
   
    //获得最新加入的图书
public static List<Book> Get5newBooks()
    {
      //  MembershipUser user = Membership.GetUser();
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand("select top 4 BookID,BookName,CategoryID,ISBN,UserID,BookTips,AddDateTime from Book order by AddDateTime desc", connection))
            {
                command.CommandType = CommandType.Text;
                List<Book> list = new List<Book>();
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Book temp = new Book((int)reader["BookID"], (string)reader["BookName"], (int)reader["CategoryID"], (string)reader["ISBN"], (string)reader["UserID"], (string)reader["BookTips"], (DateTime)reader["AddDateTime"],-1);
                        list.Add(temp);
                    }
                }
                return list;
            }
        }
    }
    //获得最多评论的前4本书
    public static List<Book> GetHotBooks()
    {
        //  MembershipUser user = Membership.GetUser();
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
        {
            using (SqlCommand command = new SqlCommand("GetHotBooks", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                List<Book> list = new List<Book>();
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Book temp = new Book((int)reader["BookID"], (string)reader["BookName"],0,"","","",DateTime .Now ,Convert.ToInt32 (reader ["hot"]));
                        list.Add(temp);
                    }
                }
                return list;
            }
        }
    }
    //
    //public static Book  GetCategorybyBookID(int BookID)
    //{
    //    using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
    //    {
    //        using (SqlCommand command = new SqlCommand("GetBookbyBookID", connection))
    //        {
    //            command.CommandType = CommandType.StoredProcedure;
    //            command.Parameters.Add(new SqlParameter("BookID", BookID));
    //            Book book = null;
    //            connection.Open();
    //            using (SqlDataReader reader = command.ExecuteReader())
    //            {
    //                while (reader.Read())
    //                {
    //                    book = new Book((int)reader["BookID"], (string)reader["BookName"], (int)reader["CategoryID"], (string)reader["ISBN"], (string)reader["UserID"], (string)reader["BookTips"], (DateTime)reader["AddDateTime"],-1);
                       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -