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

Three Tier Code Generator For ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.78/5 (34 votes)
8 Jul 200512 min read 426.4K   22.2K   251  
Generates three tier code for ASP.NET.
//**==========================================================================================
//**
//** FILE  : Admin.cs
//** Author: Stevan Rodrigues
//**
//**==========================================================================================
//**
//** (c) The contents of this file , and of any file or document derived from it , are copyright 
//** to SiteBuilders . Unlicensed alteration, change or copying in any form, 
//** whether written, by photocopy, by print or by any other methods of reproduction is 
//** strictly prohibited.
//**
//**==========================================================================================
using System;
using Company.ThreeTierDemo.Components.Interface;
using WebChamps.Components.Parent;
using Microsoft.ApplicationBlocks.Data;
//*********************************************************************
//
// Company.ThreeTierDemo.Components.Data Namespace
//
//*********************************************************************
namespace Company.ThreeTierDemo.Components.Data
{
	//*********************************************************************
	//
	// Class: Admin
	//
 	//Description: This class belongs to Data Access tier which encapsulates
 	// all data logic necessary to add/update/query/delete 	 records
 	// of Admin_Tb within database.
	//
	//*********************************************************************
	public class Admin : DataObject
	{

		//*********************************************************************
		//
		// ShowAdmin Method
		//
		// The ShowAdmin_Tb method Shows the specified content from
		// the Admin_Tb database table.
		// Other relevant sources:
		// File : ProcShowAdmin_Tb.sql - ProcShowAdmin_Tb Stored Procedure
		//
		//*********************************************************************
		public static System.Data.DataSet ShowAdmin()
		{
			System.Data.DataSet MsDataSet;
			System.Data.SqlClient.SqlParameter[] MsSqlParameter = {};


			try
			{
				// Fill the Dataset object with records
			MsDataSet = SqlHelper.ExecuteDataset(ConnectionString, System.Data.CommandType.StoredProcedure, "ProcShowAdmin_Tb", MsSqlParameter);
			return MsDataSet;
			}
			catch (System.Exception ex)
			{
				throw new WebChamps.Components.Web.AppException("An error occurred while executing the Company.ThreeTierDemo.Components.Data.Admin.ShowAdmin", ex);

			}
			finally
			{
				//Some action
			}

		}


		//*********************************************************************
		//
		// SelectAdmin Method
		//
		// The SelectAdmin_Tb method Selects the specified content from
		// the Admin_Tb database table.
		// Other relevant sources:
		// File : ProcSelectAdmin_Tb.sql - ProcSelectAdmin_Tb Stored Procedure
		//
		//*********************************************************************
		public static System.Data.SqlClient.SqlDataReader SelectAdmin(Int32 AdminId)
		{
			System.Data.SqlClient.SqlDataReader MsDataReader;
			System.Data.SqlClient.SqlParameter[] MsSqlParameter = {
					new System.Data.SqlClient.SqlParameter( "@AdminId", AdminId)
					};

			try
			{
				MsDataReader = SqlHelper.ExecuteReader(ConnectionString, "ProcSelectAdmin_Tb",  MsSqlParameter);
			return MsDataReader;
			}
			catch (System.Exception ex)
			{
				throw new WebChamps.Components.Web.AppException("An error occurred while executing the Company.ThreeTierDemo.Components.Data.Admin.SelectAdmin", ex);

			}
			finally
			{
				//Some action
			}

		}


		//*********************************************************************
		//
		// AddAdmin Method
		//
		// The AddAdmin_Tb method Adds the specified content from
		// the Admin_Tb database table.
		// Other relevant sources:
		// File : ProcAddAdmin_Tb.sql - ProcAddAdmin_Tb Stored Procedure
		//
		//*********************************************************************
		public static Int32 AddAdmin(IAdmin ParamAdmin, String Username)
		{
			System.Data.SqlClient.SqlParameter[] MsSqlParameter = {
					new System.Data.SqlClient.SqlParameter( "@AdminId",  ParamAdmin.AdminId), 
					new System.Data.SqlClient.SqlParameter( "@FirstName", ParamAdmin.FirstName ), 
					new System.Data.SqlClient.SqlParameter( "@LastName", ParamAdmin.LastName ), 
					new System.Data.SqlClient.SqlParameter( "@Username", ParamAdmin.Username ), 
					new System.Data.SqlClient.SqlParameter( "@Password", ParamAdmin.Password ), 
					new System.Data.SqlClient.SqlParameter( "@AddedDate", System.DateTime.Now), 
					new System.Data.SqlClient.SqlParameter( "@UpdatedDate", System.DateTime.Now), 
					new System.Data.SqlClient.SqlParameter( "@EditUsername", Username ), 
					new System.Data.SqlClient.SqlParameter("ReturnValue", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, 0, 0, System.String.Empty, System.Data.DataRowVersion.Default, null)
					};

			try
			{
				SqlHelper.ExecuteNonQuery(ConnectionString, "ProcAddAdmin_Tb",  MsSqlParameter);

				return System.Convert.ToInt32(MsSqlParameter[8].Value);
			}
			catch (System.Exception ex)
			{
				throw new WebChamps.Components.Web.AppException("An error occurred while executing the Company.ThreeTierDemo.Components.Data.Admin.AddAdmin", ex);

			}
			finally
			{
				//Some action
			}

		}


		//*********************************************************************
		//
		// UpdateAdmin Method
		//
		// The UpdateAdmin_Tb method Updates the specified content from
		// the Admin_Tb database table.
		// Other relevant sources:
		// File : ProcUpdateAdmin_Tb.sql - ProcUpdateAdmin_Tb Stored Procedure
		//
		//*********************************************************************
		public static Int32 UpdateAdmin(IAdmin ParamAdmin, String Username)
		{
			System.Data.SqlClient.SqlParameter[] MsSqlParameter = {
					new System.Data.SqlClient.SqlParameter( "@AdminId",  ParamAdmin.AdminId), 
					new System.Data.SqlClient.SqlParameter( "@FirstName", ParamAdmin.FirstName ), 
					new System.Data.SqlClient.SqlParameter( "@LastName", ParamAdmin.LastName ), 
					new System.Data.SqlClient.SqlParameter( "@Username", ParamAdmin.Username ), 
					new System.Data.SqlClient.SqlParameter( "@Password", ParamAdmin.Password ), 
					new System.Data.SqlClient.SqlParameter( "@UpdatedDate", System.DateTime.Now), 
					new System.Data.SqlClient.SqlParameter( "@EditUsername", Username ), 
					new System.Data.SqlClient.SqlParameter("ReturnValue", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, 0, 0, System.String.Empty, System.Data.DataRowVersion.Default, null)
					};

			try
			{
				SqlHelper.ExecuteNonQuery(ConnectionString, "ProcUpdateAdmin_Tb",  MsSqlParameter);

				return System.Convert.ToInt32(MsSqlParameter[7].Value);
			}
			catch (System.Exception ex)
			{
				throw new WebChamps.Components.Web.AppException("An error occurred while executing the Company.ThreeTierDemo.Components.Data.Admin.UpdateAdmin", ex);

			}
			finally
			{
				//Some action
			}

		}


		//*********************************************************************
		//
		// DeleteAdmin Method
		//
		// The DeleteAdmin_Tb method Deletes the specified content from
		// the Admin_Tb database table.
		// Other relevant sources:
		// File : ProcDeleteAdmin_Tb.sql - ProcDeleteAdmin_Tb Stored Procedure
		//
		//*********************************************************************
		public static Int32 DeleteAdmin(Int32 AdminId, String Username)
		{
			System.Data.SqlClient.SqlParameter[] MsSqlParameter = {
					new System.Data.SqlClient.SqlParameter( "@AdminId", AdminId), 
					new System.Data.SqlClient.SqlParameter( "@DeletedDate", System.DateTime.Now), 
					new System.Data.SqlClient.SqlParameter( "@EditUsername", Username ), 
					new System.Data.SqlClient.SqlParameter("ReturnValue", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, 0, 0, System.String.Empty, System.Data.DataRowVersion.Default, null)
					};


			try
			{
				SqlHelper.ExecuteNonQuery(ConnectionString, "ProcDeleteAdmin_Tb",  MsSqlParameter);

				return System.Convert.ToInt32(MsSqlParameter[3].Value);
			}
			catch (System.Exception ex)
			{
				throw new WebChamps.Components.Web.AppException("An error occurred while executing the Company.ThreeTierDemo.Components.Data.Admin.DeleteAdmin", ex);

			}
			finally
			{
				//Some action
			}

		}


	}
}


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
Software Developer (Senior)
Australia Australia
Stevan is a Microsoft Certified Solutions Developer in .Net Architecture (MCSD.Net Early Achiever – one among the first 2500 worldwide), Microsoft Certified Application Developer in .Net – MCAD.Net (Charter Member - one among the first 5000 developers worldwide).

Comments and Discussions