📄 picturelisting.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.Controls
{
public class PictureListing : GalleryThemedControl
{
#region Private Members
private int columnCount = 0;
private int rowCount = 0;
private int totalColumns = 0;
private bool totalColumnsFound = false;
private int totalPictures = 0;
#endregion
#region Public Properties
[DefaultValue( 1 )]
public int CurrentPage
{
get { return currentPage; }
set { currentPage = value; }
}
private int currentPage = 1;
[DefaultValue( 4 )]
public int Columns
{
get { return columns; }
set { columns = value; }
}
private int columns = 4;
[DefaultValue( 3 )]
public int Rows
{
get { return rows; }
set { rows = value; }
}
private int rows = 3;
#endregion
#region Child Controls
private GalleryThreadSortDropDownList PictureSortDDL;
private HyperLink SlideShowLink;
private RepeaterPlusNone Pictures;
private RssButton rssButton;
private PagingControl pagination;
private HtmlTableCell footerRow;
#endregion
#region Skin
protected override void AttachChildControls()
{
PictureSortDDL = (GalleryThreadSortDropDownList)FindControl( "SortPictures" );
SlideShowLink = (HyperLink)FindControl( "SlideShowLink" );
Pictures = (RepeaterPlusNone)FindControl( "Pictures" );
rssButton = (RssButton)FindControl( "RssButton" );
pagination = (PagingControl)FindControl( "Pagination" );
footerRow = FindControl( "FooterRow" ) as HtmlTableCell;
InitializeChildControls();
}
private void InitializeChildControls()
{
Pictures.ItemDataBound += new RepeaterItemEventHandler(Pictures_ItemDataBound);
Pictures.NoneItemsDataBound += new RepeaterItemEventHandler(Pictures_NoneItemsDataBound);
PictureSortDDL.SelectedIndexChanged += new EventHandler(PictureSortDDL_SelectedIndexChanged);
GalleryUserCookie userCookie = new GalleryUserCookie(CSContext.Current.User);
PictureSortDDL.AutoPostBack = true;
PictureSortDDL.SelectedSortByValue = userCookie.ThreadSortBy;
PictureSortDDL.SelectedSortOrderValue = userCookie.ThreadSortOrder;
// Find out the width/height for the slideshow
int width = CurrentGallery.SlideshowX + 300;
int height = CurrentGallery.SlideshowY + 150;
if(width < 800) width = 800;
if(height < 550) height = 550;
SlideShowLink.NavigateUrl = "javascript:void(0);";
SlideShowLink.Attributes.Add("onclick", "javascript:window.open('" + GalleryUrls.Instance().ViewSlideshow(CurrentGallery.ApplicationKey, CSContext.Current.CategoryID) + "', '', 'width=" + width + ",height=" + height + ",status=0,titlebar=0,toolbar=0,scrollbars=0');");
SlideShowLink.Text = ResourceManager.GetString("Gallery_SlideShow");
if(rssButton != null)
{
if(CSContext.Current.CategoryID == -1)
rssButton.NavigateUrl = GalleryUrls.Instance().Rss(RssType.Pictures, CSContext.Current.ApplicationKey);
else
rssButton.NavigateUrl = GalleryUrls.Instance().Rss(RssType.Pictures, CSContext.Current.ApplicationKey, CSContext.Current.CategoryID);
rssButton.ImageUrl = Globals.GetSkinPath() + "/images/gallery_xml.gif";
}
}
#endregion
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// Set the default columns and rows
Columns = CurrentGallery.PictureListingColumns;
Rows = CurrentGallery.PictureListingRows;
// Grab the page number, if present
if(this.Page.Request.QueryString["ppage"] != null)
CurrentPage = int.Parse(this.Page.Request.QueryString["ppage"]);
}
public override void DataBind()
{
base.DataBind ();
BindPictures();
}
private void BindPictures()
{
// Find out how many total pictures there are
if(CSContext.Current.CategoryID != -1)
totalPictures = PostCategories.GetCategory(CSContext.Current.CategoryID, CategoryType.GalleryPicture, CurrentGallery.SectionID).TotalThreads;
else
totalPictures = CurrentGallery.TotalThreads;
// Setup the pagination
pagination.CurrentPage = CurrentPage;
pagination.TotalPages = (int)Math.Ceiling( (double)totalPictures / (double)(Columns*Rows) );
pagination.PrefixText = "page";
pagination.QueryName = "ppage";
pagination.NavigateUrl = Page.Request.RawUrl;
pagination.BindPages();
// Set up the query
GalleryThreadQuery query = new GalleryThreadQuery();
query.SectionID = CurrentGallery.SectionID;
query.CategoryID = CSContext.Current.CategoryID;
query.PageIndex = CurrentPage-1;
query.PageSize = Columns*Rows;
query.SortBy = PictureSortDDL.SelectedSortByValue;
query.SortOrder = PictureSortDDL.SelectedSortOrderValue;
// Set the datasource and bind
Pictures.DataSource = Components.Pictures.GetPictures(query).Threads;
Pictures.DataBind();
// Set the footer row colspan
if(footerRow != null)
footerRow.ColSpan = totalColumns;
}
private void Pictures_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Picture dataItem = e.Item.DataItem as Picture;
switch( e.Item.ItemType )
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
HyperLink PictureNameLink = (HyperLink)e.Item.FindControl( "PictureName" );
Literal TotalViews = (Literal)e.Item.FindControl( "TotalViews");
PictureNameLink.Text = dataItem.Subject;
PictureNameLink.NavigateUrl = GalleryUrls.Instance().ViewPicture(CurrentGallery.ApplicationKey, CSContext.Current.CategoryID, dataItem);
PictureNameLink.Font.Bold = true;
if (TotalViews != null)
TotalViews.Text = string.Format( ResourceManager.GetString( "Gallery_PictureListing_TotalViews" ), dataItem.Views );
GalleryImage ThumbImage = (GalleryImage)e.Item.FindControl( "ThumbImage" );
ThumbImage.PostID = dataItem.PostID;
ThumbImage.NavigateUrl = GalleryUrls.Instance().ViewPicture(CurrentGallery.ApplicationKey, CSContext.Current.CategoryID, dataItem);
ThumbImage.Picture = dataItem;
ThumbImage.DataBind();
GalleryImage ThumbLargeImage = e.Item.FindControl( "ThumbLargeImage" ) as GalleryImage;
if(ThumbLargeImage != null)
{
ThumbLargeImage.PostID = dataItem.PostID;
ThumbLargeImage.NavigateUrl = GalleryUrls.Instance().ViewPicture(CurrentGallery.ApplicationKey, CSContext.Current.CategoryID, dataItem);
ThumbLargeImage.Picture = dataItem;
ThumbLargeImage.DataBind();
}
RatingListing ratingListing = (RatingListing)e.Item.FindControl( "RatingListing" );
ratingListing.ApplicationKey = CurrentGallery.ApplicationKey;
ratingListing.PictureID = dataItem.PostID;
ratingListing.Picture = dataItem;
ratingListing.DataBind();
// Set column width
HtmlTableCell tableColumn = e.Item.FindControl("TableColumn") as HtmlTableCell;
if(tableColumn != null)
tableColumn.Width = (100 / Columns).ToString() + "%";
// Begin a column, if necessary
if(columnCount == 0)
{
Literal BeginRowLabel = (Literal)e.Item.FindControl( "BeginRow" );
BeginRowLabel.Text = "<tr>";
}
columnCount++;
if(!totalColumnsFound)
totalColumns++;
// End a column, if necessary
if((columnCount == Columns) || ((rowCount*Columns+columnCount) == totalPictures))
{
Literal EndRowLabel = (Literal)e.Item.FindControl( "EndRow" );
EndRowLabel.Text = "</tr>";
columnCount = 0;
totalColumnsFound = true;
rowCount++;
}
break;
}
}
private void PictureSortDDL_SelectedIndexChanged(object sender, EventArgs e)
{
GalleryUserCookie userCookie = new GalleryUserCookie(CSContext.Current.User);
userCookie.ThreadSortBy = PictureSortDDL.SelectedSortByValue;
userCookie.ThreadSortOrder = PictureSortDDL.SelectedSortOrderValue;
BindPictures();
}
private void Pictures_NoneItemsDataBound(object sender, RepeaterItemEventArgs e)
{
Literal NoRecordsLabel = (Literal)e.Item.FindControl( "NoRecords" );
NoRecordsLabel.Text = ResourceManager.GetString( "ForumMembers_NoRecords" );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -