示例#1
0
 public static ClientDataSet.EntityNodeDataTable GetEntityNodes(Guid organizationId, Guid nodeTypeId)
 {
     using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
     {
         return(adapter.GetEntityNodesByType(nodeTypeId));
     }
 }
示例#2
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);
        }
示例#3
0
 private static ClientDataSet.EntityNodeRow GetEntityNode(Guid entityNodeId, Guid organizationId)
 {
     using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
     {
         ClientDataSet.EntityNodeDataTable table = adapter.GetEntityNode(entityNodeId);
         return((table.Count > 0) ? table[0] : null);
     }
 }
示例#4
0
        public static void UpdateEntityNodePath(Guid entityNodeId, string fullPath)
        {
            Guid organizationId = UserContext.Current.OrganizationId;

            ClientDataSet.EntityNodeRow row = GetEntityNode(entityNodeId, organizationId);
            if (row != null)
            {
                row.FullPath = fullPath;

                using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
                {
                    adapter.Update(row);
                }
            }
        }
示例#5
0
        private static void DeleteChildEntityNodes(ClientDataSet.EntityNodeRow parentRow, Guid organizationId)
        {
            parentRow.Deleted = true;

            ClientDataSet.EntityNodeDataTable table = null;
            using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
            {
                adapter.Update(parentRow);

                table = adapter.GetEntityNodesByParentEntityNodeId(parentRow.EntityNodeId);
            }

            foreach (ClientDataSet.EntityNodeRow row in table)
            {
                DeleteChildEntityNodes(row, organizationId);
            }
        }
示例#6
0
        public static void MergeEntityNode(Guid sourceId, Guid targetId)
        {
            Guid organizationId = UserContext.Current.OrganizationId;

            ClientDataSet.EntityNodeRow sourceRow = GetEntityNode(sourceId, organizationId);
            ClientDataSet.EntityNodeRow destRow   = GetEntityNode(targetId, organizationId);

            if (sourceRow != null && destRow != null)
            {
                destRow.Name = sourceRow.Name;

                sourceRow.Deleted = true;

                using (EntityNodeTableAdapter adapter = new EntityNodeTableAdapter(OrganizationProvider.GetConnectionString(organizationId)))
                {
                    adapter.Update(destRow);
                    adapter.Update(sourceRow);
                }
            }
        }
示例#7
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);
        }
示例#8
0
        /// <summary>
        /// Changes the parent of the specified entity node.
        /// </summary>
        /// <param name="entityNodeId">The identifier of the entity node.</param>
        /// <param name="parentEntityNodeId">The identifier of new parent of the entity node.</param>
        public static void ChangeParentEntityNode(Guid entityNodeId, Guid?parentEntityNodeId)
        {
            Guid organizationId = UserContext.Current.OrganizationId;

            ClientDataSet.EntityNodeRow row = GetEntityNode(entityNodeId, organizationId);
            if (row != null)
            {
                if (parentEntityNodeId.HasValue && (parentEntityNodeId.Value != Guid.Empty))
                {
                    row.ParentEntityNodeId = parentEntityNodeId.Value;
                }
                else
                {
                    row.SetParentEntityNodeIdNull();
                }

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