public virtual void Remove(string objXml) { DbObject obj2 = this.Parse(objXml); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(obj2.GetType()), true); string str = obj2.GetValue(pkDynamicPropertyInfo.PropertyName).ToString(); this.InvokeGenericMethod(this.DbContext, obj2.GetType(), "Delete", new Type[] { typeof(string) }, new object[] { str }); }
public virtual DbObject Update(User user, string objXml) { DbObject obj2 = this.Parse(objXml); DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(obj2.GetType()), true); string arg = obj2.GetValue(pkDynamicPropertyInfo.PropertyName).ToString(); SqlStringBuilder builder = new SqlStringBuilder(pkDynamicPropertyInfo.DataFieldName); builder.AppendFormat(" = '{0}'", arg); DbObject des = this.InvokeGenericMethod(this.DbContext, obj2.GetType(), "QueryObject", new Type[] { typeof(string), typeof(bool) }, new object[] { builder.ToString(), true }) as DbObject; if (user != null) { this.SetLastUpdater(obj2, user.Id); } A.Commons.Utils.CloneUtils.CloneObjectIgnoreId(obj2, des); this.InvokeGenericMethod(this.DbContext, obj2.GetType(), "Update", new Type[] { obj2.GetType() }, new object[] { des }); return(des); }
/// <summary> /// Will be executed before the object is saved to the database. /// </summary> protected override void OnSaving() { if (!DbObject.IsLoaded && DbVal.IsEmpty(DbObject.GetValue("OrderNumber").Int, ValType.Int)) { _SetRightOrderNumber(); } ModProfile.CheckAndSetOSMode(DbObject, "OSMode", DbObject["OsMode"].New.String); if (!DbObject.IsLoaded) { ModProfile.IsUniqueAKProfile(DbObject); } if (!DbObject.IsDeleted) { _HandleTroubleProduct(); } base.OnSaving(); }
public static DbQuerySql CreateInsertAll(ITable table, DbObject value, DbObjectDatabase database, object userState = null) { // If the table is not configured, throw an exception. if (!table.IsConfigured) throw new DbException("Cannot create a database query for the table \'{0}\'. The table is not configured.".FormatWith(table.LocalName)); // If the table requires a database, check that a database is configured for this server. if (table.DefaultDatabase && (database == null)) throw new DbException("Cannot create a database query for the table \'{0}\'. The table requires a database but the server does not have a database configured.".FormatWith(table.LocalName)); // Check the table type matches the database object type. if (table.Type != value.GetType()) throw new DbException("Cannot create a database insert query for table \'{0}\', because object type \'{1}\' does not match the table type \'{2}\'.".FormatWith(table.LocalName, table.Type.Name, value.GetType().Name)); // Get the table name. string tableName = DbQuerySql.GetTableName(table, database); // Create the query. DbQuerySql query = new DbQuerySql( "INSERT INTO {0} ({1}) VALUES ({2})".FormatWith( DbQuerySql.GetFieldNames(table, tableName), DbQuerySql.GetFieldIndices(table, 0) ), table, userState); // Add the parameters. foreach (DbField field in table.Fields) { query.parameters.Add(value.GetValue(field.LocalName)); } // Return the query. return query; }