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

📄 _orderdetails.cs

📁 EasyObjects 是ORM的典型应用的例子是学习研究的很好的范例
💻 CS
📖 第 1 页 / 共 2 页
字号:
/*
'===============================================================================
'  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 OrderDetailsSchema : NCI.EasyObjects.Schema
	{
		private static ArrayList _entries;
		public static SchemaItem OrderID = new SchemaItem("OrderID", DbType.Int32, false, false, false, true, true, false);
		public static SchemaItem ProductID = new SchemaItem("ProductID", DbType.Int32, false, false, false, true, true, false);
		public static SchemaItem UnitPrice = new SchemaItem("UnitPrice", DbType.Currency, false, false, false, false, false, true);
		public static SchemaItem Quantity = new SchemaItem("Quantity", DbType.Int16, false, false, false, false, false, true);
		public static SchemaItem Discount = new SchemaItem("Discount", DbType.Single, false, false, false, false, false, true);

		public override ArrayList SchemaEntries
		{
			get
			{
				if (_entries == null )
				{
					_entries = new ArrayList();
					_entries.Add(OrderDetailsSchema.OrderID);
					_entries.Add(OrderDetailsSchema.ProductID);
					_entries.Add(OrderDetailsSchema.UnitPrice);
					_entries.Add(OrderDetailsSchema.Quantity);
					_entries.Add(OrderDetailsSchema.Discount);
				}
				return _entries;
			}
		}
		
		public static bool HasAutoKey 
		{
			get { return false;	}
		}

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

	public abstract class _OrderDetails : EasyObject
	{

		public _OrderDetails()
		{
			OrderDetailsSchema _schema = new OrderDetailsSchema();
			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>
		/// <param name="ProductID"></param>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadByPrimaryKey(int OrderID, int ProductID)
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					ListDictionary parameters = new ListDictionary();

					// Add in parameters
					parameters.Add(OrderDetailsSchema.OrderID.FieldName, OrderID);
					parameters.Add(OrderDetailsSchema.ProductID.FieldName, ProductID);

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

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.OrderID.Value = OrderID;
					this.Where.ProductID.Value = ProductID;
					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_GetAllOrderDetails", 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.UnitPrice = 0;
			this.Quantity = 1;
			this.Discount = 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_AddOrderDetails";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					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)
					{
					}
					else
					{
					}
					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_UpdateOrderDetails";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					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;
					this.Where.ProductID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetUpdateCommandWrapper();

					dbCommand.Parameters.Clear();
					CreateParameters(db, dbCommand);
					
					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_DeleteOrderDetails";
					dbCommand = db.GetStoredProcCommand(sqlCommand);
					db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Current);
					db.AddInParameter(dbCommand, "ProductID", DbType.Int32, "ProductID", DataRowVersion.Current);
					
					return dbCommand;

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

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

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

		private void CreateParameters(Database db, DbCommand dbCommand)
		{
			db.AddInParameter(dbCommand, "OrderID", DbType.Int32, "OrderID", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "ProductID", DbType.Int32, "ProductID", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "UnitPrice", DbType.Currency, "UnitPrice", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "Quantity", DbType.Int16, "Quantity", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "Discount", DbType.Single, "Discount", DataRowVersion.Current);
		}
		
		#region Properties
		public virtual int OrderID
		{
			get
			{
				return this.GetInteger(OrderDetailsSchema.OrderID.FieldName);
	    	}
			set
			{
				this.SetInteger(OrderDetailsSchema.OrderID.FieldName, value);
			}
		}
		public virtual int ProductID
		{
			get
			{
				return this.GetInteger(OrderDetailsSchema.ProductID.FieldName);
	    	}
			set
			{
				this.SetInteger(OrderDetailsSchema.ProductID.FieldName, value);
			}
		}
		public virtual decimal UnitPrice
		{
			get
			{
				return this.GetDecimal(OrderDetailsSchema.UnitPrice.FieldName);
	    	}
			set
			{
				this.SetDecimal(OrderDetailsSchema.UnitPrice.FieldName, value);
			}
		}
		public virtual short Quantity
		{
			get
			{
				return this.GetShort(OrderDetailsSchema.Quantity.FieldName);
	    	}
			set
			{
				this.SetShort(OrderDetailsSchema.Quantity.FieldName, value);
			}
		}
		public virtual float Discount
		{
			get
			{
				return this.GetFloat(OrderDetailsSchema.Discount.FieldName);
	    	}
			set
			{
				this.SetFloat(OrderDetailsSchema.Discount.FieldName, value);
			}
		}

		public override string TableName
		{
			get { return "Order Details"; }
		}
		
		#endregion		
		
		#region String Properties
		public virtual string s_OrderID
		{
			get
			{
			    return this.IsColumnNull(OrderDetailsSchema.OrderID.FieldName) ? string.Empty : base.GetIntegerAsString(OrderDetailsSchema.OrderID.FieldName);
			}
			set
			{
			    if(string.Empty == value)
			        this.SetColumnNull(OrderDetailsSchema.OrderID.FieldName);
			    else
			        this.OrderID = base.SetIntegerAsString(OrderDetailsSchema.OrderID.FieldName, value);
			}
		}
		public virtual string s_ProductID
		{
			get
			{
			    return this.IsColumnNull(OrderDetailsSchema.ProductID.FieldName) ? string.Empty : base.GetIntegerAsString(OrderDetailsSchema.ProductID.FieldName);
			}
			set
			{
			    if(string.Empty == value)
			        this.SetColumnNull(OrderDetailsSchema.ProductID.FieldName);
			    else
			        this.ProductID = base.SetIntegerAsString(OrderDetailsSchema.ProductID.FieldName, value);
			}
		}
		public virtual string s_UnitPrice
		{
			get
			{
			    return this.IsColumnNull(OrderDetailsSchema.UnitPrice.FieldName) ? string.Empty : base.GetDecimalAsString(OrderDetailsSchema.UnitPrice.FieldName);
			}
			set
			{

⌨️ 快捷键说明

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