📄 aggregategallerylisting.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Data.SqlTypes;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.Controls
{
public class AggregateGalleryListing : GalleryTemplatedWebControl
{
#region Child Controls
private Repeater GroupRepeater;
#endregion
#region Public Properties
[DefaultValue( 10 )]
public virtual Int32 ItemsPerPage
{
get
{
Object state = ViewState["ItemsPerPage"];
if(state != null)
return (Int32)state;
return 10;
}
set
{ ViewState["ItemsPerPage"] = value; }
}
#endregion
#region Skin
protected override void AttachChildControls()
{
GroupRepeater = (Repeater)FindControl( "GroupRepeater" );
GroupRepeater.ItemCreated += new RepeaterItemEventHandler(GroupRepeater_ItemCreated);
GroupRepeater.ItemDataBound += new RepeaterItemEventHandler(GroupRepeater_ItemDataBound);
}
#endregion
protected override void OnLoad(EventArgs e)
{
if(!Page.IsPostBack)
this.DataBind();
base.OnLoad(e);
}
public override void DataBind()
{
base.DataBind ();
BindGalleries();
}
private void BindGalleries()
{
GroupRepeater.DataSource = Galleries.GetGalleryGroups(true, false, false);
GroupRepeater.DataBind();
}
private void GroupRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Group group = e.Item.DataItem as Group;
if(group == null)
return;
switch ( e.Item.ItemType )
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
GalleryRepeater galleryRepeater = e.Item.FindControl( "GalleryRepeater" ) as GalleryRepeater;
galleryRepeater.GroupID = group.GroupID;
galleryRepeater.Mode = ControlUserMode.GalleryUser;
galleryRepeater.Paginate = true;
galleryRepeater.ItemsPerPage = ItemsPerPage;
if(Page.Request.QueryString[group.GroupID.ToString() + "page"] != null)
galleryRepeater.CurrentPage = int.Parse(Page.Request.QueryString[group.GroupID.ToString() + "page"]);
galleryRepeater.ItemDataBound += new RepeaterItemEventHandler(galleryRepeater_ItemDataBound);
break;
}
}
private void GroupRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Group group = e.Item.DataItem as Group;
switch ( e.Item.ItemType )
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
Literal groupTitle = (Literal)e.Item.FindControl( "GroupTitle" );
groupTitle.Text = group.Name;
GalleryRepeater galleryRepeater = e.Item.FindControl( "GalleryRepeater" ) as GalleryRepeater;
AggregatePagingControl pagination = (AggregatePagingControl)e.Item.FindControl("Pagination");
if((pagination != null) && (galleryRepeater != null))
{
// Setup the pagination
pagination.CurrentPage = galleryRepeater.CurrentPage;
pagination.TotalPages = (int)Math.Ceiling( (double)galleryRepeater.TotalGalleries / (double)ItemsPerPage );
pagination.PrefixText = "page";
pagination.QueryName = galleryRepeater.GroupID.ToString() + "page";
pagination.NavigateUrl = Page.Request.RawUrl;
pagination.BindPages();
}
break;
}
}
private void galleryRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Gallery gallery = e.Item.DataItem as Gallery;
switch ( e.Item.ItemType )
{
case ListItemType.Footer:
/*GalleryRepeater repeater = sender as GalleryRepeater;
AggregatePagingControl pagination = (AggregatePagingControl)e.Item.FindControl("Pagination");
if((pagination != null) && (repeater != null))
{
// Setup the pagination
pagination.CurrentPage = repeater.CurrentPage;
pagination.TotalPages = (int)Math.Ceiling( (double)repeater.TotalGalleries / (double)ItemsPerPage );
pagination.PrefixText = "page";
pagination.QueryName = repeater.GroupID.ToString() + "page";
pagination.NavigateUrl = Page.Request.RawUrl;
pagination.BindPages();
}*/
break;
case ListItemType.Item:
case ListItemType.AlternatingItem:
GalleryImage randomPicture = e.Item.FindControl( "RandomPicture" ) as GalleryImage;
HyperLink name = e.Item.FindControl( "Name" ) as HyperLink;
Literal description = e.Item.FindControl( "Description" ) as Literal;
Literal dateCreated = e.Item.FindControl( "DateCreated" ) as Literal;
Literal dateChanged = e.Item.FindControl( "DateChanged" ) as Literal;
Literal totalPictures = e.Item.FindControl( "TotalPictures" ) as Literal;
if(randomPicture != null)
{
Picture picture = Pictures.GetRandomPicture( gallery.SectionID, -1 );
if(picture != null)
{
randomPicture.PostID = picture.PostID;
randomPicture.NavigateUrl = GalleryUrls.Instance().ViewGallery(gallery.ApplicationKey);
randomPicture.Picture = picture;
}
else
randomPicture.Visible = false;
}
if(name != null)
{
name.Text = gallery.Name;
name.NavigateUrl = GalleryUrls.Instance().ViewGallery( gallery.ApplicationKey );
}
if(description != null)
{
if(gallery.Description.Length > 50)
description.Text = gallery.Description.Substring(0, 50) + "...";
else
description.Text = gallery.Description;
if(description.Text != string.Empty)
description.Text += "<br/>";
}
if(totalPictures != null)
totalPictures.Text = gallery.TotalThreads.ToString();
if(gallery.MostRecentPostDate == SqlDateTime.MinValue.Value.AddYears(44))
{
if(dateChanged != null)
dateChanged.Visible = false;
}
else
{
User cUser = CSContext.Current.User;
User pUser = Users.GetUser(gallery.MostRecentPostAuthorID, false);
DateTime changedDate = gallery.MostRecentPostDate;
DateTime createdDate = gallery.DateCreated;
string dateFormat;
if(!pUser.IsAnonymous)
{
changedDate = pUser.GetTimezone(gallery.MostRecentPostDate);
createdDate = pUser.GetTimezone(gallery.DateCreated);
}
if(!cUser.IsAnonymous)
{
dateFormat = cUser.Profile.DateFormat;
}
else
dateFormat = CSContext.Current.SiteSettings.DateFormat;
if(dateChanged != null)
dateChanged.Text = changedDate.ToString(dateFormat) + " " + changedDate.ToString(CSContext.Current.SiteSettings.TimeFormat);
if(dateCreated != null)
dateCreated.Text = createdDate.ToString(dateFormat) + " " + createdDate.ToString(CSContext.Current.SiteSettings.TimeFormat);
}
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -