예제 #1
0
        /// <summary>
        /// 生成默认视图
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public (Domain.QueryView DefaultView, List <Dependency.Domain.Dependency> Dependents) Get(Schema.Domain.Entity entity, List <Schema.Domain.Attribute> attributes)
        {
            Domain.QueryView view = new Domain.QueryView
            {
                Name        = entity.LocalizedName,
                EntityId    = entity.EntityId,
                EntityName  = entity.Name,
                IsDefault   = true,
                StateCode   = Core.RecordState.Enabled,
                IsPrivate   = false,
                QueryViewId = Guid.NewGuid(),
                CreatedBy   = entity.CreatedBy
            };
            //fetch
            QueryExpression _queryExpression = new QueryExpression(entity.Name, _appContext.GetFeature <ICurrentUser>().UserSettings.LanguageId);

            _queryExpression.Distinct = false;
            _queryExpression.NoLock   = true;
            _queryExpression.AddOrder("createdon", OrderType.Descending);
            var primaryField = attributes.Find(n => n.IsPrimaryField);

            _queryExpression.ColumnSet = new ColumnSet(primaryField.Name.ToLower(), "createdon");
            if (entity.EntityMask == EntityMaskEnum.User)
            {
                _queryExpression.ColumnSet.AddColumn("ownerid");
            }
            view.FetchConfig = _queryExpression.SerializeToJson();
            //layout
            GridDescriptor grid = new GridDescriptor();
            RowDescriptor  row  = new RowDescriptor();

            row.AddCell(new CellDescriptor()
            {
                Name = primaryField.Name.ToLower(), EntityName = entity.Name, IsHidden = false, IsSortable = true, Width = 150
            });
            row.AddCell(new CellDescriptor()
            {
                Name = "createdon", EntityName = entity.Name, IsHidden = false, IsSortable = true, Width = 150
            });
            if (entity.EntityMask == EntityMaskEnum.User)
            {
                row.AddCell(new CellDescriptor()
                {
                    Name = "ownerid", EntityName = entity.Name, IsHidden = false, IsSortable = true, Width = 150
                });
            }
            grid.AddRow(row);
            grid.AddSort(new QueryColumnSortInfo("createdon", false));
            view.LayoutConfig = grid.SerializeToJson(false);

            var dependents = new List <Dependency.Domain.Dependency>();

            foreach (var item in attributes.Where(x => x.Name.IsCaseInsensitiveEqual(primaryField.Name) || x.Name.IsCaseInsensitiveEqual("createdon") || x.Name.IsCaseInsensitiveEqual("ownerid")))
            {
                var dp = new Dependency.Domain.Dependency();
                //dp.DependentComponentType = DependencyComponentTypes.Get(QueryViewDefaults.ModuleName);
                dp.DependentObjectId = view.QueryViewId;
                //dp.RequiredComponentType = DependencyComponentTypes.Get(AttributeDefaults.ModuleName);
                dp.RequiredObjectId = item.AttributeId;
                dependents.Add(dp);
            }
            return(view, dependents);
        }
예제 #2
0
        /// <summary>
        /// 生成默认表单
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public (Domain.SystemForm DefaultForm, List <Dependency.Domain.Dependency> Dependents) Get(Schema.Domain.Entity entity)
        {
            Domain.SystemForm form = new Domain.SystemForm
            {
                CanBeDeleted = false,
                CreatedBy    = entity.CreatedBy,
                CreatedOn    = DateTime.Now,
                Description  = _loc["form_default"],
                EntityId     = entity.EntityId,
                FormType     = (int)FormType.Main,
                Name         = entity.LocalizedName,
                StateCode    = RecordState.Enabled,
                SystemFormId = Guid.NewGuid(),
                IsDefault    = true
            };

            var            nameAttribute = _defaultAttributeProvider.GetSysAttributes(entity).Find(x => x.Name.IsCaseInsensitiveEqual("name"));
            FormDescriptor formObj       = new FormDescriptor();

            formObj.Name      = entity.LocalizedName;
            formObj.IsShowNav = false;
            formObj.Panels    = new List <PanelDescriptor>
            {
                new PanelDescriptor()
                {
                    Name = _loc["form_information"]
                    ,
                    Label = _loc["form_information"]
                    ,
                    IsExpanded = true
                    ,
                    IsShowLabel = true
                    ,
                    IsVisible = true
                    ,
                    Sections = new List <SectionDescriptor>()
                    {
                        new SectionDescriptor()
                        {
                            IsShowLabel = false
                            , IsVisible = true
                            , Label     = _loc["form_information"]
                            , Columns   = 2
                            , Rows      = new List <RowDescriptor>()
                            {
                                new RowDescriptor()
                                {
                                    IsVisible = true
                                    , Cells   = new List <CellDescriptor>()
                                    {
                                        new CellDescriptor()
                                        {
                                            IsShowLabel = true, IsVisible = true, Label = nameAttribute.LocalizedName, Control = new ControlDescriptor()
                                            {
                                                EntityName = entity.Name, Name = "name", ControlType = FormControlType.Standard
                                            }
                                        }
                                        , new CellDescriptor()
                                        {
                                            Control = new ControlDescriptor()
                                            {
                                                ControlType = FormControlType.None
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            form.FormConfig = formObj.SerializeToJson(false);
            var dp = new Dependency.Domain.Dependency();

            //dp.DependentComponentType = DependencyComponentTypes.Get(FormDefaults.ModuleName);
            dp.DependentObjectId = form.SystemFormId;
            //dp.RequiredComponentType = DependencyComponentTypes.Get(AttributeDefaults.ModuleName);
            dp.RequiredObjectId = nameAttribute.AttributeId;
            var dependents = new List <Dependency.Domain.Dependency>()
            {
                dp
            };

            return(form, dependents);
        }