📄 comment.cs
字号:
namespace PowerEasy.SqlServerDal.Contents
{
using Microsoft.Practices.EnterpriseLibrary.Data;
using PowerEasy.IDal.Contents;
using PowerEasy.Model.Contents;
using PowerEasy.SqlServerDal;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
public class Comment : IComment
{
private int m_TotalOfCommentInfo;
public bool Add(CommentInfo commentInfo)
{
Parameters parms = new Parameters();
GetParameters(commentInfo, parms);
return DBHelper.ExecuteSql("INSERT INTO [PE_Comment](CommentId,GeneralId,TopicId,NodeId,CommentTitle,[Content],UpdateDateTime,Score,[Position],Status,Agree,Oppose,Neutral,IP,IsElite,IsPrivate,UserName,Face,Email,ReplyUserName) Values (@CommentId,@GeneralId,@TopicId,@NodeId,@CommentTitle,@Content,@UpdateDateTime,@Score,@Position,@Status,0,0,0,@IP,0,@IsPrivate,@UserName,@Face,@Email,@ReplyUserName)", parms);
}
public bool AdministratorReply(CommentInfo commentInfo)
{
Parameters cmdParams = new Parameters();
cmdParams.AddInParameter("@CommentId", DbType.Int32, commentInfo.CommentId);
cmdParams.AddInParameter("@Reply", DbType.String, commentInfo.Reply);
cmdParams.AddInParameter("@ReplyAdmin", DbType.String, commentInfo.ReplyAdmin);
cmdParams.AddInParameter("@ReplyDateTime", DbType.DateTime, commentInfo.ReplyDateTime);
cmdParams.AddInParameter("@ReplyIsPrivate", DbType.Boolean, commentInfo.ReplyIsPrivate);
return DBHelper.ExecuteSql("UPDATE PE_Comment SET Reply=@Reply,ReplyAdmin=@ReplyAdmin,ReplyDateTime=@ReplyDateTime,ReplyIsPrivate=@ReplyIsPrivate WHERE CommentId=@CommentId", cmdParams);
}
private static CommentInfo CommentInfoAndUserInfoFromDataReader(NullableDataReader dr)
{
CommentInfo info = CommentInfoCommonFromDataReader(dr);
info.UserFace = dr.GetString("UserFace");
info.UserPoint = dr.GetInt32("UserPoint");
info.UserExp = dr.GetInt32("UserExp");
info.FaceHeight = dr.GetInt32("FaceHeight");
info.FaceWidth = dr.GetInt32("FaceWidth");
info.UserRegTime = dr.GetDateTime("RegTime");
info.UserId = dr.GetInt32("UserID");
info.Email = dr.GetString("Email");
return info;
}
private static CommentInfo CommentInfoCommonFromDataReader(NullableDataReader dr)
{
CommentInfo info = new CommentInfo();
info.CommentId = dr.GetInt32("CommentId");
info.Agree = dr.GetInt32("Agree");
info.CommentTitle = dr.GetString("CommentTitle");
info.Content = dr.GetString("Content");
info.GeneralId = dr.GetInt32("GeneralId");
info.IP = dr.GetString("IP");
info.IsElite = dr.GetBoolean("IsElite");
info.IsPrivate = dr.GetBoolean("IsPrivate");
info.Neutral = dr.GetInt32("Neutral");
info.Oppose = dr.GetInt32("Oppose");
info.Position = dr.GetInt32("Position");
info.Reply = dr.GetString("Reply");
info.ReplyAdmin = dr.GetString("ReplyAdmin");
info.ReplyDateTime = dr.GetDateTime("ReplyDateTime");
info.ReplyIsPrivate = dr.GetBoolean("ReplyIsPrivate");
info.Status = dr.GetBoolean("Status");
info.TopicId = dr.GetInt32("TopicId");
info.UpdateDateTime = dr.GetDateTime("UpdateDateTime");
info.UserName = dr.GetString("UserName");
info.NodeId = dr.GetInt32("NodeId");
info.Score = dr.GetInt32("Score");
info.Face = dr.GetString("Face");
info.ReplyUserName = dr.GetString("ReplyUserName");
return info;
}
private static CommentInfo CommentInfoFromDataReader(NullableDataReader dr)
{
CommentInfo info = CommentInfoCommonFromDataReader(dr);
info.Email = dr.GetString("Email");
return info;
}
public bool Delete(int commentId)
{
Parameters cmdParams = new Parameters();
cmdParams.AddInParameter("@CommentId", DbType.Int32, commentId);
return DBHelper.ExecuteSql("DELETE FROM PE_Comment WHERE CommentId=@CommentId", cmdParams);
}
public bool Delete(string commentIds)
{
return DBHelper.ExecuteSql("DELETE FROM PE_Comment WHERE CommentId IN (" + commentIds + ")");
}
public bool Delete(int commentId, string userName)
{
Parameters cmdParams = new Parameters();
cmdParams.AddInParameter("@CommentId", DbType.Int32, commentId);
cmdParams.AddInParameter("@UserName", DbType.String, userName);
return DBHelper.ExecuteSql("DELETE FROM PE_Comment WHERE CommentId=@CommentId AND UserName=@UserName", cmdParams);
}
public bool Elite(int commentId, bool isElite)
{
Parameters cmdParams = new Parameters();
cmdParams.AddInParameter("@CommentId", DbType.Int32, commentId);
cmdParams.AddInParameter("@IsElite", DbType.Boolean, isElite);
return DBHelper.ExecuteSql("UPDATE PE_Comment SET IsElite=@IsElite WHERE CommentId=@CommentId", cmdParams);
}
public CommentInfo GetCommentInfo(int commentId)
{
Parameters cmdParams = new Parameters();
cmdParams.AddInParameter("@CommentId", DbType.Int32, commentId);
using (NullableDataReader reader = DBHelper.ExecuteReaderSql("SELECT * FROM PE_Comment WHERE CommentId=@CommentId", cmdParams))
{
if (reader.Read())
{
return CommentInfoFromDataReader(reader);
}
return new CommentInfo(true);
}
}
public CommentInfo GetExtendCommentInfo(int commentId)
{
Parameters cmdParams = new Parameters();
cmdParams.AddInParameter("@CommentId", DbType.Int32, commentId);
using (NullableDataReader reader = DBHelper.ExecuteReaderSql("SELECT * FROM PE_Comment LEFT JOIN PE_Users ON PE_Comment.UserName=PE_Users.UserName WHERE PE_Comment.CommentId=@CommentId", cmdParams))
{
if (reader.Read())
{
return CommentInfoAndUserInfoFromDataReader(reader);
}
return new CommentInfo(true);
}
}
public IList<CommentInfo> GetList(int startRowIndexId, int maxNumberRows)
{
return this.GetList(startRowIndexId, maxNumberRows, "DESC", "");
}
public IList<CommentInfo> GetList(int startRowIndexId, int maxNumberRows, int generalId)
{
string filter = " GeneralId=" + generalId.ToString() + " ";
return this.GetList(startRowIndexId, maxNumberRows, "DESC", filter);
}
public IList<CommentInfo> GetList(int startRowIndexId, int maxNumberRows, int generalId, int type)
{
StringBuilder builder = new StringBuilder();
builder.Append(" PE_Comment.GeneralId=" + generalId.ToString() + " ");
switch (type)
{
case 1:
builder.Append("AND PE_Comment.Status=1 ");
break;
case 2:
builder.Append("AND PE_Comment.Status=0 ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -