📄 postmessage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using infoWeb.WebModules.Accounts.Business;
namespace infoWeb.WebModules.Forums.Web
{
/// <summary>
/// Summary description for Post.
/// </summary>
public class PostMessage : infoWeb.ThePhile.Web.PhilePage
{
protected System.Web.UI.WebControls.TableCell MessageBoxHeader;
protected System.Web.UI.WebControls.TextBox Subject;
protected System.Web.UI.WebControls.TextBox Message;
protected System.Web.UI.WebControls.TextBox Key;
protected System.Web.UI.WebControls.TableRow SubjectRow;
protected System.Web.UI.WebControls.TableRow KeyRow;
protected System.Web.UI.WebControls.TableRow SpecialTagsRow;
protected Web.Controls.User.Header Header;
protected System.Web.UI.WebControls.Table MessageBox;
private int forumID;
private int topicID;
private int replyID;
private bool canModerateForums;
SiteIdentity currUser;
Business.Member currMember;
private void Page_Load(object sender, System.EventArgs e)
{
// if the user is not authenticated, redirect to the login page
if (!Context.User.Identity.IsAuthenticated)
{
Response.Redirect("/ThePhile/Modules/Users/Login.aspx", true);
}
// retrieve the current user/member
currUser = (SiteIdentity)Context.User.Identity;
currMember = new Business.Member();
currMember.LoadFromUser(currUser.UserID);
// if the user is not registered for the forum, redirect to the profile page
if (currMember.ID == -1)
{
Response.Redirect("MyProfile.aspx", true);
}
// check if the user has the permission to moderate the forums
SitePrincipal currentPrincipal = (SitePrincipal)Context.User;
canModerateForums = currentPrincipal.HasPermission(
(int)ForumsPermissions.ModerateForums);
// if the user wants to edit a topic or reply, but does not have the permission to do so,
// redirect to the login page
if (Request.QueryString["Action"].ToString().ToLower().StartsWith("edit")
&& !canModerateForums)
{
Response.Redirect("/ThePhile/Modules/Users/Login.aspx?ShowError=true", true);
}
// extract the ForumID, if specified
if (Request.QueryString["ForumID"] == null)
forumID = -1;
else
forumID = int.Parse(Request.QueryString["ForumID"]);
// extract the TopicID, if specified
if (Request.QueryString["TopicID"] == null)
topicID = -1;
else
topicID = int.Parse(Request.QueryString["TopicID"]);
// extract the ReplyID, if specified
if (Request.QueryString["ReplyID"] == null)
replyID = -1;
else
replyID = int.Parse(Request.QueryString["ReplyID"]);
if (!Page.IsPostBack)
{
// show/hide the icons for the special tags, according to the settings
SpecialTagsRow.Visible = Configuration.ModuleConfig.GetSettings().SpecialTagsEnabled;
// save the referrer Url
ViewState["ReferrerUrl"] = Request.UrlReferrer.ToString();
Business.Forum forum = new Business.Forum(forumID);
Business.Topic topic = new Business.Topic(topicID);
Business.Reply reply = new Business.Reply(replyID);
// show the fields and the navigation path, according to the
// action to complete, and the forum/topic/reply ID
switch(Request.QueryString["Action"].ToString().ToLower())
{
case "newtopic":
SubjectRow.Visible = true;
KeyRow.Visible = canModerateForums;
MessageBoxHeader.Text = "New topic";
Header.ForumID = forumID;
break;
case "edittopic":
SubjectRow.Visible = true;
KeyRow.Visible = canModerateForums;
MessageBoxHeader.Text = "Edit topic";
Subject.Text = topic.Subject;
Key.Text = topic.Key;
Message.Text = topic.Message;
Header.TopicID = topicID;
break;
case "newreply":
SubjectRow.Visible = false;
KeyRow.Visible = false;
MessageBoxHeader.Text = "New reply";
Header.TopicID = topicID;
// a topic or another reply can being quoted by this new reply, check it it is the case
int quoteTopicID;
int quoteReplyID;
// extract the QuoteTopicID, if specified
if (Request.QueryString["QuoteTopicID"] == null)
quoteTopicID = -1;
else
quoteTopicID = int.Parse(Request.QueryString["QuoteTopicID"]);
// extract the QuoteReplyID, if specified
if (Request.QueryString["QuoteReplyID"] == null)
quoteReplyID = -1;
else
quoteReplyID = int.Parse(Request.QueryString["QuoteReplyID"]);
// if a topic is being quoted, add it to the MessageBox
if (quoteTopicID != -1)
{
Business.Topic existentTopic = new Business.Topic(quoteTopicID);
Message.Text += string.Format("[QUOTE]{0}[/QUOTE]", existentTopic.Message);
}
// if a reply is being quoted, add it to the MessageBox
if (quoteReplyID != -1)
{
Business.Reply existentReply = new Business.Reply(quoteReplyID);
Message.Text += string.Format("[QUOTE]{0}[/QUOTE]", existentReply.Message);
}
break;
case "editreply":
SubjectRow.Visible = false;
KeyRow.Visible = false;
Message.Text = reply.Message;
MessageBoxHeader.Text = "Edit reply";
Header.TopicID = reply.Topic.ID;
break;
}
}
}
public bool CanModerateForums
{
get { return canModerateForums; }
}
protected void SubmitMessage_Click(object sender, EventArgs e)
{
Business.Forum forum = new Business.Forum(forumID);
Business.Topic topic = new Business.Topic(topicID);
Business.Reply reply = new Business.Reply(replyID);
switch(Request.QueryString["Action"].ToString().ToLower())
{
// create a new topic
case "newtopic":
int newID = forum.AddTopic(Key.Text, Subject.Text, Message.Text, currMember.ID).ID;
Response.Redirect("Topic.aspx?TopicID=" + newID.ToString(), true);
break;
// edit an existent topic
case "edittopic":
topic.Key = Key.Text;
topic.Subject = Subject.Text;
topic.Message = Message.Text;
topic.Update();
break;
// add a new reply
case "newreply":
topic.AddReply(Message.Text, currMember.ID);
// add the parameter to the Referrer Url to jump to the last page of the topic
if (!ViewState["ReferrerUrl"].ToString().ToLower().EndsWith("&display=lastpage"))
ViewState["ReferrerUrl"] += "&Display=LastPage";
break;
// edit an existent reply
case "editreply":
reply.Message = Message.Text;
reply.Update();
break;
}
// redirect to the referrer page
Response.Redirect(ViewState["ReferrerUrl"].ToString());
}
protected void CancelMessage_Click(object sender, EventArgs e)
{
// go back to the referrer page
Response.Redirect(ViewState["ReferrerUrl"].ToString());
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -