⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pictureadmin.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{

	public class PictureAdmin : GalleryAdminTemplatedWebControl
	{

		#region Child Controls

		private GalleryImage CurrentThumb;
		private CategoryCheckBoxList Categories;
		private TextBox Name;
		private TextBox Description;
		private HtmlInputFile PictureData;

		private Button Save;
		private Button Cancel;

		#endregion

		#region Public Properties

		[DefaultValue( "" )]
		public virtual string ApplicationKey
		{
			get
			{
				Object state = ViewState["ApplicationKey"];
				if(state != null)
					return (string)state;
				return "";
			}
			set { ViewState["ApplicationKey"] = value; }
		}

		[DefaultValue( 0 )]
		public virtual Int32 CategoryID
		{
			get
			{
				Object state = ViewState["CategoryID"];
				if(state != null)
					return (Int32)state;
				return 0;
			}
			set { ViewState["CategoryID"] = value; }
		}

		[DefaultValue( 0 )]
		public virtual Int32 PictureID
		{
			get
			{
				Object state = ViewState["PictureID"];
				if(state != null)
					return (Int32)state;
				return 0;
			}
			set { ViewState["PictureID"] = value; }
		}

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			CurrentThumb = (GalleryImage)FindControl( "PictureCurrentThumb" );
			Categories = (CategoryCheckBoxList)FindControl( "Categories" );
			Name = (TextBox)FindControl( "PictureName" );
			Description = (TextBox)FindControl( "PictureDescription" );
			PictureData = (HtmlInputFile)FindControl( "PictureFileToUpload" );

			Save = (Button)FindControl( "PictureSave" );
			Cancel = (Button)FindControl( "PictureCancel" );

			InitializeChildControls();
		}

		private void InitializeChildControls() 
		{
			Save.Click += new EventHandler(Save_Click);
			Cancel.Click += new EventHandler(Cancel_Click);
			Cancel.CausesValidation = false;
		}

		#endregion

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			ApplicationKey = CSContext.Current.ApplicationKey;
			CategoryID = CSContext.Current.CategoryID;
			PictureID = CSContext.Current.PostID;

			// Access check
            if (PictureID != -1)
                // Check permission against updating/deleting existing picture
			    Permissions.AccessCheck( Galleries.GetGallery(ApplicationKey), Permission.Post, CSContext.Current.User, Pictures.GetPicture(PictureID) );
            else
                // if PictureID = -1, then we are creating a new picture and only need to check
                // access agaisnt creating a new post to this Section.
                Permissions.AccessCheck( Galleries.GetGallery(ApplicationKey), Permission.Post, CSContext.Current.User );
		}

		protected override void OnLoad(EventArgs e)
		{
			if(!Page.IsPostBack)
				this.DataBind();
			base.OnLoad(e);
		}

		public override void DataBind()
		{
			base.DataBind();

			// Populate the categories checkboxes
			Categories.SectionID = Galleries.GetGallery(ApplicationKey).SectionID;
			Categories.DataBind();

			if(PictureID != -1)
			{
				Picture picture = Pictures.GetPicture(PictureID);
				Name.Text = Globals.HtmlDecode(picture.Subject);
				Description.Text = picture.Body;

				FindControl( "CurrentThumbRow" ).Visible = true;
				FindControl( "FileUploadRow" ).Visible = false;

				// Mark all of the picture's categories checked
				Categories.ClearSelection();
				ArrayList selectedCategories = Pictures.GetPictureCategories(picture);
				foreach(PostCategory category in selectedCategories)
					Categories.Items.FindByValue( category.CategoryID.ToString() ).Selected = true;
			}
			else
			{
				Name.Text = "";
				Description.Text = "";
				FindControl( "CurrentThumbRow" ).Visible = false;
				FindControl( "FileUploadRow" ).Visible = true;

				// Mark only the current category checked
				Categories.ClearSelection();
				if(CategoryID != -1)
					Categories.Items.FindByValue( CategoryID.ToString() ).Selected = true;
			}

			// Update the thumbnail
			CurrentThumb.PostID = PictureID;
			if(PictureID != -1)
				CurrentThumb.NavigateUrl = GalleryUrls.Instance().ViewPicture(ApplicationKey, Pictures.GetPicture(PictureID) );
			CurrentThumb.DataBind();

			// Set some resource labels
			Save.Text = ResourceManager.GetString("Save");
			Cancel.Text = ResourceManager.GetString("Cancel");
		}

		private void Save_Click(object sender, EventArgs e)
		{
			bool redirectHighlight = false;

			if(PictureID == -1)
			{
				CreatePicture();
				redirectHighlight = true;
			}
			else
				UpdatePicture();

			// Finishing stuff
			if(CSContext.Current["Url"] != null)
				Globals.RedirectSiteUrl();
			else
			{
				if(redirectHighlight)
					Page.Response.Redirect(GalleryUrls.Instance().Admin_ManagePictures(ApplicationKey, CategoryID, PictureID), true);
				else
					Page.Response.Redirect(GalleryUrls.Instance().Admin_ManagePictures(ApplicationKey, CategoryID), true);
			}
		}

		private void CreatePicture()
		{
			Picture picture = new Picture();

			picture.Subject = Name.Text;
			picture.Body = Description.Text;

			if((PictureData != null) && (PictureData.PostedFile != null) && (PictureData.PostedFile.ContentLength > 0))
			{
				// Create the picture in the database
				Pictures.CreatePicture(CurrentGallery.SectionID, picture, new PostAttachment(PictureData.PostedFile));
			}

			// Update the picture's categories
			ArrayList selectedCategories = new ArrayList();
			foreach(ListItem li in Categories.Items)
				if(li.Selected)
					selectedCategories.Add(li.Text);
			Pictures.UpdatePictureCategories(picture, (string[])selectedCategories.ToArray(typeof(string)));

			// Get the PostID
			PictureID = picture.PostID;
		}

		private void UpdatePicture()
		{
			Picture picture = Pictures.GetPicture(PictureID);

			picture.Subject = Name.Text;
			picture.Body = Description.Text;
			Pictures.UpdatePicture(picture);

			// Update the picture's categories
			ArrayList selectedCategories = new ArrayList();
			foreach(ListItem li in Categories.Items)
				if(li.Selected)
					selectedCategories.Add(li.Text);
			Pictures.UpdatePictureCategories(picture, (string[])selectedCategories.ToArray(typeof(string)));
		}

		private void Cancel_Click(Object sender, EventArgs e)
		{
			if(CSContext.Current.Url != null)
				Globals.RedirectSiteUrl();
			else
				CSContext.Current.Context.Response.Redirect( GalleryUrls.Instance().Admin_ManagePictures(ApplicationKey, CategoryID), true );
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -