?? bookmanager.cs
字號(hào):
?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 圖書(shū)及圖書(shū)類(lèi)別業(yè)務(wù)錠邏輯層
/// </summary>
public class BookManager
{
public BookManager()
{
}
//獲得類(lèi)別列表
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;
}
}
}
//獲得圖書(shū)列表通過(guò)類(lèi)別名和用戶(hù)名 ,注:管理自己圖書(shū)時(shí)調(diào)用
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;
}
}
}
//獲得圖書(shū)列表通過(guò)類(lèi)別名 ,注:呈現(xiàn)圖書(shū)時(shí)調(diào)用
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;
}
}
}
//產(chǎn)生首頁(yè)隨機(jī)圖書(shū)的方法。
public static List<Book> GetBooks()
{
return GetBookbyCategory(GetRandomCategory());
}
//獲得一個(gè)隨機(jī)非空類(lèi)別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;
}
}
}
}
//通過(guò)BookID獲得圖書(shū)信息
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;
}
}
}
//獲得最新加入的圖書(shū)
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;
}
}
}
//獲得最多評(píng)論的前4本書(shū)
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);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -