📄 basegridcontrol.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Text;
using System.Web.UI;
using CommunityServer.Components;
using ComponentArt.Web.UI;
using CA = ComponentArt.Web.UI;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;
namespace CommunityServer.ControlPanel.UI
{
/// <summary>
/// Summary description for BaseControl.
/// </summary>
public class BaseGridControl : UserControl
{
public BaseGridControl()
{
}
# region CA Grid Preferences
/// <summary>
/// Users option to have Grid Groups Expanded by default, Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User
/// </summary>
public bool ExpandGrouping
{
get{return Globals.SafeBool(this.PanelPage.CurrentUser.GetExtendedAttribute("CPExpandGroups"),true);}
}
/// <summary>
/// Users option to allow CA Grid Grouping where enabled, Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User
/// </summary>
public bool EnableGrouping
{
get{return Globals.SafeBool(this.PanelPage.CurrentUser.GetExtendedAttribute("CPEnableGroups"),false);}
}
private string enableSearchBox = null;
/// <summary>
/// Users option to allow CA Grid SearchBox where enabled, Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User (can be overridden on the init section of the page / control)
/// </summary>
public bool EnableSearchBox
{
get{return Globals.SafeBool(enableSearchBox,Globals.SafeBool(this.PanelPage.CurrentUser.GetExtendedAttribute("CPEnableSearchBox"),false));}
set{enableSearchBox = value.ToString();}
}
/// <summary>
/// Users option to force Client Mode, Callback Mode or auto... Where auto is defined as less than 500 items = client
/// Auto will default to Client and requires the developer to set Callback if required. This value gets bound on ApplyUserSettings
/// and can be overridden there if required.
/// </summary>
private CA.GridRunningMode gridMode = CA.GridRunningMode.Client;
public CA.GridRunningMode GridMode
{
get
{
if(this.PanelPage.CurrentUser.GetExtendedAttribute("CPGridMode") != null &&
CA.GridRunningMode.IsDefined(typeof(CA.GridRunningMode), this.PanelPage.CurrentUser.GetExtendedAttribute("CPGridMode")))
return (CA.GridRunningMode)CA.GridRunningMode.Parse(typeof(CA.GridRunningMode),this.PanelPage.CurrentUser.GetExtendedAttribute("CPGridMode"));
else
return gridMode;
}
set
{
if(!CA.GridRunningMode.IsDefined(typeof(CA.GridRunningMode), this.PanelPage.CurrentUser.GetExtendedAttribute("CPGridMode")))
{
gridMode = value;
if(Grid != null)
Grid.RunningMode = value;
}
}
}
/// <summary>
/// This switch toggles between a pager in the footer and a scollbar in the grid
/// </summary>
private bool showScrollBar = false;
public bool ShowScrollBar
{
get{return showScrollBar;}
set{showScrollBar = value;}
}
/// <summary>
/// The users prefered Grid Page Size, Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User
/// </summary>
public int DefaultPageSize
{
get
{
if(this.DefaultScalePageSize)
return Globals.SafeInt(this.PanelPage.CurrentUser.GetExtendedAttribute("CPPageSize"),10) / CurrentGridRowSize;
else
return Globals.SafeInt(this.PanelPage.CurrentUser.GetExtendedAttribute("CPPageSize"),10);
}
}
/// <summary>
/// Hide the whole heading row of CA Grids if neither grouping or searching are enabled,
/// Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User
/// </summary>
public bool ShowHeading
{
get
{
if (EnableGrouping == false && EnableSearchBox == false)
return false;
else
return true;
}
}
/// <summary>
/// The users option to allow the developer to scale the page size for multi row grids,
/// Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User
/// </summary>
public bool DefaultScalePageSize
{
//The scale page size allows page designers to set how many rows a normal grid row will take to render, and
//should allow for more consistant grid rendering sizes (This proprty has been disabled by default to prevent confusion)
get{return Globals.SafeBool(this.PanelPage.CurrentUser.GetExtendedAttribute("CPPageSizeScale"),false);}
}
/// <summary>
/// The number of records in the grid. You need to set this value if running in callback mode where setting the grid
/// Dataset to a subset of the records. If the dataset contains all records you dont need to manually set this.
/// </summary>
private int recordCount = 0;
public int RecordCount
{
get
{
if(Grid != null)
return (recordCount > Grid.RecordCount) ? recordCount : Grid.RecordCount;
else
return recordCount;
}
set
{
recordCount = value;
if(Grid != null)
Grid.RecordCount = value;
}
}
private int currentGridRowSize = 1;
/// <summary>
/// A setting which can be changed from the default on a page to allow the developer to
/// Limit the number of row returned if they are larger than standard single line rows
/// Will return default values before the OnLoad event
/// Due to dependancy on CSConect.Current.User
/// </summary>
public int CurrentGridRowSize
{
get{return currentGridRowSize;}
set
{
currentGridRowSize = value;
if(Grid != null)
Grid.PageSize = this.DefaultPageSize;
}
}
#endregion
/// <summary>
/// Override this function to put content in the grid.
/// Be sure to call base after you bind data to the grid or call ApplyUserSettings()
/// </summary>
protected virtual void buildGrid()
{
this.ApplyUserSettings();
}
protected PanelPage PanelPage
{
get { return Page as PanelPage;}
}
protected CA.Grid Grid = null;
protected override void CreateChildControls()
{
Grid = (CA.Grid)FindControl("Grid1");
base.CreateChildControls ();
}
/// <summary>
/// This method configures the main grid properties tipically you would override ConfigureGrid
/// To add page specific functionality
/// </summary>
protected virtual void ConfigureBasicGrid()
{
ConfigureGridProperties();
ConfigureGridLevelProperties();
ConfigureGridColumnProperties();
AddGridLoadingTemplate();
}
/// <summary>
/// Override this to add page specific formatting to your grid
/// </summary>
protected virtual void ConfigureGrid(){}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
// Page.RegisterStartupScript(this.ClientID, string.Format(@"<script language=""javascript"">
// window.{0}_OldOnResize = window.onresize;
// window.onresize = new Function ('window.{0}.Render(); if (window.{0}_OldOnResize) {{ window.{0}_OldOnResize(); }}');
//</script>", Grid.ClientObjectId));
}
protected override void Render(HtmlTextWriter writer)
{
Grid.RecordCount = RecordCount;
if(!this.ShowScrollBar)
{
if(this.GridMode == CA.GridRunningMode.Client)
{
Grid.SliderPopupClientTemplateId = "SliderTemplate";
Grid.SliderPopupOffsetX = 20;
}
else
{
Grid.SliderPopupClientTemplateId = null;
Grid.SliderPopupOffsetX = 72;
}
}
base.Render (writer);
}
public virtual void OnNeedDataSource(object sender, EventArgs e)
{
buildGrid();
}
public virtual void OnNeedRebind(object sender, EventArgs e)
{
Grid.DataBind();
Grid.RecordCount = this.RecordCount;
}
public virtual void OnPageChanged(object sender, CA.GridPageIndexChangedEventArgs e)
{
Grid.CurrentPageIndex = e.NewIndex;
}
public virtual void OnFilter(object sender, CA.GridFilterCommandEventArgs e)
{
Grid.Filter = e.FilterExpression;
}
public virtual void OnSort(object sender, CA.GridSortCommandEventArgs e)
{
Grid.Sort = e.SortExpression;
}
public virtual void OnGroup(object sender, CA.GridGroupCommandEventArgs e)
{
Grid.GroupBy = e.GroupExpression;
}
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
ConfigureBasicGrid();
ConfigureGrid();
this.Grid.NeedDataSource += new CA.Grid.NeedDataSourceEventHandler(this.OnNeedDataSource);
this.Grid.GroupCommand += new CA.Grid.GroupCommandEventHandler(this.OnGroup);
this.Grid.FilterCommand += new CA.Grid.FilterCommandEventHandler(this.OnFilter);
this.Grid.PageIndexChanged += new CA.Grid.PageIndexChangedEventHandler(this.OnPageChanged);
this.Grid.SortCommand += new CA.Grid.SortCommandEventHandler(this.OnSort);
this.Grid.NeedRebind += new CA.Grid.NeedRebindEventHandler(this.OnNeedRebind);
}
#region GridHelpers
/// <summary>
/// Adds the standard properties to the base CA Grid. The minimum required in the control is now
/// id, runat, and Width. If editing is necessary, AllowEditing, EditOnClickSelectedItem,
/// AutoCallBackOn, and ClientSideOn properties and JS should be inclided manually
/// </summary>
protected virtual void ConfigureGridProperties()
{
Grid.CssClass="Grid";
if(this.EnableSearchBox && GridMode == GridRunningMode.Client )
{
Grid.SearchTextCssClass="GridHeaderText";
Grid.SearchOnKeyPress=true;
}
Grid.HeaderCssClass="GridHeader";
Grid.FooterCssClass="GridFooter";
if(!this.ShowScrollBar)
{
Grid.PagerTextCssClass="GridFooterText";
Grid.PagerButtonWidth=41;
Grid.PagerButtonHeight=22;
Grid.PagerImagesFolderUrl= string.Format("{0}images/caimages/pager", SiteUrls.Instance().Locations["ControlPanel"]);
}
else
ConfigureScrollBarProperties();
Grid.ImagesBaseUrl= string.Format("{0}images/caimages", SiteUrls.Instance().Locations["ControlPanel"]);
Grid.EditOnClickSelectedItem = false;
Grid.ManualPaging = false;
Grid.RunningMode = GridMode;
Grid.PageSize = this.DefaultPageSize;
//This prevents the grid cols from shrinking too far if one col contains too much data
//Grid.FillContainer = true;
//Commenting out the previous line causes the grids to resize to the window appropriately now
}
/// <summary>
/// Used to setup a scrollbar for the grid instead of a pager
/// </summary>
protected virtual void ConfigureScrollBarProperties()
{
Grid.ShowFooter = false;
Grid.ScrollBar= CA.GridScrollBarMode.Auto;
Grid.ScrollTopBottomImagesEnabled= true;
Grid.ScrollTopBottomImageHeight= 2;
Grid.ScrollTopBottomImageWidth= 16;
Grid.ScrollImagesFolderUrl= string.Format("{0}images/caimages/scroller", SiteUrls.Instance().Locations["ControlPanel"]);
Grid.ScrollButtonWidth= 16;
Grid.ScrollButtonHeight=17;
Grid.ScrollBarCssClass="ScrollBar";
Grid.ScrollGripCssClass="ScrollGrip";
Grid.ScrollBarWidth=16;
//Grid.ScrollPopupClientTemplateId="ScrollPopupTemplate";
}
/// <summary>
/// Set the default CS properties on the Level[0] Grid element.
/// Only the DataKeyField should be provided manually.
/// </summary>
protected virtual void ConfigureGridLevelProperties()
{
CA.GridLevel l = Grid.Levels[0];
l.ShowTableHeading = false;
l.ShowSelectorCells = false;
l.RowCssClass = "Row";
l.ColumnReorderIndicatorImageUrl = "";
l.DataCellCssClass = "DataCell";
l.HeadingCellCssClass = "HeadingCell";
l.HeadingCellHoverCssClass = "HeadingCellHover";
l.HeadingCellActiveCssClass = "HeadingCellActive";
l.HeadingRowCssClass = "HeadingRow";
l.HeadingTextCssClass = "HeadingCellText";
l.SelectedRowCssClass = "SelectedRow";
l.GroupHeadingCssClass="GroupHeading";
l.SortAscendingImageUrl="asc.gif";
l.SortDescendingImageUrl="desc.gif";
l.SortImageWidth = 10;
l.SortImageHeight = 19;
l.EditCellCssClass="EditDataCell";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -