// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
using System.ComponentModel;
using System.Globalization;
-namespace System.Data {
+namespace System.Data
+{
/// <summary>
/// Represents the collection of tables for the DataSet.
/// </summary>
#if NET_2_0
sealed
#endif
- class DataTableCollection : InternalDataCollectionBase
- {
+ class DataTableCollection : InternalDataCollectionBase {
DataSet dataSet;
DataTable[] mostRecentTables;
- #region Constructors
+
+ #region Constructors
internal DataTableCollection (DataSet dataSet)
: base ()
{
this.dataSet = dataSet;
}
-
+
#endregion
-
+
#region Properties
- public DataTable this[int index] {
+ public DataTable this [int index] {
get {
if (index < 0 || index >= List.Count)
- throw new IndexOutOfRangeException(String.Format("Cannot find table {0}", index));
- return (DataTable)(List[index]);
+ throw new IndexOutOfRangeException (String.Format ("Cannot find table {0}", index));
+ return (DataTable)(List [index]);
}
}
- public DataTable this[string name] {
- get {
+ public DataTable this [string name] {
+ get {
int index = IndexOf (name, true);
- return index < 0 ? null : (DataTable) List[index];
+ return index < 0 ? null : (DataTable) List [index];
}
}
#if NET_2_0
public DataTable this [string name, string tbNamespace] {
- get {
+ get {
int index = IndexOf (name, tbNamespace, true);
- return index < 0 ? null : (DataTable) List[index];
+ return index < 0 ? null : (DataTable) List [index];
}
}
#endif
}
#endregion
-
- #region Methods
+
+ #region Methods
public
#if !NET_2_0
virtual
#endif
- DataTable Add ()
+ DataTable Add ()
{
DataTable Table = new DataTable ();
Add (Table);
#if !NET_2_0
virtual
#endif
- void Add (DataTable table)
+ void Add (DataTable table)
{
OnCollectionChanging (new CollectionChangeEventArgs (CollectionChangeAction.Add, table));
// check if the reference is a null reference
- if(table == null)
- throw new ArgumentNullException("table");
-
+ if (table == null)
+ throw new ArgumentNullException ("table");
+
// check if the list already contains this tabe.
- if(List.Contains(table))
- throw new ArgumentException("DataTable already belongs to this DataSet.");
-
- // check if table is part of another DataSet
+ if (List.Contains (table))
+ throw new ArgumentException ("DataTable already belongs to this DataSet.");
+
+ // check if table is part of another DataSet
if (table.DataSet != null && table.DataSet != this.dataSet)
throw new ArgumentException ("DataTable already belongs to another DataSet");
// if the table name is null or empty string.
- // give her a name.
+ // give her a name.
if (table.TableName == null || table.TableName == string.Empty)
NameTable (table);
-
+
// check if the collection has a table with the same name.
#if !NET_2_0
int tmp = IndexOf (table.TableName);
// if we found a table with same name we have to check
// that it is the same case.
// indexof can return a table with different case letters.
- if (tmp != -1)
- {
- if(table.TableName == this[tmp].TableName)
- throw new DuplicateNameException("A DataTable named '" + table.TableName + "' already belongs to this DataSet.");
- }
+ if (tmp != -1 &&
+ table.TableName == this [tmp].TableName)
+ throw new DuplicateNameException ("A DataTable named '" + table.TableName + "' already belongs to this DataSet.");
List.Add (table);
table.dataSet = dataSet;
#if !NET_2_0
virtual
#endif
- DataTable Add (string name)
+ DataTable Add (string name)
{
DataTable table = new DataTable (name);
this.Add (table);
}
#endif
- public void AddRange (DataTable[] tables)
+ public void AddRange (DataTable [] tables)
{
if (dataSet != null && dataSet.InitInProgress) {
mostRecentTables = tables;
mostRecentTables = null;
}
- public bool CanRemove (DataTable table)
+ public bool CanRemove (DataTable table)
{
- return CanRemove(table, false);
+ return CanRemove (table, false);
}
- public void Clear ()
+ public void Clear ()
{
List.Clear ();
}
- public bool Contains (string name)
+ public bool Contains (string name)
{
return (-1 != IndexOf (name, false));
}
-
+
#if NET_2_0
- public bool Contains (string name, string tableNamespace)
+ public bool Contains (string name, string tableNamespace)
{
- return (IndexOf (name, tableNamespace) != -1) ;
+ return (IndexOf (name, tableNamespace) != -1);
}
-#endif
public void CopyTo (DataTable [] array, int index)
{
CopyTo ((Array) array, index);
}
+#endif
public
#if !NET_2_0
virtual
#endif
- int IndexOf (DataTable table)
+ int IndexOf (DataTable table)
{
return List.IndexOf (table);
}
#if !NET_2_0
virtual
#endif
- int IndexOf (string name)
+ int IndexOf (string tableName)
{
- return IndexOf (name, false);
+ return IndexOf (tableName, false);
}
#if NET_2_0
- public int IndexOf (string name, string tableNamespace)
+ public int IndexOf (string tableName, string tableNamespace)
{
if (tableNamespace == null)
throw new ArgumentNullException ("'tableNamespace' argument cannot be null.",
"tableNamespace");
- return IndexOf (name, tableNamespace, false);
+ return IndexOf (tableName, tableNamespace, false);
}
#endif
-
- public void Remove (DataTable table)
+
+ public void Remove (DataTable table)
{
OnCollectionChanging (new CollectionChangeEventArgs (CollectionChangeAction.Remove, table));
- if (CanRemove(table, true))
+ if (CanRemove (table, true))
table.dataSet = null;
- List.Remove(table);
+ List.Remove (table);
table.dataSet = null;
OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, table));
}
- public void Remove (string name)
+ public void Remove (string name)
{
int index = IndexOf (name, false);
if (index == -1)
- throw new ArgumentException ("Table " + name + " does not belong to this DataSet");
+ throw new ArgumentException ("Table " + name + " does not belong to this DataSet");
RemoveAt (index);
}
}
#endif
- public void RemoveAt (int index)
+ public void RemoveAt (int index)
{
- Remove(this[index]);
+ Remove (this [index]);
}
#endregion
#region Protected methods
-
#if !NET_2_0
protected internal virtual
#else
internal
#endif
- void OnCollectionChanging (CollectionChangeEventArgs Args)
+ void OnCollectionChanging (CollectionChangeEventArgs ccevent)
{
if (CollectionChanging != null)
- CollectionChanging (this, Args);
+ CollectionChanging (this, ccevent);
}
-
#if !NET_2_0
protected virtual
#else
internal
#endif
- void OnCollectionChanged (CollectionChangeEventArgs Args)
+ void OnCollectionChanged (CollectionChangeEventArgs ccevent)
{
if (CollectionChanged != null)
- CollectionChanged (this, Args);
+ CollectionChanged (this, ccevent);
}
#endregion
return index;
} while (index != -1 && index < Count);
-
+
if (count == 1)
return match;
private int IndexOf (string name, bool error, int start)
{
int count = 0, match = -1;
- for (int i = start; i < List.Count; i++)
- {
+ for (int i = start; i < List.Count; i++) {
String name2 = ((DataTable) List[i]).TableName;
if (String.Compare (name, name2, false) == 0)
return i;
while (Contains (Name + i))
i++;
- Table.TableName = Name + i;
+ Table.TableName = Name + i;
}
-
+
// check if a table can be removed from this collectiuon.
// if the table can not be remved act according to throwException parameter.
// if it is true throws an Exception, else return false.
- private bool CanRemove(DataTable table, bool throwException)
+ private bool CanRemove (DataTable table, bool throwException)
{
-
// check if table is null reference
if (table == null) {
- if(throwException)
- throw new ArgumentNullException("table");
+ if (throwException)
+ throw new ArgumentNullException ("table");
return false;
}
// check if the table has the same DataSet as this collection.
- if(table.DataSet != this.dataSet) {
- if(!throwException)
+ if (table.DataSet != this.dataSet) {
+ if (!throwException)
return false;
- throw new ArgumentException("Table " + table.TableName + " does not belong to this DataSet.");
+ throw new ArgumentException ("Table " + table.TableName + " does not belong to this DataSet.");
}
-
+
// check the table has a relation attached to it.
if (table.ParentRelations.Count > 0 || table.ChildRelations.Count > 0) {
- if(!throwException)
+ if (!throwException)
return false;
- throw new ArgumentException("Cannot remove a table that has existing relations. Remove relations first.");
+ throw new ArgumentException ("Cannot remove a table that has existing relations. Remove relations first.");
}
// now we check if any ForeignKeyConstraint is referncing 'table'.
}
ForeignKeyConstraint fc = c as ForeignKeyConstraint;
- if (fc == null)
+ if (fc == null)
continue;
if (!throwException)
#region Events
- [ResDescriptionAttribute ("Occurs whenever this collection's membership changes.")]
+ [ResDescriptionAttribute ("Occurs whenever this collection's membership changes.")]
public event CollectionChangeEventHandler CollectionChanged;
public event CollectionChangeEventHandler CollectionChanging;