⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replies.cs

📁 wrox c#高级编程
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;


namespace Wrox.WebModules.Forums.Data
{
	public class ReplyDetails
	{
		public int CategoryID;
		public int ForumID;
		public int TopicID;
		public int ReplyID;
		public string Message;
		public DateTime AddedDate;
		public int MemberID;
		public string MemberIP;
		public string MemberName;
		public string Email;
		public bool ShowEmail;
		public string Signature;
		public string AvatarUrl;
		public string Homepage;
	}

	public class Replies : Wrox.WebModules.Data.DbObject
	{
		public Replies(string newConnectionString) : base(newConnectionString)
		{	}

		// return all the replies for the specified topic
		public DataSet GetReplies(int topicID)
		{
			// create the parameter
			SqlParameter[] parameters = { new SqlParameter("@TopicID", SqlDbType.Int, 4) };
			parameters[0].Value = topicID;

			return RunProcedure("sp_Forums_GetReplies", parameters, "Replies");
		}

		// return the replies for the specified topic and in the specified virtual page
		// there is also an output param to return the total number of replies for the topic
		public DataSet GetReplies(int topicID, int pageNumber, int pageSize)
		{
			// create the parameter
			SqlParameter[] parameters = {
				new SqlParameter("@TopicID", SqlDbType.Int, 4),
				new SqlParameter("@PageNumber", SqlDbType.Int, 4),
				new SqlParameter("@PageSize", SqlDbType.Int, 4)
			};
			parameters[0].Value = topicID;
			parameters[1].Value = pageNumber;
			parameters[2].Value = pageSize;

			return RunProcedure("sp_Forums_GetRepliesByPage", parameters, "Replies");
		}	

		// return only the record with the specified ID
		public ReplyDetails GetDetails(int replyID)
		{
			// create the parameter
			SqlParameter[] parameters = { new SqlParameter("@ReplyID", SqlDbType.Int, 4) };
			parameters[0].Value = replyID;
			
			using(DataSet replies = RunProcedure("sp_Forums_GetReplyDetails", parameters, "Replies"))
			{
				ReplyDetails details = new ReplyDetails();
				// if the record was found, set the properties of the class instance
				if (replies.Tables[0].Rows.Count > 0)
				{
					DataRow rowReply = replies.Tables[0].Rows[0];
					details.CategoryID = (int)rowReply["CategoryID"];
					details.ForumID = (int)rowReply["ForumID"];
					details.TopicID = (int)rowReply["TopicID"];
					details.ReplyID = (int)rowReply["ReplyID"];
					details.Message = rowReply["Message"].ToString();
					details.AddedDate = Convert.ToDateTime(rowReply["AddedDate"]);
					details.MemberID = (int)rowReply["MemberID"];
					details.MemberIP = rowReply["MemberIP"].ToString();
					details.MemberName = rowReply["MemberName"].ToString();
					details.Email = rowReply["Email"].ToString();
					details.ShowEmail = Convert.ToBoolean(rowReply["ShowEmail"]);
					details.Signature = rowReply["Signature"].ToString();
					details.AvatarUrl = rowReply["AvatarUrl"].ToString();
					details.Homepage = rowReply["Homepage"].ToString();
				}
				else
					details.ReplyID = -1;

				return details;
			}
		}

		// return only the record with the specified ID in row format
		public DataRow GetDetailsRow(int replyID)
		{
			// create the parameter
			SqlParameter[] parameters = { new SqlParameter("@ReplyID", SqlDbType.Int, 4) };
			parameters[0].Value = replyID;
			
			using(DataSet replies = RunProcedure("sp_Forums_GetReplyDetails", parameters, "Replies"))
			{
				// return the first row, which is the only one
				return replies.Tables[0].Rows[0];
			}
		}

		// add a new record
		public int Add(int forumID, int topicID, string message, int memberID, string memberIP)
		{
			int numAffected;
	
			// create the parameters
			SqlParameter[] parameters = { 
				new SqlParameter("@ForumID", SqlDbType.Int, 4),
				new SqlParameter("@TopicID", SqlDbType.Int, 4),
				new SqlParameter("@Message", SqlDbType.Text),
				new SqlParameter("@MemberID", SqlDbType.Int, 4),
				new SqlParameter("@MemberIP", SqlDbType.VarChar, 15),
				new SqlParameter("@ReplyID", SqlDbType.Int, 4)
			};	
			
			// set the values
			parameters[0].Value = forumID;
			parameters[1].Value = topicID;
			parameters[2].Value = message.Trim();
			parameters[3].Value = memberID;
			parameters[4].Value = memberIP.Trim();
			parameters[5].Direction = ParameterDirection.Output;

			// run the procedure
			RunProcedure("sp_Forums_InsertReply", parameters, out numAffected);

			return (int)parameters[5].Value;
		}


		// update all the fields of the specified category
		public bool Update(int replyID, string message)
		{
			int numAffected;
		
			// create the parameters
			SqlParameter[] parameters = {
				new SqlParameter("@ReplyID", SqlDbType.Int, 4),
				new SqlParameter("@Message", SqlDbType.Text),
			};
			
			// set the values
			parameters[0].Value = replyID;
			parameters[1].Value = message.Trim();

			RunProcedure("sp_Forums_UpdateReply", parameters, out numAffected);

			return (numAffected == 1);
		}


		// delete the record identified by the specified ID
		public bool Delete(int replyID)
		{
			int numAffected;
		
			// create the parameter
			SqlParameter[] parameters = { new SqlParameter("@ReplyID", SqlDbType.Int, 4) };
			parameters[0].Value = replyID;
			
			RunProcedure("sp_Forums_DeleteReply", parameters, out numAffected);

			return (numAffected == 1);
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -