예제 #1
0
        public static AutoList Convert(string fullName)
        {
            var objectCache = Ioc.Resolve <IObjectCache>();

            return(objectCache.GetOrSet(() => {
                var type = fullName.GetTypeByFullName();

                var classDescription = fullName.GetClassDescription();
                if (classDescription != null)
                {
                    var classPropertyAttribute = classDescription.ClassPropertyAttribute;

                    var auto = new AutoList {
                        Key = fullName,
                        Name = classPropertyAttribute.Name,
                        Icon = classPropertyAttribute.Icon
                    };

                    var propertys = classDescription.Propertys;
                    auto.SearchOptions = AutoTableMapping.GetSearchOptions(propertys);

                    //tabs
                    auto.Tabs = AutoTableMapping.GetTabs(propertys);

                    foreach (var item in propertys)
                    {
                        if (item.FieldAttribute != null && item.FieldAttribute.ListShow)
                        {
                            if (item.Name == "Id")
                            {
                                continue;
                            }

                            var tableColumn = new TableColumn {
                                Label = item.DisplayAttribute?.Name,
                                Prop = item.Property.Name.ToFristLower(),

                                Width = item.FieldAttribute.Width
                            };
                            tableColumn = AutoTableMapping.GetType(tableColumn, item.Property, item.FieldAttribute);
                            if (!item.FieldAttribute.Width.IsNullOrEmpty())
                            {
                                tableColumn.Width = item.FieldAttribute.Width;
                            }
                        }
                    }

                    return auto;
                }

                return null;
            }, fullName + "AutoList").Value);
        }
예제 #2
0
        public Tuple <ServiceResult, AutoTable> TableNoData(string type, object query, AutoBaseModel autoBaseModel)
        {
            Type      typeFind     = null;
            object    instanceFind = null;
            AutoTable autoTable    = null;
            var       checkType    = Resolve <IUIBaseService>().CheckType(type, ref typeFind, ref instanceFind);

            if (!checkType.Succeeded)
            {
                return(new Tuple <ServiceResult, AutoTable>(checkType, new AutoTable()));
            }

            autoTable = AutoTableMapping.Convert(typeFind.FullName);

            return(new Tuple <ServiceResult, AutoTable>(ServiceResult.Success, autoTable));
        }
예제 #3
0
        public Tuple <ServiceResult, AutoTable> Table(string type, object query, AutoBaseModel autoBaseModel)
        {
            Type   typeFind     = null;
            object instanceFind = null;

            var checkType = Resolve <IUIBaseService>().CheckType(type, ref typeFind, ref instanceFind);

            if (!checkType.Succeeded)
            {
                return(new Tuple <ServiceResult, AutoTable>(checkType, new AutoTable()));
            }

            var autoTable = AutoTableMapping.Convert(typeFind.FullName);

            #region IAutoTable类型

            // 如果是IAutoTable类型,则数据从AutoTable中获取,否则从Api接口中获取
            if (instanceFind is IAutoTable)
            {
                var target     = new Interpreter().SetVariable("autoTable", instanceFind);
                var parameters = new[]
                {
                    new Parameter("query", query),
                    new Parameter("baseModel", autoBaseModel)
                };
                try {
                    autoTable.Result = target.Eval("autoTable.PageTable(query,baseModel)", parameters);
                } catch (Exception ex) {
                    return(new Tuple <ServiceResult, AutoTable>(ServiceResult.FailedWithMessage(ex.Message),
                                                                new AutoTable()));
                }
            }

            #endregion IAutoTable类型

            #region autoConfig类型

            else if (instanceFind is IAutoConfig)
            {
                var data   = Resolve <IAlaboAutoConfigService>().GetObjectList(typeFind);
                var result = PagedList <object> .Create(data, data.Count, 100, 1);

                var apiRusult = new PageResult <object> {
                    PageCount   = result.PageCount,
                    Result      = result,
                    RecordCount = result.RecordCount,
                    CurrentSize = result.CurrentSize,
                    PageIndex   = result.PageIndex,
                    PageSize    = result.PageSize
                };
                autoTable.Result = apiRusult;
            }
            else if (instanceFind is IEntity)
            {
                var result = DynamicService.ResolveMethod(typeFind.Name, "GetApiPagedList", query);
                if (!result.Item1.Succeeded)
                {
                    return(new Tuple <ServiceResult, AutoTable>(result.Item1, new AutoTable()));
                }

                autoTable.Result = result.Item2;
            }

            #endregion autoConfig类型

            return(new Tuple <ServiceResult, AutoTable>(ServiceResult.Success, autoTable));
        }