コード例 #1
0
        public string GetObjectDisplayName(SysEntity entity, int object_id)
        {
            EntityData data = this.GetObject(entity, object_id);

            if (data != null)
            {
                string displayFieldName = entity.GetDisplayFieldName();
                if (data.ContainsKey(displayFieldName))
                {
                    return(Convert.ToString(data[displayFieldName]));
                }
            }
            return(null);
        }
コード例 #2
0
        public static SysField GetDisplayField(this SysEntity entity, DataContext context)
        {
            string key_name = entity.GetDisplayFieldName();

            if (entity.Fields == null)
            {
                throw new ApplicationException("entity.Fieds没有加载");
            }
            SysField field = context.FirstOrDefault <SysField>(f => (f.EntityId == entity.EntityId) && (f.FieldName == key_name));

            if (field == null)
            {
                throw new ApplicationException(string.Format("没有找到显示字段:{0} -{1}", entity.EntityName, key_name));
            }
            return(field);
        }
コード例 #3
0
        private static void LoadEntitySchema()
        {
            EntityCacheBase cache = EntityCacheBase.LoadCache();

            using (List <SysEntity> .Enumerator enumerator = cache.SysEntity.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Func <SysMobileStepEntity, bool> predicate = null;
                    SysEntity    e         = enumerator.Current;
                    EntitySchema es        = new EntitySchema();
                    bool?        isHistory = e.IsHistory;
                    es.IsHistory = isHistory.HasValue ? isHistory.GetValueOrDefault() : false;
                    SysOneMoreRelation relation = e.ChildOneMoreRelations.FirstOrDefault <SysOneMoreRelation>(p => p.Is_Tree == true);
                    if (relation != null)
                    {
                        es.TreeRelationFieldName = relation.ChildField.FieldName;
                    }
                    es.IsChangeTableVersion = false;
                    if (predicate == null)
                    {
                        predicate = delegate(SysMobileStepEntity p) {
                            long?entityId = p.EntityId;
                            long num      = e.EntityId;
                            return((entityId.GetValueOrDefault() == num) && entityId.HasValue);
                        };
                    }
                    if (cache.SysMobileStepEntity.Where <SysMobileStepEntity>(predicate).Count <SysMobileStepEntity>() > 0)
                    {
                        es.IsChangeTableVersion = true;
                    }
                    es.EntityId    = e.EntityId;
                    es.EntityName  = e.EntityName;
                    es.KeyName     = e.GetKeyFieldName();
                    es.EntityType  = cache.GetEntityType(e.EntityId);
                    es.DisplayName = e.GetDisplayFieldName();
                    int?privilegeMode = e.PrivilegeMode;
                    es.PrivilegeMode = privilegeMode.HasValue ? privilegeMode.GetValueOrDefault() : -2147483647;
                    privilegeMode    = e.RequiredLevel;
                    es.RequiredLevel = privilegeMode.HasValue ? privilegeMode.GetValueOrDefault() : -2147483647;
                    LoadUniqueKey(es, e, cache);
                    LoadFields(es, e, cache);
                    LoadRelations(es, e, cache);
                    Add(es);
                }
            }
        }
コード例 #4
0
        internal EntityData LoadFullWithEntity(SysEntity entity, int object_id, ProcessInstanceCacheFactory piCacheFactory)
        {
            EntityData data      = null;
            Type       tableType = TableCache.GetTableType(entity.EntityName);
            object     obj2      = this.context.FindById(tableType, new object[] { object_id });

            if (obj2 != null)
            {
                data = ObjectToEntityData(obj2, entity);
            }
            if (data != null)
            {
                EntityCache cache = new EntityCache(this);
                using (IEnumerator <SysField> enumerator = entity.Fields.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Func <SysEnumItem, bool> predicate = null;
                        SysField p = enumerator.Current;
                        if (p.DataType == 12)
                        {
                            if ((p.RefEntity != null) && (data[p.FieldName] != null))
                            {
                                string     displayFieldName = p.RefEntity.GetDisplayFieldName();
                                EntityData da = cache.GetObject(p.RefEntity, (int)data[p.FieldName]);
                                if (da == null)
                                {
                                    throw new ApplicationException(string.Format("[{0}]-[{1}]的引用字段[{2}]有值[{3}],但是对应的[{4}]不存在", new object[] { entity.EntityName, object_id, p.FieldName, data[p.FieldName], p.RefEntity.EntityName }));
                                }
                                if (da.ContainsKey(displayFieldName))
                                {
                                    da[p.FieldName] = data[displayFieldName];
                                }
                            }
                        }
                        else
                        {
                            if (p.DataType == 13)
                            {
                                if (((p.RefEnum != null) && (p.RefEnum.EnumItems != null)) && (data[p.FieldName] != null))
                                {
                                    if (predicate == null)
                                    {
                                        predicate = delegate(SysEnumItem i) {
                                            int?itemValue = i.ItemValue;
                                            int num       = (int)data[p.FieldName];
                                            return((itemValue.GetValueOrDefault() == num) && itemValue.HasValue);
                                        };
                                    }
                                    SysEnumItem item = p.RefEnum.EnumItems.FirstOrDefault <SysEnumItem>(predicate);
                                    if (item != null)
                                    {
                                        data[p.FieldName] = item.DisplayText;
                                    }
                                }
                                continue;
                            }
                            if (p.DataType == 11)
                            {
                                if (data[p.FieldName].ToInt() == 0)
                                {
                                    data[p.FieldName] = "否";
                                }
                                else
                                {
                                    data[p.FieldName] = "是";
                                }
                                continue;
                            }
                            if ((p.DataType == 15) && (data[p.FieldName] != null))
                            {
                                string[] source = data[p.FieldName].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                if (source.Count <string>() != 2)
                                {
                                    throw new ApplicationException(string.Format("[{0}]中[entity_id]或者[object_id]缺失", data[p.FieldName]));
                                }
                                long      entityId    = source[0].ToLong();
                                int       num2        = source[1].ToInt();
                                SysEntity entityCache = piCacheFactory.PCacheFactory.GetEntityCache(entityId);
                                if (entityCache != null)
                                {
                                    string     key   = entityCache.GetDisplayFieldName();
                                    EntityData data2 = cache.GetObject(entityCache, num2);
                                    if (data2 == null)
                                    {
                                        throw new ApplicationException(string.Format("[{0}]-[{1}]的引用字段[{2}]有值[{3}],但是对应的[{4}]不存在", new object[] { entity.EntityName, num2, p.FieldName, data[p.FieldName], entityCache.EntityName }));
                                    }
                                    if (data2.ContainsKey(key))
                                    {
                                        data[p.FieldName] = data2[key];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(data);
        }