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

Web Application Page Patterns

Rate me:
Please Sign up or sign in to vote.
4.47/5 (4 votes)
23 Jan 200710 min read 47.2K   349   53  
Two common design patterns for web application pages: the Single Entity Postback Editor and the Multi-Entity Postback Editor
/*
'===============================================================================
'  Generated From - CSharp_dOOdads_BusinessEntity.vbgen
' 
'  ** IMPORTANT  ** 
'  How to Generate your stored procedures:
' 
'  SQL        = SQL_StoredProcs.vbgen
'  ACCESS     = Access_StoredProcs.vbgen
'  ORACLE     = Oracle_StoredProcs.vbgen
'  FIREBIRD   = FirebirdStoredProcs.vbgen
'  POSTGRESQL = PostgreSQL_StoredProcs.vbgen
'
'  The supporting base class SqlClientEntity is in the Architecture directory in "dOOdads".
'  
'  This object is 'abstract' which means you need to inherit from it to be able
'  to instantiate it.  This is very easilly done. You can override properties and
'  methods in your derived class, this allows you to regenerate this class at any
'  time and not worry about overwriting custom code. 
'
'  NEVER EDIT THIS FILE.
'
'  public class YourObject :  _YourObject
'  {
'
'  }
'
'===============================================================================
*/

// Generated by MyGeneration Version # (1.2.0.2)

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Specialized;

using MyGeneration.dOOdads;

namespace WebAppPatterns.Bizlayer
{
	public abstract class _Product : SqlClientEntity
	{
		public _Product()
		{
			this.QuerySource = "Product";
			this.MappingName = "Product";

		}	

		//=================================================================
		//  public Overrides void AddNew()
		//=================================================================
		//
		//=================================================================
		public override void AddNew()
		{
			base.AddNew();
			
		}
		
		
		public override void FlushData()
		{
			this._whereClause = null;
			this._aggregateClause = null;
			base.FlushData();
		}
		
		//=================================================================
		//  	public Function LoadAll() As Boolean
		//=================================================================
		//  Loads all of the records in the database, and sets the currentRow to the first row
		//=================================================================
		public bool LoadAll() 
		{
			ListDictionary parameters = null;
			
			return base.LoadFromSql("[" + this.SchemaStoredProcedure + "proc_ProductLoadAll]", parameters);
		}
	
		//=================================================================
		// public Overridable Function LoadByPrimaryKey()  As Boolean
		//=================================================================
		//  Loads a single row of via the primary key
		//=================================================================
		public virtual bool LoadByPrimaryKey(int ProductID)
		{
			ListDictionary parameters = new ListDictionary();
			parameters.Add(Parameters.ProductID, ProductID);

		
			return base.LoadFromSql("[" + this.SchemaStoredProcedure + "proc_ProductLoadByPrimaryKey]", parameters);
		}
		
		#region Parameters
		protected class Parameters
		{
			
			public static SqlParameter ProductID
			{
				get
				{
					return new SqlParameter("@ProductID", SqlDbType.Int, 0);
				}
			}
			
			public static SqlParameter Name
			{
				get
				{
					return new SqlParameter("@Name", SqlDbType.VarChar, 50);
				}
			}
			
			public static SqlParameter Price
			{
				get
				{
					return new SqlParameter("@Price", SqlDbType.Decimal, 0);
				}
			}
			
		}
		#endregion		
	
		#region ColumnNames
		public class ColumnNames
		{  
            public const string ProductID = "ProductID";
            public const string Name = "Name";
            public const string Price = "Price";

			static public string ToPropertyName(string columnName)
			{
				if(ht == null)
				{
					ht = new Hashtable();
					
					ht[ProductID] = _Product.PropertyNames.ProductID;
					ht[Name] = _Product.PropertyNames.Name;
					ht[Price] = _Product.PropertyNames.Price;

				}
				return (string)ht[columnName];
			}

			static private Hashtable ht = null;			 
		}
		#endregion
		
		#region PropertyNames
		public class PropertyNames
		{  
            public const string ProductID = "ProductID";
            public const string Name = "Name";
            public const string Price = "Price";

			static public string ToColumnName(string propertyName)
			{
				if(ht == null)
				{
					ht = new Hashtable();
					
					ht[ProductID] = _Product.ColumnNames.ProductID;
					ht[Name] = _Product.ColumnNames.Name;
					ht[Price] = _Product.ColumnNames.Price;

				}
				return (string)ht[propertyName];
			}

			static private Hashtable ht = null;			 
		}			 
		#endregion	

		#region StringPropertyNames
		public class StringPropertyNames
		{  
            public const string ProductID = "s_ProductID";
            public const string Name = "s_Name";
            public const string Price = "s_Price";

		}
		#endregion		
		
		#region Properties
	
		public virtual int ProductID
	    {
			get
	        {
				return base.Getint(ColumnNames.ProductID);
			}
			set
	        {
				base.Setint(ColumnNames.ProductID, value);
			}
		}

		public virtual string Name
	    {
			get
	        {
				return base.Getstring(ColumnNames.Name);
			}
			set
	        {
				base.Setstring(ColumnNames.Name, value);
			}
		}

		public virtual decimal Price
	    {
			get
	        {
				return base.Getdecimal(ColumnNames.Price);
			}
			set
	        {
				base.Setdecimal(ColumnNames.Price, value);
			}
		}


		#endregion
		
		#region String Properties
	
		public virtual string s_ProductID
	    {
			get
	        {
				return this.IsColumnNull(ColumnNames.ProductID) ? string.Empty : base.GetintAsString(ColumnNames.ProductID);
			}
			set
	        {
				if(string.Empty == value)
					this.SetColumnNull(ColumnNames.ProductID);
				else
					this.ProductID = base.SetintAsString(ColumnNames.ProductID, value);
			}
		}

		public virtual string s_Name
	    {
			get
	        {
				return this.IsColumnNull(ColumnNames.Name) ? string.Empty : base.GetstringAsString(ColumnNames.Name);
			}
			set
	        {
				if(string.Empty == value)
					this.SetColumnNull(ColumnNames.Name);
				else
					this.Name = base.SetstringAsString(ColumnNames.Name, value);
			}
		}

		public virtual string s_Price
	    {
			get
	        {
				return this.IsColumnNull(ColumnNames.Price) ? string.Empty : base.GetdecimalAsString(ColumnNames.Price);
			}
			set
	        {
				if(string.Empty == value)
					this.SetColumnNull(ColumnNames.Price);
				else
					this.Price = base.SetdecimalAsString(ColumnNames.Price, value);
			}
		}


		#endregion		
	
		#region Where Clause
		public class WhereClause
		{
			public WhereClause(BusinessEntity entity)
			{
				this._entity = entity;
			}
			
			public TearOffWhereParameter TearOff
			{
				get
				{
					if(_tearOff == null)
					{
						_tearOff = new TearOffWhereParameter(this);
					}

					return _tearOff;
				}
			}

			#region WhereParameter TearOff's
			public class TearOffWhereParameter
			{
				public TearOffWhereParameter(WhereClause clause)
				{
					this._clause = clause;
				}
				
				
				public WhereParameter ProductID
				{
					get
					{
							WhereParameter where = new WhereParameter(ColumnNames.ProductID, Parameters.ProductID);
							this._clause._entity.Query.AddWhereParameter(where);
							return where;
					}
				}

				public WhereParameter Name
				{
					get
					{
							WhereParameter where = new WhereParameter(ColumnNames.Name, Parameters.Name);
							this._clause._entity.Query.AddWhereParameter(where);
							return where;
					}
				}

				public WhereParameter Price
				{
					get
					{
							WhereParameter where = new WhereParameter(ColumnNames.Price, Parameters.Price);
							this._clause._entity.Query.AddWhereParameter(where);
							return where;
					}
				}


				private WhereClause _clause;
			}
			#endregion
		
			public WhereParameter ProductID
		    {
				get
		        {
					if(_ProductID_W == null)
	        	    {
						_ProductID_W = TearOff.ProductID;
					}
					return _ProductID_W;
				}
			}

			public WhereParameter Name
		    {
				get
		        {
					if(_Name_W == null)
	        	    {
						_Name_W = TearOff.Name;
					}
					return _Name_W;
				}
			}

			public WhereParameter Price
		    {
				get
		        {
					if(_Price_W == null)
	        	    {
						_Price_W = TearOff.Price;
					}
					return _Price_W;
				}
			}

			private WhereParameter _ProductID_W = null;
			private WhereParameter _Name_W = null;
			private WhereParameter _Price_W = null;

			public void WhereClauseReset()
			{
				_ProductID_W = null;
				_Name_W = null;
				_Price_W = null;

				this._entity.Query.FlushWhereParameters();

			}
	
			private BusinessEntity _entity;
			private TearOffWhereParameter _tearOff;
			
		}
	
		public WhereClause Where
		{
			get
			{
				if(_whereClause == null)
				{
					_whereClause = new WhereClause(this);
				}
		
				return _whereClause;
			}
		}
		
		private WhereClause _whereClause = null;	
		#endregion
	
		#region Aggregate Clause
		public class AggregateClause
		{
			public AggregateClause(BusinessEntity entity)
			{
				this._entity = entity;
			}
			
			public TearOffAggregateParameter TearOff
			{
				get
				{
					if(_tearOff == null)
					{
						_tearOff = new TearOffAggregateParameter(this);
					}

					return _tearOff;
				}
			}

			#region AggregateParameter TearOff's
			public class TearOffAggregateParameter
			{
				public TearOffAggregateParameter(AggregateClause clause)
				{
					this._clause = clause;
				}
				
				
				public AggregateParameter ProductID
				{
					get
					{
							AggregateParameter aggregate = new AggregateParameter(ColumnNames.ProductID, Parameters.ProductID);
							this._clause._entity.Query.AddAggregateParameter(aggregate);
							return aggregate;
					}
				}

				public AggregateParameter Name
				{
					get
					{
							AggregateParameter aggregate = new AggregateParameter(ColumnNames.Name, Parameters.Name);
							this._clause._entity.Query.AddAggregateParameter(aggregate);
							return aggregate;
					}
				}

				public AggregateParameter Price
				{
					get
					{
							AggregateParameter aggregate = new AggregateParameter(ColumnNames.Price, Parameters.Price);
							this._clause._entity.Query.AddAggregateParameter(aggregate);
							return aggregate;
					}
				}


				private AggregateClause _clause;
			}
			#endregion
		
			public AggregateParameter ProductID
		    {
				get
		        {
					if(_ProductID_W == null)
	        	    {
						_ProductID_W = TearOff.ProductID;
					}
					return _ProductID_W;
				}
			}

			public AggregateParameter Name
		    {
				get
		        {
					if(_Name_W == null)
	        	    {
						_Name_W = TearOff.Name;
					}
					return _Name_W;
				}
			}

			public AggregateParameter Price
		    {
				get
		        {
					if(_Price_W == null)
	        	    {
						_Price_W = TearOff.Price;
					}
					return _Price_W;
				}
			}

			private AggregateParameter _ProductID_W = null;
			private AggregateParameter _Name_W = null;
			private AggregateParameter _Price_W = null;

			public void AggregateClauseReset()
			{
				_ProductID_W = null;
				_Name_W = null;
				_Price_W = null;

				this._entity.Query.FlushAggregateParameters();

			}
	
			private BusinessEntity _entity;
			private TearOffAggregateParameter _tearOff;
			
		}
	
		public AggregateClause Aggregate
		{
			get
			{
				if(_aggregateClause == null)
				{
					_aggregateClause = new AggregateClause(this);
				}
		
				return _aggregateClause;
			}
		}
		
		private AggregateClause _aggregateClause = null;	
		#endregion
	
		protected override IDbCommand GetInsertCommand() 
		{
		
			SqlCommand cmd = new SqlCommand();
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.CommandText = "[" + this.SchemaStoredProcedure + "proc_ProductInsert]";
	
			CreateParameters(cmd);
			
			SqlParameter p;
			p = cmd.Parameters[Parameters.ProductID.ParameterName];
			p.Direction = ParameterDirection.Output;
    
			return cmd;
		}
	
		protected override IDbCommand GetUpdateCommand()
		{
		
			SqlCommand cmd = new SqlCommand();
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.CommandText = "[" + this.SchemaStoredProcedure + "proc_ProductUpdate]";
	
			CreateParameters(cmd);
			      
			return cmd;
		}
	
		protected override IDbCommand GetDeleteCommand()
		{
		
			SqlCommand cmd = new SqlCommand();
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.CommandText = "[" + this.SchemaStoredProcedure + "proc_ProductDelete]";
	
			SqlParameter p;
			p = cmd.Parameters.Add(Parameters.ProductID);
			p.SourceColumn = ColumnNames.ProductID;
			p.SourceVersion = DataRowVersion.Current;

  
			return cmd;
		}
		
		private IDbCommand CreateParameters(SqlCommand cmd)
		{
			SqlParameter p;
		
			p = cmd.Parameters.Add(Parameters.ProductID);
			p.SourceColumn = ColumnNames.ProductID;
			p.SourceVersion = DataRowVersion.Current;

			p = cmd.Parameters.Add(Parameters.Name);
			p.SourceColumn = ColumnNames.Name;
			p.SourceVersion = DataRowVersion.Current;

			p = cmd.Parameters.Add(Parameters.Price);
			p.SourceColumn = ColumnNames.Price;
			p.SourceVersion = DataRowVersion.Current;


			return cmd;
		}
	}
}

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
Architect Milliman
United States United States
I have been involved in professional software development for over 15 years, focusing on distributed applications on both Microsoft and Java platforms.

I also like long walks on the beach and a sense of humor and don't like mean people Wink | ;-)

Comments and Discussions