コード例 #1
0
ファイル: CommonOperation.cs プロジェクト: rhdlmv/aopiocwcf
        private void SetLastUpdater(object obj, string userId)
        {
            DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(obj.GetType());

            if (DbObjectTools.GetDynamicPropertyInfo(obj.GetType(), "LastUpdateUserId") != null)
            {
                ((DbObject)obj).SetValue <string>("LastUpdateUserId", userId);
            }
        }
コード例 #2
0
        public static List <string> GetModelNames(Module module)
        {
            List <string> list = new List <string>();

            foreach (Type type in module.GetTypes())
            {
                DbObjectInfo dbObjectInfo = DbObjectTools.GetDbObjectInfo(type);
                list.Add(dbObjectInfo.TableName);
            }
            return(list);
        }
コード例 #3
0
        public void Delete <T>(string id) where T : DbObject, new()
        {
            IDbObjectInfo <T>   dbObjectInfo          = this.DbRuleContext.GetDbObjectInfo <T>();
            DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(typeof(T)), true);
            T model = this.QueryObject <T>(pkDynamicPropertyInfo.DataFieldName, id, true);

            dbObjectInfo.SetModifyDatetime(model);
            if (dbObjectInfo.IsLogicalDelete)
            {
                dbObjectInfo.SetLogicalDelete(model);
                this.DbObjectOperator.Update(model);
            }
            else
            {
                this.DbObjectOperator.Delete(model);
            }
        }
コード例 #4
0
ファイル: CommonOperation.cs プロジェクト: rhdlmv/aopiocwcf
        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);
        }
コード例 #5
0
ファイル: CommonOperation.cs プロジェクト: rhdlmv/aopiocwcf
        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 });
        }
コード例 #6
0
 private void BindUpdateCloneFunction()
 {
     this.UpdateCloneFunction = null;
     if (this.UpdateExceptFields.Count > 0)
     {
         Func <T, T, T> cloneFunction = this.GetCloneModelFunction((from t in this.UpdateExceptFields select t.ObjectFieldName).ToArray <string>());
         this.UpdateCloneFunction = delegate(IDbContext context, T model, string[] updateFields)
         {
             Func <T, T, T> cloneModelFunction = cloneFunction;
             if (updateFields != null)
             {
                 cloneModelFunction = this.GetCloneModelFunction((from t in this.AllFields
                                                                  where this.UpdateExceptFields.Contains(t) || (!t.ReadOnly && !updateFields.Contains <string>(t.ObjectFieldName))
                                                                  select t.ObjectFieldName).ToArray <string>());
             }
             DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(typeof(T)), true);
             object obj2  = model.GetValue(pkDynamicPropertyInfo.PropertyName);
             T      local = context.QueryObject <T>(pkDynamicPropertyInfo.DataFieldName, obj2, true);
             cloneModelFunction(model, local);
             return(local);
         };
     }
 }
コード例 #7
0
        private void BindRemoveCloneFunction()
        {
            Func <PropertyInfo, bool>       predicate = null;
            Func <DataFieldAttribute, bool> func2     = null;

            this.RemoveCloneFunction = null;
            if (this.LogicalDeleteField != null)
            {
                if (predicate == null)
                {
                    predicate = p => p.Name == LogicalDeleteField.ObjectFieldName;
                }
                PropertyInfo property = this.PropertyInfos.FirstOrDefault <PropertyInfo>(predicate);
                if (func2 == null)
                {
                    func2 = f => f.ObjectFieldName != LogicalDeleteField.ObjectFieldName;
                }
                DataFieldAttribute[] attributeArray = this.AllFields.Where <DataFieldAttribute>(func2).ToArray <DataFieldAttribute>();
                Func <T, T, T>       cloneFunction  = this.GetCloneModelFunction((from t in attributeArray select t.ObjectFieldName).ToArray <string>());
                this.RemoveCloneFunction = delegate(IDbContext context, T model)
                {
                    DynamicPropertyInfo pkDynamicPropertyInfo = DbObjectTools.GetPkDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(typeof(T)), true);
                    object obj2  = model.GetValue(pkDynamicPropertyInfo.PropertyName);
                    T      local = context.QueryObject <T>(pkDynamicPropertyInfo.DataFieldName, obj2, false);
                    if (local != null)
                    {
                        cloneFunction(model, local);
                        property.SetValue(local, true, null);
                        property.SetValue(model, true, null);
                    }
                    return(local);
                };
            }
        }