📄 addpost.cs
字号:
namespace ASPNET.StarterKit.Communities.Discuss {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AddPost Class
//
// Represents the Add Post page. Enables users to post new messages.
//
//*********************************************************************
public class AddPost : ContentAddPage {
string _skinFileName = "Discuss_AddPost.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Discuss.DiscussSection";
TextBox txtTitle;
TopicPicker dropTopics;
HtmlTextBox txtBodyText;
Panel pnlModerateOptions;
CheckBox chkPinned;
CheckBox chkAnnouncement;
CheckBox chkLocked;
Title lblPreviewTitle;
DisplayTopic topicPreview;
PostBodyText lblPreviewBodyText;
Label lblUsername;
//*********************************************************************
//
// SkinLoadPost
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadPost(Object s, SkinLoadEventArgs e) {
// Find Title
txtTitle = (TextBox)GetControl(e.Skin, "txtTitle");
// Find Topic Picker
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
// Find Body Text
txtBodyText = (HtmlTextBox)GetControl(e.Skin, "txtBodyText");
// Find Moderator Panel
pnlModerateOptions = (Panel)GetControl(e.Skin, "pnlModerateOptions");
if (objUserInfo.MayEdit || objUserInfo.MayModerate)
pnlModerateOptions.Visible = true;
else
pnlModerateOptions.Visible = false;
// Find Pinned Checkbox
chkPinned = (CheckBox)GetControl(e.Skin, "chkPinned");
// Find Announcement Checkbox
chkAnnouncement = (CheckBox)GetControl(e.Skin, "chkAnnouncement");
// Find Locked Checkbox
chkLocked = (CheckBox)GetControl(e.Skin, "chkLocked");
// Find Preview Title
lblPreviewTitle = (Title)GetControl(e.Skin, "lblPreviewTitle");
// Find Username Label
lblUsername = (Label)GetControl(e.Skin, "lblUsername");
lblUsername.Text = objUserInfo.Username;
// Find the topic preview
topicPreview = (DisplayTopic)GetControl(e.Skin, "topicPreview");
// Find Preview Body Text
lblPreviewBodyText = (PostBodyText)GetControl(e.Skin, "lblPreviewBodyText");
}
//*********************************************************************
//
// PreviewPost Method
//
// When previewing, we want to transfer everything from
// the text boxes to the labels.
//
//*********************************************************************
void PreviewPost(Object s, EventArgs e) {
lblPreviewTitle.Text = txtTitle.Text;
if (objSectionInfo.EnableTopics)
topicPreview.Name = dropTopics.SelectedItem.Text;
lblPreviewBodyText.Text = txtBodyText.Text;
}
//*********************************************************************
//
// SubmitPost Method
//
// This method is raised by clicking the Add button in the Add
// Post form. It adds the post to the database.
//
//*********************************************************************
void SubmitPost(Object s, EventArgs e) {
if (Page.IsValid) {
// Check moderation status
int moderationStatus = 1;
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
moderationStatus = 0;
// Get Topic
int topicID = -1;
if (objSectionInfo.EnableTopics)
topicID = dropTopics.SelectedTopicID;
// Add to Content Pages
int contentPageID = DiscussUtility.AddPost
(
objUserInfo.Username,
objSectionInfo.ID,
topicID,
txtTitle.Text,
moderationStatus,
chkPinned.Checked,
chkAnnouncement.Checked,
chkLocked.Checked,
txtBodyText.Text
);
// Show warning message if moderation enabled
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
Context.Response.Redirect(CommunityGlobals.CalculatePath("Messages_Message.aspx?message=moderation"));
// Otherwise, redirect to default page and send notifications
Context.Server.ScriptTimeout = 10 * 60;
Context.Response.Redirect(CommunityGlobals.CalculatePath("Default.aspx"), false);
Context.Response.Flush();
Context.Response.Close();
NotifyUtility.SendNotifications(objSectionInfo.ID, contentPageID, txtTitle.Text, objUserInfo.Username);
Context.Response.End();
}
}
//*********************************************************************
//
// AddPost Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public AddPost() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Specify Discuss Section Content
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadPost);
this.Preview += new PreviewEventHandler(PreviewPost);
this.Submit += new SubmitEventHandler(SubmitPost);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -