?? editphoto.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;
//*********************************************************************
//
// EditPhoto Class
//
// Represents the Edit Photo page. Enables users to edit existing photos.
//
//*********************************************************************
public class EditPhoto : ContentEditPage {
string _skinFileName = "PhotoGallery_AddPhoto.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.PhotoGallery.PhotoGallerySection";
HtmlInputFile txtPhotoFile;
TextBox txtPhotoTitle;
TextBox txtPhotoBriefDescription;
HtmlTextBox txtPhotoFullDescription;
TopicPicker dropTopics;
DisplayPhotoImage imgPhoto;
UploadValidator valUpload;
//*********************************************************************
//
// 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; }
}
//*********************************************************************
//
// 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 image preview
imgPhoto = (DisplayPhotoImage)GetControl(e.Skin, "imgPhoto");
// Get the Upload validator (and hide it)
valUpload = (UploadValidator)GetControl(e.Skin, "valUpload");
valUpload.Visible = false;
}
//*********************************************************************
//
// OnLoad Method
//
// Assigns values to the controls from the page skin.
//
//*********************************************************************
override protected void OnLoad(EventArgs e) {
string imagePath;
if (!Page.IsPostBack) {
// Get the ContentPageID from QueryString
ContentPageID = Int32.Parse(Page.Request.QueryString["id"]);
// Get the photo info
PhotoInfo _photoInfo = (PhotoInfo)PhotoUtility.GetPhoto(objUserInfo.Username, ContentPageID);
// Store the original Image ID
ImageID = _photoInfo.ImageID;
// Populate the controls
EnsureChildControls();
// assign topic
dropTopics.SelectedTopicID = _photoInfo.TopicID;
txtPhotoTitle.Text = _photoInfo.Title;
txtPhotoBriefDescription.Text = _photoInfo.BriefDescription;
txtPhotoFullDescription.Text = _photoInfo.FullDescription;
imagePath = ImageUtility.BuildImagePath(_photoInfo.ImageID, _photoInfo.ImageName);
imgPhoto.ImageUrl = CommunityGlobals.CalculatePath(imagePath);
}
}
//*********************************************************************
//
// SubmitPhoto Method
//
// This method is raised by clicking the Add button in the Edit
// Photo form. It adds the event to the database.
//
//*********************************************************************
private void SubmitPhoto(Object s, EventArgs e) {
if (Page.IsValid) {
// Get Topic
int _topicID = -1;
if (objSectionInfo.EnableTopics)
_topicID = Int32.Parse(dropTopics.SelectedItem.Value);
// Edit the Photo
PhotoUtility.EditPhoto
(
objUserInfo.Username,
objSectionInfo.ID,
ContentPageID,
txtPhotoTitle.Text,
txtPhotoBriefDescription.Text,
txtPhotoFullDescription.Text,
_topicID
);
// Update image
ImageUtility.UpdateSectionImage(ImageID, txtPhotoFile.PostedFile);
// Redirect back to Book Page
Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ContentPageID)));
}
}
//*********************************************************************
//
// EditPhoto Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public EditPhoto() : 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 + -