public valueControl(TreeNode node, FetchXmlBuilder fetchXmlBuilder, TreeBuilderControl tree) { InitializeComponent(); InitializeFXB(null, fetchXmlBuilder, tree, node); _attributeName = TreeNodeHelper.GetAttributeFromNode(Node.Parent, "attribute"); _entityName = TreeNodeHelper.GetAttributeFromNode(Node.Parent, "entity"); if (String.IsNullOrWhiteSpace(_entityName)) { _entityName = TreeNodeHelper.GetAttributeFromNode(Node.Parent.Parent.Parent, "name"); } else { // TODO: Entity is an alias, get the actual entity name } if (fxb.NeedToLoadEntity(_entityName)) { if (!fxb.working) { fxb.LoadEntityDetails(_entityName, RefreshValues); } } else { RefreshValues(); } }
private void PopulateControls() { cmbEntity.Items.Clear(); var entities = form.GetDisplayEntities(); if (entities != null) { foreach (var entity in entities) { cmbEntity.Items.Add(entity.Value.LogicalName); } } var parententityname = TreeNodeHelper.GetAttributeFromNode(node.Parent, "name"); if (form.NeedToLoadEntity(parententityname)) { if (!form.working) { form.LoadEntityDetails(parententityname, RefreshRelationships); } } else { RefreshRelationships(); } RefreshAttributes(); }
private void RefreshAttributes() { cmbFrom.Items.Clear(); cmbTo.Items.Clear(); if (cmbEntity.SelectedItem != null) { var linkentity = cmbEntity.SelectedItem.ToString(); var linkAttributes = form.GetDisplayAttributes(linkentity); foreach (var attribute in linkAttributes) { if (attribute.IsPrimaryId == true || attribute.AttributeType == AttributeTypeCode.Lookup || attribute.AttributeType == AttributeTypeCode.Customer || attribute.AttributeType == AttributeTypeCode.Owner) { cmbFrom.Items.Add(attribute.LogicalName); } } } var parententity = TreeNodeHelper.GetAttributeFromNode(node.Parent, "name"); var parentAttributes = form.GetDisplayAttributes(parententity); foreach (var attribute in parentAttributes) { if (attribute.IsPrimaryId == true || attribute.AttributeType == AttributeTypeCode.Lookup || attribute.AttributeType == AttributeTypeCode.Customer || attribute.AttributeType == AttributeTypeCode.Owner) { cmbTo.Items.Add(attribute.LogicalName); } } }
public EntityNode(TreeNode node) { EntityName = TreeNodeHelper.GetAttributeFromNode(node, "name"); var alias = TreeNodeHelper.GetAttributeFromNode(node, "alias"); name = !string.IsNullOrEmpty(alias) ? alias : EntityName; }
private void RefreshRelationships() { cmbRelationship.Items.Clear(); var parententityname = TreeNodeHelper.GetAttributeFromNode(Node.Parent, "name"); var entities = fxb.GetDisplayEntities(); if (entities != null && entities.ContainsKey(parententityname)) { var parententity = entities[parententityname]; var mo = parententity.ManyToOneRelationships; var om = parententity.OneToManyRelationships; var mm = parententity.ManyToManyRelationships; var list = new List <EntityRelationship>(); if (mo.Length > 0) { cmbRelationship.Items.Add("- M:1 -"); list.Clear(); foreach (var rel in mo) { list.Add(new EntityRelationship(rel, EntityRole.Referencing, parententityname, fxb)); } list.Sort(); cmbRelationship.Items.AddRange(list.ToArray()); } if (om.Length > 0) { cmbRelationship.Items.Add("- 1:M -"); list.Clear(); foreach (var rel in om) { list.Add(new EntityRelationship(rel, EntityRole.Referenced, parententityname, fxb)); } list.Sort(); cmbRelationship.Items.AddRange(list.ToArray()); } if (mm.Length > 0) { var greatparententityname = Node.Parent.Parent != null?TreeNodeHelper.GetAttributeFromNode(Node.Parent.Parent, "name") : ""; cmbRelationship.Items.Add("- M:M -"); list.Clear(); foreach (var rel in mm) { if (rel.Entity1LogicalName == parententityname || rel.Entity1LogicalName == greatparententityname && rel.IntersectEntityName == parententityname) { list.Add(new EntityRelationship(rel, EntityRole.Referencing, parententityname, fxb, greatparententityname)); } if (rel.Entity2LogicalName == parententityname || rel.Entity2LogicalName == greatparententityname && rel.IntersectEntityName == parententityname) { list.Add(new EntityRelationship(rel, EntityRole.Referenced, parententityname, fxb, greatparententityname)); } } list.Sort(); cmbRelationship.Items.AddRange(list.ToArray()); } } }
private void RefreshRelationships() { cmbRelationship.Items.Clear(); var parententityname = TreeNodeHelper.GetAttributeFromNode(node.Parent, "name"); var entities = form.GetDisplayEntities(); if (entities != null && entities.ContainsKey(parententityname)) { var parententity = entities[parententityname]; var mo = parententity.ManyToOneRelationships; var om = parententity.OneToManyRelationships; var mm = parententity.ManyToManyRelationships; var list = new List <EntityRelationship>(); if (mo.Length > 0) { cmbRelationship.Items.Add("- M:1 -"); list.Clear(); foreach (var rel in mo) { list.Add(new EntityRelationship(rel, parententityname, form)); } list.Sort(); cmbRelationship.Items.AddRange(list.ToArray()); } if (om.Length > 0) { cmbRelationship.Items.Add("- 1:M -"); list.Clear(); foreach (var rel in om) { list.Add(new EntityRelationship(rel, parententityname, form)); } list.Sort(); cmbRelationship.Items.AddRange(list.ToArray()); } if (mm.Length > 0) { var greatparententityname = node.Parent.Parent != null?TreeNodeHelper.GetAttributeFromNode(node.Parent.Parent, "name") : ""; cmbRelationship.Items.Add("- M:M -"); list.Clear(); foreach (var rel in mm) { list.Add(new EntityRelationship(rel, parententityname, form, greatparententityname)); } list.Sort(); cmbRelationship.Items.AddRange(list.ToArray()); } } }
private void RefreshAttributes() { if (!IsInitialized) { return; } cmbFrom.Items.Clear(); cmbTo.Items.Clear(); if (cmbEntity.SelectedItem != null) { var linkentity = cmbEntity.SelectedItem.ToString(); cmbFrom.Items.AddRange(GetRelevantLinkAttributes(linkentity)); } var parententity = TreeNodeHelper.GetAttributeFromNode(Node.Parent, "name"); cmbTo.Items.AddRange(GetRelevantLinkAttributes(parententity)); ValidationSuspended = false; }
private void RefreshRelationships() { cmbRelationship.Items.Clear(); var parententityname = TreeNodeHelper.GetAttributeFromNode(node.Parent, "name"); var entities = FetchXmlBuilder.GetDisplayEntities(); if (entities != null && entities.ContainsKey(parententityname)) { var parententity = entities[parententityname]; var mo = parententity.ManyToOneRelationships; var om = parententity.OneToManyRelationships; var mm = parententity.ManyToManyRelationships; if (mo.Length > 0) { cmbRelationship.Items.Add("- M:1 -"); foreach (var rel in mo) { cmbRelationship.Items.Add(new EntityRelationship(rel, parententityname)); } } if (om.Length > 0) { cmbRelationship.Items.Add("- 1:M -"); foreach (var rel in om) { cmbRelationship.Items.Add(new EntityRelationship(rel, parententityname)); } } if (mm.Length > 0) { var greatparententityname = node.Parent.Parent != null?TreeNodeHelper.GetAttributeFromNode(node.Parent.Parent, "name") : ""; cmbRelationship.Items.Add("- M:M -"); foreach (var rel in mm) { cmbRelationship.Items.Add(new EntityRelationship(rel, parententityname, greatparententityname)); } } } }
private List <string> GetAliases(TreeNode node) { var result = new List <string>(); if (node.Name == "entity" || node.Name == "link-entity") { foreach (TreeNode child in node.Nodes) { if (child.Name == "attribute") { var alias = TreeNodeHelper.GetAttributeFromNode(child, "alias"); if (!string.IsNullOrEmpty(alias)) { result.Add(alias); } } } } foreach (TreeNode child in node.Nodes) { result.AddRange(GetAliases(child)); } return(result); }
private void cmbRelationship_SelectedIndexChanged(object sender, EventArgs e) { if (cmbRelationship.SelectedItem != null && cmbRelationship.SelectedItem is EntityRelationship) { var rel = (EntityRelationship)cmbRelationship.SelectedItem; var parent = TreeNodeHelper.GetAttributeFromNode(node.Parent, "name"); if (rel.Relationship is OneToManyRelationshipMetadata) { var om = (OneToManyRelationshipMetadata)rel.Relationship; if (parent == om.ReferencedEntity) { cmbEntity.Text = om.ReferencingEntity; cmbFrom.Text = om.ReferencingAttribute; cmbTo.Text = om.ReferencedAttribute; } else if (parent == om.ReferencingEntity) { cmbEntity.Text = om.ReferencedEntity; cmbFrom.Text = om.ReferencedAttribute; cmbTo.Text = om.ReferencingAttribute; } else { MessageBox.Show("Not a valid relationship. Please enter entity and attributes manually."); } chkIntersect.Checked = false; } else if (rel.Relationship is ManyToManyRelationshipMetadata) { var mm = (ManyToManyRelationshipMetadata)rel.Relationship; if (parent == mm.IntersectEntityName) { var greatparent = TreeNodeHelper.GetAttributeFromNode(node.Parent.Parent, "name"); if (greatparent == mm.Entity1LogicalName) { cmbEntity.Text = mm.Entity2LogicalName; cmbFrom.Text = mm.Entity2IntersectAttribute; cmbTo.Text = mm.Entity2IntersectAttribute; } else if (greatparent == mm.Entity2LogicalName) { cmbEntity.Text = mm.Entity1LogicalName; cmbFrom.Text = mm.Entity1IntersectAttribute; cmbTo.Text = mm.Entity1IntersectAttribute; } else { MessageBox.Show("Not a valid M:M-relationship. Please enter entity and attributes manually."); } } else { cmbEntity.Text = mm.IntersectEntityName; if (parent == mm.Entity1LogicalName) { cmbFrom.Text = mm.Entity1IntersectAttribute; cmbTo.Text = mm.Entity1IntersectAttribute; } else if (parent == mm.Entity2LogicalName) { cmbFrom.Text = mm.Entity2IntersectAttribute; cmbTo.Text = mm.Entity2IntersectAttribute; } else { MessageBox.Show("Not a valid M:M-relationship. Please enter entity and attributes manually."); } chkIntersect.Checked = true; } } } }
private void cmbRelationship_SelectedIndexChanged(object sender, EventArgs e) { if (cmbRelationship.SelectedItem != null && cmbRelationship.SelectedItem is EntityRelationship rel) { var parent = TreeNodeHelper.GetAttributeFromNode(Node.Parent, "name"); string entity; string from; string to; bool intersect; if (rel.Relationship is OneToManyRelationshipMetadata om) { if (parent == om.ReferencedEntity && rel.Role == EntityRole.Referenced) { entity = om.ReferencingEntity; from = om.ReferencingAttribute; to = om.ReferencedAttribute; } else if (parent == om.ReferencingEntity && rel.Role == EntityRole.Referencing) { entity = om.ReferencedEntity; from = om.ReferencedAttribute; to = om.ReferencingAttribute; } else { MessageBox.Show("Not a valid relationship. Please enter entity and attributes manually."); return; } intersect = false; } else if (rel.Relationship is ManyToManyRelationshipMetadata mm) { if (fxb.NeedToLoadEntity(mm.Entity1LogicalName)) { fxb.LoadEntityDetails(mm.Entity1LogicalName, null, false); } if (fxb.NeedToLoadEntity(mm.Entity2LogicalName)) { fxb.LoadEntityDetails(mm.Entity2LogicalName, null, false); } var entity1PrimaryKey = fxb.GetPrimaryIdAttribute(mm.Entity1LogicalName); var entity2PrimaryKey = fxb.GetPrimaryIdAttribute(mm.Entity2LogicalName); if (parent == mm.IntersectEntityName) { var greatparent = TreeNodeHelper.GetAttributeFromNode(Node.Parent.Parent, "name"); if (greatparent == mm.Entity1LogicalName && rel.Role == EntityRole.Referencing) { entity = mm.Entity2LogicalName; from = entity2PrimaryKey; to = mm.Entity2IntersectAttribute; } else if (greatparent == mm.Entity2LogicalName && rel.Role == EntityRole.Referenced) { entity = mm.Entity1LogicalName; from = entity1PrimaryKey; to = mm.Entity1IntersectAttribute; } else { MessageBox.Show("Not a valid M:M-relationship. Please enter entity and attributes manually."); return; } intersect = true; } else { entity = mm.IntersectEntityName; if (parent == mm.Entity1LogicalName && rel.Role == EntityRole.Referencing) { from = mm.Entity1IntersectAttribute; to = entity1PrimaryKey; } else if (parent == mm.Entity2LogicalName && rel.Role == EntityRole.Referenced) { from = mm.Entity2IntersectAttribute; to = entity2PrimaryKey; } else { MessageBox.Show("Not a valid M:M-relationship. Please enter entity and attributes manually."); return; } intersect = true; } } else { MessageBox.Show("Not a valid relationship. Please enter entity and attributes manually."); return; } BeginInit(); cmbEntity.Text = entity; cmbFrom.Text = from; cmbTo.Text = to; chkIntersect.Checked = intersect; EndInit(); Save(false); } }