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

📄 managepictures.cs

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

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

namespace CommunityServer.Galleries.Controls
{

	public class ManagePictures : GalleryAdminTemplatedWebControl
	{

		private static int HighlightID = -1;

		#region Child Controls

		private ParentCategoryDropDown CategoriesList;
		private Repeater PicturesList;

		#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( 1 )]
		public virtual Int32 CurrentPage
		{
			get
			{
				Object state = ViewState["CurrentPage"];
				if(state != null)
					return (Int32)state;
				return 1;
			}
			set
			{ ViewState["CurrentPage"] = value; }
		}

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

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

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			CategoriesList = (ParentCategoryDropDown)FindControl( "CategoriesList" );
			PicturesList = (Repeater)FindControl( "PicturesList" );

			CategoriesList.AutoPostBack = true;
			CategoriesList.SelectedIndexChanged += new EventHandler(CategoriesList_SelectedIndexChanged);
			PicturesList.ItemCommand += new RepeaterCommandEventHandler(PicturesList_ItemCommand);
			PicturesList.ItemDataBound += new RepeaterItemEventHandler(PicturesList_ItemDataBound);
		}

		#endregion

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

			// Access check
			Permissions.AccessCheck( Galleries.GetGallery(ApplicationKey), Permission.Post, CSContext.Current.User );

			// Get the ID of the item to highlight
			if(Page.Request.QueryString["HighlightID"] != null)
				HighlightID = int.Parse(Page.Request.QueryString["HighlightID"]);
			else
				HighlightID = -1;

			// Grab the page number, if present
			if(this.Page.Request.QueryString["page"] != null)
				CurrentPage = int.Parse(this.Page.Request.QueryString["page"]);
		}

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

		public override void DataBind()
		{
			base.DataBind();
			BindCategories();
			BindPictures();
		}

		private void BindCategories()
		{
			CategoriesList.SectionID = Galleries.GetGallery(ApplicationKey).SectionID;
			CategoriesList.EnableAllSelection = true;
			CategoriesList.EnableRootSelection = false;
			CategoriesList.DataBind();

			// Select the current category
			CategoriesList.SelectedCategoryID = CategoryID;
		}

		private void BindPictures()
		{
			// Find out how many total pictures there are
			if(CategoryID != -1)
				TotalPictures = PostCategories.GetCategory(CategoryID, CategoryType.GalleryPicture, Galleries.GetGalleryID(ApplicationKey), true).TotalThreads;
			else
				TotalPictures = Galleries.GetGallery(ApplicationKey, false).TotalThreads;

			// Set up the query
			GalleryThreadQuery query = new GalleryThreadQuery();
			query.SectionID = CurrentGallery.SectionID;
			query.CategoryID = CategoryID;
			query.PageIndex = CurrentPage-1;
			query.PageSize = Rows;

			// Set the datasource and bind
			PicturesList.DataSource = Pictures.GetPictures(query, false).Threads;
			PicturesList.DataBind();
		}

		private void PicturesList_ItemDataBound(object sender, RepeaterItemEventArgs e) 
		{
			Picture dataItem = e.Item.DataItem as Picture;

			switch( e.Item.ItemType ) 
			{
				case ListItemType.Header:

					((HtmlTableCell)e.Item.FindControl("pictureColumn")).Width = Galleries.GetGallery(ApplicationKey, false).ThumbnailX.ToString() + "px";

					break;
				case ListItemType.Item:
				case ListItemType.AlternatingItem:

					GalleryImage Thumbnail = (GalleryImage)e.Item.FindControl( "Thumbnail" );
					HyperLink Name = (HyperLink)e.Item.FindControl( "PictureName" );
					Label Views = (Label)e.Item.FindControl( "Views" );
					Label Comments = (Label)e.Item.FindControl( "Comments" );
			
					if(HighlightID == dataItem.PostID)
					{
						HtmlTableCell thumbnailCell = (HtmlTableCell)e.Item.FindControl( "thumbnailCell" );
						Page.RegisterStartupScript("BackToBlue", "<script language='JavaScript'>setTimeout(\"HighlightThumbnailCell('" + thumbnailCell.ClientID + "', 'yellow', 0)\", 0);</script>");
					}

					Thumbnail.ImageType = GalleryImageType.Thumbnail;
					Thumbnail.PostID = dataItem.PostID;
					Thumbnail.Picture = dataItem;
					Thumbnail.NavigateUrl = GalleryUrls.Instance().ViewPicture(ApplicationKey, dataItem);
					
					Name.Text = dataItem.Subject;
					Name.NavigateUrl = GalleryUrls.Instance().ViewPicture(ApplicationKey, dataItem);

					Views.Text = dataItem.Views.ToString();
					Comments.Text = dataItem.Replies.ToString();

					Button EditButton = (Button)e.Item.FindControl( "Edit" );
					Button DeleteButton = (Button)e.Item.FindControl( "Delete" );

					EditButton.CommandArgument = dataItem.PostID.ToString();
					DeleteButton.CommandArgument = dataItem.PostID.ToString();

					EditButton.Text = ResourceManager.GetString( "Edit" );
					DeleteButton.Text = ResourceManager.GetString( "Delete" );

					break;
				case ListItemType.Footer:

					Button CreateButton = (Button)e.Item.FindControl( "Create" );
					CreateButton.Text = ResourceManager.GetString( "Create" );

					if(TotalPictures > Rows)
					{
						int totalPages = (int)Math.Ceiling( (double)TotalPictures / (double)Rows );
						HtmlGenericControl Pagination = (HtmlGenericControl)e.Item.FindControl( "Pagination" );
						Pagination.Visible = true;
						Pagination.Controls.Clear();
						Pagination.Controls.Add( new LiteralControl( ResourceManager.GetString( "Gallery_Page" ) + " " ) );

						for(int i = 1 ; i <= totalPages ; i ++)
						{
							if(i == CurrentPage)
							{
								Pagination.Controls.Add( new LiteralControl( i.ToString() + " " ) );
							}
							else
							{
								HyperLink pageLink = new HyperLink();
								if(CategoryID != -1)
									pageLink.NavigateUrl = GalleryUrls.Instance().Admin_ManagePictures(ApplicationKey, CategoryID) + "&page=" + i.ToString();
								else
									pageLink.NavigateUrl = GalleryUrls.Instance().Admin_ManagePictures(ApplicationKey, CategoryID) + "&page=" + i.ToString();
								pageLink.Text = i.ToString();
								Pagination.Controls.Add( pageLink );
								Pagination.Controls.Add( new LiteralControl( " " ) );
							}
						}
					}

					break;
			}
		}

		private void PicturesList_ItemCommand(object source, RepeaterCommandEventArgs e)
		{
			switch(e.CommandName)
			{
				case "Edit":
					Page.Response.Redirect(GalleryUrls.Instance().Admin_AdminPicture(ApplicationKey, CategoryID, int.Parse((string)e.CommandArgument)), true);
					break;
				case "Delete":
					Picture picture = Pictures.GetPicture(int.Parse((string)e.CommandArgument));
					Pictures.DeletePicture(picture);
					BindPictures();
					break;
				case "Create":
					Page.Response.Redirect(GalleryUrls.Instance().Admin_AdminPicture(ApplicationKey, CategoryID, -1), true);
					break;
			}
		}

		private void CategoriesList_SelectedIndexChanged(object sender, EventArgs e)
		{
			CategoryID = CategoriesList.SelectedCategoryID;
			BindPictures();
		}
	}
}

⌨️ 快捷键说明

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