📄 editevent.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;
//*********************************************************************
//
// EditEvent Class
//
// Represents the Edit Event page. Enables users to edit existing events.
//
//*********************************************************************
public class EditEvent : ContentEditPage {
string _skinFileName = "Events_AddEvent.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Events.EventSection";
TextBox txtEventTitle;
TopicPicker dropTopics;
TextBox txtEventLink;
TextBox txtEventBriefDescription;
HtmlTextBox txtEventFullDescription;
HtmlInputFile txtImageFile;
TextBox txtEventLocation;
TextBox txtEventSpeaker;
HtmlTextBox txtEventSpeakerBiography;
Image imgEventImage;
DatePicker ctlEventDate;
DatePicker ctlEventDateVisible;
Label lblInvalidDisplayDate;
Label lblInvalidEventDate;
Label lblInvalidDateCompare;
//*********************************************************************
//
// ContentPageID Property
//
// Stores the ID of the content being edited in View State
//
//*********************************************************************
int ContentPageID {
get {
return (int)ViewState["ContentPageID"];
}
set { ViewState["ContentPageID"] = value; }
}
//*********************************************************************
//
// ImageID Property
//
// Represents the Image ID of the book being edited.
//
//*********************************************************************
int ImageID {
get { return (int)ViewState["ImageID"]; }
set { ViewState["ImageID"] = value; }
}
//*********************************************************************
//
// 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;
}
//*********************************************************************
//
// OnLoad Method
//
// Assigns values to the controls from the page skin.
//
//*********************************************************************
protected override void OnLoad(EventArgs e) {
if (!Page.IsPostBack)
{
EnsureChildControls();
// Get the ContentPageID from QueryString
ContentPageID = Int32.Parse(Page.Request.QueryString["id"]);
// Get the event information
EventInfo _eventInfo = (EventInfo)EventUtility.GetEventInfo(objUserInfo.Username, ContentPageID);
// Store the original Image ID
ImageID = _eventInfo.ImageID;
// Assign value to topics
dropTopics.SelectedTopicID = _eventInfo.TopicID;
// Assign data
txtEventTitle.Text = _eventInfo.Title;
txtEventLink.Text = _eventInfo.Link;
txtEventBriefDescription.Text = _eventInfo.BriefDescription;
txtEventFullDescription.Text = _eventInfo.FullDescription;
txtEventLocation.Text = _eventInfo.Location;
txtEventSpeaker.Text = _eventInfo.Speaker;
txtEventSpeakerBiography.Text = _eventInfo.SpeakerBiography;
ctlEventDate.Date = _eventInfo.Date.ToLocalTime();
ctlEventDateVisible.Date = _eventInfo.DateVisible.ToLocalTime();
}
}
//*********************************************************************
//
// 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) {
// Get Topic
int _topicID = -1;
if (objSectionInfo.EnableTopics)
_topicID = Int32.Parse(dropTopics.SelectedItem.Value);
// Update the Event
EventUtility.EditEvent
(
objUserInfo.Username,
objSectionInfo.ID,
ContentPageID,
txtEventTitle.Text,
txtEventLink.Text,
txtEventBriefDescription.Text,
txtEventFullDescription.Text,
txtEventLocation.Text,
txtEventSpeaker.Text,
txtEventSpeakerBiography.Text,
eventDate,
displayDate,
_topicID
);
// Update Image
if (ImageID == -1)
ImageUtility.AddSectionImage(ContentPageID, txtImageFile.PostedFile);
else
ImageUtility.UpdateSectionImage(ImageID, txtImageFile.PostedFile);
// Redirect back to Event Page
Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ContentPageID)));
}
}
//*********************************************************************
//
// EditEvent Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public EditEvent() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Specify 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 + -