D:\NorthwindForWeb\Northwind\CS\DotNet\ADO.Net\Northwind\WebControls\CollectionDataSourceWCCBase.cs
/*
* This file was generated by ProCG version 2.0
*
* File name: Northwind\WebControls\CollectionDataSourceWCCBase.cs
* Language: C# - ADO.Net
* Database: My Sql
*
* Copyright (c) 2002-2019 iGenXSoft.
* For more information visit http://www.igenxsoft.com
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Northwind.General;
using Northwind.Data;
namespace Northwind.WebControls
{
[ToolboxData("<{0}:CollectionDataSourceWCC runat=server></{0}:CollectionDataSourceWCC>")]
public class CollectionDataSourceWCCBase : WebControl
{
protected IStructDataCollection m_StructDataCollection;
protected string m_DataCollectionInstanceName;
protected int m_StartingIndex = 0;
protected int m_PageSize;
protected override void RenderContents(HtmlTextWriter writer)
{
base.RenderContents(writer);
if (this.DesignMode)
writer.Write("CollectionDataSource");
}
[Browsable(false)]
public IStructDataCollection DataCollection
{
set
{
if (DataCollectionInstanceName == null || DataCollectionInstanceName.Equals(String.Empty))
throw new Exception("DataCollectionInstanceName was not set");
m_StructDataCollection = value;
this.Page.Session[DataCollectionInstanceName] = value;
}
get
{
if (DataCollectionInstanceName == null || DataCollectionInstanceName.Equals(String.Empty))
throw new Exception("DataCollectionInstanceName was not set");
if (this.Page.Session[DataCollectionInstanceName] == null)
return null;
else
m_StructDataCollection = (IStructDataCollection)this.Page.Session[DataCollectionInstanceName];
return m_StructDataCollection;
}
}
[Browsable(true)]
public string DataCollectionInstanceName
{
set
{
m_DataCollectionInstanceName = value;
}
get
{
return (m_DataCollectionInstanceName);
}
}
[Browsable(true)]
public int StartingIndex
{
set
{
this.ViewState["StartingIndex"] = value;
m_StartingIndex = value;
}
get
{
//if (m_StartingIndex > 0)
// return m_StartingIndex;
m_StartingIndex = 0;
if (this.ViewState["StartingIndex"] != null)
{
m_StartingIndex = Convert.ToInt32(this.ViewState["StartingIndex"].ToString());
}
return (m_StartingIndex);
}
}
[Browsable(true)]
public int PageSize
{
set
{
//m_PageSize = value;
this.ViewState["PageSize"] = value;
}
get
{
if (m_PageSize > 0)
return m_PageSize;
m_PageSize = 0;
if (this.ViewState["PageSize"] != null)
{
m_PageSize = Convert.ToInt32(this.ViewState["PageSize"].ToString());
}
return (m_PageSize);
}
}
public bool NextPage()
{
if (this.StartingIndex < DataCollection.Count - PageSize)
{
StartingIndex += PageSize;
return true;
}
else
return false;
}
public bool PrevPage()
{
if (this.StartingIndex == 0)
return false;
StartingIndex -= PageSize;
if (StartingIndex < 0)
StartingIndex = 0;
return true;
}
public bool IsFirstPage()
{
if (this.StartingIndex == 0)
return true;
else
return false;
}
public bool IsLastPage()
{
if (this.StartingIndex < DataCollection.Count - PageSize)
{
return false;
}
else
return true;
}
public int NumRows
{
get
{
if (m_StructDataCollection == null)
return 0;
return m_StructDataCollection.Count;
}
}
public int CurrentPage
{
get
{
int currentPage = (StartingIndex+1) / PageSize;
return currentPage;
}
set
{
StartingIndex = value * PageSize;
}
}
public int NumPages
{
get
{
if (this.DataCollection.Count % PageSize == 0)
return this.DataCollection.Count / PageSize;
else
return this.DataCollection.Count / PageSize + 1;
}
}
public int NumItemsInPage
{
get
{
if (this.DataCollection == null)
return 0;
int numItemsInPage = this.DataCollection.Count - StartingIndex;
if (numItemsInPage > PageSize)
numItemsInPage = PageSize;
return numItemsInPage;
}
}
public int NumItemsInCurrentPage
{
get
{
if (this.DataCollection == null)
return 0;
if (!IsLastPage())
return NumItemsInPage;
else
{
int mumItemsInLastPage = NumRows - ((NumPages-1) * NumItemsInPage);
return mumItemsInLastPage;
}
}
}
}
}
// 4781 ProCG uses this line - don't edit it