2002-11-06 Daniel Morgan <danmorg@sc.rr.com>
[mono.git] / mcs / class / System.Data / System.Data / DataRowCollection.cs
1 //
2 // System.Data.DataRowCollection.cs
3 //
4 // Author:
5 //   Daniel Morgan <danmorg@sc.rr.com>
6 //   Tim Coleman <tim@timcoleman.com>
7 //
8 // (C) Ximian, Inc 2002
9 // (C) Copyright 2002 Tim Coleman
10 // (C) Copyright 2002 Daniel Morgan
11 //
12
13 using System;
14 using System.Collections;
15 using System.ComponentModel;
16
17 namespace System.Data
18 {
19         /// <summary>
20         /// Collection of DataRows in a DataTable
21         /// </summary>
22         [Serializable]
23         public class DataRowCollection : InternalDataCollectionBase 
24         {
25                 private DataTable table;
26
27                 /// <summary>
28                 /// Internal constructor used to build a DataRowCollection.
29                 /// </summary>
30                 protected internal DataRowCollection (DataTable table) : base ()
31                 {
32                         this.table = table;
33                 }
34
35                 /// <summary>
36                 /// Gets the row at the specified index.
37                 /// </summary>
38                 public DataRow this[int index] 
39                 {
40                         get { return (DataRow) list[index]; }
41                 }
42
43                 /// <summary>
44                 /// This member overrides InternalDataCollectionBase.List
45                 /// </summary>
46                 protected internal override ArrayList List 
47                 {
48                         get { return list; }
49                 }               
50
51                 /// <summary>
52                 /// Adds the specified DataRow to the DataRowCollection object.
53                 /// </summary>
54                 public void Add (DataRow row) 
55                 {
56                         //TODO: AutoIncrement
57                         //TODO: validation
58                         list.Add (row);
59                         row.RowStateInternal = DataRowState.Added;
60                 }
61
62                 /// <summary>
63                 /// Creates a row using specified values and adds it to the DataRowCollection.
64                 /// </summary>
65                 public virtual DataRow Add (object[] values) 
66                 {
67                         DataRow row = table.NewRow ();
68                         row.ItemArray = values;
69                         Add (row);
70                         return row;
71                 }
72
73                 /// <summary>
74                 /// Clears the collection of all rows.
75                 /// </summary>
76                 [MonoTODO]
77                 public void Clear () 
78                 {
79                         list.Clear ();
80                 }
81
82                 /// <summary>
83                 /// Gets a value indicating whether the primary key of any row in the collection contains
84                 /// the specified value.
85                 /// </summary>
86                 [MonoTODO]
87                 public bool Contains (object key) 
88                 {
89                         throw new NotImplementedException ();
90                 }
91
92                 /// <summary>
93                 /// Gets a value indicating whether the primary key column(s) of any row in the 
94                 /// collection contains the values specified in the object array.
95                 /// </summary>
96                 [MonoTODO]
97                 public bool Contains (object[] keys) 
98                 {
99                         throw new NotImplementedException ();
100                 }
101
102                 /// <summary>
103                 /// Gets the row specified by the primary key value.
104                 /// </summary>
105                 [MonoTODO]
106                 public DataRow Find (object key) 
107                 {
108                         throw new NotImplementedException ();
109                 }
110
111                 /// <summary>
112                 /// Gets the row containing the specified primary key values.
113                 /// </summary>
114                 [MonoTODO]
115                 public DataRow Find (object[] keys) 
116                 {
117                         throw new NotImplementedException ();
118                 }
119
120                 /// <summary>
121                 /// Inserts a new row into the collection at the specified location.
122                 /// </summary>
123                 public void InsertAt (DataRow row, int pos) 
124                 {
125                         list.Insert (pos, row);
126                 }
127
128                 /// <summary>
129                 /// Removes the specified DataRow from the collection.
130                 /// </summary>
131                 public void Remove (DataRow row) 
132                 {
133                         list.Remove (row);
134                 }
135
136                 /// <summary>
137                 /// Removes the row at the specified index from the collection.
138                 /// </summary>
139                 public void RemoveAt (int index) 
140                 {
141                         list.RemoveAt (index);
142                 }
143
144                 ///<summary>
145                 ///Internal method used to validate a given DataRow with respect
146                 ///to the DataRowCollection
147                 ///</summary>
148                 [MonoTODO]
149                 internal void ValidateDataRowInternal(DataRow row)
150                 {
151                         //FIXME: this validates constraints in the order they appear
152                         //in the collection. Most probably we need to do it in a 
153                         //specific order like unique/primary keys first, then Foreignkeys, etc
154                         foreach(Constraint constraint in table.Constraints)
155                         {
156                                 constraint.AssertConstraint(row);
157                         }
158
159                 }
160
161         }
162 }