📄 _products.cs
字号:
/*
'===============================================================================
' 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 ProductsSchema : NCI.EasyObjects.Schema
{
private static ArrayList _entries;
public static SchemaItem ProductID = new SchemaItem("ProductID", DbType.Int32, true, false, false, true, true, false);
public static SchemaItem ProductName = new SchemaItem("ProductName", DbType.String, SchemaItemJustify.None, 40, false, false, false, false);
public static SchemaItem SupplierID = new SchemaItem("SupplierID", DbType.Int32, false, true, false, false, true, false);
public static SchemaItem CategoryID = new SchemaItem("CategoryID", DbType.Int32, false, true, false, false, true, false);
public static SchemaItem QuantityPerUnit = new SchemaItem("QuantityPerUnit", DbType.String, SchemaItemJustify.None, 20, true, false, false, false);
public static SchemaItem UnitPrice = new SchemaItem("UnitPrice", DbType.Currency, false, true, false, false, false, true);
public static SchemaItem UnitsInStock = new SchemaItem("UnitsInStock", DbType.Int16, false, true, false, false, false, true);
public static SchemaItem UnitsOnOrder = new SchemaItem("UnitsOnOrder", DbType.Int16, false, true, false, false, false, true);
public static SchemaItem ReorderLevel = new SchemaItem("ReorderLevel", DbType.Int16, false, true, false, false, false, true);
public static SchemaItem Discontinued = new SchemaItem("Discontinued", DbType.Boolean, false, false, false, false, false, true);
public override ArrayList SchemaEntries
{
get
{
if (_entries == null )
{
_entries = new ArrayList();
_entries.Add(ProductsSchema.ProductID);
_entries.Add(ProductsSchema.ProductName);
_entries.Add(ProductsSchema.SupplierID);
_entries.Add(ProductsSchema.CategoryID);
_entries.Add(ProductsSchema.QuantityPerUnit);
_entries.Add(ProductsSchema.UnitPrice);
_entries.Add(ProductsSchema.UnitsInStock);
_entries.Add(ProductsSchema.UnitsOnOrder);
_entries.Add(ProductsSchema.ReorderLevel);
_entries.Add(ProductsSchema.Discontinued);
}
return _entries;
}
}
public static bool HasAutoKey
{
get { return true; }
}
public static bool HasRowID
{
get { return false; }
}
}
#endregion
public abstract class _Products : EasyObject
{
public _Products()
{
ProductsSchema _schema = new ProductsSchema();
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="ProductID"></param>
/// <returns>A Boolean indicating success or failure of the query</returns>
public bool LoadByPrimaryKey(int ProductID)
{
switch(this.DefaultCommandType)
{
case CommandType.StoredProcedure:
ListDictionary parameters = new ListDictionary();
// Add in parameters
parameters.Add(ProductsSchema.ProductID.FieldName, ProductID);
return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "daab_GetProducts", parameters, CommandType.StoredProcedure);
case CommandType.Text:
this.Query.ClearAll();
this.Where.WhereClauseReset();
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_GetAllProducts", 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.UnitsInStock = 0;
this.UnitsOnOrder = 0;
this.ReorderLevel = 0;
this.Discontinued = false;
}
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_AddProducts";
dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddParameter(dbCommand, "ProductID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "ProductID", 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, "ProductID", DbType.Int32, "ProductID", DataRowVersion.Default);
}
else
{
db.AddParameter(dbCommand, "ProductID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "ProductID", 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_UpdateProducts";
dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "ProductID", DbType.Int32, "ProductID", 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.ProductID.Operator = WhereParameter.Operand.Equal;
dbCommand = this.Query.GetUpdateCommandWrapper();
dbCommand.Parameters.Clear();
CreateParameters(db, dbCommand);
db.AddInParameter(dbCommand, "ProductID", DbType.Int32, "ProductID", 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_DeleteProducts";
dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "ProductID", DbType.Int32, "ProductID", DataRowVersion.Current);
return dbCommand;
case CommandType.Text:
this.Query.ClearAll();
this.Where.WhereClauseReset();
this.Where.ProductID.Operator = WhereParameter.Operand.Equal;
dbCommand = this.Query.GetDeleteCommandWrapper();
dbCommand.Parameters.Clear();
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, "ProductName", DbType.String, "ProductName", DataRowVersion.Current);
db.AddInParameter(dbCommand, "SupplierID", DbType.Int32, "SupplierID", DataRowVersion.Current);
db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current);
db.AddInParameter(dbCommand, "QuantityPerUnit", DbType.String, "QuantityPerUnit", DataRowVersion.Current);
db.AddInParameter(dbCommand, "UnitPrice", DbType.Currency, "UnitPrice", DataRowVersion.Current);
db.AddInParameter(dbCommand, "UnitsInStock", DbType.Int16, "UnitsInStock", DataRowVersion.Current);
db.AddInParameter(dbCommand, "UnitsOnOrder", DbType.Int16, "UnitsOnOrder", DataRowVersion.Current);
db.AddInParameter(dbCommand, "ReorderLevel", DbType.Int16, "ReorderLevel", DataRowVersion.Current);
db.AddInParameter(dbCommand, "Discontinued", DbType.Boolean, "Discontinued", DataRowVersion.Current);
}
#region Properties
public virtual int ProductID
{
get
{
return this.GetInteger(ProductsSchema.ProductID.FieldName);
}
set
{
this.SetInteger(ProductsSchema.ProductID.FieldName, value);
}
}
public virtual string ProductName
{
get
{
return this.GetString(ProductsSchema.ProductName.FieldName);
}
set
{
this.SetString(ProductsSchema.ProductName.FieldName, value);
}
}
public virtual int SupplierID
{
get
{
return this.GetInteger(ProductsSchema.SupplierID.FieldName);
}
set
{
this.SetInteger(ProductsSchema.SupplierID.FieldName, value);
}
}
public virtual int CategoryID
{
get
{
return this.GetInteger(ProductsSchema.CategoryID.FieldName);
}
set
{
this.SetInteger(ProductsSchema.CategoryID.FieldName, value);
}
}
public virtual string QuantityPerUnit
{
get
{
return this.GetString(ProductsSchema.QuantityPerUnit.FieldName);
}
set
{
this.SetString(ProductsSchema.QuantityPerUnit.FieldName, value);
}
}
public virtual decimal UnitPrice
{
get
{
return this.GetDecimal(ProductsSchema.UnitPrice.FieldName);
}
set
{
this.SetDecimal(ProductsSchema.UnitPrice.FieldName, value);
}
}
public virtual short UnitsInStock
{
get
{
return this.GetShort(ProductsSchema.UnitsInStock.FieldName);
}
set
{
this.SetShort(ProductsSchema.UnitsInStock.FieldName, value);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -