?? addphoto.cs
字號:
namespace ASPNET.StarterKit.Communities.PhotoGallery {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AddPhoto Class
//
// Represents the Add Photo page. Enables users to list new photos.
//
//*********************************************************************
public class AddPhoto : ContentAddPage {
string _skinFileName = "PhotoGallery_AddPhoto.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.PhotoGallery.PhotoGallerySection";
HtmlInputFile txtPhotoFile;
TextBox txtPhotoTitle;
TextBox txtPhotoBriefDescription;
HtmlTextBox txtPhotoFullDescription;
TopicPicker dropTopics;
DisplayPhotoImage imgPhoto;
//*********************************************************************
//
// SkinLoadPhoto
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadPhoto(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 TopicPicker control
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
// find the controls
txtPhotoFile = (HtmlInputFile) GetControl (e.Skin, "txtPhotoFile");
txtPhotoTitle = (TextBox) GetControl(e.Skin,"txtPhotoTitle");
txtPhotoBriefDescription = (TextBox) GetControl (e.Skin, "txtPhotoBriefDescription");
txtPhotoFullDescription = (HtmlTextBox)GetControl(e.Skin, "txtPhotoFullDescription");
// Find and hide image preview
imgPhoto = (DisplayPhotoImage)GetControl(e.Skin, "imgPhoto");
imgPhoto.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 SubmitPhoto(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 = Int32.Parse(dropTopics.SelectedItem.Value);
// Add the Photo
int contentPageID = PhotoUtility.AddPhoto
(
objUserInfo.Username,
objSectionInfo.ID,
moderationStatus,
txtPhotoTitle.Text,
txtPhotoBriefDescription.Text,
txtPhotoFullDescription.Text,
topicID
);
// Add the Image
ImageUtility.AddSectionImage(contentPageID, txtPhotoFile.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, txtPhotoTitle.Text, objUserInfo.Username);
Context.Response.End();
}
}
//*********************************************************************
//
// AddPhoto Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public AddPhoto() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Specify Section Content
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadPhoto);
this.Submit += new SubmitEventHandler(SubmitPhoto);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -