|
/*
* This is the base class for all Businsess Objects
* It Contains Common method for populating business object
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
public abstract class AWBase
{
protected string SqlSelectString;
protected Type BusObjectType;
protected List<AWBase> LoadData()
{
List<AWBase> _list = new List<AWBase>();
DBHelper dbHelper = new DBHelper();
//Get Data
DataTable dtBusinessObject = dbHelper.RetrieveTable(SqlSelectString);
//Custom Attributes
object[] attributes = BusObjectType.GetCustomAttributes(typeof(MapInfo), false);
//Loop through all records in Table
if (dtBusinessObject != null && dtBusinessObject.Rows.Count > 1)
{
for (int introw = 0; introw < dtBusinessObject.Rows.Count; introw++)
{
AWBase busObject = (AWBase)Activator.CreateInstance(BusObjectType);
//loop through all custom attributes
for (int i = 0; i < attributes.Length; i++)
{
MapInfo mapinfo = (MapInfo)attributes[i];
object DBValue = dtBusinessObject.Rows[introw][mapinfo.DBFieldName];
PropertyInfo pinfo = BusObjectType.GetProperty(mapinfo.ObjPropertyName);
pinfo.SetValue(busObject, DBValue.GetType() == typeof(DBNull) ? null: DBValue, null);
}
_list.Add(busObject);
}
}
return _list;
}
}
|
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.
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
MCSD.NET Early Achiever,MCDBA SQL 2000,MCITP SQL 2005 Charter Member,MCPD Charter Member