2004-05-15 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data / DataTable.cs
index aa45e346f50817cc4d5bea6dc17c4b76c3e08773..39ff652bda047835ec4e1e5b1c055c13a04d5c1d 100644 (file)
@@ -32,7 +32,6 @@ namespace System.Data {
        [DefaultProperty ("TableName")]
        [DesignTimeVisible (false)]
        [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DataTableEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
-       [TypeConverterAttribute("System.ComponentModel.ComponentConverter, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
        [Serializable]
        public class DataTable : MarshalByValueComponent, IListSource, ISupportInitialize, ISerializable 
        {
@@ -75,7 +74,7 @@ namespace System.Data {
                  /// An enum variable indicating whether BeginInit() or EndInit() is called.
                 /// Delegate to call a function which performs cleanup after EndInit() is called
                 /// </summary>
-                public enum initStatus { NotInitialized, BeginInit, EndInit };
+                internal enum initStatus { NotInitialized, BeginInit, EndInit };
         
                private initStatus _initStatus;
         
@@ -132,7 +131,16 @@ namespace System.Data {
                {
                        string schema = info.GetString ("XmlSchema");
                        string data = info.GetString ("XmlDiffGram");
-                       
+
+                       DataSet ds = new DataSet ();
+                       ds.ReadXmlSchema (new StringReader (schema));
+                       ds.Tables [0].CopyProperties (this);
+                       ds = new DataSet ();
+                       ds.Tables.Add (this);
+                       ds.ReadXml (new StringReader (data), XmlReadMode.IgnoreSchema);
+                       ds.Tables.Remove (this);
+/* keeping for a while. With the change above, we shouldn't have to consider 
+ * DataTable mode in schema inference/read.
                        XmlSchemaMapper mapper = new XmlSchemaMapper (this);
                        XmlTextReader xtr = new XmlTextReader(new StringReader (schema));
                        mapper.Read (xtr);
@@ -140,6 +148,7 @@ namespace System.Data {
                        XmlDiffLoader loader = new XmlDiffLoader (this);
                        xtr = new XmlTextReader(new StringReader (data));
                        loader.Load (xtr);
+*/
                }
 
 #if NET_2_0
@@ -279,7 +288,7 @@ namespace System.Data {
                [DataSysDescription ("The expression used to compute the data-bound value of this row.")]       
                [DefaultValue ("")]
                public string DisplayExpression {
-                       get { return "" + _displayExpression; }
+                       get { return _displayExpression == null ? "" : _displayExpression; }
                        set { _displayExpression = value; }
                }
 
@@ -356,7 +365,7 @@ namespace System.Data {
                [DataCategory ("Data")]
                [DataSysDescription ("Indicates the XML uri namespace for the elements contained in this table.")]
                public string Namespace {
-                       get { return "" + _nameSpace; }
+                       get { return _nameSpace == null ? "" : _nameSpace; }
                        set { _nameSpace = value; }
                }
 
@@ -381,7 +390,7 @@ namespace System.Data {
                [DataSysDescription ("Indicates the Prefix of the namespace used for this table in XML representation.")]
                [DefaultValue ("")]
                public string Prefix {
-                       get { return "" + _prefix; }
+                       get { return _prefix == null ? "" : _prefix; }
                        set {
                                // Prefix cannot contain any special characters other than '_' and ':'
                                for (int i = 0; i < value.Length; i++) {
@@ -493,7 +502,7 @@ namespace System.Data {
                [DefaultValue ("")]     
                [RefreshProperties (RefreshProperties.All)]
                public string TableName {
-                       get { return "" + _tableName; }
+                       get { return _tableName == null ? "" : _tableName; }
                        set { _tableName = value; }
                }
                
@@ -521,7 +530,7 @@ namespace System.Data {
                        }
                }
 
-               public bool RowsExist(Object[] columns, Object[] relatedColumns,DataRow row)
+               internal bool RowsExist(Object[] columns, Object[] relatedColumns,DataRow row)
                {
                        object[] vals = new object[relatedColumns.Length];
                        for (int i = 0; i < vals.Length; i++)
@@ -530,7 +539,7 @@ namespace System.Data {
                        return RowsExist(columns,vals);
                }
 
-               public bool RowsExist(Object[] columns,Object[] values)
+               internal bool RowsExist(Object[] columns,Object[] values)
                {
                        bool rowsExist = false;
                        Index indx = this.GetIndexByColumns ((DataColumn[])columns);
@@ -1207,7 +1216,7 @@ namespace System.Data {
                                if (sortableColumns.Length == 0)
                                        throw new Exception("sort expression result is 0");
 
-                               RowSorter rowSorter = new RowSorter (dataRows, sortableColumns);
+                               RowSorter rowSorter = new RowSorter (this, dataRows, sortableColumns);
                                dataRows = rowSorter.SortRows ();
 
                                sortableColumns = null;
@@ -1440,6 +1449,7 @@ namespace System.Data {
                        //      {
                        //              RemoveColumn(this, e);
                        //      }
+                       this.Rows.onColumnRemoved(column.Ordinal);
                }
 
                /// <summary>
@@ -1587,7 +1597,7 @@ namespace System.Data {
                                        string columnName = columnSortInfo[0].Trim ();
                                        string sortOrder = "ASC";
                                        if (columnSortInfo.Length > 1) 
-                                               sortOrder = columnSortInfo[1].Trim ().ToUpper ();
+                                               sortOrder = columnSortInfo[1].Trim ().ToUpper (Locale);
                                        
                                        ListSortDirection sortDirection = ListSortDirection.Ascending;
                                        switch (sortOrder) {
@@ -1647,12 +1657,15 @@ namespace System.Data {
 
                private class RowSorter : IComparer 
                {
+                       private DataTable table;
                        private SortableColumn[] sortColumns;
                        private DataRow[] rowsToSort;
                        
-                       internal RowSorter(DataRow[] unsortedRows, 
+                       internal RowSorter(DataTable table,
+                                       DataRow[] unsortedRows, 
                                        SortableColumn[] sortColumns) 
                        {
+                               this.table = table;
                                this.sortColumns = sortColumns;
                                this.rowsToSort = unsortedRows;
                        }
@@ -1717,8 +1730,8 @@ namespace System.Data {
                                        return 1;
 
                                if((a is string) && (b is string)) {
-                                       a = ((string) a).ToUpper ();
-                                       b = ((string) b).ToUpper ();                    
+                                       a = ((string) a).ToUpper (table.Locale);
+                                       b = ((string) b).ToUpper (table.Locale);                        
                                }
 
                                if (a is IComparable)