Esempio n. 1
0
 public bool Create(Domain.SystemForm entity)
 {
     return(CreateCore(entity, (n) =>
     {
         _dependencyService.Create(entity);
     }));
 }
Esempio n. 2
0
 public bool Update(Domain.SystemForm entity)
 {
     if (entity.FormType == (int)FormType.Main)
     {
         _formService.Init(entity);
         //依赖于字段
         _dependencyService.Update(FormDefaults.ModuleName, entity.SystemFormId, AttributeDefaults.ModuleName, _formService.AttributeMetaDatas.Select(x => x.AttributeId).ToArray());
         //依赖于按钮
         if (entity.IsCustomButton && entity.CustomButtons.IsNotEmpty())
         {
             var buttonIds = new Guid[] { }.DeserializeFromJson(entity.CustomButtons);
             if (buttonIds.NotEmpty())
             {
                 _dependencyService.Update(FormDefaults.ModuleName, entity.SystemFormId, RibbonButtonDefaults.ModuleName, buttonIds);
             }
         }
         //依赖于视图(单据体)
         var queryViewIds = entity.GetQueryViewIds();
         if (queryViewIds.NotEmpty())
         {
             _dependencyService.Update(FormDefaults.ModuleName, entity.SystemFormId, QueryViewDefaults.ModuleName, queryViewIds.ToArray());
         }
     }
     return(true);
 }
Esempio n. 3
0
        private bool CreateCore(Domain.SystemForm entity, Action <Domain.SystemForm> createDependents)
        {
            if (entity.FormConfig.IsEmpty())
            {
                return(false);
            }
            entity.OrganizationId = _appContext.OrganizationId;
            _formService.Init(entity);
            var result = true;

            using (UnitOfWork.Build(_systemFormRepository.DbContext))
            {
                result = _systemFormRepository.Create(entity);
                //依赖项
                createDependents?.Invoke(entity);
                //本地化标签
                _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), entity.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, "LocalizedName", entity.SystemFormId)
                .Append(entity.SolutionId, entity.Description.IfEmpty(""), entity.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, "Description", entity.SystemFormId)
                .Save();
                _formService.UpdateLocalizedLabel(null);
                if (entity.FormType == (int)FormType.Dashboard)
                {
                    //solution component
                    result = _solutionComponentService.Create(entity.SolutionId, entity.SystemFormId, DashBoardDefaults.ModuleName);
                }
                //add to cache
                _cacheService.SetEntity(_systemFormRepository.FindById(entity.SystemFormId));
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取表单引用的视图
        /// </summary>
        /// <param name="systemForm"></param>
        /// <returns></returns>
        public static List <Guid> GetQueryViewIds(this Domain.SystemForm systemForm)
        {
            var         form   = new FormDescriptor().DeserializeFromJson(systemForm.FormConfig);
            List <Guid> result = new List <Guid>();

            if (form.Panels.NotEmpty())
            {
                //tabs
                foreach (var tab in form.Panels)
                {
                    foreach (var sec in tab.Sections)
                    {
                        foreach (var row in sec.Rows)
                        {
                            foreach (var cell in row.Cells)
                            {
                                if (cell.Control.ControlType == FormControlType.SubGrid)
                                {
                                    result.Add(new Guid((cell.Control.Parameters as SubGridParameters).ViewId));
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
        public bool Update(Domain.SystemForm entity, bool updatedConfig)
        {
            var original = _systemFormRepository.FindById(entity.SystemFormId);
            var result   = true;

            _formService.Init(entity);
            using (UnitOfWork.Build(_systemFormRepository.DbContext))
            {
                result = _systemFormRepository.Update(entity);
                _dependencyService.Update(entity);
                //localization
                _localizedLabelService.Update(entity.Name.IfEmpty(""), "LocalizedName", entity.SystemFormId, _appContext.BaseLanguage);
                _localizedLabelService.Update(entity.Description.IfEmpty(""), "Description", entity.SystemFormId, _appContext.BaseLanguage);
                if (updatedConfig)
                {
                    _formService.UpdateLocalizedLabel(original);
                }
                //assigning roles
                if (original.AuthorizationEnabled || !entity.AuthorizationEnabled)
                {
                    _eventPublisher.Publish(new AuthorizationStateChangedEvent
                    {
                        ObjectId = new List <Guid> {
                            entity.SystemFormId
                        }
                        ,
                        State = false
                        ,
                        ResourceName = FormDefaults.ModuleName
                    });
                }
                //set to cache
                _cacheService.SetEntity(entity);
            }
            return(result);
        }
Esempio n. 6
0
        public IFormService Init(Domain.SystemForm formEntity)
        {
            Form      = Form.DeserializeFromJson(formEntity.FormConfig);
            _entityid = formEntity.EntityId;
            var attributeMetadatas = _attributeFinder.FindByEntityId(_entityid);
            var labels             = GetLabels();

            if (Form.Header != null && Form.Header.Rows.NotEmpty())
            {
                //header
                foreach (var row in Form.Header.Rows)
                {
                    foreach (var cell in row.Cells)
                    {
                        if (cell.Control.ControlType == FormControlType.Standard ||
                            cell.Control.ControlType == FormControlType.Hidden ||
                            cell.Control.ControlType == FormControlType.Lookup ||
                            cell.Control.ControlType == FormControlType.OptionSet)
                        {
                            _attributes.Add(cell.Control.Name);
                            cell.Control.AttributeMetadata = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
                        }
                        if (cell.Label.IsNotEmpty())
                        {
                            if (labels != null)
                            {
                                var label = labels.Find(n => n.ObjectId == cell.Id);
                                if (label != null)
                                {
                                    cell.Label = label.Label;
                                }
                            }
                        }
                        else if (cell.Control.AttributeMetadata != null)
                        {
                            cell.Label = cell.Control.AttributeMetadata.LocalizedName;
                        }
                    }
                }
            }
            if (Form.Panels.NotEmpty())
            {
                //tabs
                foreach (var tab in Form.Panels)
                {
                    if (labels != null && tab.Label.IsNotEmpty())
                    {
                        var label = labels.Find(n => n.ObjectId == tab.Id);
                        if (label != null)
                        {
                            tab.Label = label.Label;
                        }
                    }
                    foreach (var sec in tab.Sections)
                    {
                        if (labels != null && sec.Label.IsNotEmpty())
                        {
                            var label = labels.Find(n => n.ObjectId == sec.Id);
                            if (label != null)
                            {
                                sec.Label = label.Label;
                            }
                        }
                        foreach (var row in sec.Rows)
                        {
                            foreach (var cell in row.Cells)
                            {
                                if (cell.Control.ControlType == FormControlType.Standard ||
                                    cell.Control.ControlType == FormControlType.Hidden ||
                                    cell.Control.ControlType == FormControlType.Lookup ||
                                    cell.Control.ControlType == FormControlType.OptionSet)
                                {
                                    _attributes.Add(cell.Control.Name);
                                    cell.Control.AttributeMetadata = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
                                }
                                if (cell.Label.IsNotEmpty())
                                {
                                    if (labels != null)
                                    {
                                        var label = labels.Find(n => n.ObjectId == cell.Id);
                                        if (label != null)
                                        {
                                            cell.Label = label.Label;
                                        }
                                    }
                                }
                                else if (cell.Control.AttributeMetadata != null)
                                {
                                    cell.Label = cell.Control.AttributeMetadata.LocalizedName;
                                }
                            }
                        }
                    }
                }
            }
            //if (_form.Sections.NotEmpty())
            //{
            //    //sections
            //    foreach (var sec in _form.Sections)
            //    {
            //        foreach (var row in sec.Rows)
            //        {
            //            foreach (var cell in row.Cells)
            //            {
            //                _attributes.Add(cell.Control.Name);
            //                cell.Control.AttributeMetadata = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
            //            }
            //        }
            //    }
            //}
            if (Form.Footer != null && Form.Footer.Rows.NotEmpty())
            {
                //footer
                foreach (var row in Form.Footer.Rows)
                {
                    foreach (var cell in row.Cells)
                    {
                        if (cell.Control.ControlType == FormControlType.Standard ||
                            cell.Control.ControlType == FormControlType.Hidden ||
                            cell.Control.ControlType == FormControlType.Lookup ||
                            cell.Control.ControlType == FormControlType.OptionSet)
                        {
                            _attributes.Add(cell.Control.Name);
                            cell.Control.AttributeMetadata = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
                        }
                        if (cell.Label.IsNotEmpty())
                        {
                            if (labels != null)
                            {
                                var label = labels.Find(n => n.ObjectId == cell.Id);
                                if (label != null)
                                {
                                    cell.Label = label.Label;
                                }
                            }
                        }
                        else if (cell.Control.AttributeMetadata != null)
                        {
                            cell.Label = cell.Control.AttributeMetadata.LocalizedName;
                        }
                    }
                }
            }
            AttributeMetaDatas = attributeMetadatas.Where(n => _attributes.Contains(n.Name, StringComparer.InvariantCultureIgnoreCase)).ToList();
            foreach (var attr in AttributeMetaDatas)
            {
                SetAttributeItems(attr);
            }
            return(this);
        }
Esempio n. 7
0
        public void UpdateLocalizedLabel(Domain.SystemForm original)
        {
            //删除原有的
            if (original != null)
            {
                DeleteOriginalLabels(original);
            }
            var attributeMetadatas = _attributeFinder.FindByEntityId(_entityid);
            var solutionId         = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案

            if (Form.Header != null && Form.Header.Rows.NotEmpty())
            {
                //header
                foreach (var row in Form.Header.Rows)
                {
                    foreach (var cell in row.Cells)
                    {
                        if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty())
                        {
                            if (cell.Control.ControlType == FormControlType.Standard ||
                                cell.Control.ControlType == FormControlType.Hidden ||
                                cell.Control.ControlType == FormControlType.Lookup ||
                                cell.Control.ControlType == FormControlType.OptionSet)
                            {
                                var attr = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
                                if (attr != null && !cell.Label.IsCaseInsensitiveEqual(attr.LocalizedName))//与字段显示名称不一致时
                                {
                                    _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id);
                                }
                            }
                            else
                            {
                                _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id);
                            }
                        }
                    }
                }
            }
            if (Form.NavGroups.NotEmpty())
            {
                //navs
                foreach (var navg in Form.NavGroups)
                {
                    if (!navg.Id.Equals(Guid.Empty) && navg.Label.IsNotEmpty())
                    {
                        _localizedLabelBatchBuilder.Append(solutionId, navg.Label, FormDefaults.ModuleName, "LayoutLabel", navg.Id);
                    }
                    foreach (var item in navg.NavItems)
                    {
                        _localizedLabelBatchBuilder.Append(solutionId, item.Label, FormDefaults.ModuleName, "LayoutLabel", item.Id);
                    }
                }
            }
            if (Form.Panels.NotEmpty())
            {
                //tabs
                foreach (var tab in Form.Panels)
                {
                    if (!tab.Id.Equals(Guid.Empty) && tab.Label.IsNotEmpty())
                    {
                        _localizedLabelBatchBuilder.Append(solutionId, tab.Label, FormDefaults.ModuleName, "LayoutLabel", tab.Id);
                    }
                    foreach (var sec in tab.Sections)
                    {
                        if (!sec.Id.Equals(Guid.Empty) && sec.Label.IsNotEmpty())
                        {
                            _localizedLabelBatchBuilder.Append(solutionId, sec.Label, FormDefaults.ModuleName, "LayoutLabel", sec.Id);
                        }
                        foreach (var row in sec.Rows)
                        {
                            foreach (var cell in row.Cells)
                            {
                                if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty())
                                {
                                    if (cell.Control.ControlType == FormControlType.Standard ||
                                        cell.Control.ControlType == FormControlType.Hidden ||
                                        cell.Control.ControlType == FormControlType.Lookup ||
                                        cell.Control.ControlType == FormControlType.OptionSet)
                                    {
                                        var attr = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
                                        if (attr != null && !cell.Label.IsCaseInsensitiveEqual(attr.LocalizedName))//与字段显示名称不一致时
                                        {
                                            _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id);
                                        }
                                    }
                                    else
                                    {
                                        _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id);
                                    }
                                }
                            }
                        }
                    }
                }
                if (Form.Footer != null && Form.Footer.Rows.NotEmpty())
                {
                    //footer
                    foreach (var row in Form.Footer.Rows)
                    {
                        foreach (var cell in row.Cells)
                        {
                            if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty())
                            {
                                if (cell.Control.ControlType == FormControlType.Standard ||
                                    cell.Control.ControlType == FormControlType.Hidden ||
                                    cell.Control.ControlType == FormControlType.Lookup ||
                                    cell.Control.ControlType == FormControlType.OptionSet)
                                {
                                    var attr = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name));
                                    if (attr != null && !cell.Label.IsCaseInsensitiveEqual(attr.LocalizedName))//与字段显示名称不一致时
                                    {
                                        _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id);
                                    }
                                }
                                else
                                {
                                    _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id);
                                }
                            }
                        }
                    }
                }
            }
            _localizedLabelBatchBuilder.Save();
        }
Esempio n. 8
0
        public void DeleteOriginalLabels(Domain.SystemForm original)
        {
            var         oldForm   = new FormDescriptor().DeserializeFromJson(original.FormConfig);
            List <Guid> objectIds = new List <Guid>();

            if (oldForm.Header != null && oldForm.Header.Rows.NotEmpty())
            {
                //header
                foreach (var row in oldForm.Header.Rows)
                {
                    foreach (var cell in row.Cells)
                    {
                        if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty())
                        {
                            objectIds.Add(cell.Id);
                        }
                    }
                }
            }
            if (oldForm.NavGroups.NotEmpty())
            {
                //navs
                foreach (var navg in oldForm.NavGroups)
                {
                    if (!navg.Id.Equals(Guid.Empty) && navg.Label.IsNotEmpty())
                    {
                        objectIds.Add(navg.Id);
                    }
                    foreach (var item in navg.NavItems)
                    {
                        if (!item.Id.Equals(Guid.Empty) && item.Label.IsNotEmpty())
                        {
                            objectIds.Add(item.Id);
                        }
                    }
                }
            }
            if (oldForm.Panels.NotEmpty())
            {
                //tabs
                foreach (var tab in oldForm.Panels)
                {
                    if (!tab.Id.Equals(Guid.Empty) && tab.Label.IsNotEmpty())
                    {
                        objectIds.Add(tab.Id);
                    }
                    foreach (var sec in tab.Sections)
                    {
                        if (!sec.Id.Equals(Guid.Empty) && sec.Label.IsNotEmpty())
                        {
                            objectIds.Add(sec.Id);
                        }
                        foreach (var row in sec.Rows)
                        {
                            foreach (var cell in row.Cells)
                            {
                                if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty())
                                {
                                    objectIds.Add(cell.Id);
                                }
                            }
                        }
                    }
                }
            }
            if (oldForm.Footer != null && oldForm.Footer.Rows.NotEmpty())
            {
                //footer
                foreach (var row in oldForm.Footer.Rows)
                {
                    foreach (var cell in row.Cells)
                    {
                        if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty())
                        {
                            objectIds.Add(cell.Id);
                        }
                    }
                }
            }
            if (objectIds.NotEmpty())
            {
                _localizedLabelService.DeleteById(objectIds.ToArray());
            }
        }
Esempio n. 9
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);
        }