/// <summary> /// Deletes an instance of a relationship object from the active model /// </summary> /// <param name="instance">The instance to delete</param> /// <returns>true if deleted</returns> internal bool DeleteRelationshipInstance(IECRelationshipInstance instance) { //var modelRefP = (IntPtr)ECApiExample.App.Context.ActiveModelReference.MdlModelRefP(); var modelRefP = (IntPtr)BMI.Utilities.ComApp.ActiveModelReference.MdlModelRefP(); return(DeleteRelationshipInstance(modelRefP, instance)); }
public void UpdateWBSParts(ArrayList assocItems, IECInstance selectedECInstance) { if (assocItems == null || assocItems.Count == 0 || selectedECInstance == null) { return; } //set cache of WBS items (classname, relationship name) IDictionary <string, string> aitems = new Dictionary <string, string> (); foreach (string item in assocItems) { string[] part = item.Split(new char[] { '|' }); if (part.Length < 1) { continue; } string className = part[0]; string relClassName = part[1]; if (!aitems.ContainsKey(className)) { aitems.Add(className, relClassName); } } DgnUtilities dgnUtil = DgnUtilities.GetInstance(); IECRelationshipInstanceCollection ecList = selectedECInstance.GetRelationshipInstances(); if (ecList == null || ecList.Count == 0) { return; } bool needWBS = false; string msg = string.Empty; //iterate thru relationship instances IEnumerator en = ecList.GetEnumerator(); while (en.MoveNext()) { IECRelationshipInstance rel = en.Current as IECRelationshipInstance; if (rel == null) { continue; } string wbsRelationshipName = rel.ClassDefinition.Name; IECInstance wbsSource = rel.Source; if (wbsSource == null) { continue; } string wbsSourceClassName = wbsSource.ClassDefinition.Name; //match wbs type and pass to UpdateWBSComboxValue() if (!aitems.ContainsKey(wbsSourceClassName)) { continue; } if (UpdateWBSComboxValue(wbsSource, wbsRelationshipName) == WBSUpdateType.NeedToCreate) { IECPropertyValue sourceVal = wbsSource.FindPropertyValue(s_WBSName, false, false, false); string val = string.Empty; if (sourceVal != null && !sourceVal.IsNull) { val = sourceVal.StringValue; } msg = msg + "\n" + string.Format(LocalizableStrings.MissingWbs, wbsSourceClassName, val); needWBS = true; } } if (needWBS && !string.IsNullOrEmpty(msg)) { string val = WorkspaceUtilities.GetMSConfigVariable("AllowPlacementOnMissingWBSItems"); if (string.IsNullOrEmpty(val) || val != "1") { dgnUtil.RunKeyin("BMECH DEFERDEFAULTCMD"); } //this value is used in consistency manager placement. //setting to false allows CM to display instances correctly dgnUtil.ConsistencyPlacementValidState = false; string message = string.Format(LocalizableStrings.AlertMissingWbs, msg); dgnUtil.ConsistencyPlacementErrorMessage = message; MessageBox.Show(message, LocalizableStrings.WBSAlert, MessageBoxButtons.OK, MessageBoxIcon.Warning); WorkspaceUtilities.DisplayWarningMessage(LocalizableStrings.WBSAlert, message); } }
private void OnCellValueChanged ( object sender, DataGridViewCellEventArgs e ) { if (e.ColumnIndex != 1) { return; } if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } IECClass ecClass = getECClassInformationForCurrentSelection(e.RowIndex); //this[ClassColumn, e.RowIndex].Tag as IECClass; IECRelationshipClass ecRelClass = getECRelationshipClassInformationForCurrentSelection(e.RowIndex); //this[ClassColumn, e.RowIndex].Tag as IECRelationshipClass; string strVal = LocalizableStrings.None; if (null != this[ComboBoxColumn, e.RowIndex].Value) { strVal = this[ComboBoxColumn, e.RowIndex].Value.ToString(); } if (strVal == _cstr_Varies) { return; } DgnUtilities dgnUtil = DgnUtilities.GetInstance(); IECInstance newECIsnt = getInstanceForCurrentSelection(e.RowIndex, strVal); // get from Tag //dgnUtil.GetSourceInstance (ecClass, strVal); foreach (IECInstance ecInstance in _instList) { IECRelationshipInstanceCollection ecRelCol = ecInstance.GetRelationshipInstances(); IEnumerator <IECRelationshipInstance> ecRelInstEnum = ecRelCol.GetEnumerator(); bool newSourceSet = false; while (ecRelInstEnum.MoveNext()) { IECRelationshipInstance ecRelInst = ecRelInstEnum.Current; if (!ecRelInst.ClassDefinition.Is(ecRelClass)) { continue; } if (strVal == LocalizableStrings.None || string.IsNullOrEmpty(strVal)) { ecRelCol.Remove(ecRelInst); } else { ecRelInst.Source = newECIsnt; } newSourceSet = true; break; } if (!newSourceSet && newECIsnt != null) { IECRelationshipInstance temporaryRelInst = ecRelClass.CreateInstance() as IECRelationshipInstance; temporaryRelInst.Source = newECIsnt; temporaryRelInst.Target = ecInstance; ecInstance.GetRelationshipInstances().Add(temporaryRelInst); } IECInstance ecInst = newECIsnt; if (ecInst != null) { if ((dgnUtil.IsECInstanceFromReferenceFile(ecInst) || dgnUtil.IsECInstanceReferencedOut(ecInst) || ecInst.IsReadOnly)) { ecInst = null; } } DataGridViewImageCell tempImageCell = this["optionEdit", e.RowIndex] as DataGridViewImageCell; tempImageCell.Tag = ecInst; tempImageCell = this["optionDelete", e.RowIndex] as DataGridViewImageCell; tempImageCell.Tag = ecInst; //Mark the property (having business key CA/or NAME property if no Business key is defined) as changed and set the event which will reset the property pane. //This is required to update UNIT and SERVICE property listed in property pane on the fly whenever user changes the UNIT or SERVICE in ASSOCIATIONS pane. IECPropertyValue propVal = BusinessKeyUtility.GetPropertyValue(ecInstance); if (propVal != null) { ecInstance.OnECPropertyValueChanged(propVal); } } SaveSettings(); }
/// <summary> /// Deletes an instance of a relationship object from the specified model /// </summary> /// <param name="modelRefP">Pointer to the model that the instance is to be deleted from</param> /// <param name="instance">The instance to delete</param> /// <returns>true if deleted</returns> internal bool DeleteRelationshipInstance(IntPtr modelRefP, IECRelationshipInstance instance) { return(XmlInstanceDelete.DeleteRelationshipInstance(modelRefP, instance)); }
/// <summary> /// Writes a relationship instance to the specified model /// </summary> /// <param name="modelRefP">The model to write to</param> /// <param name="instance">The instance to be written</param> /// <returns>The instance ID if successful</returns> internal string CreateRelationshipInstance(IntPtr modelRefP, IECRelationshipInstance instance) { return(XmlInstanceCreate.CreateRelationshipInstance(modelRefP, instance)); }