📄 addevent.cs
字号:
namespace ASPNET.StarterKit.Communities.Events {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AddEvent Class
//
// Represents the Add Event page. Enables users to list new events.
//
//*********************************************************************
public class AddEvent : ContentAddPage {
string _skinFileName = "Events_AddEvent.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Events.EventSection";
TextBox txtEventTitle;
TopicPicker dropTopics;
TextBox txtEventLink;
TextBox txtEventBriefDescription;
HtmlTextBox txtEventFullDescription;
TextBox txtEventLocation;
TextBox txtEventSpeaker;
HtmlTextBox txtEventSpeakerBiography;
HtmlInputFile txtImageFile;
Image imgEventImage;
DatePicker ctlEventDate;
DatePicker ctlEventDateVisible;
Label lblInvalidDisplayDate;
Label lblInvalidEventDate;
Label lblInvalidDateCompare;
//*********************************************************************
//
// SkinLoadEvent
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadEvent(Object s, SkinLoadEventArgs e) {
// Find the Form so that we can change the EncType of the post.
HtmlForm form = (HtmlForm)Page.FindControl("PageForm");
form.Enctype="multipart/form-data";
// Find Topic Picker
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
// Find Event Title
txtEventTitle = (TextBox)GetControl(e.Skin, "txtEventTitle" );
// Find Event Link
txtEventLink = (TextBox)GetControl(e.Skin, "txtEventLink");
// Find Event Brief Description
txtEventBriefDescription = (TextBox)GetControl(e.Skin, "txtEventBriefDescription" );
// Find Event Full Description
txtEventFullDescription = (HtmlTextBox)GetControl(e.Skin, "txtEventFullDescription" );
// Find Event Location
txtEventLocation = (TextBox)GetControl(e.Skin, "txtEventLocation" );
// Find Event Speaker
txtEventSpeaker = (TextBox)GetControl(e.Skin, "txtEventSpeaker" );
// Find Event Speaker Biography
txtEventSpeakerBiography = (HtmlTextBox)GetControl(e.Skin, "txtEventSpeakerBiography" );
// Find Event Date
ctlEventDate = (DatePicker)GetControl(e.Skin, "ctlEventDate" );
// Find Event Date Visible
ctlEventDateVisible = (DatePicker)GetControl(e.Skin, "ctlEventDateVisible" );
// Find the image upload control
txtImageFile = (HtmlInputFile)GetControl(e.Skin, "txtImageFile");
// Find and hide the event image control
imgEventImage = (Image)GetControl(e.Skin, "imgEventImage");
imgEventImage.Visible = false;
// Find Error Labels
lblInvalidDisplayDate = (Label)GetControl(e.Skin, "lblInvalidDisplayDate");
lblInvalidEventDate = (Label)GetControl(e.Skin, "lblInvalidEventDate");
lblInvalidDateCompare = (Label)GetControl(e.Skin, "lblInvalidDateCompare");
// Hide Error Labels by default
lblInvalidEventDate.Visible = false;
lblInvalidDisplayDate.Visible = false;
lblInvalidDateCompare.Visible = false;
}
//*********************************************************************
//
// SubmitEvent Method
//
// This method is raised by clicking the Add button in the Add
// Event form. It adds the event to the database.
//
//*********************************************************************
private void SubmitEvent(Object s, EventArgs e) {
// Check for valid dates
DateTime eventDate;
DateTime displayDate;
try {
eventDate = ctlEventDate.Date.ToUniversalTime();
} catch {
lblInvalidEventDate.Visible = true;
return;
}
try {
displayDate = ctlEventDateVisible.Date.ToUniversalTime();
} catch {
lblInvalidDisplayDate.Visible = true;
return;
}
if (eventDate < displayDate) {
lblInvalidDateCompare.Visible = true;
return;
}
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 = Int32.Parse(dropTopics.SelectedItem.Value);
// Add the Event
int contentPageID = EventUtility.AddEvent
(
objSectionInfo.ID,
objUserInfo.Username,
txtEventTitle.Text,
txtEventLink.Text,
txtEventBriefDescription.Text,
txtEventFullDescription.Text,
txtEventLocation.Text,
txtEventSpeaker.Text,
txtEventSpeakerBiography.Text,
eventDate,
displayDate,
topicID,
moderationStatus
);
// Add the Image
ImageUtility.AddSectionImage(contentPageID, txtImageFile.PostedFile);
// 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, txtEventTitle.Text, objUserInfo.Username);
Context.Response.End();
}
}
//*********************************************************************
//
// AddEvent Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public AddEvent() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Specify Event Section Content
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadEvent);
this.Submit += new SubmitEventHandler(SubmitEvent);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -