Пример #1
0
        public static Guid InsertEntityNode(Guid organizationId, Guid?instanceId, string name, Guid entityNodeTypeId, Guid entityId, Guid parentEntityNodeId, EntityLevel level)
        {
            ClientDataSet.EntityNodeDataTable table = new ClientDataSet.EntityNodeDataTable();
            ClientDataSet.EntityNodeRow       row   = table.NewEntityNodeRow();

            row.EntityNodeId = Guid.NewGuid();
            row.Name         = name;
            if (level == EntityLevel.Instance)
            {
                if (instanceId.HasValue)
                {
                    row.InstanceId = instanceId.Value;
                }
            }
            row.OrganizationId   = organizationId;
            row.EntityNodeTypeId = entityNodeTypeId;
            row.EntityId         = entityId;
            row.FullPath         = string.Empty;
            if (parentEntityNodeId != Guid.Empty)
            {
                row.ParentEntityNodeId = parentEntityNodeId;
            }
            row.OrderNumber = 0;
            table.AddEntityNodeRow(row);

            using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
            {
                adapter.Update(row);
            }

            return(row.EntityNodeId);
        }
Пример #2
0
        public static ClientDataSet.EntityNodeDataTable GetEntityNodesTree(Guid organizationId, Guid?instanceId, Guid entityId, string entityName)
        {
            ClientDataSet.EntityNodeDataTable table = null;
            using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
            {
                table = adapter.GetEntityNodesByEntityId(entityId, organizationId, instanceId);
            }

            string customRootNodeText = EntityFieldProvider.Entities[entityId.ToString()].CustomRootNodeText;

            ClientDataSet.EntityNodeRow rootRow = table.NewEntityNodeRow();
            rootRow.EntityNodeId = Guid.Empty;
            if (!string.IsNullOrEmpty(customRootNodeText))
            {
                rootRow.Name = customRootNodeText.Replace("#organizationName#", UserContext.Current.Organization.Name);
            }
            else
            {
                rootRow.Name = entityName;
            }
            rootRow.EntityId       = entityId;
            rootRow.OrganizationId = organizationId;
            rootRow.SetParentEntityNodeIdNull();
            table.AddEntityNodeRow(rootRow);

            foreach (ClientDataSet.EntityNodeRow row in table)
            {
                if (row.EntityNodeId != Guid.Empty)
                {
                    if (row.IsParentEntityNodeIdNull())
                    {
                        row.ParentEntityNodeId = Guid.Empty;
                    }
                }
            }

            table.AcceptChanges();

            return(table);
        }