Click here to Skip to main content
15,896,541 members
Articles / Programming Languages / C#

Genesis Hybrid Smart Client Framework part III

Rate me:
Please Sign up or sign in to vote.
4.29/5 (10 votes)
19 Jun 2009Ms-PL10 min read 34.1K   7  
This is part III of a VII part series. This article covers the back-end of the Genesis Smart Client Framework including the database design.
��USE [BlueMarble.Genesis.Dev] /****** Object:  StoredProcedure [dbo].[Security_ApplicationRole_GetPaged]    Script Date: 05/20/2009 22:36:57 ******/

SET ANSI_NULLS OFF

GO

SET QUOTED_IDENTIFIER ON

GO

/*

----------------------------------------------------------------------------------------------------

-- Date Created: 20 May 2007



-- Created By: Eliyahu Business Systems (http://www.eliyahu.co.za)

-- Purpose: Gets records from the Security_ApplicationRole table passing page index and page count parameters

----------------------------------------------------------------------------------------------------

*/





CREATE PROCEDURE [dbo].[Security_ApplicationRole_GetPaged]

(



	@WhereClause varchar (2000)  ,



	@OrderBy varchar (2000)  ,



	@PageIndex int   ,



	@PageSize int   

)

AS





				

				BEGIN

				DECLARE @PageLowerBound int

				DECLARE @PageUpperBound int

				

				-- Set the page bounds

				SET @PageLowerBound = @PageSize * @PageIndex

				SET @PageUpperBound = @PageLowerBound + @PageSize



				IF (@OrderBy is null or LEN(@OrderBy) < 1)

				BEGIN

					-- default order by to first column

					SET @OrderBy = '[ApplicationGuid]'

				END



				-- SQL Server 2005 Paging

				declare @SQL as nvarchar(4000)

				SET @SQL = 'WITH PageIndex AS ('

				SET @SQL = @SQL + ' SELECT'

				IF @PageSize > 0

				BEGIN

					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)

				END

				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'

				SET @SQL = @SQL + ', [ApplicationGuid]'

				SET @SQL = @SQL + ', [RoleGuid]'

				SET @SQL = @SQL + ' FROM dbo.[Security_ApplicationRole]'

				IF LEN(@WhereClause) > 0

				BEGIN

					SET @SQL = @SQL + ' WHERE ' + @WhereClause

				END

				SET @SQL = @SQL + ' ) SELECT'

				SET @SQL = @SQL + ' [ApplicationGuid],'

				SET @SQL = @SQL + ' [RoleGuid]'

				SET @SQL = @SQL + ' FROM PageIndex'

				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)

				IF @PageSize > 0

				BEGIN

					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)

				END

				exec sp_executesql @SQL

				

				-- get row count

				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'

				SET @SQL = @SQL + ' FROM dbo.[Security_ApplicationRole]'

				IF LEN(@WhereClause) > 0

				BEGIN

					SET @SQL = @SQL + ' WHERE ' + @WhereClause

				END

				exec sp_executesql @SQL

			

				END

GO

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, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
We Fix Code
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions