private void CloseInternal(bool entityClosing) { if (m_render != null) { m_render.DetachEnvironment(this); } Debug.Assert(LodLevel == -1 || entityClosing); Debug.Assert(!HasPhysics || entityClosing); if (DataView != null) { DataView.Close(); DataView = null; } foreach (var module in m_modules.Values) { module.Proxy.Close(); } HasPhysics = false; m_currentLod = -1; base.Close(); // Close the entity. Should close physics and all that good stuff as well. IsClosed = true; }
protected void FormAccepted(IFormInterface form) { if ( _sourceLinkRefresh && (_sourceLink != null) && (_sourceLink.Source != null) && (_sourceLink.Source.DataView.State == DataSetState.Browse) && (form.MainSource != null) //&& //!Object.ReferenceEquals(FSourceLink.Source.DataView, AForm.MainSource.DataView) // Do not refresh if this is a surrogate ) { switch (Mode) { case FormMode.Delete: form.MainSource.DataView.Close(); // Close the data view first to prevent the following refresh from causing an unnecessary requery _sourceLink.Source.DataView.Refresh(); break; case FormMode.Insert: case FormMode.Edit: // Find the nearest row in current set DataView sourceView = _sourceLink.Source.DataView; DataView targetView = form.MainSource.DataView; if (sourceView != targetView) { // Determine RefreshSourceKey // Determine RefreshKey // if SourceLinkRefreshKeyNames and RefreshKeyNames are specified, use them, otherwise // if the current order of the source link data view is a subset of the columns in the detail view, use it, otherwise // find the minimum key in the source link data view that is a subset of the columns in the detail view and use it Schema.Order sourceKey = null; Schema.Order targetKey = null; if ((SourceLinkRefreshKeyNames != "") && (RefreshKeyNames != "")) { string[] sourceKeyNames = SourceLinkRefreshKeyNames.Split(new char[] { ';', ',' }); string[] targetKeyNames = RefreshKeyNames.Split(new char[] { ';', ',' }); if (sourceKeyNames.Length == targetKeyNames.Length) { sourceKey = new Schema.Order(); targetKey = new Schema.Order(); for (int index = 0; index < sourceKeyNames.Length; index++) { sourceKey.Columns.Add(new Schema.OrderColumn(sourceView.TableVar.Columns[sourceKeyNames[index]], true)); targetKey.Columns.Add(new Schema.OrderColumn(targetView.TableVar.Columns[targetKeyNames[index]], true)); } } } if (sourceKey == null) { if ((sourceView.Order != null) && sourceView.Order.Columns.IsSubsetOf(targetView.TableVar.Columns)) { sourceKey = sourceView.Order; targetKey = sourceView.Order; } else { Schema.Key minimumKey = sourceView.TableVar.Keys.MinimumSubsetKey(targetView.TableVar.Columns); if (minimumKey != null) { sourceKey = new Schema.Order(minimumKey); targetKey = sourceKey; } } } if (sourceKey != null) { using (Row row = new Row(sourceView.Process.ValueManager, new Schema.RowType(sourceKey.Columns))) { for (int index = 0; index < sourceKey.Columns.Count; index++) { DataField targetField = targetView[targetKey.Columns[index].Column.Name]; if (targetField.HasValue()) { row[index] = targetField.Value; } else { row.ClearValue(index); } } targetView.Close(); // to prevent unnecessary requery string saveOrder = String.Empty; if (!sourceView.Order.Equals(sourceKey)) { saveOrder = sourceView.OrderString; try { sourceView.Order = sourceKey; } catch (Exception exception) { if (sourceView.OrderString != saveOrder) { sourceView.OrderString = saveOrder; } else { sourceView.Refresh(); } throw new ClientException(ClientException.Codes.UnableToFindModifiedRow, exception); } } try { sourceView.Refresh(row); } finally { if ((saveOrder != String.Empty) && (sourceView.OrderString != saveOrder)) { sourceView.OrderString = saveOrder; } } } } else { targetView.Close(); sourceView.Refresh(); } } break; } } if ((Mode == FormMode.Insert) && _autoAcceptAfterInsertOnQuery) { IFormInterface localForm = (IFormInterface)FindParent(typeof(IFormInterface)); if (localForm.Mode == FormMode.Query) { localForm.Close(CloseBehavior.AcceptOrClose); } } if (_onFormAccepted != null) { _onFormAccepted.Execute(this, new EventParams("AForm", form)); } if (OnFormAcceptedEvent != null) { OnFormAcceptedEvent(form); } }