Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Data / System / Data / DataRowCollection.cs / 1 / DataRowCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data {
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
#if WINFSInternalOnly
internal
#else
public
#endif
sealed class DataRowCollection : InternalDataCollectionBase {
private sealed class DataRowTree : RBTree {
internal DataRowTree() : base(TreeAccessMethod.INDEX_ONLY) {
}
protected override int CompareNode (DataRow record1, DataRow record2) {
throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CompareNodeInDataRowTree);
}
protected override int CompareSateliteTreeNode (DataRow record1, DataRow record2) {
throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CompareSateliteTreeNodeInDataRowTree);
}
}
private readonly DataTable table;
private readonly DataRowTree list = new DataRowTree();
internal int nullInList = 0;
///
/// Creates the DataRowCollection for the given table.
///
internal DataRowCollection(DataTable table) {
this.table = table;
}
public override int Count {
get {
return list.Count;
}
}
///
/// Gets the row at the specified index.
///
public DataRow this[int index] {
get {
return list[index];
}
}
///
/// Adds the specified to the object.
///
public void Add(DataRow row) {
table.AddRow(row, -1);
}
public void InsertAt(DataRow row, int pos) {
if (pos < 0)
throw ExceptionBuilder.RowInsertOutOfRange(pos);
if (pos >= list.Count)
table.AddRow(row, -1);
else
table.InsertRow(row, -1, pos);
}
internal void DiffInsertAt(DataRow row, int pos) {
if ((pos < 0) || (pos == list.Count)) {
table.AddRow(row, pos >-1? pos+1 : -1);
return;
}
if (table.NestedParentRelations.Length > 0) { // get in this trouble only if table has a nested parent
// get into trouble if table has JUST a nested parent? how about multi parent!
if (pos < list.Count) {
if (list[pos] != null) {
throw ExceptionBuilder.RowInsertTwice(pos, table.TableName);
}
list.RemoveAt(pos);
nullInList--;
table.InsertRow(row, pos+1, pos);
}
else {
while (pos>list.Count) {
list.Add(null);
nullInList++;
}
table.AddRow(row, pos+1);
}
}
else {
table.InsertRow(row, pos+1, pos > list.Count ? -1 : pos);
}
}
public Int32 IndexOf(DataRow row) {
if ((null == row) || (row.Table != this.table) || ((0 == row.RBTreeNodeId) && (row.RowState == DataRowState.Detached))) //Webdata 102857
return -1;
return list.IndexOf(row.RBTreeNodeId, row);
}
///
/// Creates a row using specified values and adds it to the
/// .
///
internal DataRow AddWithColumnEvents(params object[] values) {
DataRow row = table.NewRow(-1);
row.ItemArray = values;
table.AddRow(row, -1);
return row;
}
public DataRow Add(params object[] values) {
int record = table.NewRecordFromArray(values);
DataRow row = table.NewRow(record);
table.AddRow(row, -1);
return row;
}
internal void ArrayAdd(DataRow row) {
row.RBTreeNodeId = list.Add(row);
}
internal void ArrayInsert(DataRow row, int pos) {
row.RBTreeNodeId = list.Insert(pos, row);
}
internal void ArrayClear() {
list.Clear();
}
internal void ArrayRemove(DataRow row) {
if (row.RBTreeNodeId == 0) {
throw ExceptionBuilder.InternalRBTreeError(RBTreeError.AttachedNodeWithZerorbTreeNodeId);
}
list.RBDelete(row.RBTreeNodeId);
row.RBTreeNodeId = 0;
}
///
/// Gets
/// the row specified by the primary key value.
///
///
public DataRow Find(object key) {
return table.FindByPrimaryKey(key);
}
///
/// Gets the row containing the specified primary key values.
///
public DataRow Find(object[] keys) {
return table.FindByPrimaryKey(keys);
}
///
/// Clears the collection of all rows.
///
public void Clear() {
table.Clear(false);
}
///
///
/// Gets a value indicating whether the primary key of any row in the
/// collection contains the specified value.
///
///
public bool Contains(object key) {
return(table.FindByPrimaryKey(key) != null);
}
///
///
/// Gets a value indicating if the with
/// the specified primary key values exists.
///
///
public bool Contains(object[] keys) {
return(table.FindByPrimaryKey(keys) != null);
}
public override void CopyTo(Array ar, int index) {
list.CopyTo(ar, index);
}
public void CopyTo(DataRow[] array, int index) {
list.CopyTo(array, index);
}
public override IEnumerator GetEnumerator() {
return list.GetEnumerator();
}
///
/// Removes the specified from the collection.
///
public void Remove(DataRow row) {
if ((null == row) || (row.Table != table) || (-1 == row.rowID)) {
throw ExceptionBuilder.RowOutOfRange();
}
if ((row.RowState != DataRowState.Deleted) && (row.RowState != DataRowState.Detached))
row.Delete();
if (row.RowState != DataRowState.Detached)
row.AcceptChanges();
}
///
///
/// Removes the row with the specified index from
/// the collection.
///
///
public void RemoveAt(int index) {
Remove(this[index]);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace System.Data {
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
#if WINFSInternalOnly
internal
#else
public
#endif
sealed class DataRowCollection : InternalDataCollectionBase {
private sealed class DataRowTree : RBTree {
internal DataRowTree() : base(TreeAccessMethod.INDEX_ONLY) {
}
protected override int CompareNode (DataRow record1, DataRow record2) {
throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CompareNodeInDataRowTree);
}
protected override int CompareSateliteTreeNode (DataRow record1, DataRow record2) {
throw ExceptionBuilder.InternalRBTreeError(RBTreeError.CompareSateliteTreeNodeInDataRowTree);
}
}
private readonly DataTable table;
private readonly DataRowTree list = new DataRowTree();
internal int nullInList = 0;
///
/// Creates the DataRowCollection for the given table.
///
internal DataRowCollection(DataTable table) {
this.table = table;
}
public override int Count {
get {
return list.Count;
}
}
///
/// Gets the row at the specified index.
///
public DataRow this[int index] {
get {
return list[index];
}
}
///
/// Adds the specified to the object.
///
public void Add(DataRow row) {
table.AddRow(row, -1);
}
public void InsertAt(DataRow row, int pos) {
if (pos < 0)
throw ExceptionBuilder.RowInsertOutOfRange(pos);
if (pos >= list.Count)
table.AddRow(row, -1);
else
table.InsertRow(row, -1, pos);
}
internal void DiffInsertAt(DataRow row, int pos) {
if ((pos < 0) || (pos == list.Count)) {
table.AddRow(row, pos >-1? pos+1 : -1);
return;
}
if (table.NestedParentRelations.Length > 0) { // get in this trouble only if table has a nested parent
// get into trouble if table has JUST a nested parent? how about multi parent!
if (pos < list.Count) {
if (list[pos] != null) {
throw ExceptionBuilder.RowInsertTwice(pos, table.TableName);
}
list.RemoveAt(pos);
nullInList--;
table.InsertRow(row, pos+1, pos);
}
else {
while (pos>list.Count) {
list.Add(null);
nullInList++;
}
table.AddRow(row, pos+1);
}
}
else {
table.InsertRow(row, pos+1, pos > list.Count ? -1 : pos);
}
}
public Int32 IndexOf(DataRow row) {
if ((null == row) || (row.Table != this.table) || ((0 == row.RBTreeNodeId) && (row.RowState == DataRowState.Detached))) //Webdata 102857
return -1;
return list.IndexOf(row.RBTreeNodeId, row);
}
///
/// Creates a row using specified values and adds it to the
/// .
///
internal DataRow AddWithColumnEvents(params object[] values) {
DataRow row = table.NewRow(-1);
row.ItemArray = values;
table.AddRow(row, -1);
return row;
}
public DataRow Add(params object[] values) {
int record = table.NewRecordFromArray(values);
DataRow row = table.NewRow(record);
table.AddRow(row, -1);
return row;
}
internal void ArrayAdd(DataRow row) {
row.RBTreeNodeId = list.Add(row);
}
internal void ArrayInsert(DataRow row, int pos) {
row.RBTreeNodeId = list.Insert(pos, row);
}
internal void ArrayClear() {
list.Clear();
}
internal void ArrayRemove(DataRow row) {
if (row.RBTreeNodeId == 0) {
throw ExceptionBuilder.InternalRBTreeError(RBTreeError.AttachedNodeWithZerorbTreeNodeId);
}
list.RBDelete(row.RBTreeNodeId);
row.RBTreeNodeId = 0;
}
///
/// Gets
/// the row specified by the primary key value.
///
///
public DataRow Find(object key) {
return table.FindByPrimaryKey(key);
}
///
/// Gets the row containing the specified primary key values.
///
public DataRow Find(object[] keys) {
return table.FindByPrimaryKey(keys);
}
///
/// Clears the collection of all rows.
///
public void Clear() {
table.Clear(false);
}
///
///
/// Gets a value indicating whether the primary key of any row in the
/// collection contains the specified value.
///
///
public bool Contains(object key) {
return(table.FindByPrimaryKey(key) != null);
}
///
///
/// Gets a value indicating if the with
/// the specified primary key values exists.
///
///
public bool Contains(object[] keys) {
return(table.FindByPrimaryKey(keys) != null);
}
public override void CopyTo(Array ar, int index) {
list.CopyTo(ar, index);
}
public void CopyTo(DataRow[] array, int index) {
list.CopyTo(array, index);
}
public override IEnumerator GetEnumerator() {
return list.GetEnumerator();
}
///
/// Removes the specified from the collection.
///
public void Remove(DataRow row) {
if ((null == row) || (row.Table != table) || (-1 == row.rowID)) {
throw ExceptionBuilder.RowOutOfRange();
}
if ((row.RowState != DataRowState.Deleted) && (row.RowState != DataRowState.Detached))
row.Delete();
if (row.RowState != DataRowState.Detached)
row.AcceptChanges();
}
///
///
/// Removes the row with the specified index from
/// the collection.
///
///
public void RemoveAt(int index) {
Remove(this[index]);
}
}
}
// 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
- WebBrowserProgressChangedEventHandler.cs
- ThreadStaticAttribute.cs
- XmlElementList.cs
- TypeLibConverter.cs
- GridViewColumn.cs
- FamilyTypefaceCollection.cs
- UdpDiscoveryEndpointElement.cs
- DataTableClearEvent.cs
- AuthenticationSchemesHelper.cs
- ProtocolsConfiguration.cs
- ActivityDesignerResources.cs
- Floater.cs
- ExtractedStateEntry.cs
- WindowVisualStateTracker.cs
- TextEditor.cs
- RoamingStoreFile.cs
- SystemIPInterfaceProperties.cs
- UIElementHelper.cs
- Int16KeyFrameCollection.cs
- EventPrivateKey.cs
- TransactionInformation.cs
- SlotInfo.cs
- RectAnimation.cs
- ServiceMoniker.cs
- ConfigXmlDocument.cs
- ExtendedProperty.cs
- DataBoundLiteralControl.cs
- Propagator.ExtentPlaceholderCreator.cs
- WebScriptClientGenerator.cs
- TriggerCollection.cs
- TypeToArgumentTypeConverter.cs
- SafeBitVector32.cs
- Size.cs
- RepeaterCommandEventArgs.cs
- MyContact.cs
- ResourcesGenerator.cs
- GridToolTip.cs
- SessionState.cs
- StrokeNodeOperations.cs
- HtmlTableRowCollection.cs
- SessionState.cs
- SHA1Managed.cs
- PropertyGridEditorPart.cs
- ProjectionNode.cs
- TextReader.cs
- Matrix3DValueSerializer.cs
- ThousandthOfEmRealDoubles.cs
- _UriSyntax.cs
- ObjectAnimationUsingKeyFrames.cs
- DataStreamFromComStream.cs
- ExtendedPropertyCollection.cs
- CodeTypeOfExpression.cs
- BufferedStream.cs
- MultipartContentParser.cs
- SqlDataReaderSmi.cs
- ContainerFilterService.cs
- CharKeyFrameCollection.cs
- OracleConnectionStringBuilder.cs
- Matrix.cs
- PolicyVersion.cs
- NetNamedPipeSecurity.cs
- DataControlField.cs
- NameValuePair.cs
- DBProviderConfigurationHandler.cs
- JavaScriptSerializer.cs
- PresentationTraceSources.cs
- HtmlElement.cs
- PropertyPushdownHelper.cs
- X509SecurityToken.cs
- SymbolType.cs
- ServiceOperationListItemList.cs
- StringWriter.cs
- Matrix3DConverter.cs
- ScriptReference.cs
- GridViewDeleteEventArgs.cs
- ScopelessEnumAttribute.cs
- TransformProviderWrapper.cs
- Decorator.cs
- AudioLevelUpdatedEventArgs.cs
- OpCodes.cs
- TransactionInterop.cs
- ViewStateModeByIdAttribute.cs
- DbDataReader.cs
- TypeDescriptor.cs
- DesigntimeLicenseContextSerializer.cs
- ScriptingWebServicesSectionGroup.cs
- ActionFrame.cs
- ipaddressinformationcollection.cs
- WorkflowItemPresenter.cs
- IIS7WorkerRequest.cs
- KeyedHashAlgorithm.cs
- ArgumentException.cs
- Set.cs
- PageCodeDomTreeGenerator.cs
- NativeMethods.cs
- PageMediaType.cs
- ByteAnimation.cs
- SaveFileDialog.cs
- AutomationIdentifier.cs
- GenericAuthenticationEventArgs.cs