Procházet zdrojové kódy

2005-05-04 Sureshkumar T <[email protected]>
* Test/System.Data/DataTableTest.cs: ClearTest () : added case for checking whether TableCleared event is fired.
* System.Data.dll.sources: Added DataTableClearEventArgs.cs and DataTableClearEventHandler.cs.
* System.Data/DataTable.cs: Clear (): Raise TableCleared event.
* System.Data/DataTableClearEventArgs.cs: Args for DataTableClearEventHandler.
* System.Data/DataTableClearEventHandler.cs: Handler for DataTable.TableClear event.


svn path=/trunk/mcs/; revision=44017

Sureshkumar T před 20 roky
rodič
revize
8a6fcaf4c2

+ 5 - 0
mcs/class/System.Data/ChangeLog

@@ -1,3 +1,8 @@
+2005-05-04  Sureshkumar T  <[email protected]>
+
+	* System.Data.dll.sources: Added DataTableClearEventArgs.cs and
+	DataTableClearEventHandler.cs.
+
 2005-04-27  Sureshkumar T  <[email protected]>
 
 	* System.Data_test.dll.sources: Added DataTableReaderTest.cs

+ 2 - 0
mcs/class/System.Data/System.Data.dll.sources

@@ -37,6 +37,8 @@ System.Data/DataSet.cs
 System.Data/DataSysDescriptionAttribute.cs
 System.Data/DataTable.cs
 System.Data/DataTableCollection.cs
+System.Data/DataTableClearEventArgs.cs
+System.Data/DataTableClearEventHandler.cs
 System.Data/DataTableTypeConverter.cs
 System.Data/DataTablePropertyDescriptor.cs
 System.Data/DataTableReader.cs

+ 7 - 0
mcs/class/System.Data/System.Data/ChangeLog

@@ -1,5 +1,12 @@
 2005-05-04  Sureshkumar T  <[email protected]>
 
+	* DataTable.cs: Clear (): Raise TableCleared event.
+
+	* DataTableClearEventArgs.cs: Args for DataTableClearEventHandler.
+
+	* DataTableClearEventHandler.cs: Handler for DataTable.TableClear
+	event.
+
 	* DataRow.cs: AcceptChanges: raise row changing & row changed
 	events.
 

+ 24 - 1
mcs/class/System.Data/System.Data/DataTable.cs

@@ -678,6 +678,10 @@ namespace System.Data {
 		public void Clear () {
                         // Foriegn key constraints are checked in _rows.Clear method
 			_rows.Clear ();
+#if NET_2_0
+                        OnTableCleared (new DataTableClearEventArgs (this));
+#endif // NET_2_0
+
 		}
 
 		/// <summary>
@@ -1618,6 +1622,16 @@ namespace System.Data {
 			OnColumnChanged(e);
 		}
 
+#if NET_2_0
+                /// <summary>
+		/// Raises TableCleared Event and delegates to subscribers
+		/// </summary>
+		protected virtual void OnTableCleared (DataTableClearEventArgs e) {
+			if (TableCleared != null)
+				TableCleared (this, e);
+		}
+#endif // NET_2_0
+
 		/// <summary>
 		/// Raises the ColumnChanging event.
 		/// </summary>
@@ -1756,7 +1770,16 @@ namespace System.Data {
 		[DataCategory ("Data")]	
 		[DataSysDescription ("Occurs when a row in the table marked for deletion. Throw an exception to cancel the deletion.")]
 		public event DataRowChangeEventHandler RowDeleting;
-		
+
+#if NET_2_0
+		/// <summary>
+		/// Occurs after the Clear method is called on the datatable.
+		/// </summary>
+		[DataCategory ("Data")]	
+		[DataSysDescription ("Occurs when the rows in a table is cleared . Throw an exception to cancel the deletion.")]
+		public event DataTableClearEventHandler TableCleared;
+#endif // NET_2_0
+
 		#endregion // Events
 
 		/// <summary>

+ 57 - 0
mcs/class/System.Data/System.Data/DataTableClearEventArgs.cs

@@ -0,0 +1,57 @@
+//
+// System.Data.DataTableClearEventArgs.cs
+//
+// Author:
+//   Sureshkumar T <[email protected]>
+//
+//
+
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) Authors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// 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
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+namespace System.Data 
+{
+        public sealed class DataTableClearEventArgs : EventArgs
+        {
+                #region Fields
+                private readonly DataTable _table;
+                #endregion //Fields
+
+                #region Constructors
+                public DataTableClearEventArgs(DataTable table) 
+                {
+                        _table = table;
+                }
+                #endregion // Constructors
+
+
+                #region Properties
+                public DataTable Table { get { return _table; } }
+                public string TableName { get { return _table.TableName ; } }
+                public string TableNamespace { get { return _table.Namespace; } }
+                #endregion // Properties
+        }
+}
+#endif // NET_2_0

+ 43 - 0
mcs/class/System.Data/System.Data/DataTableClearEventHandler.cs

@@ -0,0 +1,43 @@
+//
+// System.Data.DataColumnChangeEventHandler.cs
+//
+// Author:
+//   Sureshkumar T <[email protected]>
+//
+//
+
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) Authors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// 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
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+namespace System.Data
+{
+	/// <summary>
+	/// Represents the method that will handle the the TableCleared event.
+	/// </summary>
+	[Serializable]
+	public delegate void DataTableClearEventHandler(object sender, DataTableClearEventArgs e);
+
+}
+#endif // NET_2_0

+ 2 - 0
mcs/class/System.Data/Test/System.Data/ChangeLog

@@ -5,6 +5,8 @@
 	well. Simplified table creation for ClearReset test.
 	- Added a test to check whether Commit RowChanging & RowChanged
 	event is fired.
+	- ClearTest () : added case for checking whether TableCleared
+	event is fired.
 
 2005-04-29  Sureshkumar T  <[email protected]>
 

+ 14 - 0
mcs/class/System.Data/Test/System.Data/DataTableTest.cs

@@ -1212,8 +1212,15 @@ namespace MonoTests.System.Data
                         table.Rows.Add (new object [] { 4, "mono 4" });
 
                         table.AcceptChanges ();
+#if NET_2_0
+                        _tableClearedEventFired = false;
+                        table.TableCleared += new DataTableClearEventHandler (OnTableCleared);
+#endif // NET_2_0
                         
                         table.Clear ();
+#if NET_2_0
+                        AssertEquals ("#0 should have fired cleared event", true, _tableClearedEventFired);
+#endif // NET_2_0
                         
                         DataRow r = table.Rows.Find (1);
                         AssertEquals ("#1 should have cleared", true, r == null);
@@ -1222,6 +1229,13 @@ namespace MonoTests.System.Data
                         table.Rows.Add (new object [] { 2, "mono 2" });
                         AssertEquals ("#2 should add row", 1, table.Rows.Count);
                 }
+#if NET_2_0
+                private bool _tableClearedEventFired = false;
+                private void OnTableCleared (object src, DataTableClearEventArgs args)
+                {
+                        _tableClearedEventFired = true;
+                }
+#endif // NET_2_0
                 
 
 		[Test]