Esempio n. 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);
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void LoadTree()
        {
            if (EntityId != Guid.Empty && UserContext.Current != null)
            {
                Entity entity     = EntityFieldProvider.Entities[EntityId.ToString()];
                Guid?  instanceId = new Guid?();
                if (entity.HierarchyStartLevel == EntityLevel.Instance)
                {
                    instanceId = new Guid?(UserContext.Current.InstanceId);
                }
                ClientDataSet.EntityNodeDataTable dt = new ClientDataSet.EntityNodeDataTable();
                if (UserContext.Current != null)
                {
                    this.OnClientNodeClicked = "onClientNodeClicked";
                    //                    this.ContextMenus.AddRange(CustomContextMenus.Values);
                    base.DataFieldID       = dt.EntityNodeIdColumn.ColumnName;
                    base.DataFieldParentID = dt.ParentEntityNodeIdColumn.ColumnName;
                    base.DataTextField     = dt.NameColumn.ColumnName;
                    base.DataValueField    = dt.EntityNodeIdColumn.ColumnName;
                    this.DataSource        = EntityNodeProvider.GetEntityNodesTree(UserContext.Current.OrganizationId, instanceId, EntityId, entity.Name);
                    this.DataBind();
                    if (this.Nodes.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(CustomRootNodeText))
                        {
                            this.Nodes[0].Text = CustomRootNodeText;
                        }

                        if ((AllowRootNodeSelection.HasValue && !AllowRootNodeSelection.Value) || (!AllowRootNodeSelection.HasValue && !Entity.EnableRootNodeSelection))
                        {
                            this.Nodes[0].Checkable = false;
                            this.Nodes[0].Category  = "3";
                        }
                        this.Nodes[0].Expanded = true;
                    }
                }
            }

            ClientDataSet.EntityNodesRelatedEntityNodesDataTable t = EntityNodeProvider.GetAllEntityNodesRelatedEntityNodes(UserContext.Current.OrganizationId, EntityNodeId, EntityId);
            RadTreeNode rtn;

            foreach (ClientDataSet.EntityNodesRelatedEntityNodesRow row in t.Rows)
            {
                rtn = this.FindNodeByValue(row.RelatedEntityNodeId.ToString());
                if (rtn == null)
                {
                    row.Delete();
                    continue;
                }
                if (rtn.Category != "3")
                {
                    if (row.RelationType == (int)RelationType.Checked)
                    {
                        rtn.Checked = true;
                    }
                    else if (row.RelationType == (int)RelationType.CheckedAndAllChildren)
                    {
                        rtn.Checked  = true;
                        rtn.Category = "1";
                    }
                    else if (row.RelationType == (int)RelationType.Blocked)
                    {
                        rtn.Checked  = true;
                        rtn.Category = "2";
                    }
                }
            }

            SetStateNode(this.Nodes[0]);
            ProcessNodes(this.Nodes[0]);

            if (OnLoaded != null)
            {
                OnLoaded(this, new EventArgs());
            }
        }