public void Insert <T>(dynamic tran, T entity) where T : new() { if (entity == null) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "the object which want to update is null."); } Type info = typeof(T); DataTable dt = EntityConvertor <T> .ToDataTable(new List <T>() { entity }); DBHelper.GetInstance(mContext).InsertTable(tran, dt, "_" + info.Name); }
public void InsertList <T>(dynamic tran, List <T> list) where T : new() { if (list == null || list.Count == 0) { throw new FinanceException(FinanceResult.IMPERFECT_DATA, "the object which want to update is null or empty."); } Type info = typeof(T); DataTable dt = EntityConvertor <T> .ToDataTable(list); DBHelper.GetInstance(mContext).InsertTable(tran, dt, "_" + info.Name); }
public List <T> Query <T>(dynamic tran, T entity) where T : new() { Type info = typeof(T); var members = info.GetProperties(); string filter = string.Empty; if (entity != null) { object val = null; foreach (var mi in members) { if (mi.PropertyType == typeof(string) || mi.PropertyType == typeof(char)) { val = mi.GetValue(entity, null); if (val != null && !val.Equals(string.Empty)) { filter = appendfilter(filter, "_" + mi.Name + " = '" + val + "'"); } } else if (mi.PropertyType == typeof(long) || mi.PropertyType == typeof(decimal) || mi.PropertyType == typeof(byte) || mi.PropertyType == typeof(sbyte) || mi.PropertyType == typeof(short) || mi.PropertyType == typeof(int) || mi.PropertyType == typeof(ushort) || mi.PropertyType == typeof(uint) || mi.PropertyType == typeof(ulong) || mi.PropertyType == typeof(float) || mi.PropertyType == typeof(double)) { val = mi.GetValue(entity, null); if (!(decimal.Parse(val.ToString())).Equals(decimal.Zero)) { filter = appendfilter(filter, "_" + mi.Name + " = " + val + ""); } } else { } } } string tableName = "_" + info.Name; string sql = string.Format("select * from {0} ", tableName); if (!string.IsNullOrEmpty(filter)) { sql += " where " + filter; } DataTable dt = DBHelper.GetInstance(mContext).ExecuteDt(tran, sql); return(EntityConvertor <T> .ToList(dt)); }