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); }
public static void CopyEntityNode(Guid organizationId, Guid?instanceId, Guid sourceId, Guid targetId, EntityLevel level) { ClientDataSet.EntityNodeRow source = GetEntityNode(sourceId, organizationId); if (source != null) { InsertEntityNode(organizationId, instanceId, source.Name, source.EntityNodeTypeId, source.EntityId, targetId, level); } }
public static void DeleteEntityNode(Guid entityNodeId) { Guid organizationId = UserContext.Current.OrganizationId; ClientDataSet.EntityNodeRow row = GetEntityNode(entityNodeId, organizationId); if (row != null) { DeleteChildEntityNodes(row, organizationId); } }
public static string GetEntityNodePath(Guid entityNodeId) { string result = string.Empty; ClientDataSet.EntityNodeRow row = EntityNodeProvider.GetEntityNode(entityNodeId); if (row != null) { result = row.FullPath; } return(result); }
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); } } }
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); } }
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); } } }
private void CloneNode(RadTreeNode radTreeNode, RadTreeNode targetNode) { foreach (RadTreeNode sourceNode in radTreeNode.Nodes) { Guid sourceId = new Guid(sourceNode.Value); ClientDataSet.EntityNodeRow source = EntityNodeProvider.GetEntityNode(sourceId); RadTreeNode rtn = new RadTreeNode(); rtn.Text = sourceNode.Text; rtn.Value = EntityNodeProvider.InsertEntityNode(UserContext.Current.OrganizationId, this.SelectedInstanceId, source.Name, source.EntityNodeTypeId, source.EntityId, new Guid(targetNode.Value), this.Entity.HierarchyStartLevel).ToString(); rtn.Category = sourceNode.Category; rtn.ContextMenuID = sourceNode.ContextMenuID; targetNode.Nodes.Add(rtn); Bll.Providers.EntityNodeProvider.UpdateEntityNodePath(new Guid(rtn.Value), rtn.GetFullPath(" > ")); if (sourceNode.Nodes.Count > 0) { CloneNode(sourceNode, rtn); } } }
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); }
public static string GetEntityValueAndName(Guid entityNodeTypeId, string fieldName, object value) { foreach (Entity ent in EntityFieldProvider.Entities) { if (ent.Id.Equals(entityNodeTypeId)) { EntityField field = ent.Fields[fieldName]; if (field != null) { if (field.ListValues != null && field.ListValues.Count > 0) { System.Collections.Generic.Dictionary <string, object[]> .KeyCollection.Enumerator keys = field.ListValues.Keys.GetEnumerator(); foreach (object[] obj in field.ListValues.Values) { if (!keys.MoveNext()) { break; } if (obj[0].Equals(value)) { return(keys.Current); } } } else if (field.DataType.Equals(typeof(Entity))) { if (value is Guid) { ClientDataSet.EntityNodeRow row = EntityNodeProvider.GetEntityNode((Guid)value); if (row != null) { return(row.Name); } } } } } } return(Convert.ToString(value, CultureInfo.CurrentCulture)); }
/// <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); } } }
protected void Tree_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e) { if (e == null) { return; } List.Visible = false; if (e.MenuItem.Value.StartsWith("CREATE", StringComparison.OrdinalIgnoreCase)) { string[] menuItemValues = e.MenuItem.Value.Split('_'); bool maxRestricted = false; if (new Guid(e.Node.Value) != Guid.Empty) { EntityNodeType ent = Entity.NodeTypes[menuItemValues[1]]; if (ent != null && ent.MaxRestrict > 0) { maxRestricted = IsRestricted(e.Node, menuItemValues[1], ent.MaxRestrict, this.Entity.HierarchyMaxDepth); } } if (!maxRestricted) { Guid entityId = Bll.Providers.EntityNodeProvider.InsertEntityNode(UserContext.Current.OrganizationId, this.SelectedInstanceId, "new", new Guid(menuItemValues[1]), this.EntityId, new Guid(e.Node.Value), this.Entity.HierarchyStartLevel); RadTreeNode rtn = new RadTreeNode(); rtn.Text = "new"; rtn.Value = entityId.ToString("N"); rtn.Category = menuItemValues[1]; rtn.ContextMenuID = "Menu" + menuItemValues[1]; e.Node.Nodes.Add(rtn); e.Node.Expanded = true; Bll.Providers.EntityNodeProvider.UpdateEntityNodePath(entityId, rtn.GetFullPath(" > ")); StartNodeInEditMode(rtn.Value); } else { RestrictErrorLabel.Text = Resources.EntityControl_RestrictErrorLabel_Text; RestrictErrorLabel.Visible = true; } } else if (e.MenuItem.Value.ToUpperInvariant() == "DELETE") { EntityNodeProvider.DeleteEntityNode(new Guid(e.Node.Value)); Tree.FindNodeByValue(e.Node.Value).Remove(); } else if (e.MenuItem.Value.ToUpperInvariant() == "CLONE") { Guid sourceId = new Guid(e.Node.Value); ClientDataSet.EntityNodeRow source = EntityNodeProvider.GetEntityNode(sourceId); if (source.IsParentEntityNodeIdNull()) { source.ParentEntityNodeId = Guid.Empty; } RadTreeNode rtn = new RadTreeNode(); rtn.Text = e.Node.Text + "_Copy" + (e.Node.ParentNode.Nodes.Count + 1).ToString(CultureInfo.InvariantCulture); rtn.Value = EntityNodeProvider.InsertEntityNode(UserContext.Current.OrganizationId, this.SelectedInstanceId, rtn.Text, source.EntityNodeTypeId, source.EntityId, source.ParentEntityNodeId, this.Entity.HierarchyStartLevel).ToString(); rtn.Category = e.Node.Category; rtn.ContextMenuID = e.Node.ContextMenuID; e.Node.ParentNode.Nodes.Add(rtn); Bll.Providers.EntityNodeProvider.UpdateEntityNodePath(new Guid(rtn.Value), rtn.GetFullPath(" > ")); CloneNode(e.Node, rtn); } else if (e.MenuItem.Value == Resources.EntityControl_AddNodeType || e.MenuItem.Value == Resources.EntityControl_EditNodeType) { List.DataBind(); List.Visible = true; } else { if (!string.IsNullOrEmpty(e.MenuItem.Value)) { Response.Redirect(string.Format(CultureInfo.InvariantCulture, e.MenuItem.Value, e.Node.Value)); } } }