📄 commentutility.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
//*********************************************************************
//
// CommentUtility Class
//
// Contains static utility methods used by the Comments module.
//
//*********************************************************************
public class CommentUtility {
//*********************************************************************
//
// AddComment Method
//
// Adds a new comment to the database.
//
//*********************************************************************
public static int AddComment
(
int contentPageID,
ModerationStatus moderationStatus,
string username,
string title,
string body
) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdAdd = new SqlCommand("Community_CommentsAddComment", conPortal);
cmdAdd.CommandType = CommandType.StoredProcedure;
// Add Parameters
cmdAdd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdAdd.Parameters.Add("@contentPageID", contentPageID);
cmdAdd.Parameters.Add("@moderationStatus", moderationStatus);
cmdAdd.Parameters.Add("@username", username);
cmdAdd.Parameters.Add("@title", title);
cmdAdd.Parameters.Add("@metaDescription", ContentPageUtility.CalculateMetaDescription(body));
cmdAdd.Parameters.Add("@metaKeys", ContentPageUtility.CalculateMetaKeys(body));
cmdAdd.Parameters.Add("@body", SqlDbType.NText);
cmdAdd.Parameters[ "@body" ].Value = body;
conPortal.Open();
cmdAdd.ExecuteNonQuery();
int result = (int)cmdAdd.Parameters["@RETURN_VALUE"].Value;
conPortal.Close();
return result;
}
//*********************************************************************
//
// GetComment Method
//
// Gets a particular comment from the database.
//
//*********************************************************************
public static ContentInfo GetComment(string username, int contentPageID) {
CommentInfo comment = null;
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGet = new SqlCommand("Community_CommentsGetComment", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
// Add Parameters
cmdGet.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdGet.Parameters.Add("@username", username);
cmdGet.Parameters.Add("@contentPageID", contentPageID);
// Get Comment from DB
conPortal.Open();
SqlDataReader dr = cmdGet.ExecuteReader();
if (dr.Read())
comment = new CommentInfo(dr);
conPortal.Close();
return (ContentInfo)comment;
}
//*********************************************************************
//
// GetComments Method
//
// Retrieves a list of comments from the database.
//
//*********************************************************************
public static CommentCollection GetComments(string username, int contentPageID, int orderBy) {
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdGet = new SqlCommand("Community_CommentsGetComments", conPortal);
cmdGet.CommandType = CommandType.StoredProcedure;
// Add Parameters
cmdGet.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
cmdGet.Parameters.Add("@username", username);
cmdGet.Parameters.Add("@contentPageID", contentPageID);
cmdGet.Parameters.Add("@orderBy", orderBy);
CommentCollection colComments = new CommentCollection();
conPortal.Open();
SqlDataReader dr = cmdGet.ExecuteReader();
while (dr.Read())
colComments.Add(new CommentInfo(dr));
conPortal.Close();
return colComments;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -