⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _orders.cs

📁 EasyObjects 是ORM的典型应用的例子是学习研究的很好的范例
💻 CS
📖 第 1 页 / 共 3 页
字号:
/*
'===============================================================================
'  Generated From - CSharp_EasyObject_BusinessEntity.vbgen
' 
'  ** IMPORTANT  ** 
'  How to Generate your stored procedures:
' 
'  SQL      = SQL_DAAB_StoredProcs.vbgen
'  
'  This object is 'abstract' which means you need to inherit from it to be able
'  to instantiate it.  This is very easily 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.Common;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.IO;

using Microsoft.Practices.EnterpriseLibrary.Data;
using NCI.EasyObjects;

namespace EasyObjectsQuickStart.BLL
{

	#region Schema

	public class OrdersSchema : NCI.EasyObjects.Schema
	{
		private static ArrayList _entries;
		public static SchemaItem OrderID = new SchemaItem("OrderID", DbType.Int32, true, false, false, true, true, false);
		public static SchemaItem CustomerID = new SchemaItem("CustomerID", DbType.StringFixedLength, SchemaItemJustify.None, 5, true, false, true, false);
		public static SchemaItem EmployeeID = new SchemaItem("EmployeeID", DbType.Int32, false, true, false, false, true, false);
		public static SchemaItem OrderDate = new SchemaItem("OrderDate", DbType.DateTime, false, true, false, false, false, false);
		public static SchemaItem RequiredDate = new SchemaItem("RequiredDate", DbType.DateTime, false, true, false, false, false, false);
		public static SchemaItem ShippedDate = new SchemaItem("ShippedDate", DbType.DateTime, false, true, false, false, false, false);
		public static SchemaItem ShipVia = new SchemaItem("ShipVia", DbType.Int32, false, true, false, false, true, false);
		public static SchemaItem Freight = new SchemaItem("Freight", DbType.Currency, false, true, false, false, false, true);
		public static SchemaItem ShipName = new SchemaItem("ShipName", DbType.String, SchemaItemJustify.None, 40, true, false, false, false);
		public static SchemaItem ShipAddress = new SchemaItem("ShipAddress", DbType.String, SchemaItemJustify.None, 60, true, false, false, false);
		public static SchemaItem ShipCity = new SchemaItem("ShipCity", DbType.String, SchemaItemJustify.None, 15, true, false, false, false);
		public static SchemaItem ShipRegion = new SchemaItem("ShipRegion", DbType.String, SchemaItemJustify.None, 15, true, false, false, false);
		public static SchemaItem ShipPostalCode = new SchemaItem("ShipPostalCode", DbType.String, SchemaItemJustify.None, 10, true, false, false, false);
		public static SchemaItem ShipCountry = new SchemaItem("ShipCountry", DbType.String, SchemaItemJustify.None, 15, true, false, false, false);

		public override ArrayList SchemaEntries
		{
			get
			{
				if (_entries == null )
				{
					_entries = new ArrayList();
					_entries.Add(OrdersSchema.OrderID);
					_entries.Add(OrdersSchema.CustomerID);
					_entries.Add(OrdersSchema.EmployeeID);
					_entries.Add(OrdersSchema.OrderDate);
					_entries.Add(OrdersSchema.RequiredDate);
					_entries.Add(OrdersSchema.ShippedDate);
					_entries.Add(OrdersSchema.ShipVia);
					_entries.Add(OrdersSchema.Freight);
					_entries.Add(OrdersSchema.ShipName);
					_entries.Add(OrdersSchema.ShipAddress);
					_entries.Add(OrdersSchema.ShipCity);
					_entries.Add(OrdersSchema.ShipRegion);
					_entries.Add(OrdersSchema.ShipPostalCode);
					_entries.Add(OrdersSchema.ShipCountry);
				}
				return _entries;
			}
		}
		
		public static bool HasAutoKey 
		{
			get { return true;	}
		}

		public static bool HasRowID 
		{
			get { return false;	}
		}
	}
	#endregion

	public abstract class _Orders : EasyObject
	{

		public _Orders()
		{
			OrdersSchema _schema = new OrdersSchema();
			this.SchemaEntries = _schema.SchemaEntries;
			this.SchemaGlobal = "dbo";
		}
		
		public override void FlushData() 	 
		{ 	 
			this._whereClause = null; 	 
			this._aggregateClause = null; 	 
			base.FlushData(); 	 
		}
			   
		/// <summary>
		/// Loads the business object with info from the database, based on the requested primary key.
		/// </summary>
		/// <param name="OrderID"></param>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadByPrimaryKey(int OrderID)
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					ListDictionary parameters = new ListDictionary();

					// Add in parameters
					parameters.Add(OrdersSchema.OrderID.FieldName, OrderID);

					return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "daab_GetOrders", parameters, CommandType.StoredProcedure);

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.OrderID.Value = OrderID;
					return this.Query.Load();

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}
	
		/// <summary>
		/// Loads all records from the table.
		/// </summary>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadAll()
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "daab_GetAllOrders", null, CommandType.StoredProcedure);

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					return this.Query.Load();

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		/// <summary>
		/// Adds a new record to the internal table.
		/// </summary>
		public override void AddNew()
		{
			base.AddNew();
			this.ApplyDefaults();
		}

		/// <summary>
		/// Apply any default values to columns
		/// </summary>
		protected override void ApplyDefaults()
		{
			this.Freight = 0;
		}

		protected override DbCommand GetInsertCommand(CommandType commandType)
		{	
			DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "daab_AddOrders";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					db.AddParameter(dbCommand, "OrderID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "OrderID", DataRowVersion.Default, Convert.DBNull);
					CreateParameters(db, dbCommand);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					foreach(SchemaItem item in this.SchemaEntries)
					{
						if (!item.IsComputed)
						{
							if ((item.IsAutoKey && this.IdentityInsert) || !item.IsAutoKey)
							{
								this.Query.AddInsertColumn(item);
							}
						}
					}
					dbCommand = this.Query.GetInsertCommandWrapper();

					dbCommand.Parameters.Clear();
					if (this.IdentityInsert)
					{
						db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Default);
					}
					else
					{
						db.AddParameter(dbCommand, "OrderID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "OrderID", DataRowVersion.Default, Convert.DBNull);
					}
					CreateParameters(db, dbCommand);

					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		protected override DbCommand GetUpdateCommand(CommandType commandType)
		{
            DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "daab_UpdateOrders";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Current);
					CreateParameters(db, dbCommand);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					foreach(SchemaItem item in this.SchemaEntries)
					{
						if (!(item.IsAutoKey || item.IsComputed))
						{
							this.Query.AddUpdateColumn(item);
						}
					}

					this.Where.WhereClauseReset();
					this.Where.OrderID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetUpdateCommandWrapper();

					dbCommand.Parameters.Clear();
					CreateParameters(db, dbCommand);
					db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Current);
					
					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		protected override DbCommand GetDeleteCommand(CommandType commandType)
		{
            DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "daab_DeleteOrders";
					dbCommand = db.GetStoredProcCommand(sqlCommand);
					db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Current);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.OrderID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetDeleteCommandWrapper();

					dbCommand.Parameters.Clear();
					db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Current);
					
					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		private void CreateParameters(Database db, DbCommand dbCommand)
		{
			db.AddInParameter(dbCommand, "CustomerID", DbType.StringFixedLength, "CustomerID", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "EmployeeID", DbType.Int32, "EmployeeID", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "OrderDate", DbType.DateTime, "OrderDate", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "RequiredDate", DbType.DateTime, "RequiredDate", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShippedDate", DbType.DateTime, "ShippedDate", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipVia", DbType.Int32, "ShipVia", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "Freight", DbType.Currency, "Freight", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipName", DbType.String, "ShipName", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipAddress", DbType.String, "ShipAddress", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipCity", DbType.String, "ShipCity", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipRegion", DbType.String, "ShipRegion", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipPostalCode", DbType.String, "ShipPostalCode", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ShipCountry", DbType.String, "ShipCountry", DataRowVersion.Current);
		}
		
		#region Properties
		public virtual int OrderID
		{
			get
			{
				return this.GetInteger(OrdersSchema.OrderID.FieldName);
	    	}
			set
			{
				this.SetInteger(OrdersSchema.OrderID.FieldName, value);
			}
		}
		public virtual string CustomerID
		{
			get
			{
				return this.GetString(OrdersSchema.CustomerID.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.CustomerID.FieldName, value);
			}
		}
		public virtual int EmployeeID
		{
			get
			{
				return this.GetInteger(OrdersSchema.EmployeeID.FieldName);
	    	}
			set
			{
				this.SetInteger(OrdersSchema.EmployeeID.FieldName, value);
			}
		}
		public virtual DateTime OrderDate
		{
			get
			{
				return this.GetDateTime(OrdersSchema.OrderDate.FieldName);
	    	}
			set
			{
				this.SetDateTime(OrdersSchema.OrderDate.FieldName, value);
			}
		}
		public virtual DateTime RequiredDate
		{
			get
			{
				return this.GetDateTime(OrdersSchema.RequiredDate.FieldName);
	    	}
			set
			{
				this.SetDateTime(OrdersSchema.RequiredDate.FieldName, value);
			}
		}
		public virtual DateTime ShippedDate
		{
			get
			{
				return this.GetDateTime(OrdersSchema.ShippedDate.FieldName);
	    	}
			set
			{
				this.SetDateTime(OrdersSchema.ShippedDate.FieldName, value);
			}
		}
		public virtual int ShipVia
		{
			get
			{
				return this.GetInteger(OrdersSchema.ShipVia.FieldName);
	    	}
			set
			{
				this.SetInteger(OrdersSchema.ShipVia.FieldName, value);
			}
		}
		public virtual decimal Freight
		{
			get
			{
				return this.GetDecimal(OrdersSchema.Freight.FieldName);
	    	}
			set
			{
				this.SetDecimal(OrdersSchema.Freight.FieldName, value);
			}
		}
		public virtual string ShipName
		{
			get
			{
				return this.GetString(OrdersSchema.ShipName.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.ShipName.FieldName, value);
			}
		}
		public virtual string ShipAddress
		{
			get
			{
				return this.GetString(OrdersSchema.ShipAddress.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.ShipAddress.FieldName, value);
			}
		}
		public virtual string ShipCity
		{
			get
			{
				return this.GetString(OrdersSchema.ShipCity.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.ShipCity.FieldName, value);
			}
		}
		public virtual string ShipRegion
		{
			get
			{
				return this.GetString(OrdersSchema.ShipRegion.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.ShipRegion.FieldName, value);
			}
		}
		public virtual string ShipPostalCode
		{
			get
			{
				return this.GetString(OrdersSchema.ShipPostalCode.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.ShipPostalCode.FieldName, value);
			}
		}
		public virtual string ShipCountry
		{
			get
			{
				return this.GetString(OrdersSchema.ShipCountry.FieldName);
	    	}
			set
			{
				this.SetString(OrdersSchema.ShipCountry.FieldName, value);
			}
		}

		public override string TableName
		{
			get { return "Orders"; }
		}
		
		#endregion		
		
		#region String Properties
		public virtual string s_OrderID
		{
			get
			{
			    return this.IsColumnNull(OrdersSchema.OrderID.FieldName) ? string.Empty : base.GetIntegerAsString(OrdersSchema.OrderID.FieldName);
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -