📄 feedbackdao.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using WesternByte.MyBlog.Core.Article;
using WesternByte.MyBlog.Core.Essay;
using WesternByte.MyBlog.Core.Blog;
namespace WesternByte.MyBlog.Core.FeedBack
{
/// <summary>
/// feedBackDAO 的摘要说明。
/// </summary>
public class FeedBackDAO :DbObject
{
//选取某个反馈信息
public FeedBackVO Load(int id)
{
Connection.Open();
SqlCommand sqlComm = new SqlCommand("select * from FeedBack where FeedBackID = " + id,Connection);
SqlDataReader tmpReader = sqlComm.ExecuteReader();
FeedBackVO feedBackVO = new FeedBackVO();
if(tmpReader.Read())
{
feedBackVO.FeedBackID = Convert.ToInt32(tmpReader["FeedBackID"].ToString());
feedBackVO.BlogID = Convert.ToInt32(tmpReader["BlogID"].ToString());
feedBackVO.Subject = tmpReader["Subject"].ToString();
feedBackVO.Content = tmpReader["Content"].ToString();
feedBackVO.ContentID = Convert.ToInt32(tmpReader["ContentID"].ToString());
feedBackVO.Category = tmpReader["Category"].ToString();
feedBackVO.Time = tmpReader["Time"].ToString();
feedBackVO.CategoryID = Convert.ToInt32(tmpReader["CategoryID"].ToString());
feedBackVO.Username = tmpReader["Username"].ToString();
feedBackVO.Url = tmpReader["Url"].ToString();
}
tmpReader.Close();
Connection.Close();
return feedBackVO;
}
//添加反馈
public int Insert(FeedBackVO feedBackVO)
{
int flag = 0;
Connection.Open();
string sql = "insert into FeedBack(Subject,Content,[Time],ContentID,Category,CategoryID,BlogID,Username,Url) values('"+feedBackVO.Subject+"','"+feedBackVO.Content+"','"+feedBackVO.Time+"',"+feedBackVO.ContentID+",'"+feedBackVO.Category+"',"+feedBackVO.CategoryID+","+feedBackVO.BlogID+",'"+feedBackVO.Username+"','"+feedBackVO.Url+"')";
SqlCommand sqlComm = new SqlCommand(sql,Connection);
flag = sqlComm.ExecuteNonQuery();
Connection.Close();
if(flag>0)
{
switch(feedBackVO.Category)
{
case "e":
EssayDAO eDAO = new EssayDAO();
flag += eDAO.FeedBack(feedBackVO.ContentID);
break;
case "a":
ArticleDAO aDAO = new ArticleDAO();
flag += aDAO.FeedBack(feedBackVO.ContentID);
break;
}
BlogDAO bDAO = new BlogDAO();
flag += bDAO.InsertFeedBack(feedBackVO.BlogID);
}
return flag;
}
//删除反馈信息
public int Delete(int id)
{
int flag = 0;
FeedBackVO fVO = Load(id);
Connection.Open();
string sql = "delete from FeedBack where FeedBackID = " + id;
SqlCommand sqlComm = new SqlCommand(sql,Connection);
flag = sqlComm.ExecuteNonQuery();
Connection.Close();
if(flag>0)
{
switch(fVO.Category)
{
case "e":
EssayDAO eDAO = new EssayDAO();
flag += eDAO.DFeedBack(fVO.ContentID);
break;
case "a":
ArticleDAO aDAO = new ArticleDAO();
flag += aDAO.DFeedBack(fVO.ContentID);
break;
}
BlogDAO bDAO = new BlogDAO();
flag += bDAO.DeleteFeedBack(fVO.BlogID,1);
}
return flag;
}
//删除某条信息的反馈信息
public int Delete(int contentID,string Category)
{
int flag = 0;
Connection.Open();
string sql = "delete from FeedBack where contentID = " + contentID + " and Category = '" + Category + "'";
SqlCommand sqlComm = new SqlCommand(sql,Connection);
flag = sqlComm.ExecuteNonQuery();
Connection.Close();
return flag;
}
//删除某分类下的信息的反馈信息
public int DeleteC(int CategoryID)
{
int flag = 0;
Connection.Open();
string sql = "delete from FeedBack where CategoryID = " + CategoryID;
SqlCommand sqlComm = new SqlCommand(sql,Connection);
flag = sqlComm.ExecuteNonQuery();
Connection.Close();
return flag;
}
//删除反馈信息
public int DeleteB(int blogID)
{
int flag = 0;
Connection.Open();
string sql = "delete from FeedBack where blogID = " + blogID;
SqlCommand sqlComm = new SqlCommand(sql,Connection);
flag = sqlComm.ExecuteNonQuery();
Connection.Close();
return flag;
}
//选取反馈列表信息
public DataSet LoadList(int BlogID,int ContentID,string Category,string key)
{
DataSet Datas=new DataSet();
Connection.Open();
string sql = "select * from FeedBack where 1=1";
if(BlogID!=0)sql+= " and BlogID = " + BlogID;
if(ContentID!=0)sql+= " and ContentID = " + ContentID;
if(Category!="")sql += " and Category = '" + Category + "'";
if(key!="")sql += " and (Subject like '%" + key + "%' or Content like '%" + key + "%'";
sql += " order by FeedBackID desc";
SqlDataAdapter sqlDA = new SqlDataAdapter(sql,Connection);
sqlDA.Fill( Datas, "FeedBack" );
Connection.Close();
return Datas;
}
//选取反馈列表信息
public DataSet LoadList(int BlogID,int startPage,int pageSize)
{
DataSet Datas=new DataSet();
Connection.Open();
string sql = "select * from FeedBack where BlogID = " + BlogID + " order by [time] desc";
SqlDataAdapter sqlDA = new SqlDataAdapter(sql,Connection);
sqlDA.Fill( Datas,startPage,pageSize, "FeedBack" );
Connection.Close();
return Datas;
}
//选取反馈总数
public int LoadCount(int BlogID)
{
int flag = 0;
Connection.Open();
string sql = "select count(*) as count from FeedBack where BlogID = " + BlogID;
SqlCommand sqlComm = new SqlCommand(sql,Connection);
SqlDataReader tmpReader = sqlComm.ExecuteReader();
if(tmpReader.Read())
{
flag = Convert.ToInt32(tmpReader["Count"].ToString());
}
Connection.Close();
return flag;
}
//选取反馈总数
public int LoadCount(int BlogID,int CategoryID,int ContentID,string Category,string key)
{
int flag = 0;
Connection.Open();
string sql = "select count(*) as count from FeedBack where 1=1";
if(BlogID!=0)sql+= " and BlogID = " + BlogID;
if(CategoryID!=0)sql += " and CategoryID = " + CategoryID;
if(ContentID!=0)sql+= " and ContentID = " + ContentID;
if(Category!="")sql += " and Category = '" + Category + "'";
if(key!="")sql += " and (Subject like '%" + key + "%' or Content like '%" + key + "%'";
SqlCommand sqlComm = new SqlCommand(sql,Connection);
SqlDataReader tmpReader = sqlComm.ExecuteReader();
if(tmpReader.Read()){
flag = Convert.ToInt32(tmpReader["Count"].ToString());
}
Connection.Close();
return flag;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -