Beispiel #1
0
        private IndexList BuildSortIndex(SortColumnCollection col)
        {
            IndexList arrayList = new IndexList();

            PropertyDescriptor[] sortProperties = BuildSortProperties(col);
            for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++)
            {
                object   rowItem = this.baseList[rowIndex];
                object[] values  = new object[col.Count];

                // Hier bereits Wertabruf um dies nicht während des Sortierens tun zu müssen.
                for (int criteriaIndex = 0; criteriaIndex < sortProperties.Length; criteriaIndex++)
                {
                    object value = sortProperties[criteriaIndex].GetValue(rowItem);
                    // Hier auf Verträglichkeit testen um Vergleiche bei Sortierung zu vereinfachen.
                    // Muss IComparable und gleicher Typ sein.

                    if (value != null && value != DBNull.Value)
                    {
                        if (!(value is IComparable))
                        {
                            throw new InvalidOperationException("ReportDataSource:BuildSortArray - > This type doesn't support IComparable." + value.ToString());
                        }

                        values[criteriaIndex] = value;
                    }
                }
                arrayList.Add(new SortComparer(col, rowIndex, values));
            }

            if (arrayList[0].ObjectArray.GetLength(0) == 1)
            {
                List <BaseComparer> lbc = BaseListStrategy.GenericSorter(arrayList);
                arrayList.Clear();
                arrayList.AddRange(lbc);
            }
            else
            {
                arrayList.Sort();
            }
            return(arrayList);
        }
Beispiel #2
0
        private IndexList  BuildSortIndex(Collection <AbstractColumn> col)
        {
            IndexList arrayList = new IndexList();

            for (int rowIndex = 0; rowIndex < this.table.Rows.Count; rowIndex++)
            {
                DataRow  rowItem = this.table.Rows[rowIndex];
                object[] values  = new object[col.Count];
                for (int criteriaIndex = 0; criteriaIndex < col.Count; criteriaIndex++)
                {
                    AbstractColumn c     = (AbstractColumn)col[criteriaIndex];
                    object         value = rowItem[c.ColumnName];

                    if (value != null && value != DBNull.Value)
                    {
                        if (!(value is IComparable))
                        {
                            throw new InvalidOperationException(value.ToString());
                        }

                        values[criteriaIndex] = value;
                    }
                    else
                    {
                        values[criteriaIndex] = DBNull.Value;
                    }
                }
                arrayList.Add(new SortComparer(col, rowIndex, values));
            }

            if (arrayList[0].ObjectArray.GetLength(0) == 1)
            {
                List <BaseComparer> lbc = BaseListStrategy.GenericSorter(arrayList);
                arrayList.Clear();
                arrayList.AddRange(lbc);
            }
            else
            {
                arrayList.Sort();
            }
            return(arrayList);
        }