コード例 #1
0
        public virtual string Sort(QueryBuilder queryBuilder, IQueryOptions options, TableKey queryLevelTable)
        {
            IEnumerable <ColumnInfo> orderByColumns = null;


            Direction = SortingDirection.ASC;

            if (queryLevelTable == StorageDbSchemaProvider.StudyTableName)
            {
                var studyTable = SchemaProvider.GetTableInfo(StorageDbSchemaProvider.StudyTableName);

                orderByColumns = new ColumnInfo [] { studyTable.KeyColumn };

                Direction = SortingDirection.DESC;
            }
            else if (queryLevelTable == StorageDbSchemaProvider.SeriesTableName)
            {
                orderByColumns = SchemaProvider.GetColumnInfo((uint)DicomTag.SeriesNumber);
            }

            if (queryLevelTable == StorageDbSchemaProvider.ObjectInstanceTableName)
            {
                orderByColumns = SchemaProvider.GetColumnInfo((uint)DicomTag.InstanceNumber);
            }


            if (null != orderByColumns)
            {
                SortBy = string.Join(",", orderByColumns.Select(column => (string)column));

                foreach (var column in orderByColumns)
                {
                    if (!queryBuilder.ProcessedColumns.ContainsKey(queryLevelTable) ||
                        (queryBuilder.ProcessedColumns.ContainsKey(queryLevelTable) &&
                         !queryBuilder.ProcessedColumns[queryLevelTable].Contains(column)))
                    {
                        queryBuilder.ProcessColumn(queryLevelTable, column);
                    }
                }

                string queryText = queryBuilder.GetQueryText(queryLevelTable, options);


                if (ApplyPagination && CanPaginate(queryBuilder, options, queryLevelTable))
                {
                    CountColumn = "TotalRows";

                    return(string.Format(Sorting_Template,
                                         queryText,
                                         CountColumn,
                                         string.Format(OrderBy_Template, SortBy, GetDirection()),
                                         string.Format(Pagination_Template, options.Offset, options.Limit)));
                }
                else
                {
                    return(queryText + string.Format(OrderBy_Template,
                                                     SortBy,
                                                     GetDirection( )));
                }
            }
            else
            {
                return(queryBuilder.GetQueryText(queryLevelTable, options));
            }
        }