Example #1
0
        /// <summary>
        ///     get group
        /// </summary>
        /// <param name="propertys"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private static FieldGroup GetGroup(PropertyDescription[] propertys, object model)
        {
            var fieldGroup = new FieldGroup {
                GroupName = "default"
            };

            fieldGroup.Items.AddRange(GetFormFieds(propertys, model));
            return(fieldGroup);
        }
Example #2
0
        /// <summary>
        ///     将视图转成AutoForm
        /// </summary>
        /// <param name="fullName"></param>
        /// <returns></returns>
        public static AutoForm Convert(string fullName)
        {
            var objectCache = Ioc.Resolve <IObjectCache>();

            return(objectCache.GetOrSet(() => {
                var classDescription = fullName.GetClassDescription();
                if (classDescription != null)
                {
                    var classPropertyAttribute = classDescription.ClassPropertyAttribute;
                    var auto = new AutoForm {
                        Key = fullName,
                        Name = classPropertyAttribute.Name,
                        ViewLinks = classDescription.ViewLinks,
                        Title = classPropertyAttribute.Name,
                    };
                    // 构建字段

                    var groups = classPropertyAttribute.GroupName.Split(",");
                    var propertys = classDescription.Propertys;

                    if (groups.Length == 0)
                    {
                        var fieldGroup = new FieldGroup {
                            GroupName = "default"
                        };
                        fieldGroup.Items.AddRange(GetFormFieds(propertys));
                        auto.Groups.Add(fieldGroup);
                    }
                    else
                    {
                        // 多标签
                        long i = 0;
                        foreach (var group in groups)
                        {
                            i++;
                            var fieldGroup = new FieldGroup();
                            fieldGroup.GroupName = group;
                            var groupPropertys = propertys.Where(r => r.FieldAttribute?.GroupTabId == i).ToArray();
                            if (group.Trim().IsNullOrEmpty())
                            {
                                groupPropertys = propertys;
                            }

                            fieldGroup.Items.AddRange(GetFormFieds(groupPropertys));
                            auto.Groups.Add(fieldGroup);
                        }
                    }

                    return auto;
                }

                return null;
            }, fullName + "AutoForm").Value);
        }
Example #3
0
        /// <summary>
        ///     convert to auto form from model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static AutoForm Convert(object model)
        {
            //cache class descrption
            var fullName         = model.GetType().FullName;
            var classDescription = fullName.GetClassDescription();

            if (classDescription == null)
            {
                return(null);
            }
            var classPropertyAttribute = classDescription.ClassPropertyAttribute;
            var auto = new AutoForm {
                Key = fullName,

                ViewLinks = classDescription.ViewLinks,
            };

            auto.Border = new Border(classPropertyAttribute);
            // builder filed
            var groups    = classPropertyAttribute.GroupName.Split(",");
            var propertys = classDescription.Propertys;

            if (groups.Length == 0)
            {
                var fieldGroup = new FieldGroup {
                    GroupName = "default"
                };
                fieldGroup.Items.AddRange(GetFormFieds(propertys, model));
                auto.Groups.Add(fieldGroup);
            }
            else
            {
                //group
                long i = 0;
                foreach (var group in groups)
                {
                    i++;
                    var fieldGroup = new FieldGroup();
                    fieldGroup.GroupName = group;
                    var groupPropertys = propertys.Where(r => r.FieldAttribute?.GroupTabId == i).ToArray();
                    if (group.Trim().IsNullOrEmpty())
                    {
                        groupPropertys = propertys;
                    }

                    fieldGroup.Items.AddRange(GetFormFieds(groupPropertys, model));
                    auto.Groups.Add(fieldGroup);
                }
            }

            return(auto);
        }