📄 commentaccessor.cs
字号:
using System;
using System.Collections.Generic;
using Common.Entities;
using System.Data.SqlClient;
using System.Data;
using Common;
namespace DAL.Accessor
{
public class CommentAccessor
{
public bool CommentAdd(Comment comment)
{
bool flg = false;
SqlParameter[] sqlParamenter = {
new SqlParameter("@Article",SqlDbType.Int,4),
new SqlParameter("@name",SqlDbType.VarChar,20),
new SqlParameter("@Content",SqlDbType.VarChar,200),
new SqlParameter("@DateTime",SqlDbType.DateTime)
};
sqlParamenter[0].Value = comment.Article;
sqlParamenter[1].Value = comment.Name;
sqlParamenter[2].Value = comment.Content;
sqlParamenter[3].Value = DateTime.Now.ToShortDateString();
using(SqlConnection sqlConnection = new SqlConnection())
{
sqlConnection.ConnectionString = SqlHelper.ConnectionStringLocalTransaction;
SqlHelper.ExecuteNonQuery(sqlConnection, CommandType.StoredProcedure, "Comment_ADD", sqlParamenter);
flg = true;
}
return flg;
}
public List<Comment> GetCommentList()
{
List<Comment> list = new List<Comment>();
SqlDataReader read = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Comment_List", null);
while(read.Read())
{
Comment comment = new Comment();
comment.CommentID = int.Parse(read["CommentID"].ToString());
comment.Name = read["name"].ToString();
comment.Content = read["Content"].ToString();
comment.Title = read["Title"].ToString();
list.Add(comment);
}
return list;
}
//删除操作
public bool DeleteComment(int id)
{
bool flg = false;
SqlParameter[] sqlParamenter = {
new SqlParameter("@id",SqlDbType.Int,4)
};
sqlParamenter[0].Value = id;
using(SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = SqlHelper.ConnectionStringLocalTransaction;
SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "Comment_Delete", sqlParamenter);
flg = true;
}
return flg;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -