📄 commentmanager.cs
字号:
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.Data.SqlClient;
using System.Collections.Generic;
/// <summary>
/// CommentManager 评论类的业务罗辑层
/// </summary>
public class CommentManager
{
public CommentManager()
{
}
//获得图书的评论
public static List<Comment> GetCommentByBookID(int BookID)
{
using(SqlConnection connection = new SqlConnection (ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command= new SqlCommand ("GetCommentByBookID",connection ))
{
command.CommandType = CommandType.StoredProcedure;
List<Comment> list = new List<Comment>();
command.Parameters.Add(new SqlParameter("@BookID", BookID));
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Comment temp = new Comment((int)reader["CommentID"], (string)reader["UserID"], (int)reader["BookID"], (DateTime)reader["ComeentTime"], (String)reader["ComeentContext"],(string)reader["CommentCaption"]);
list.Add(temp);
}
}
return list;
}
}
}
//加入评论
public static void AddComment(string Caption, string CommentContext, int BookID)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("AddComment", connection))
{
command.CommandType = CommandType.StoredProcedure;
command .Parameters .Add (new SqlParameter ("@UserID",Membership.GetUser().UserName .ToString ()));
command .Parameters .Add (new SqlParameter ("@BookID",BookID));
command .Parameters .Add (new SqlParameter ("@CommentTime",DateTime.Now ));
command.Parameters.Add(new SqlParameter("@CommentContext", CommentContext));
command .Parameters .Add (new SqlParameter ("@CommentCaption",Caption ));
connection.Open ();
command .ExecuteNonQuery ();
}
}
}
//删除评论
public static void DeleteComment(int CommentID)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("DeleteComment", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@CommentID", CommentID));
connection.Open();
command.ExecuteNonQuery();
}
}
}
//Links的添加方法
public static void InsertLink(string linkaddr,string linkcontext,string linkclass)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShow"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("AddLink", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters .Add(new SqlParameter ("@LinkAddress",linkaddr));
command.Parameters.Add(new SqlParameter("@LinkContext", linkcontext));
command.Parameters.Add(new SqlParameter("@LinkClass", linkclass));
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -