Click here to Skip to main content
15,885,309 members
Articles / Web Development / ASP.NET

PixelDragonsMVC.NET - An open source MVC framework

Rate me:
Please Sign up or sign in to vote.
4.58/5 (8 votes)
29 Jun 200710 min read 85K   811   73  
An MVC framework with built-in NHibernate support that makes creating ASP.NET 2 applications easier by minimizing code and configuration
/***********************************************************
 * 
 * Copyright 2007 Pixel Dragons Ltd. All rights reserved.
 * 
 * http://www.codeplex.com/PixelDragonsMVC for licence, more
 * information and latest source code. 
 * 
 * Check out our other stuff at http://www.pixeldragons.com
 * 
 ***********************************************************/

using System;
using System.Collections;
using System.Collections.Generic;

using NHibernate.Expression;

namespace PixelDragons.MVC.Persistence
{
    public enum SortDirection { None, Ascending, Descending }

	public class PageSettings 
	{
        public PageSettings()
		{
		}

		private Dictionary<string, SortDirection> _columnSorting = null;
        private List<SimpleExpression> _filterExpressions = null;
		private int _pageSize = 10;
        private int _currentPageIndex = 0;
		private int _totalPageCount = 0;
		private int _totalItemCount = 0;
		private bool _calculateTotal = false;

        public Dictionary<string, SortDirection> ColumnSorting
		{
			get 
			{
                if (_columnSorting == null)
				{
                    _columnSorting = new Dictionary<string, SortDirection>();
				}

                return _columnSorting; 
			}
            set { _columnSorting = value; }
		}

		public List<SimpleExpression> FilterExpressions
		{
			get 
			{ 
				if (_filterExpressions == null)
				{
                    _filterExpressions = new List<SimpleExpression>();
				}

				return _filterExpressions; 
			}
			set { _filterExpressions = value; }
		}

		public int PageSize
		{
			get { return _pageSize; }
			set 
			{ 
				if (_pageSize < 1)
				{
					throw new ArgumentOutOfRangeException("PageSize", _pageSize, "Page Size cannot be less than 1");
				}
				_pageSize = value; 
			}
		}

        public int CurrentPageIndex
		{
            get { return _currentPageIndex; }
            set { _currentPageIndex = value; }
		}

		public int TotalPageCount
		{
			get { return _totalPageCount; }
		}

        public int TotalItemCount
		{
            get { return _totalItemCount; }
			set 
			{
                if (_totalItemCount < 0)
				{
                    throw new ArgumentOutOfRangeException("ItemCount", _totalItemCount, "Item Count cannot be less than zero");
				}

                _totalItemCount = value;
                _totalPageCount = _totalItemCount / PageSize;
                if ((_totalItemCount % PageSize) > 0)
				{
					_totalPageCount ++;
				}
				//check if current page is still valid
                if (CurrentPageIndex > MaxPageIndex)
				{
                    CurrentPageIndex = MaxPageIndex;
				}
			}
		}

		public bool IsFirstPage()
		{
            return CurrentPageIndex == 0;
		}

		public bool IsLastPage()
		{
            return CurrentPageIndex == MaxPageIndex;
		}

		public int MaxPageIndex
		{
			get
			{
				return TotalPageCount - 1;
			}
		}

		public bool CalculateTotal
		{
			get { return _calculateTotal; }
			set { _calculateTotal = value; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions