///-------------------------------------------------------------------------------- /// <summary>This method loads PropertyReferences into the view model.</summary> /// /// <param name="entity">The entity to load.</param> /// <param name="solution">The associated solution.</param> /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param> ///-------------------------------------------------------------------------------- public void LoadPropertyReferences(Entity entity, Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (PropertyReferences == null) { PropertyReferences = new EnterpriseDataObjectList <PropertyReferenceViewModel>(); } if (loadChildren == true) { foreach (PropertyReference item in entity.PropertyReferenceList) { PropertyReferenceViewModel itemView = new PropertyReferenceViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); PropertyReferences.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies propertyreference updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditPropertyReferencePerformed(PropertyReferenceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.PropertyReference != null) { foreach (PropertyReferenceViewModel item in PropertyReferences) { if (item.PropertyReference.PropertyID == data.PropertyReference.PropertyID) { isItemMatch = true; item.PropertyReference.TransformDataFromObject(data.PropertyReference, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new PropertyReference data.PropertyReference.Entity = Entity; PropertyReferenceViewModel newItem = new PropertyReferenceViewModel(data.PropertyReference, Solution); newItem.Updated += new EventHandler(Children_Updated); PropertyReferences.Add(newItem); Entity.PropertyReferenceList.Add(newItem.PropertyReference); Solution.PropertyReferenceList.Add(newItem.PropertyReference); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of PropertyReference from the view model.</summary> /// /// <param name="itemView">The PropertyReference to delete.</param> ///-------------------------------------------------------------------------------- public void DeletePropertyReference(PropertyReferenceViewModel itemView) { itemView.Updated -= Children_Updated; PropertyReferences.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of PropertyReference to the view model.</summary> /// /// <param name="itemView">The PropertyReference to add.</param> ///-------------------------------------------------------------------------------- public void AddPropertyReference(PropertyReferenceViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); PropertyReferences.Add(itemView); Add(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method is used to copy/paste a new item.</summary> /// /// <param name="copyItem">The item to copy/paste.</param> /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param> ///-------------------------------------------------------------------------------- public PropertyReferenceViewModel PastePropertyReference(PropertyReferenceViewModel copyItem, bool savePaste = true) { PropertyReference newItem = new PropertyReference(); newItem.ReverseInstance = new PropertyReference(); newItem.TransformDataFromObject(copyItem.PropertyReference, null, false); newItem.PropertyID = Guid.NewGuid(); newItem.IsAutoUpdated = false; // try to find Entity by existing id first, second by old id, finally by name newItem.ReferencedEntity = Solution.EntityList.FindByID((Guid)copyItem.PropertyReference.ReferencedEntityID); if (newItem.ReferencedEntity == null && Solution.PasteNewGuids[copyItem.PropertyReference.ReferencedEntityID.ToString()] is Guid) { newItem.ReferencedEntity = Solution.EntityList.FindByID((Guid)Solution.PasteNewGuids[copyItem.PropertyReference.ReferencedEntityID.ToString()]); } if (newItem.ReferencedEntity == null) { newItem.ReferencedEntity = Entity.Feature.EntityList.Find("Name", copyItem.PropertyReference.Name); } if (newItem.ReferencedEntity == null) { newItem.OldReferencedEntityID = newItem.ReferencedEntityID; newItem.ReferencedEntityID = Guid.Empty; } // try to find referenced Property by existing id first, second by old id, finally by name newItem.ReferencedProperty = Solution.PropertyList.FindByID((Guid)copyItem.PropertyReference.ReferencedPropertyID); if (newItem.ReferencedProperty == null && Solution.PasteNewGuids[copyItem.PropertyReference.ReferencedPropertyID.ToString()] is Guid) { newItem.ReferencedProperty = Solution.PropertyList.FindByID((Guid)Solution.PasteNewGuids[copyItem.PropertyReference.ReferencedPropertyID.ToString()]); } if (newItem.ReferencedProperty == null) { newItem.ReferencedProperty = Solution.PropertyList.Find("Name", copyItem.PropertyReference.Name); } if (newItem.ReferencedProperty == null && newItem.ReferencedEntity != null && copyItem.PropertyReference.ReferencedProperty != null) { newItem.ReferencedProperty = newItem.ReferencedEntity.PropertyList.Find(p => p.PropertyName == copyItem.PropertyReference.ReferencedProperty.PropertyName); } if (newItem.ReferencedProperty == null) { newItem.OldReferencedPropertyID = newItem.ReferencedPropertyID; newItem.ReferencedPropertyID = Guid.Empty; } newItem.Entity = Entity; newItem.Solution = Solution; PropertyReferenceViewModel newView = new PropertyReferenceViewModel(newItem, Solution); newView.ResetModified(true); AddPropertyReference(newView); // paste children if (savePaste == true) { Solution.PropertyReferenceList.Add(newItem); Entity.PropertyReferenceList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }