using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataHolder.Containers;
using DataHolder.DataPersistence;
using System.Text;
namespace DBWebControls.Controls{
/// <summary>
/// Summary description for GenericListPage.
/// </summary>
public class GenericListPage :System.Web.UI.Page
{
private DataGrid MainDataGrid;
private ControlsBinder filterControls;
private Button FilterButton;
private TextBox itemsPerPage;
protected WebNavigator.NavListPageState CurrentPage;
protected WebNavigator.PageNavigator Navigator;
public void InitListPage( DataGrid p_MainDataGrid, ControlsBinder p_filterControls, Button p_FilterButton, TextBox p_itemsPerPage)
{
MainDataGrid = p_MainDataGrid;
filterControls = p_filterControls;
FilterButton = p_FilterButton;
itemsPerPage = p_itemsPerPage;
FilterButton.Click +=new EventHandler(FilterData);
MainDataGrid.SortCommand += new DataGridSortCommandEventHandler(MainDataGrid_SortCommand);
MainDataGrid.PageIndexChanged += new DataGridPageChangedEventHandler(MainDataGrid_PageIndexChanged);
}
#region PageOverrides
protected override void OnLoad(EventArgs e)
{
Navigator = WebNavigator.PageNavigator.GetNavigator(this);
//because on web another web type is created
CurrentPage = (WebNavigator.NavListPageState)Navigator[this.GetType().BaseType];
base.OnLoad (e);
if(!this.IsPostBack)
{
MainDataGrid.CurrentPageIndex = 0;
BindDataGrid();
}
else
filterControls.GetValuesFromControls(CurrentPage.ListState.GEfilters);
}
protected override void OnPreRender(EventArgs e)
{
filterControls.SetValuesToControls(CurrentPage.ListState.GEfilters);
base.OnPreRender (e);
}
#endregion
#region BindData
public virtual void SetDataGridDataSource()
{
MainDataGrid.DataSource = CurrentPage.ListState.LoadedData;
MainDataGrid.DataBind();
}
public virtual void BindDataGrid()
{
MainDataGrid.PageSize = int.Parse(itemsPerPage.Text);
int RowsCount = 0;
ColumnFilterInfoCollection cfi = CurrentPage.ListState.GetFilterValues();
OrderByInfoCollection obi = CurrentPage.ListState.GetorderByInfo();
GenericDataCollection gecoll = LoadDataPagedData(out RowsCount, cfi, obi, MainDataGrid.PageSize, MainDataGrid.CurrentPageIndex, 0);
MainDataGrid.VirtualItemCount = RowsCount;
CurrentPage.ListState.LoadedData = gecoll;
SetDataGridDataSource();
}
#endregion
#region Events
public virtual void FilterData(object sender, System.EventArgs e)
{
MainDataGrid.CurrentPageIndex = 0;
BindDataGrid();
}
public virtual void MainDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if(CurrentPage.ListState.SortColumn == e.SortExpression)
{
if(CurrentPage.ListState.SortDirection == ListSortDirection.Ascending)
CurrentPage.ListState.SortDirection = ListSortDirection.Descending;
else
CurrentPage.ListState.SortDirection = ListSortDirection.Ascending;
}
else
{
CurrentPage.ListState.SortColumn = e.SortExpression;
CurrentPage.ListState.SortDirection = ListSortDirection.Ascending;
}
BindDataGrid();
}
public virtual void MainDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
MainDataGrid.CurrentPageIndex = e.NewPageIndex;
BindDataGrid();
}
#endregion
#region LoadData Abstracts
public virtual GenericDataCollection LoadDataPagedData(out int RowsCount, ColumnFilterInfoCollection filters, OrderByInfoCollection orderinfo,int PageSize, int CurrentPageIndex, int EmptySpacesInPage)
{
throw new Exception("List Page Exception : LoadDataPagedData function not implemented");
}
#endregion
#region ListUtils
public void DataSelected(object Data, bool CloseWindow, bool PostBackParent)
{
if(CurrentPage.ItemSelected != null)
CurrentPage.ItemSelected(CurrentPage, Data);
StringBuilder sb = new StringBuilder(500);
sb.Append("<script language=\"javascript\">\r\n");
if(PostBackParent)
sb.Append("window.opener.document.forms[0].submit();\r\n");
if(CloseWindow)
sb.Append("window.close();\r\n");
sb.Append("</script>");
RegisterStartupScript("closewindow",sb.ToString());
}
#endregion
}
}
|