public int Edit <T>(DB type, Action <T> handler) where T : DataObject, new() { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(Edit <T>(cc, handler)); } }
public static T ExecProcToObject <T>(object parameter) where T : new() { using (IConnectinContext cc = DBContext.DB1) { return(ExecProcToObject <T>(cc, parameter)); } }
public static object ExecProc(object parameter) { using (IConnectinContext cc = DBContext.DB1) { return(ExecProc(cc, parameter)); } }
public int Edit <T>(IConnectinContext cc, Action <T> handler) where T : DataObject, new() { T item = new T(); handler(item); return(Edit <T>(cc, item.GetChangeFields())); }
public static object ExecProc(DB db, object parameter) { using (IConnectinContext cc = DBContext.GetConnection(db)) { return(ExecProc(cc, parameter)); } }
public static IList <T> List <T>(this string sql) where T : new() { using (IConnectinContext cc = DBContext.DB1) { return(List <T>(sql, cc)); } }
public static IList <T> List <T>(this string sql, DB db, Region region) where T : new() { using (IConnectinContext cc = DBContext.GetConnection(db)) { return(List <T>(sql, cc, region)); } }
/// <summary> /// 数据保存后处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public override void Executed(IConnectinContext cc, object data, PropertyMapper pm, string table) { Command cmd = new Command("select @@IDENTITY "); object value = cc.ExecuteScalar(cmd); pm.Handler.Set(data, Convert.ChangeType(value, pm.Handler.Property.PropertyType)); }
public static T ListFirst <T>(this string sql, DB db) where T : new() { using (IConnectinContext cc = DBContext.GetConnection(db)) { return(ListFirst <T>(sql, cc)); } }
public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, DB type, Region region, params string[] orderby) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(GetValues <RESULT, Entity>(field, cc, region, orderby)); } }
public IList <T> List <T>(JoinTable table, params string[] orders) where T : new() { using (IConnectinContext cc = DBContext.GetConnection(DB.DB1)) { return(List <T>(table, cc, null, null)); } }
public RESULT GetValue <RESULT, Entity>(IFieldInfo field) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.DB1) { return(GetValue <RESULT, Entity>(field)); } }
public static IList <T> List <T>(this string sql, string connName) where T : new() { using (IConnectinContext cc = DBContext.GetConnection(connName)) { return(List <T>(sql, cc)); } }
public T ListFirst <T>(DB type) where T : Mappings.DataObject, new() { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(ListFirst <T>(cc, null)); } }
public RESULT Min <RESULT, Entity>(string field, bool DISTINCT) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.DB1) { return(Min <RESULT, Entity>(field, DISTINCT, cc)); } }
public RESULT Avg <RESULT, Entity>(string field, bool DISTINCT, DB type) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(Avg <RESULT, Entity>(field, DISTINCT, cc)); } }
public static T GetValue <T>(this string sql) { using (IConnectinContext cc = DBContext.DB1) { return(GetValue <T>(sql, cc)); } }
public int Count <T>(string field, bool DISTINCT, DB type) where T : Mappings.DataObject { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(Count <T>(field, DISTINCT, cc)); } }
public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, params string[] orderby) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.DB1) { return(GetValues <RESULT, Entity>(field, cc, (Region)null, orderby)); } }
public IList <T> List <T>(DB type, Region region) where T : Mappings.DataObject, new() { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(List <T>(cc, region, null)); } }
public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, int pageindex, int pagesize, params string[] orderby) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.DB1) { return(GetValues <RESULT, Entity>(field, cc, new Region(pageindex, pagesize), orderby)); } }
public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, DB type, int pageindex, int pagesize) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(GetValues <RESULT, Entity>(field, cc, pageindex, pagesize)); } }
public IList <RESULT> GetValues <RESULT, Entity>(IFieldInfo field, Region region) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.DB1) { return(GetValues <RESULT, Entity>(field, cc, region)); } }
public int Edit <T>(DB type, params Field[] fields) where T : DataObject, new() { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(Edit <T>(cc, fields)); } }
public static int Execute(this string sql) { using (IConnectinContext cc = DBContext.DB1) { return(Execute(sql, cc)); } }
public int Count <T>(DB type) where T : Mappings.DataObject { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(Count <T>(cc)); } }
public static int Execute(this string sql, string connName) { using (IConnectinContext cc = DBContext.GetConnection(connName)) { return(Execute(sql, cc)); } }
public IList <T> List <T>(DB type, params string[] orderby) where T : Mappings.DataObject, new() { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(List <T>(cc, null, orderby)); } }
public static T GetValue <T>(this string sql, string connName) { using (IConnectinContext cc = DBContext.GetConnection(connName)) { return(GetValue <T>(sql, cc)); } }
public RESULT Min <RESULT, Entity>(string field, DB type) where Entity : Mappings.DataObject { using (IConnectinContext cc = DBContext.GetConnection(type)) { return(Min <RESULT, Entity>(field, false, cc)); } }
internal int Delete(IConnectinContext cc) { int result = 0; ObjectMapper om = ObjectMapper.GetOM(this.GetType()); if (om.ID == null) throw new PeanutException(DataMsg.ID_MAP_NOTFOUND); result = OnDeleteObject(cc, om.Table, om.ID.ColumnName, om.ID.Handler.Get(this)); return result; }
internal int Save(IConnectinContext cc) { int result = 0; ObjectMapper om = ObjectMapper.GetOM(this.GetType()); if (EntityState._Loaded) { if (EntityState._FieldState.Count == 0) return 0; result=EditData(cc, om); } else { if (EntityState._FieldState.Count == 0) throw new PeanutException(DataMsg.OBJECT_UPDATA_NOTFOUND); result= NewData(cc, om); EntityState._Loaded = true; } EntityState._FieldState.Clear(); return result; }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { string data = Convert.ToString(value); if (System.Text.RegularExpressions.Regex.Match( data, Regex, RegexOptions.IgnoreCase).Length == 0) { return false; } } return true; }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { string data = Convert.ToString(value); if (MinLength != null && MinLength > data.Length) { return false; } if (MaxLength != null && data.Length > MaxLength) { return false; } } return true; }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value == null) return true; if (string.IsNullOrEmpty((string)value)) return true; string sql = "select {0} from {1} where {0}=@p1"; Command cmd = new Command(string.Format(sql, pm.ColumnName, pm.OM.Table)); cmd.AddParameter("p1", value); object result = cc.ExecuteScalar(cmd); return result == null || result == DBNull.Value; }
/// <summary> /// 验证实体属性值 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> public bool Validating(object value, object source,Mappings.PropertyMapper pm,IConnectinContext cc ) { return OnValidating(value, source, pm, cc); }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected abstract bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc);
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { bool result= value != null && !string.IsNullOrEmpty(value.ToString()); if (!result && string.IsNullOrEmpty(Message)) Message = string.Format("{0}成员值不能为空!", pm.ColumnName); return result; }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { DateTime data = Convert.ToDateTime(value); if (MinValue != null) { if (MinValue >data) { return false; } } if (MaxValue != null) { if (data > MaxValue) { return false; } } } return true; }
/// <summary> /// 数据保存前处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table) { string uid = Guid.NewGuid().ToString("N"); pm.Handler.Set(data, uid); }
private int NewData(IConnectinContext cc, ObjectMapper om) { int result = 0; Insert insert = new Insert(om.Table); object value = null; if (om.ID != null) { if (om.ID.Value != null) { if (!om.ID.Value.AfterByUpdate) { om.ID.Value.Executing(cc, this, om.ID,om.Table); insert.AddField(om.ID.ColumnName, om.ID.Handler.Get(this)); } } else { insert.AddField(om.ID.ColumnName, om.ID.Handler.Get(this)); } } for(int i =0;i<om.Properties.Count;i++) { PropertyMapper pm = om.Properties[i]; if (!EntityState._FieldState.ContainsKey(pm.Handler.Property.Name)) { if (pm.Value != null && !pm.Value.AfterByUpdate) { pm.Value.Executing(cc, this, pm, om.Table); } } value = pm.Handler.Get(this); if (EntityState._FieldState.ContainsKey(pm.Handler.Property.Name)) { if (pm.Cast != null) { value = pm.Cast.ToColumn(value, pm.Handler.Property.PropertyType, this); } insert.AddField(pm.ColumnName, value); } } result=insert.Execute(cc); if (om.ID != null && om.ID.Value != null && om.ID.Value.AfterByUpdate) om.ID.Value.Executed(cc, this, om.ID,om.Table); return result; }
/// <summary> /// 数据保存后处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public virtual void Executed(IConnectinContext cc, object data, PropertyMapper pm, string table) { }
private int EditData(IConnectinContext cc,ObjectMapper om) { if (om.ID == null) throw new PeanutException(DataMsg.UPDATE_ERROR_ID_NOTFOUND); Update update = new Update(om.Table); for (int i = 0; i < om.Properties.Count; i++) { PropertyMapper pm= om.Properties[i]; System.Reflection.PropertyInfo pi = pm.Handler.Property; if (EntityState._FieldState.ContainsKey(pm.Handler.Property.Name)) { if (pm.Cast != null) { update.AddField(pm.ColumnName,"p_"+pi.Name,pm.Cast.ToColumn(pm.Handler.Get(this), pm.Handler.Property.PropertyType,this)); } else { update.AddField(pm.ColumnName, "p_" + pi.Name, pm.Handler.Get(this)); } } } update.Where.SqlText.Append(om.ID.ColumnName).Append("=@p1"); update.Where.Parameters.Add(new Command.Parameter { Name = "p1", Value = om.ID.Handler.Get(this) }); return update.Execute(cc); }
/// <summary> /// 数据保存前处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table) { pm.Handler.Set(data, true); }
/// <summary> /// 数据保存后处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public override void Executed(IConnectinContext cc, object data, PropertyMapper pm, string table) { Command cmd = new Command("select @@IDENTITY "); object value = cc.ExecuteScalar(cmd); pm.Handler.Set(data,Convert.ChangeType( value,pm.Handler.Property.PropertyType)); }
/// <summary> /// 数据保存前处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table) { pm.Handler.Set(data, DateTime.Now.Day.ToString()); }
/// <summary> /// 数据保存前处理过程 /// </summary> /// <param name="cc">数据库上下文</param> /// <param name="data">实体对象</param> /// <param name="pm">属性映射描述</param> /// <param name="table">相关表信息</param> public override void Executing(IConnectinContext cc, object data, PropertyMapper pm, string table) { if (mInputType == InputType.Int) { pm.Handler.Set(data, Enum.GetValues(pm.Handler.Property.PropertyType).GetValue((int)mValue)); } else if (mInputType == InputType.String) { Enum.Parse(pm.Handler.Property.PropertyType, mValue.ToString()); } else { pm.Handler.Set(data, Enum.GetValues(pm.Handler.Property.PropertyType).GetValue(0)); } }