217 lines
7.5 KiB
C#
217 lines
7.5 KiB
C#
using Microsoft.SharePoint;
|
|
using Microsoft.SharePoint.Utilities;
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
namespace SPSolutions.SharePoint.WebControls
|
|
{
|
|
public class SPManualPager : WebControl, IPostBackEventHandler
|
|
{
|
|
private PagingCalculator m_pagingCalculator;
|
|
private static readonly string NextPageCommand = "previouspage";
|
|
private static readonly string PreviousPageCommand = "nextpage";
|
|
public event EventHandler ClickNext;
|
|
|
|
//[MethodImpl(MethodImplOptions.Synchronized)]
|
|
//add
|
|
//{
|
|
// //this.ClickNext = (EventHandler)Delegate.Combine(this.ClickNext, value);
|
|
// this.ClickNext += value;
|
|
//}
|
|
//[MethodImpl(MethodImplOptions.Synchronized)]
|
|
//remove
|
|
//{
|
|
// //this.ClickNext = (EventHandler)Delegate.Remove(this.ClickNext, value);
|
|
// this.ClickNext -= value;
|
|
//}
|
|
|
|
public event EventHandler ClickPrevious;
|
|
//{
|
|
// [MethodImpl(MethodImplOptions.Synchronized)]
|
|
// add
|
|
// {
|
|
// //this.ClickPrevious = (EventHandler)Delegate.Combine(this.ClickPrevious, value);
|
|
// this.ClickPrevious += value;
|
|
// }
|
|
// [MethodImpl(MethodImplOptions.Synchronized)]
|
|
// remove
|
|
// {
|
|
// //this.ClickPrevious = (EventHandler)Delegate.Remove(this.ClickPrevious, value);
|
|
// this.ClickPrevious -= value;
|
|
// }
|
|
//}
|
|
public int PageNumber
|
|
{
|
|
get
|
|
{
|
|
return this.ParseIntegerFromViewState(this.ViewState["PageNumber"], 1);
|
|
}
|
|
set
|
|
{
|
|
this.ViewState["PageNumber"] = value;
|
|
}
|
|
}
|
|
public int PageSize
|
|
{
|
|
get
|
|
{
|
|
return this.ParseIntegerFromViewState(this.ViewState["PageSize"], 10);
|
|
}
|
|
set
|
|
{
|
|
this.ViewState["PageSize"] = value;
|
|
}
|
|
}
|
|
public int NumberOfRecords
|
|
{
|
|
get
|
|
{
|
|
return this.ParseIntegerFromViewState(this.ViewState["NumberOfRecords"], 0);
|
|
}
|
|
set
|
|
{
|
|
this.ViewState["NumberOfRecords"] = value;
|
|
}
|
|
}
|
|
public int LowestDataItemIndex
|
|
{
|
|
get
|
|
{
|
|
return this.m_pagingCalculator.BeginningIndex;
|
|
}
|
|
}
|
|
public int HighestDataItemIndex
|
|
{
|
|
get
|
|
{
|
|
return this.m_pagingCalculator.EndingIndex;
|
|
}
|
|
}
|
|
private static string PreviousImageUrl
|
|
{
|
|
get
|
|
{
|
|
return "/_layouts/15/" + SPContext.Current.Web.Language.ToString(CultureInfo.InvariantCulture) + "/images/prev.gif";
|
|
}
|
|
}
|
|
public bool PreviousPageLinkIsEnabled
|
|
{
|
|
get
|
|
{
|
|
return this.m_pagingCalculator.HasPreviousPage;
|
|
}
|
|
}
|
|
private static string NextImageUrl
|
|
{
|
|
get
|
|
{
|
|
return "/_layouts/15/" + SPContext.Current.Web.Language.ToString(CultureInfo.InvariantCulture) + "/images/next.gif";
|
|
}
|
|
}
|
|
public bool NextPageLinkIsEnabled
|
|
{
|
|
get
|
|
{
|
|
return this.m_pagingCalculator.HasNextPage;
|
|
}
|
|
}
|
|
public SPManualPager()
|
|
{
|
|
this.m_pagingCalculator = new PagingCalculator(1, 10, 0);
|
|
}
|
|
private int ParseIntegerFromViewState(object viewStateObject, int defaultValue)
|
|
{
|
|
if (viewStateObject == null)
|
|
{
|
|
return defaultValue;
|
|
}
|
|
if (viewStateObject is int)
|
|
{
|
|
return (int)viewStateObject;
|
|
}
|
|
int result;
|
|
if (!int.TryParse(viewStateObject.ToString(), out result))
|
|
{
|
|
return defaultValue;
|
|
}
|
|
return result;
|
|
}
|
|
protected override void Render(HtmlTextWriter output)
|
|
{
|
|
this.m_pagingCalculator.NumberOfRecords = this.NumberOfRecords;
|
|
this.m_pagingCalculator.PageSize = this.PageSize;
|
|
this.m_pagingCalculator.PageNumber = this.PageNumber;
|
|
if (this.LowestDataItemIndex >= 0 && this.HighestDataItemIndex >= 0)
|
|
{
|
|
output.Write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td valign=\"center\">");
|
|
this.RenderImage(output, this.PreviousPageLinkIsEnabled, SPManualPager.PreviousPageCommand, SPManualPager.PreviousImageUrl, "/_layouts/15/images/blank.gif", SPResource.GetString("multipagesPreviousPage", new object[0]));
|
|
output.Write("</td><td valign=\"center\" class=\"ms-listheaderlabel\" nowrap>");
|
|
output.Write(" ");
|
|
output.Write((this.LowestDataItemIndex + 1).ToString(Thread.CurrentThread.CurrentCulture.NumberFormat));
|
|
output.Write("-");
|
|
output.Write((this.HighestDataItemIndex + 1).ToString(Thread.CurrentThread.CurrentCulture.NumberFormat));
|
|
output.Write(" </td><td valign=\"center\">");
|
|
this.RenderImage(output, this.NextPageLinkIsEnabled, SPManualPager.NextPageCommand, SPManualPager.NextImageUrl, "/_layouts/15/images/blank.gif", SPResource.GetString("multipagesNextPage", new object[0]));
|
|
output.Write("</td></tr></table>");
|
|
}
|
|
}
|
|
private void RenderImage(HtmlTextWriter output, bool isEnabled, string postbackEventArgument, string enabledImageUrl, string disabledImageUrl, string toolTip)
|
|
{
|
|
string value = disabledImageUrl;
|
|
if (isEnabled)
|
|
{
|
|
output.Write("<a href=\"#\" onclick=\"");
|
|
output.Write(this.Page.ClientScript.GetPostBackEventReference(this, postbackEventArgument));
|
|
output.Write("; return false;\">");
|
|
value = enabledImageUrl;
|
|
}
|
|
output.Write("<img src=\"");
|
|
output.Write(value);
|
|
output.Write("\" border=\"0\" alt=\"");
|
|
output.Write(SPEncode.HtmlEncode(toolTip));
|
|
output.Write("\"/>");
|
|
if (isEnabled)
|
|
{
|
|
output.Write("</a>");
|
|
}
|
|
}
|
|
protected virtual void OnClickNext(EventArgs args)
|
|
{
|
|
this.PageNumber++;
|
|
if (ClickNext != null)
|
|
{
|
|
this.ClickNext(this, args);
|
|
}
|
|
}
|
|
protected virtual void OnClickPrevious(EventArgs args)
|
|
{
|
|
this.PageNumber--;
|
|
if (this.ClickPrevious != null)
|
|
{
|
|
this.ClickPrevious(this, args);
|
|
}
|
|
}
|
|
public void RaisePostBackEvent(string eventArgument)
|
|
{
|
|
if (eventArgument == null)
|
|
{
|
|
throw new ArgumentNullException("eventArgument");
|
|
}
|
|
string a = eventArgument.ToLower(CultureInfo.InvariantCulture);
|
|
EventArgs args = new EventArgs();
|
|
if (a == SPManualPager.PreviousPageCommand)
|
|
{
|
|
this.OnClickPrevious(args);
|
|
return;
|
|
}
|
|
if (a == SPManualPager.NextPageCommand)
|
|
{
|
|
this.OnClickNext(args);
|
|
}
|
|
}
|
|
}
|
|
}
|