📄 addarticle.cs
字号:
namespace ASPNET.StarterKit.Communities.Articles {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AddArticle Class
//
// Represents the Add Article page. Enables users to list new articles.
//
//*********************************************************************
public class AddArticle : ContentAddPage {
string _skinFileName = "Articles_AddArticle.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Articles.ArticleSection";
TextBox txtTitle;
TopicPicker dropTopics;
TextBox txtBriefDescription;
HtmlTextBox txtBodyText;
Title lblPreviewTitle;
DisplayTopic topicPreview;
BriefDescription lblPreviewBriefDescription;
ArticleBodyText lblPreviewBodyText;
//*********************************************************************
//
// SkinLoadArticle
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadArticle(Object s, SkinLoadEventArgs e) {
// Find Title
txtTitle = (TextBox)GetControl(e.Skin, "txtTitle");
// Find Topic Picker
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
// Find Intro Text
txtBriefDescription = (TextBox)GetControl(e.Skin, "txtBriefDescription");
// Find Body Text
txtBodyText = (HtmlTextBox)GetControl(e.Skin, "txtBodyText");
// Find Preview Title
lblPreviewTitle = (Title)GetControl(e.Skin, "lblPreviewTitle");
// Find the topic preview
topicPreview = (DisplayTopic)GetControl(e.Skin, "topicPreview");
// Find Preview Intro Text
lblPreviewBriefDescription = (BriefDescription)GetControl(e.Skin, "lblPreviewBriefDescription");
// Find Preview Body Text
lblPreviewBodyText = (ArticleBodyText)GetControl(e.Skin, "lblPreviewBodyText");
}
//*********************************************************************
//
// PreviewArticle Method
//
// When previewing an article, we want to transfer everything from
// the text boxes to the labels.
//
//*********************************************************************
void PreviewArticle(Object s, EventArgs e) {
lblPreviewTitle.Text = txtTitle.Text;
if (objSectionInfo.EnableTopics)
topicPreview.Name = dropTopics.SelectedItem.Text;
lblPreviewBriefDescription.Text = txtBriefDescription.Text;
lblPreviewBodyText.Text = txtBodyText.Text;
}
//*********************************************************************
//
// SubmitArticle Method
//
// This method is raised by clicking the Add button in the Add
// Article form. It adds the article to the database.
//
//*********************************************************************
void SubmitArticle(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 = ArticleUtility.AddArticle
(
objUserInfo.Username,
objSectionInfo.ID,
topicID,
txtTitle.Text,
txtBriefDescription.Text,
moderationStatus,
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();
}
}
//*********************************************************************
//
// AddArticle Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public AddArticle() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Assign section content
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadArticle);
this.Preview += new PreviewEventHandler(PreviewArticle);
this.Submit += new SubmitEventHandler(SubmitArticle);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -