test notes:
IDAL/DALBase.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace IDAL
{
public class DALBase<T> : MarshalByRefObject
{
private IPersistBroker _persistBroker;
public DALBase()
{
this._persistBroker = PersistBrokerManager.PersistBroker("");
}
/// <summary>
/// 数据库连接
/// </summary>
protected IPersistBroker PersistBroker
{
get
{
return _persistBroker;
}
}
/// <summary>
/// 检查记录是否存在
/// </summary>
/// <returns>true:记录存在, false:记录不存在</returns>
public virtual bool IsExist(DomainObject obj )
{
PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
if (properties.Length <= 0)
{
return false;
}
string _field = string.Empty;
string wstr = string.Empty;
foreach (PropertyInfo item in properties)
{
string name = item.Name.Replace("_PK", "");
object value = item.GetValue(obj, null);
if (item.Name.IndexOf("_PK") > -1)
{
wstr += " " + name.Replace("_PK", "") + "='" + (value == null ? "" : value.ToString()) + "' and";
}
_field += name + ",";
}
_field = _field.TrimEnd(new char[] { ',' });
wstr = wstr.Remove(wstr.Length - 3, 3);
string tbname = "TBL" + obj.GetType().Name;
string sqlText = string.Format("SELECT {0} FROM {1} WHERE {2} ", _field, tbname, wstr);
DataSet ds = null;
ds = this.PersistBroker.Query(sqlText);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
return true;
}
return false;
}
public bool AddDomainObject(DomainObject obj)
{
try
{
try
{
DBDateTime dbDateTime = GetNowDBDateTime();
DateTime workDateTime = FormatHelper.ToDateTime(dbDateTime.DBDate, dbDateTime.DBTime);
PropertyInfo[] properties = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo item in properties)