Beispiel #1
0
        /// <summary>
        ///     获取值的类型
        /// </summary>
        /// <param name="type">值类型</param>
        /// <param name="id">如果是列表页面需要传入ID,编辑页面不需要传入</param>
        public object GetValue(Type type, Guid id)
        {
            var report = GetReport(type.FullName);
            var values = new List <object>();
            var data   = Activator.CreateInstance(type);

            if (report != null)
            {
                var reportDescription = new ClassDescription(data.GetType());
                if (reportDescription.ClassPropertyAttribute.PageType == ViewPageType.List)
                {
                    var request = JsonConvert.DeserializeObject <List <JObject> >(report.Value);
                    foreach (var item in request)
                    {
                        PropertyDescription.SetValue(data, item);
                        if (data.GetType().GetProperty("Id").GetValue(data).ToString() == id.ToString())
                        {
                            return(data);
                        }
                    }
                }
                else
                {
                    var request = JsonConvert.DeserializeObject <JObject>(report.Value);
                    PropertyDescription.SetValue(data, request);
                    return(data);
                }

                return(Activator.CreateInstance(type));
            }

            return(Activator.CreateInstance(type));
        }
Beispiel #2
0
        /// <summary>
        ///     获取值的类型
        /// </summary>
        /// <param name="type">值类型</param>
        /// <param name="id">如果是列表页面需要传入ID,编辑页面不需要传入</param>
        public object GetValue(Type type, Guid id)
        {
            var config = GetConfig(type.FullName);
            var data   = Activator.CreateInstance(type);

            // 如果包含Id的字段
            var idField = type.GetProperty("Id");

            if (idField != null)
            {
                if (id.IsGuidNullOrEmpty())
                {
                    return(data);
                }
            }

            if (config != null)
            {
                var configDescription = new ClassDescription(data.GetType());
                var classDescription  = new ClassDescription(type);
                //获取  Json有扩展的属性
                var propertys = classDescription.Propertys.Where(r => !r.FieldAttribute.ExtensionJson.IsNullOrEmpty())
                                .ToList();

                if (configDescription.ClassPropertyAttribute.PageType == ViewPageType.List)
                {
                    var request = JsonConvert.DeserializeObject <List <JObject> >(config.Value);
                    foreach (var item in request)
                    {
                        PropertyDescription.SetValue(data, item);
                        if (data.GetType().GetProperty("Id").GetValue(data).ToString() == id.ToString())
                        {
                            if (propertys.Any())
                            {
                                // json 格式数据处理
                                data = item.ToObject(type);
                                return(data);
                            }

                            return(data);
                        }
                    }
                }
                else
                {
                    var request = JsonConvert.DeserializeObject <JObject>(config.Value);
                    PropertyDescription.SetValue(data, request);
                    //  data = JsonMapping.HttpContextToExtension(data, type, HttpContext);
                    return(data);
                }

                return(Activator.CreateInstance(type));
            }

            return(Activator.CreateInstance(type));
        }
Beispiel #3
0
        private void GetOtoRelationValue(ref EntityBase entity, DataRow row,
                                         RelationAttribute relAttr, PropertyDescription property)
        {
            Cryptany.Core.DPO.Mapper m = new Mapper(relAttr.RelatedType, _ps);
            //DataView dvChild = new DataView(UnderlyngDataSet.Tables[m.TableName]);
            object id = row[Mapper[property.Name]];

            //CreateFilterString(m[relAttr.RelatedColumn], dvChild, id);
            //object oId = GetIdAsObject(id);
            if (id == null || id == DBNull.Value)
            {
                return;
            }
            IEntity e = _ps.GetEntityById(relAttr.RelatedType, id);

            property.SetValue(entity, e);
        }
Beispiel #4
0
        public List <object> GetObjectList(Type type)
        {
            var list   = new List <object>();
            var report = GetReport(type.FullName);

            if (report != null)
            {
                var request = JsonConvert.DeserializeObject <List <JObject> >(report.Value);
                foreach (var item in request)
                {
                    var data = Activator.CreateInstance(type);
                    PropertyDescription.SetValue(data, item);
                    list.Add(data);
                }
            }

            return(list);
        }
Beispiel #5
0
        private object GetValue(Type type)
        {
            var report = GetReport(type.FullName);

            if (report != null)
            {
                var reportDescription = new ClassDescription(report.GetType());
                ///如果是编辑页面获取数据库里头的字,如果列表页面使用 GetList<T>来获取值
                ///如果列表页面编辑的时候,应该要传入ID
                if (reportDescription.ClassPropertyAttribute.PageType == ViewPageType.Edit)
                {
                    var data    = Activator.CreateInstance(type);
                    var request = JsonConvert.DeserializeObject <JObject>(report.Value);
                    PropertyDescription.SetValue(data, request);
                    return(data);
                }

                return(Activator.CreateInstance(type));
            }

            return(Activator.CreateInstance(type));
        }
Beispiel #6
0
        public IEnumerable <SelectListItem> GetList <T>(Func <T, bool> predicate, Func <T, object> textSelector,
                                                        Func <T, object> valueSelector) where T : class, IReport
        {
            var report = GetReport(typeof(T).FullName);
            var values = new List <T>();

            if (report != null)
            {
                var request = JsonConvert.DeserializeObject <List <JObject> >(report.Value);
                foreach (var item in request)
                {
                    var data = (T)Activator.CreateInstance(typeof(T));
                    PropertyDescription.SetValue(data, item);
                    values.Add(data);
                }
            }
            else
            {
                return(null);
            }

            return(FromIEnumerable(values.Where(predicate).ToList(), textSelector, valueSelector));
        }