Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Data / System / Data / DataRowView.cs / 1 / DataRowView.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { using System.Diagnostics; using System.ComponentModel; #if WINFSInternalOnly internal #else public #endif class DataRowView : ICustomTypeDescriptor, System.ComponentModel.IEditableObject, System.ComponentModel.IDataErrorInfo, System.ComponentModel.INotifyPropertyChanged { private readonly DataView dataView; private readonly DataRow _row; private bool delayBeginEdit; private static PropertyDescriptorCollection zeroPropertyDescriptorCollection = new PropertyDescriptorCollection(null); ////// When the PropertyChanged event happens, it must happen on the same DataRowView reference. /// This is so a generic event handler like Windows Presentation Foundation can redirect as appropriate. /// Having DataView.Equals is not sufficient for WPF, because two different instances may be equal but not equivalent. /// For DataRowView, if two instances are equal then they are equivalent. /// private System.ComponentModel.PropertyChangedEventHandler onPropertyChanged; internal DataRowView(DataView dataView, DataRow row) { this.dataView = dataView; this._row = row; } ////// Checks for same reference instead of equivalent ///or . /// /// Necessary for ListChanged event handlers to use data structures that use the default to /// instead of /// to understand if they need to add a event handler. /// public override bool Equals(object other) { return Object.ReferenceEquals(this, other); } /// Hashcode of public override Int32 GetHashCode() { // Everett compatability, must return hashcode for DataRow // this does prevent using this object in collections like Hashtable // which use the hashcode as an immutable value to identify this object // user could/should have used the DataRow property instead of the hashcode return Row.GetHashCode(); } public DataView DataView { get { return dataView; } } internal int ObjectID { get { return _row.ObjectID; } } ///Gets or sets a value in specified column. /// Specified column index. ///Uses either ///or to access /// when setting a value. public object this[int ndx] { get { return Row[ndx, RowVersionDefault]; } set { if (!dataView.AllowEdit && !IsNew) { throw ExceptionBuilder.CanNotEdit(); } SetColumnValue(dataView.Table.Columns[ndx], value); } } /// Gets the specified column value or related child view or sets a value in specified column. /// Specified column or relation name when getting. Specified column name when setting. ////// when is ambigous. Unmatched ///when getting a value. Unmatched ///when setting a value. public object this[string property] { get { DataColumn column = dataView.Table.Columns[property]; if (null != column) { return Row[column, RowVersionDefault]; } else if (dataView.Table.DataSet != null && dataView.Table.DataSet.Relations.Contains(property)) { return CreateChildView(property); } throw ExceptionBuilder.PropertyNotFound(property, dataView.Table.TableName); } set { DataColumn column = dataView.Table.Columns[property]; if (null == column) { throw ExceptionBuilder.SetFailed(property); } if (!dataView.AllowEdit && !IsNew) { throw ExceptionBuilder.CanNotEdit(); } SetColumnValue(column, value); } } // IDataErrorInfo stuff string System.ComponentModel.IDataErrorInfo.this[string colName] { get { return Row.GetColumnError(colName); } } string System.ComponentModel.IDataErrorInfo.Error { get { return Row.RowError; } } /// when setting a value. /// Gets the current version description of the ////// in relation to /// Either public DataRowVersion RowVersion { get { return (RowVersionDefault & ~DataRowVersion.Proposed); } } ///or Either private DataRowVersion RowVersionDefault { get { return Row.GetDefaultRowVersion(dataView.RowStateFilter); } } internal int GetRecord() { return Row.GetRecordFromVersion(RowVersionDefault); } internal object GetColumnValue(DataColumn column) { return Row[column, RowVersionDefault]; } internal void SetColumnValue(DataColumn column, object value) { if (delayBeginEdit) { delayBeginEdit = false; Row.BeginEdit(); } if (DataRowVersion.Original == RowVersionDefault) { throw ExceptionBuilder.SetFailed(column.ColumnName); } Row[column] = value; } ///or /// Returns a /// Specified/// for the child /// with the specified . /// . /// null or mismatch between public DataView CreateChildView(DataRelation relation) { if (relation == null || relation.ParentKey.Table != DataView.Table) { throw ExceptionBuilder.CreateChildView(); } int record = GetRecord(); object[] values = relation.ParentKey.GetKeyValues(record); RelatedView childView = new RelatedView(relation.ChildColumnsReference, values); childView.SetIndex("", DataViewRowState.CurrentRows, null); // finish construction via RelatedView.SetIndex childView.SetDataViewManager(DataView.DataViewManager); return childView; } ///and . /// Specified name. /// Unmatched public DataView CreateChildView(string relationName) { return CreateChildView(DataView.Table.ChildRelations[relationName]); } public DataRow Row { get { return _row; } } public void BeginEdit() { delayBeginEdit = true; } public void CancelEdit() { DataRow tmpRow = Row; if (IsNew) { dataView.FinishAddNew(false); } else { tmpRow.CancelEdit(); } delayBeginEdit = false; } public void EndEdit() { if (IsNew) { dataView.FinishAddNew(true); } else { Row.EndEdit(); } delayBeginEdit = false; } public bool IsNew { get { return (_row == dataView.addNewRow); } } public bool IsEdit { get { return ( Row.HasVersion(DataRowVersion.Proposed) || // It was edited or delayBeginEdit); // DataRowView.BegingEdit() was called, but not edited yet. } } public void Delete() { dataView.Delete(Row); } #region ICustomTypeDescriptor AttributeCollection ICustomTypeDescriptor.GetAttributes() { return new AttributeCollection((Attribute[])null); } string ICustomTypeDescriptor.GetClassName() { return null; } string ICustomTypeDescriptor.GetComponentName() { return null; } TypeConverter ICustomTypeDescriptor.GetConverter() { return null; } EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() { return null; } PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() { return null; } object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return null; } EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { return new EventDescriptorCollection(null); } EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) { return new EventDescriptorCollection(null); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return((ICustomTypeDescriptor)this).GetProperties(null); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { return (dataView.Table != null ? dataView.Table.GetPropertyDescriptorCollection(attributes) : zeroPropertyDescriptorCollection); } object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) { return this; } #endregion public event PropertyChangedEventHandler PropertyChanged { add { onPropertyChanged += value; } remove { onPropertyChanged -= value; } } internal void RaisePropertyChangedEvent (string propName){ // Do not try catch, we would mask users bugs. if they throw we would catch if (onPropertyChanged != null) { onPropertyChanged (this, new PropertyChangedEventArgs(propName)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //. // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data { using System.Diagnostics; using System.ComponentModel; #if WINFSInternalOnly internal #else public #endif class DataRowView : ICustomTypeDescriptor, System.ComponentModel.IEditableObject, System.ComponentModel.IDataErrorInfo, System.ComponentModel.INotifyPropertyChanged { private readonly DataView dataView; private readonly DataRow _row; private bool delayBeginEdit; private static PropertyDescriptorCollection zeroPropertyDescriptorCollection = new PropertyDescriptorCollection(null); ////// When the PropertyChanged event happens, it must happen on the same DataRowView reference. /// This is so a generic event handler like Windows Presentation Foundation can redirect as appropriate. /// Having DataView.Equals is not sufficient for WPF, because two different instances may be equal but not equivalent. /// For DataRowView, if two instances are equal then they are equivalent. /// private System.ComponentModel.PropertyChangedEventHandler onPropertyChanged; internal DataRowView(DataView dataView, DataRow row) { this.dataView = dataView; this._row = row; } ////// Checks for same reference instead of equivalent ///or . /// /// Necessary for ListChanged event handlers to use data structures that use the default to /// instead of /// to understand if they need to add a event handler. /// public override bool Equals(object other) { return Object.ReferenceEquals(this, other); } /// Hashcode of public override Int32 GetHashCode() { // Everett compatability, must return hashcode for DataRow // this does prevent using this object in collections like Hashtable // which use the hashcode as an immutable value to identify this object // user could/should have used the DataRow property instead of the hashcode return Row.GetHashCode(); } public DataView DataView { get { return dataView; } } internal int ObjectID { get { return _row.ObjectID; } } ///Gets or sets a value in specified column. /// Specified column index. ///Uses either ///or to access /// when setting a value. public object this[int ndx] { get { return Row[ndx, RowVersionDefault]; } set { if (!dataView.AllowEdit && !IsNew) { throw ExceptionBuilder.CanNotEdit(); } SetColumnValue(dataView.Table.Columns[ndx], value); } } /// Gets the specified column value or related child view or sets a value in specified column. /// Specified column or relation name when getting. Specified column name when setting. ////// when is ambigous. Unmatched ///when getting a value. Unmatched ///when setting a value. public object this[string property] { get { DataColumn column = dataView.Table.Columns[property]; if (null != column) { return Row[column, RowVersionDefault]; } else if (dataView.Table.DataSet != null && dataView.Table.DataSet.Relations.Contains(property)) { return CreateChildView(property); } throw ExceptionBuilder.PropertyNotFound(property, dataView.Table.TableName); } set { DataColumn column = dataView.Table.Columns[property]; if (null == column) { throw ExceptionBuilder.SetFailed(property); } if (!dataView.AllowEdit && !IsNew) { throw ExceptionBuilder.CanNotEdit(); } SetColumnValue(column, value); } } // IDataErrorInfo stuff string System.ComponentModel.IDataErrorInfo.this[string colName] { get { return Row.GetColumnError(colName); } } string System.ComponentModel.IDataErrorInfo.Error { get { return Row.RowError; } } /// when setting a value. /// Gets the current version description of the ////// in relation to /// Either public DataRowVersion RowVersion { get { return (RowVersionDefault & ~DataRowVersion.Proposed); } } ///or Either private DataRowVersion RowVersionDefault { get { return Row.GetDefaultRowVersion(dataView.RowStateFilter); } } internal int GetRecord() { return Row.GetRecordFromVersion(RowVersionDefault); } internal object GetColumnValue(DataColumn column) { return Row[column, RowVersionDefault]; } internal void SetColumnValue(DataColumn column, object value) { if (delayBeginEdit) { delayBeginEdit = false; Row.BeginEdit(); } if (DataRowVersion.Original == RowVersionDefault) { throw ExceptionBuilder.SetFailed(column.ColumnName); } Row[column] = value; } ///or /// Returns a /// Specified/// for the child /// with the specified . /// . /// null or mismatch between public DataView CreateChildView(DataRelation relation) { if (relation == null || relation.ParentKey.Table != DataView.Table) { throw ExceptionBuilder.CreateChildView(); } int record = GetRecord(); object[] values = relation.ParentKey.GetKeyValues(record); RelatedView childView = new RelatedView(relation.ChildColumnsReference, values); childView.SetIndex("", DataViewRowState.CurrentRows, null); // finish construction via RelatedView.SetIndex childView.SetDataViewManager(DataView.DataViewManager); return childView; } ///and . /// Specified name. /// Unmatched public DataView CreateChildView(string relationName) { return CreateChildView(DataView.Table.ChildRelations[relationName]); } public DataRow Row { get { return _row; } } public void BeginEdit() { delayBeginEdit = true; } public void CancelEdit() { DataRow tmpRow = Row; if (IsNew) { dataView.FinishAddNew(false); } else { tmpRow.CancelEdit(); } delayBeginEdit = false; } public void EndEdit() { if (IsNew) { dataView.FinishAddNew(true); } else { Row.EndEdit(); } delayBeginEdit = false; } public bool IsNew { get { return (_row == dataView.addNewRow); } } public bool IsEdit { get { return ( Row.HasVersion(DataRowVersion.Proposed) || // It was edited or delayBeginEdit); // DataRowView.BegingEdit() was called, but not edited yet. } } public void Delete() { dataView.Delete(Row); } #region ICustomTypeDescriptor AttributeCollection ICustomTypeDescriptor.GetAttributes() { return new AttributeCollection((Attribute[])null); } string ICustomTypeDescriptor.GetClassName() { return null; } string ICustomTypeDescriptor.GetComponentName() { return null; } TypeConverter ICustomTypeDescriptor.GetConverter() { return null; } EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() { return null; } PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() { return null; } object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return null; } EventDescriptorCollection ICustomTypeDescriptor.GetEvents() { return new EventDescriptorCollection(null); } EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) { return new EventDescriptorCollection(null); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return((ICustomTypeDescriptor)this).GetProperties(null); } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { return (dataView.Table != null ? dataView.Table.GetPropertyDescriptorCollection(attributes) : zeroPropertyDescriptorCollection); } object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) { return this; } #endregion public event PropertyChangedEventHandler PropertyChanged { add { onPropertyChanged += value; } remove { onPropertyChanged -= value; } } internal void RaisePropertyChangedEvent (string propName){ // Do not try catch, we would mask users bugs. if they throw we would catch if (onPropertyChanged != null) { onPropertyChanged (this, new PropertyChangedEventArgs(propName)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007..
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HtmlInputHidden.cs
- Point3DAnimationBase.cs
- ExecutedRoutedEventArgs.cs
- TextProperties.cs
- PerfProviderCollection.cs
- HtmlDocument.cs
- ObjectDataSourceChooseTypePanel.cs
- BigInt.cs
- WebPartConnectionsCancelVerb.cs
- xsdvalidator.cs
- DesignUtil.cs
- MetaForeignKeyColumn.cs
- SizeChangedEventArgs.cs
- TrailingSpaceComparer.cs
- DataGridViewCellPaintingEventArgs.cs
- ButtonPopupAdapter.cs
- HandleTable.cs
- CodeDirectionExpression.cs
- PointLightBase.cs
- ScrollBarAutomationPeer.cs
- TransactionException.cs
- ContentTypeSettingClientMessageFormatter.cs
- AttributedMetaModel.cs
- URLString.cs
- IsolatedStorage.cs
- DotExpr.cs
- HebrewNumber.cs
- GroupQuery.cs
- WeakEventManager.cs
- UInt16.cs
- FileNotFoundException.cs
- TypeListConverter.cs
- DocumentDesigner.cs
- WebPartRestoreVerb.cs
- ServiceObjectContainer.cs
- SchemaImporter.cs
- Int32EqualityComparer.cs
- XmlWellformedWriter.cs
- DbDataSourceEnumerator.cs
- TripleDES.cs
- AffineTransform3D.cs
- Process.cs
- CompositeDataBoundControl.cs
- IncomingWebResponseContext.cs
- IxmlLineInfo.cs
- compensatingcollection.cs
- XmlDigitalSignatureProcessor.cs
- MethodImplAttribute.cs
- ModelTreeEnumerator.cs
- StylusPlugInCollection.cs
- ViewBox.cs
- DocumentStream.cs
- RefreshPropertiesAttribute.cs
- ConsoleEntryPoint.cs
- SoapProtocolImporter.cs
- BuilderPropertyEntry.cs
- OdbcUtils.cs
- Odbc32.cs
- ClientSettingsSection.cs
- FileSystemInfo.cs
- MetafileEditor.cs
- ToolStripSplitButton.cs
- DoubleAverageAggregationOperator.cs
- TriggerCollection.cs
- TemplateKey.cs
- WebScriptServiceHost.cs
- DrawingContextDrawingContextWalker.cs
- ValueUnavailableException.cs
- BaseCodeDomTreeGenerator.cs
- FormsAuthenticationModule.cs
- HtmlInputHidden.cs
- OdbcDataAdapter.cs
- _ConnectOverlappedAsyncResult.cs
- SignatureToken.cs
- MainMenu.cs
- BindableAttribute.cs
- SelfIssuedAuthRSAPKCS1SignatureDeformatter.cs
- XPathDocumentNavigator.cs
- RefExpr.cs
- DataObjectAttribute.cs
- PolicyUnit.cs
- DocumentApplicationJournalEntry.cs
- DataGridTablesFactory.cs
- NullableLongMinMaxAggregationOperator.cs
- PreloadHost.cs
- MessageDecoder.cs
- DbParameterCollectionHelper.cs
- UrlAuthorizationModule.cs
- DbProviderSpecificTypePropertyAttribute.cs
- DummyDataSource.cs
- BmpBitmapEncoder.cs
- NetCodeGroup.cs
- RegexCompiler.cs
- DependencyPropertyChangedEventArgs.cs
- MembershipValidatePasswordEventArgs.cs
- TextTreeObjectNode.cs
- DoubleLinkList.cs
- Version.cs
- ExceptionList.cs
- TextControl.cs