Exemple #1
0
        /// <summary>
        /// Sorts the data rows of a DataColumnCollection (more accurate: of all columns belonging to a column group, see below), using a specified column.
        /// </summary>
        /// <param name="table">The DataColumnCollection where the data columns should be sorted.</param>
        /// <param name="cols">The columns which are used for determining the order of the entries. The sorting will be done by cols[0], then cols[1] and so on.
        /// ll this columns has to belong to the table and need to have the same column group number (otherwise an exception will be thrown). All columns with the same group number than this columns will be included in the sort process.</param>
        /// <param name="inAscendingOrder">If true, the table is sorted in ascending order. Otherwise, the table is sorted in descending order.</param>
        public static void SortRows(this DataColumnCollection table, DataColumn[] cols, bool inAscendingOrder)
        {
            if (cols == null || cols.Length == 0)
            {
                throw new ArgumentException("cols is null or empty");
            }

            using (var token = table.SuspendGetToken())
            {
                int groupNumber = table.GetColumnGroup(cols[0]);
                for (int i = 1; i < cols.Length; i++)
                {
                    if (groupNumber != table.GetColumnGroup(cols[i]))
                    {
                        throw new ArgumentException(string.Format("cols[{0}] has a deviating group number from cols[0]. Only columns belonging to the same group can be sorted", i));
                    }
                }

                for (int k = 0; k < cols.Length; k++)
                {
                    if (!table.ContainsColumn(cols[k]))
                    {
                        throw new ArgumentException("The sorting columnd provided must all be part of the DataColumnCollection (otherwise the swap algorithm can not sort this column)");
                    }
                }

                HeapSort(cols[0].Count, new MultipleDataColumnComparer(cols, inAscendingOrder).Compare, new DataColumnCollectionRowSwapper(table, groupNumber).Swap);
            }
        }
Exemple #2
0
 public DataColumnCollectionRowSwapper(DataColumnCollection coll, int forColumnGroup)
 {
     _colsToSwap = new List <DataColumn>();
     for (int i = 0; i < coll.ColumnCount; ++i)
     {
         if (coll.GetColumnGroup(i) == forColumnGroup)
         {
             _colsToSwap.Add(coll[i]);
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Ensures that the selected columns in the source <see cref="DataColumnCollection"/> do also exist in the destination <see cref="DataColumnCollection"/>.
        /// </summary>
        /// <param name="sourceTable">The source table.</param>
        /// <param name="selectedSourceDataColumns">The selected source data columns. If this parameter is null, all source columns are selected.</param>
        /// <param name="destinationTable">The destination table.</param>
        public static void EnsureColumnsExistInDestinationCollection(this DataColumnCollection sourceTable, IAscendingIntegerCollection selectedSourceDataColumns, DataColumnCollection destinationTable)
        {
            if (null == selectedSourceDataColumns || 0 == selectedSourceDataColumns.Count)
            {
                selectedSourceDataColumns = Altaxo.Collections.ContiguousIntegerRange.FromStartAndCount(0, sourceTable.ColumnCount);
            }

            foreach (var colIdx in selectedSourceDataColumns)
            {
                var srcCol = sourceTable[colIdx];

                destinationTable.EnsureExistence(
                    sourceTable.GetColumnName(srcCol),
                    srcCol.GetType(),
                    sourceTable.GetColumnKind(srcCol),
                    sourceTable.GetColumnGroup(srcCol)
                    );
            }
        }
Exemple #4
0
        /// <summary>
        /// Sorts the data rows of a DataColumnCollection (more accurate: of all columns belonging to a column group, see below), using a specified column.
        /// </summary>
        /// <param name="table">The DataColumnCollection where the data columns should be sorted.</param>
        /// <param name="col">The column which is used for determining the order of the entries.
        /// This column has to belong to the table (otherwise an exception will be thrown). All columns with the same group number than this column will be included in the sort process.</param>
        /// <param name="inAscendingOrder">If true, the table is sorted in ascending order. Otherwise, the table is sorted in descending order.</param>
        public static void SortRows(this DataColumnCollection table, DataColumn col, bool inAscendingOrder)
        {
            if (!table.ContainsColumn(col))
            {
                throw new ArgumentException("The sorting column provided must be part of the DataColumnCollection (otherwise the swap algorithm can not sort this column)");
            }

            using (var token = table.SuspendGetToken())
            {
                int columnGroup = table.GetColumnGroup(col);
                if (col is DoubleColumn)
                {
                    HeapSort(col.Count, new DoubleColumnComparer((DoubleColumn)col, inAscendingOrder).Compare, new DataColumnCollectionRowSwapper(table, columnGroup).Swap);
                }
                else
                {
                    HeapSort(col.Count, new DataColumnComparer(col, inAscendingOrder).Compare, new DataColumnCollectionRowSwapper(table, columnGroup).Swap);
                }
            }
        }