-//
-// System.Data.DataRowView.cs
-//
-// Author:
-// Rodrigo Moya <rodrigo@ximian.com>
-// Miguel de Icaza <miguel@ximian.com>
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (C) Ximian, Inc 2002
-// (C) Daniel Morgan 2002
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// 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.
-//
-
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Reflection;
-
-namespace System.Data
-{
- /// <summary>
- /// Represents a customized view of a DataRow exposed as a fully featured Windows Forms control.
- /// </summary>
- public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo
- {
- #region Fields
-
- DataView dataView;
- DataRow dataRow;
- DataRowVersion rowVersion = DataRowVersion.Default;
-
- // FIXME: what are the defaults?
- bool isEdit = false;
- bool isNew = false;
-
- #endregion // Fields
-
- #region Constructors
-
- internal DataRowView (DataView dataView, DataRow row) : this(dataView, row, false){
- }
-
- internal DataRowView (DataView dataView, DataRow row, bool isNew) {
- this.dataView = dataView;
- this.dataRow = row;
- this.isNew = isNew;
- }
-
- #endregion // Constructors
-
- #region Methods
-
- public override bool Equals(object other)
- {
- return (other != null &&
- other is DataRowView &&
- ((DataRowView)other).dataRow != null &&
- ((DataRowView)other).dataRow.Equals(this.dataRow));
- }
-
- [MonoTODO]
- public void BeginEdit ()
- {
- // FIXME:
- dataRow.BeginEdit();
- isEdit = true;
- }
-
- [MonoTODO]
- public void CancelEdit ()
- {
- // FIXME:
- dataRow.CancelEdit();
- isEdit = false;
- }
-
- [MonoTODO]
- public DataView CreateChildView (DataRelation relation)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public DataView CreateChildView (string name)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void Delete ()
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void EndEdit ()
- {
- // FIXME:
- dataRow.EndEdit();
- isEdit = false;
- }
-
- #endregion // Methods
-
- #region Properties
-
- public DataView DataView
- {
- [MonoTODO]
- get {
- return dataView;
- }
- }
-
- public bool IsEdit {
- [MonoTODO]
- get {
- return isEdit;
- }
- }
-
- public bool IsNew {
- [MonoTODO]
- get {
- return isNew;
- }
- }
-
- [System.Runtime.CompilerServices.IndexerName("Item")]
- public object this[string column] {
- [MonoTODO]
- get {
- DataColumn dc = dataView.Table.Columns[column];
- return dataRow[dc];
- }
- [MonoTODO]
- set {
- DataColumn dc = dataView.Table.Columns[column];
- dataRow[dc] = value;
- dataView.ChangedList(ListChangedType.ItemChanged,dc.Ordinal,-1);
- }
- }
-
- // the compiler creates a DefaultMemeberAttribute from
- // this IndexerNameAttribute
- public object this[int column] {
- [MonoTODO]
- get {
- DataColumn dc = dataView.Table.Columns[column];
- return dataRow[dc];
- }
- [MonoTODO]
- set {
- DataColumn dc = dataView.Table.Columns[column];
- dataRow[dc] = value;
-
- }
- }
-
- public DataRow Row {
- [MonoTODO]
- get {
- return dataRow;
- }
- }
-
- public DataRowVersion RowVersion {
- [MonoTODO]
- get {
- return rowVersion;
- }
- }
-
- [MonoTODO]
- public override int GetHashCode() {
- throw new NotImplementedException ();
- }
-
- #endregion // Properties
-
- #region ICustomTypeDescriptor implementations
-
- [MonoTODO]
- AttributeCollection ICustomTypeDescriptor.GetAttributes ()
- {
- System.ComponentModel.AttributeCollection attributes;
- attributes = AttributeCollection.Empty;
- return attributes;
- }
-
- [MonoTODO]
- string ICustomTypeDescriptor.GetClassName ()
- {
- return "";
- }
-
- [MonoTODO]
- string ICustomTypeDescriptor.GetComponentName ()
- {
- return null;
- }
-
- [MonoTODO]
- TypeConverter ICustomTypeDescriptor.GetConverter ()
- {
- return null;
- }
-
- [MonoTODO]
- EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()
- {
- return null;
- }
-
- [MonoTODO]
- PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()
- {
- return null;
- }
-
- [MonoTODO]
- object ICustomTypeDescriptor.GetEditor (Type editorBaseType)
- {
- return null;
- }
-
- [MonoTODO]
- EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()
- {
- return new EventDescriptorCollection(null);
- }
-
- [MonoTODO]
- EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)
- {
- return new EventDescriptorCollection(null);
- }
-
- [MonoTODO]
- PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()
- {
- ITypedList typedList = (ITypedList) dataView;
- return typedList.GetItemProperties(new PropertyDescriptor[0]);
- }
-
- [MonoTODO]
- PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attributes)
- {
- PropertyDescriptorCollection descriptors;
- descriptors = ((ICustomTypeDescriptor) this).GetProperties ();
- // TODO: filter out descriptors which do not contain
- // any of those attributes
- // except, those descriptors
- // that contain DefaultMemeberAttribute
- return descriptors;
- }
-
- [MonoTODO]
- object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)
- {
- return this;
- }
-
- #endregion // ICustomTypeDescriptor implementations
-
- #region IDataErrorInfo implementation
-
- string IDataErrorInfo.Error {
- [MonoTODO]
- get {
- return ""; // FIXME
- }
- }
-
- string IDataErrorInfo.this[string columnName] {
- [MonoTODO]
- get {
- return ""; // FIXME
- }
- }
-
- #endregion // IDataErrorInfo implementation
- }
-}
+//\r
+// System.Data.DataRowView.cs\r
+//\r
+// Author:\r
+// Rodrigo Moya <rodrigo@ximian.com>\r
+// Miguel de Icaza <miguel@ximian.com>\r
+// Daniel Morgan <danmorg@sc.rr.com>\r
+//\r
+// (C) Ximian, Inc 2002\r
+// (C) Daniel Morgan 2002\r
+//\r
+\r
+//\r
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+using System;\r
+using System.Collections;\r
+using System.ComponentModel;\r
+using System.Reflection;\r
+\r
+namespace System.Data\r
+{\r
+ /// <summary>\r
+ /// Represents a customized view of a DataRow exposed as a fully featured Windows Forms control.\r
+ /// </summary>\r
+ // FIXME: correct exceptions in this[] methods\r
+#if NET_2_0\r
+ public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo, INotifyPropertyChanged\r
+#else\r
+ public class DataRowView : ICustomTypeDescriptor, IEditableObject, IDataErrorInfo\r
+#endif\r
+ {\r
+ #region Fields\r
+\r
+ DataView _dataView;\r
+ DataRow _dataRow;\r
+ int _index = -1;\r
+\r
+ #endregion // Fields\r
+\r
+ #region Constructors\r
+\r
+ internal DataRowView (DataView dataView, DataRow row, int index) {\r
+ _dataView = dataView;\r
+ _dataRow = row;\r
+ _index = index;\r
+ }\r
+\r
+ #endregion // Constructors\r
+\r
+ #region Methods\r
+\r
+ public override bool Equals(object other)\r
+ {\r
+ return (other != null &&\r
+ other is DataRowView && \r
+ ((DataRowView)other)._dataRow != null && \r
+ ((DataRowView)other)._dataRow.Equals(_dataRow));\r
+ }\r
+\r
+ public void BeginEdit ()\r
+ {\r
+ _dataRow.BeginEdit();\r
+ }\r
+\r
+ public void CancelEdit ()\r
+ {\r
+ // FIXME:\r
+ if (this.Row == DataView._lastAdded) {\r
+ DataView.CompleteLastAdded(false);\r
+ }\r
+ else {\r
+ _dataRow.CancelEdit();\r
+ }\r
+ }\r
+\r
+ public DataView CreateChildView (DataRelation relation)\r
+ {\r
+ return DataView.CreateChildView(relation,_index);\r
+ }\r
+\r
+ public DataView CreateChildView (string name)\r
+ {\r
+ return CreateChildView (\r
+ Row.Table.ChildRelations [name]);\r
+ }\r
+\r
+ public void Delete ()\r
+ {\r
+ DataView.Delete(_index);\r
+ }\r
+\r
+ public void EndEdit ()\r
+ {\r
+ // FIXME:\r
+ if (this.Row == DataView._lastAdded) {\r
+ DataView.CompleteLastAdded(true);\r
+ }\r
+ else {\r
+ _dataRow.EndEdit();\r
+ }\r
+ }\r
+\r
+ private void CheckAllowEdit()\r
+ {\r
+ if (!DataView.AllowEdit && (Row != DataView._lastAdded))\r
+ throw new DataException("Cannot edit on a DataSource where AllowEdit is false.");\r
+ }\r
+\r
+ #endregion // Methods\r
+\r
+ #region Properties\r
+ \r
+ public DataView DataView {\r
+ get { return _dataView; }\r
+ }\r
+\r
+ public bool IsEdit {\r
+ get { return _dataRow.HasVersion(DataRowVersion.Proposed); }\r
+ }\r
+\r
+ // It becomes true when this instance is created by\r
+ // DataView.AddNew(). If it is true, then the DataRow is\r
+ // "Detached", and when this.EndEdit() is invoked, the row\r
+ // will be added to the table.\r
+ public bool IsNew {\r
+ [MonoTODO]\r
+ get {\r
+ return Row == DataView._lastAdded;\r
+ }\r
+ }\r
+ \r
+ [System.Runtime.CompilerServices.IndexerName("Item")]\r
+ public object this[string column] {\r
+ get {\r
+ DataColumn dc = _dataView.Table.Columns[column];\r
+\r
+ if (dc == null) {\r
+ string error = column + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName;\r
+ throw new ArgumentException(error);\r
+ }\r
+ return _dataRow[dc, GetActualRowVersion ()];\r
+ }\r
+ set {\r
+ CheckAllowEdit();\r
+ DataColumn dc = _dataView.Table.Columns[column];\r
+\r
+ if (dc == null) {\r
+ string error = column + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName;\r
+ throw new ArgumentException(error);\r
+ }\r
+ _dataRow[dc] = value;\r
+ }\r
+ }\r
+\r
+ // the compiler creates a DefaultMemeberAttribute from\r
+ // this IndexerNameAttribute\r
+ public object this[int column] {\r
+ get {\r
+ DataColumn dc = _dataView.Table.Columns[column];\r
+\r
+ if (dc == null) {\r
+ string error = column + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName;\r
+ throw new ArgumentException(error);\r
+ }\r
+ return _dataRow[dc, GetActualRowVersion ()];\r
+ }\r
+ set {\r
+ CheckAllowEdit();\r
+ DataColumn dc = _dataView.Table.Columns[column];\r
+\r
+ if (dc == null) {\r
+ string error = column + " is neither a DataColumn nor a DataRelation for table " + _dataView.Table.TableName;\r
+ throw new ArgumentException(error);\r
+ }\r
+ _dataRow[dc] = value;\r
+\r
+ }\r
+ }\r
+\r
+ private DataRowVersion GetActualRowVersion ()\r
+ {\r
+ switch (_dataView.RowStateFilter) {\r
+ case DataViewRowState.Added:\r
+ return DataRowVersion.Proposed;\r
+ case DataViewRowState.ModifiedOriginal:\r
+ case DataViewRowState.Deleted:\r
+ case DataViewRowState.Unchanged:\r
+ case DataViewRowState.OriginalRows:\r
+ return DataRowVersion.Original;\r
+ case DataViewRowState.ModifiedCurrent:\r
+ return DataRowVersion.Current;\r
+ }\r
+ return DataRowVersion.Default;\r
+ }\r
+\r
+ public DataRow Row {\r
+ [MonoTODO]\r
+ get {\r
+ return _dataRow;\r
+ }\r
+ }\r
+\r
+ public DataRowVersion RowVersion {\r
+ [MonoTODO]\r
+ get {\r
+ DataRowVersion version = DataView.GetRowVersion(_index);\r
+ if (version != DataRowVersion.Original)\r
+ version = DataRowVersion.Current;\r
+\r
+ return version;\r
+ }\r
+ }\r
+\r
+ [MonoTODO]\r
+ public override int GetHashCode() {\r
+ return _dataRow.GetHashCode();\r
+ } \r
+\r
+ internal int Index {\r
+ get { return _index; }\r
+ }\r
+\r
+ #endregion // Properties\r
+ \r
+ #region ICustomTypeDescriptor implementations\r
+ \r
+ [MonoTODO]\r
+ AttributeCollection ICustomTypeDescriptor.GetAttributes ()\r
+ {\r
+ System.ComponentModel.AttributeCollection attributes;\r
+ attributes = AttributeCollection.Empty;\r
+ return attributes;\r
+ }\r
+\r
+ [MonoTODO]\r
+ string ICustomTypeDescriptor.GetClassName ()\r
+ {\r
+ return "";\r
+ }\r
+ \r
+ [MonoTODO]\r
+ string ICustomTypeDescriptor.GetComponentName ()\r
+ {\r
+ return null;\r
+ }\r
+\r
+ [MonoTODO]\r
+ TypeConverter ICustomTypeDescriptor.GetConverter ()\r
+ {\r
+ return null;\r
+ }\r
+\r
+ [MonoTODO]\r
+ EventDescriptor ICustomTypeDescriptor.GetDefaultEvent ()\r
+ {\r
+ return null;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty ()\r
+ {\r
+ return null;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ object ICustomTypeDescriptor.GetEditor (Type editorBaseType)\r
+ {\r
+ return null;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ EventDescriptorCollection ICustomTypeDescriptor.GetEvents ()\r
+ {\r
+ return new EventDescriptorCollection(null);\r
+ }\r
+\r
+ [MonoTODO]\r
+ EventDescriptorCollection ICustomTypeDescriptor.GetEvents (Attribute [] attributes)\r
+ {\r
+ return new EventDescriptorCollection(null);\r
+ }\r
+\r
+ [MonoTODO]\r
+ PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties ()\r
+ {\r
+ if (DataView == null) {\r
+ ITypedList typedList = (ITypedList) _dataView;\r
+ return typedList.GetItemProperties(new PropertyDescriptor[0]);\r
+ }\r
+ else {\r
+ return DataView.Table.GetPropertyDescriptorCollection();\r
+ }\r
+ }\r
+\r
+ [MonoTODO]\r
+ PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties (Attribute [] attributes)\r
+ {\r
+ PropertyDescriptorCollection descriptors;\r
+ descriptors = ((ICustomTypeDescriptor) this).GetProperties ();\r
+ // TODO: filter out descriptors which do not contain\r
+ // any of those attributes\r
+ // except, those descriptors \r
+ // that contain DefaultMemeberAttribute\r
+ return descriptors;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ object ICustomTypeDescriptor.GetPropertyOwner (PropertyDescriptor pd)\r
+ {\r
+ return this;\r
+ }\r
+\r
+ #endregion // ICustomTypeDescriptor implementations\r
+\r
+ #region IDataErrorInfo implementation\r
+\r
+ string IDataErrorInfo.Error {\r
+ [MonoTODO]\r
+ get {\r
+ return ""; // FIXME\r
+ }\r
+ }\r
+\r
+ string IDataErrorInfo.this[string columnName] {\r
+ [MonoTODO]\r
+ get {\r
+ return ""; // FIXME\r
+ }\r
+ }\r
+\r
+ #endregion // IDataErrorInfo implementation\r
+ \r
+#if NET_2_0\r
+ #region INotifyPropertyChanged\r
+\r
+ public event PropertyChangedEventHandler PropertyChanged;\r
+\r
+ [MonoTODO ("to be tested..")]\r
+ void OnPropertyChanged (string propertyName)\r
+ {\r
+ if (PropertyChanged != null) {\r
+ PropertyChangedEventArgs args = new PropertyChangedEventArgs (propertyName);\r
+ PropertyChanged (this, args);\r
+ }\r
+ }\r
+ #endregion\r
+#endif\r
+ }\r
+}\r