Пример #1
1
        public static void Generate(Telerik.ReportViewer.Html5.WebForms.ReportViewer rv, IEnumerable<object> data, string extension, SortDescriptorCollection sortDescriptors, GroupDescriptorCollection grpDescriptors)
        {
            Telerik.Reporting.Report report1 = new Telerik.Reporting.Report();
            report1.DataSource = data;
            string sortCol = "";
            string sortDir = "";

            //multi sort can be done by iterating through collection like for group
            if (sortDescriptors.Count > 0)
            {
                ColumnSortDescriptor sd = sortDescriptors[0] as ColumnSortDescriptor;
                sortCol = sd.Column.UniqueName;
                sortDir = sd.SortDirection.ToString();
            }

            //Page Header Section
            Telerik.Reporting.PageHeaderSection pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();
            pageHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            pageHeaderSection1.Style.BackgroundColor = Color.Gray;
            Telerik.Reporting.TextBox txtHead = new Telerik.Reporting.TextBox();
            txtHead.Value = "Title";
            txtHead.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(3.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            txtHead.Name = "reportTitle";
            txtHead.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
            pageHeaderSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtHead });

            IEnumerator dataColl = data.GetEnumerator();
            int count = 0;
            int first = 0;
            object obj = null;

            while (dataColl.MoveNext())
            {
                if (first == 0)
                {
                    obj = dataColl.Current;
                    foreach (PropertyInfo info in obj.GetType().GetProperties())
                    {
                        count++;
                    }
                    first++;
                }
            }

            Telerik.Reporting.Drawing.Unit x = Telerik.Reporting.Drawing.Unit.Inch(0);
            Telerik.Reporting.Drawing.Unit y = Telerik.Reporting.Drawing.Unit.Inch(0);
            Telerik.Reporting.ReportItemBase[] headColumnList = new Telerik.Reporting.ReportItem[count];
            Telerik.Reporting.ReportItemBase[] detailColumnList = new Telerik.Reporting.ReportItem[count];
            Telerik.Reporting.Group group = new Telerik.Reporting.Group();
            SizeU size = new SizeU(Telerik.Reporting.Drawing.Unit.Inch((double)(22) / count), Telerik.Reporting.Drawing.Unit.Inch(0.6));
            int column = 0;

            foreach (PropertyInfo info in obj.GetType().GetProperties())
            {
                string columnName = info.Name;
                Telerik.Reporting.HtmlTextBox headerCol = CreateTxtHeader(columnName, column);
                headerCol.Style.BackgroundColor = Color.LemonChiffon;
                headerCol.Style.BorderStyle.Default = BorderType.Solid;
                headerCol.Style.BorderWidth.Default = Unit.Pixel(1);
                headerCol.CanGrow = true;
                headerCol.Location = new Telerik.Reporting.Drawing.PointU(x, y);
                headerCol.Size = size;
                headColumnList[column] = headerCol;
                Telerik.Reporting.TextBox textBox = CreateTxtDetail(columnName, column);
                textBox.Style.BorderStyle.Default = BorderType.Solid;
                textBox.Style.BorderWidth.Default = Unit.Pixel(1);
                textBox.CanGrow = true;
                textBox.Location = new Telerik.Reporting.Drawing.PointU(x, y);
                textBox.Size = size;
                detailColumnList[column] = textBox;
                textBox.ItemDataBinding += new EventHandler(textBox_ItemDataBound);
                x += Telerik.Reporting.Drawing.Unit.Inch(headerCol.Size.Width.Value);
                column++;
            }

            Telerik.Reporting.ReportItemBase[] groupColumnList = new Telerik.Reporting.ReportItem[grpDescriptors.Count];
            int i = grpDescriptors.Count;
            if (grpDescriptors.Count > 0)
            {
                Telerik.Reporting.GroupHeaderSection groupHeaderSection1 = new Telerik.Reporting.GroupHeaderSection();
                foreach (ColumnGroupDescriptor grpDescriptor in grpDescriptors)
                {
                    string grpCol = grpDescriptor.Column.UniqueName;
                    group.Groupings.Add(new Grouping("=Fields." + grpCol));
                    if (grpDescriptor.SortDirection.ToString().ToLower() == "descending")
                    {
                        group.Sortings.Add(new Sorting("=Fields." + grpCol, SortDirection.Desc));
                    }
                    else
                    {
                        group.Sortings.Add(new Sorting("=Fields." + grpCol, SortDirection.Asc));
                    }
                    i--;
                    Telerik.Reporting.TextBox hdCol = new Telerik.Reporting.TextBox();
                    hdCol.Style.BackgroundColor = Color.Orange;
                    hdCol.Style.BorderStyle.Default = BorderType.Solid;
                    hdCol.Style.BorderWidth.Default = Unit.Pixel(1);
                    hdCol.KeepTogether = true;
                    hdCol.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
                    hdCol.Value = "=[" + grpCol + "]";
                    groupColumnList[i] = hdCol;
                    group.GroupHeader = groupHeaderSection1;
                    //to avoid extra row after group col
                    group.GroupHeader.Height = Telerik.Reporting.Drawing.Unit.Inch(0);
                }
                groupHeaderSection1.Items.AddRange(groupColumnList);
            }
            if (sortCol.Length > 0)
            {
                group.Groupings.Add(new Grouping("=Fields." + sortCol));
                if (sortDir.ToLower() == "descending")
                {
                    group.Sortings.Add(new Sorting("=Fields." + sortCol, SortDirection.Desc));
                }
                else
                {
                    group.Sortings.Add(new Sorting("=Fields." + sortCol, SortDirection.Asc));
                }
            }
            ReportHeaderSection reportHeaderSection1 = new Telerik.Reporting.ReportHeaderSection();
            reportHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            reportHeaderSection1.Items.AddRange(headColumnList);
            report1.Groups.Add(group);

            //Detail Section
            Telerik.Reporting.DetailSection detailSection1 = new Telerik.Reporting.DetailSection();
            detailSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            detailSection1.Items.AddRange(detailColumnList);

            //Page Footer Section
            Telerik.Reporting.PageFooterSection pageFooterSection1 = new Telerik.Reporting.PageFooterSection();
            pageFooterSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            pageFooterSection1.Style.BackgroundColor = Color.LightGray;
            pageFooterSection1.PrintOnFirstPage = true;
            pageFooterSection1.PrintOnLastPage = true;
            Telerik.Reporting.TextBox txtFooter = new Telerik.Reporting.TextBox();
            txtFooter.Value = "='Page ' + PageNumber + ' of ' + PageCount";
            txtFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(4.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            txtFooter.Name = "pageInfoTextBox";
            txtFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
            Telerik.Reporting.PictureBox picBoxFooter = new Telerik.Reporting.PictureBox();
            picBoxFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(5.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            picBoxFooter.Value = @"C:\CCMSGoldStandard_Local\CCMSGoldStandard\CCMSAppShell\Images\no.png";
            picBoxFooter.Style.TextAlign = Telerik.Reporting.Drawing.
            HorizontalAlign.Center;
            picBoxFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(.5D, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))));
            picBoxFooter.Sizing = ImageSizeMode.AutoSize;
            pageFooterSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtFooter, picBoxFooter });

            //add all section to report
            report1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { pageHeaderSection1, reportHeaderSection1, detailSection1, pageFooterSection1 });
            report1.PageSettings.Landscape = false;
            report1.PageSettings.Margins.Bottom = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Left = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Right = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Top = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);
            Telerik.Reporting.Drawing.SizeU paperSize = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch));
            report1.PageSettings.PaperSize = paperSize;
            report1.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Custom;
            Hashtable deviceInfo = new Hashtable();
            deviceInfo["FontEmbedding"] = "Subset";
            if (extension.ToLower() == "csv")
            {
                deviceInfo["NoHeader"] = true;
                deviceInfo["NoStaticText"] = true;
            }
            Telerik.Reporting.Processing.ReportProcessor RP = new Telerik.Reporting.Processing.ReportProcessor();
            byte[] buffer = RP.RenderReport(extension.ToUpper(), report1, deviceInfo).DocumentBytes;
            string myPath = "C:";
            string file = myPath + @"\" + DateTime.Now.ToString("HHmmss") + "." + extension;
            FileStream fs = new FileStream(file, FileMode.Create);
            fs.Write(buffer, 0, buffer.Length);
            fs.Flush();
            fs.Close();

            Process.Start(file);
        }
Пример #2
0
        public static DataServiceQuery <T> Sort <T>(DataServiceQuery <T> queryable, SortDescriptorCollection sortDescriptors) where T : ISavableObject
        {
            DataServiceQuery <T> query = queryable;
            bool isFirst = true;

            if (sortDescriptors != null)
            {
                foreach (var descriptor in sortDescriptors)
                {
                    var property       = query.ElementType.GetProperty(descriptor.PropertyName);
                    var parameter      = Expression.Parameter(query.ElementType, "srt");
                    var propertyAccess = Expression.MakeMemberAccess(parameter, property);
                    var expression     = Expression.Lambda(propertyAccess, parameter);

                    string methodName = string.Empty;

                    if (isFirst)
                    {
                        methodName = descriptor.Direction == ListSortDirection.Ascending ? "OrderBy" : "OrderByDescending";
                        isFirst    = false;
                    }
                    else
                    {
                        methodName = descriptor.Direction == ListSortDirection.Ascending ? "ThenBy" : "ThenByDescending";
                    }
                    var exp = Expression.Call(typeof(Queryable), methodName, new[] { query.ElementType, expression.Body.Type }, query.Expression, Expression.Quote(expression));

                    query = query.Provider.CreateQuery(exp) as DataServiceQuery <T>;
                }
            }

            return(query);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SortCollectionManager"/> class.
        /// </summary>
        /// <param name="sourceCollection">The collection of <see cref="SortDescriptor"/>s to manage</param>
        /// <param name="descriptionCollection">The collection of <see cref="SortDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param>
        /// <param name="expressionCache">The cache with entries for the <see cref="SortDescriptor"/>s</param>
        /// <param name="validationAction">The callback for validating items that are added or changed</param>
        public SortCollectionManager(SortDescriptorCollection sourceCollection, SortDescriptionCollection descriptionCollection, ExpressionCache expressionCache, Action<SortDescriptor> validationAction)
        {
            if (sourceCollection == null)
            {
                throw new ArgumentNullException("sourceCollection");
            }
            if (descriptionCollection == null)
            {
                throw new ArgumentNullException("descriptionCollection");
            }
            if (expressionCache == null)
            {
                throw new ArgumentNullException("expressionCache");
            }
            if (validationAction == null)
            {
                throw new ArgumentNullException("validationAction");
            }

            this._sourceCollection = sourceCollection;
            this._descriptionCollection = descriptionCollection;
            this.ExpressionCache = expressionCache;
            this.ValidationAction = (item) => validationAction((SortDescriptor)item);
            this.AsINotifyPropertyChangedFunc = (item) => ((SortDescriptor)item).Notifier;

            ((INotifyCollectionChanged)descriptionCollection).CollectionChanged += this.HandleDescriptionCollectionChanged;

            this.AddCollection(sourceCollection);
        }
Пример #4
0
 public void UpdateGroupingFields()
 {
     if (this.Description == null || string.IsNullOrEmpty(this.Description.Expression))
     {
         this.groupFields = new GroupFieldElement[0];
     }
     else
     {
         this.panel.DisposeChildren();
         SortDescriptorCollection groupNames = this.Description.GroupNames;
         int count = groupNames.Count;
         List <GroupFieldElement> groupFieldElementList = new List <GroupFieldElement>();
         GridViewColumnCollection columns = this.TemplateElement.ViewTemplate.Columns;
         for (int index = 0; index < count; ++index)
         {
             GroupFieldElement groupFieldElement = new GroupFieldElement(this.TemplateElement, this.Description, groupNames[index]);
             if (groupFieldElement.Column != null)
             {
                 this.panel.Children.Add((RadElement)groupFieldElement);
                 groupFieldElementList.Add(groupFieldElement);
                 if (index < count - 1)
                 {
                     this.panel.Children.Add((RadElement) new GroupLinkElement(this.TemplateElement)
                     {
                         Type = GroupLinkElement.LinkType.NamesLink
                     });
                 }
             }
         }
         this.groupFields = groupFieldElementList.ToArray();
     }
 }
Пример #5
0
 protected virtual void InitializeViewInfo()
 {
     if (this.parentViewInfo != null)
     {
         this.rowsViewState                = new VirtualGridTableViewState(this.parentViewInfo.RowCount, 24, this.parentViewInfo.RowSpacing, true);
         this.columnsViewState             = new VirtualGridTableViewState(this.parentViewInfo.ColumnCount, 100, this.parentViewInfo.CellSpacing, false);
         this.showFilterRow                = this.parentViewInfo.showFilterRow;
         this.showHeaderRow                = this.parentViewInfo.showHeaderRow;
         this.allowColumnSort              = this.parentViewInfo.allowColumnSort;
         this.showNewRow                   = this.parentViewInfo.showNewRow;
         this.allowColumnHeaderContextMenu = this.parentViewInfo.allowColumnHeaderContextMenu;
         this.allowCellContextMenu         = this.parentViewInfo.allowCellContextMenu;
         this.allowEdit  = this.parentViewInfo.allowEdit;
         this.allowCut   = this.parentViewInfo.allowCut;
         this.allowCopy  = this.parentViewInfo.allowCopy;
         this.allowPaste = this.parentViewInfo.allowPaste;
         this.enableAlternatingRowColor = this.parentViewInfo.enableAlternatingRowColor;
         this.allowColumnResize         = this.parentViewInfo.allowColumnResize;
         this.allowRowResize            = this.parentViewInfo.allowRowResize;
     }
     else
     {
         this.rowsViewState    = new VirtualGridTableViewState(0, 24, -1, true);
         this.columnsViewState = new VirtualGridTableViewState(0, 100, -1, false);
     }
     this.rowsViewState.PropertyChanged    += new PropertyChangedEventHandler(this.rowsViewState_PropertyChanged);
     this.columnsViewState.PropertyChanged += new PropertyChangedEventHandler(this.columnsViewState_PropertyChanged);
     this.rowsViewState.PageIndexChanging  += new VirtualGridPageChangingEventHandler(this.rowsViewState_PageIndexChanging);
     this.rowsViewState.PageIndexChanged   += new EventHandler(this.rowsViewState_PageIndexChanged);
     this.childViewInfos  = new Dictionary <int, VirtualGridViewInfo>();
     this.sortDescriptors = new SortDescriptorCollection();
     this.sortDescriptors.CollectionChanged += new NotifyCollectionChangedEventHandler(this.sortDescriptors_CollectionChanged);
     this.filterDescriptors = new FilterDescriptorCollection();
     this.filterDescriptors.CollectionChanged += new NotifyCollectionChangedEventHandler(this.filterDescriptors_CollectionChanged);
 }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="descriptors"></param>
        /// <param name="name"></param>
        public static int Add(this SortDescriptorCollection descriptors, string name)
        {
            int count = descriptors.Count;

            descriptors.Add(name, ListSortDirection.Ascending);
            return(count);
        }
Пример #7
0
        protected virtual void Sort(SortDescriptorCollection descriptors)
        {
            SortDescriptor[] currentDescriptors = descriptors.ToArray();
            if (this.CurrentOperation != ItemSourceOperation.None)
            {
                return;
            }

            if (currentDescriptors.Length == 0)
            {
                this.view = this.dataSource;
                this.Filter(this.masterTemplate.FilterDescriptors);

                return;
            }

            this.CurrentOperation = ItemSourceOperation.Sorting;
            List <object> sortView = this.view as List <object>;

            if (sortView == null)
            {
                sortView = new List <object>(this.view.Count);
                foreach (object item in this.view)
                {
                    sortView.Add(item);
                }
            }

            ParallelQuery <object> query           = sortView.AsParallel();
            SortDescriptor         firstDescriptor = currentDescriptors.First();

            if (firstDescriptor.Direction == ListSortDirection.Descending)
            {
                query = query.OrderByDescending(x => this.GetValue(x, firstDescriptor.PropertyName));
            }
            else
            {
                query = query.OrderBy(x => this.GetValue(x, firstDescriptor.PropertyName));
            }

            OrderedParallelQuery <object> orderedQuery = query as OrderedParallelQuery <object>;

            for (int i = 1; i < currentDescriptors.Length; i++)
            {
                SortDescriptor currentDescriptor = currentDescriptors[i];
                if (currentDescriptor.Direction == ListSortDirection.Descending)
                {
                    orderedQuery = orderedQuery.ThenByDescending(x => this.GetValue(x, currentDescriptor.PropertyName));
                }
                else
                {
                    orderedQuery = orderedQuery.ThenBy(x => this.GetValue(x, currentDescriptor.PropertyName));
                }
            }

            this.view             = orderedQuery.ToList();
            this.CurrentOperation = ItemSourceOperation.None;
        }
Пример #8
0
        public void PerformOperation(ItemSourceOperation operation, IList descriptors, bool force = false)
        {
            switch (operation)
            {
            case ItemSourceOperation.Filtering:
                FilterDescriptorCollection filterDescriptors = descriptors as FilterDescriptorCollection;
                if (this.lastFilterExpression == filterDescriptors.Expression && !force)
                {
                    return;
                }

                this.lastFilterExpression = filterDescriptors.Expression;
                break;

            case ItemSourceOperation.Sorting:
                SortDescriptorCollection sortDescriptors = descriptors as SortDescriptorCollection;
                if (this.lastSortExpression == sortDescriptors.Expression && !force)
                {
                    return;
                }

                this.lastSortExpression = sortDescriptors.Expression;
                break;

            default:
                break;
            }

            OperationParameters operationParams = new OperationParameters(operation, descriptors);

            this.queuedOperations.Enqueue(operationParams);
            if (this.backgroundWorker.IsBusy)
            {
                OperationParameters peek;
                bool peeked = this.queuedOperations.TryPeek(out peek);
                if (peeked && peek.Operation == operationParams.Operation && peek != operationParams)
                {
                    OperationParameters dequeued;
                    this.queuedOperations.TryDequeue(out dequeued);
                }
                else if (peeked && peek.Operation != operationParams.Operation)
                {
                    this.perform = false;
                }
            }

            if (!this.backgroundWorker.IsBusy)
            {
                this.perform = true;
                this.backgroundWorker.RunWorkerAsync();
                this.OnOperationStarted(new ItemSourceOperationEventArgs(operationParams.Operation));
            }
        }
Пример #9
0
        public void InitializeDescriptors()
        {
            this.sortDescriptors = new SortDescriptorCollection((IDataDescriptorsHost)this);
            this.sortDescriptors.CollectionChanged += this.OnSortDescriptorsCollectionChanged;

            this.groupDescriptors = new GroupDescriptorCollection((IDataDescriptorsHost)this);
            this.groupDescriptors.CollectionChanged += this.OnGroupDescriptorsCollectionChanged;

            this.filterDescriptors = new FilterDescriptorCollection((IDataDescriptorsHost)this);
            this.filterDescriptors.CollectionChanged += this.OnFilterDescriptorsCollectionChanged;

            this.aggregateDescriptors = new AggregateDescriptorCollection((IDataDescriptorsHost)this);
            this.aggregateDescriptors.CollectionChanged += this.OnAggregateDescriptorsCollectionChanged;
        }
Пример #10
0
        public void CollectionManagerCollatesSortDescriptorEvents()
        {
            SortDescriptorCollection  collection            = new SortDescriptorCollection();
            SortDescriptionCollection descriptionCollection = new SortDescriptionCollection();
            ExpressionCache           cache      = new ExpressionCache();
            SortDescriptor            descriptor = null;

            this.CollectionManagerCollatesTemplate(
                (validationAction) =>
            {
                return(new SortCollectionManager(collection, descriptionCollection, cache, sd => validationAction()));
            },
                () =>
            {
                collection.Add(new SortDescriptor());
            },
                () =>
            {
                collection[0].PropertyPath = "First";
            },
                () =>
            {
                collection.Add(new SortDescriptor());
            },
                () =>
            {
                collection[1].PropertyPath = "Second";
            },
                () =>
            {
                collection[1] = new SortDescriptor();
            },
                () =>
            {
                descriptor = collection[0];
                collection.Remove(descriptor);
            },
                () =>
            {
                descriptor.PropertyPath = "Removed";
            });
        }
Пример #11
0
        public static int CompareRows(
            GridViewRowInfo x,
            GridViewRowInfo y,
            SortDescriptorCollection context)
        {
            GridViewDataOperation type = GridViewDataOperation.Sorting;

            for (int index = 0; index < context.Count; ++index)
            {
                if (context[index].PropertyIndex >= 0)
                {
                    GridViewDataColumn column = x.ViewTemplate.Columns[context[index].PropertyIndex];
                    object             xValue = column.GetValue(x, type);
                    object             yValue = column.GetValue(y, type);
                    if (column.UseDataTypeConverterWhenSorting && column.DataTypeConverter != null && column.DataTypeConverter.CanConvertTo((ITypeDescriptorContext)column, column.DataType))
                    {
                        GridViewComboBoxColumn viewComboBoxColumn = column as GridViewComboBoxColumn;
                        if (viewComboBoxColumn == null || !viewComboBoxColumn.DisplayMemberSort)
                        {
                            CultureInfo formatterCulture = GridViewRowInfoComparer.GetFormatterCulture((IFormatProvider)column.FormatInfo);
                            xValue = column.DataTypeConverter.ConvertTo((ITypeDescriptorContext)column, formatterCulture, xValue, column.DataType);
                            yValue = column.DataTypeConverter.ConvertTo((ITypeDescriptorContext)column, formatterCulture, yValue, column.DataType);
                        }
                    }
                    GridViewRowInfoComparer.GetBlobData(ref xValue, ref yValue);
                    int num = !(xValue is IComparable) || yValue == null || (object)yValue.GetType() != (object)xValue.GetType() ? DataUtils.CompareNulls(xValue, yValue) : ((IComparable)xValue).CompareTo(yValue);
                    if (num != 0)
                    {
                        if (context[index].Direction == ListSortDirection.Descending)
                        {
                            return(-num);
                        }
                        return(num);
                    }
                }
            }
            return(0);
        }
 /// <summary>
 /// Resets the <paramref name="sortDescriptions"/> collection to match the <paramref name="sortDescriptors"/> collection.
 /// </summary>
 /// <param name="sortDescriptions">The collection to reset</param>
 /// <param name="sortDescriptors">The collection to match</param>
 private static void ResetToSortDescriptors(SortDescriptionCollection sortDescriptions, SortDescriptorCollection sortDescriptors)
 {
     sortDescriptions.Clear();
     foreach (SortDescriptor descriptor in sortDescriptors)
     {
         SortDescription? description = SortCollectionManager.GetDescriptionFromDescriptor(descriptor);
         if (description.HasValue)
         {
             sortDescriptions.Add(description.Value);
         }
     }
 }
Пример #13
0
 public GridViewRowInfoComparer(SortDescriptorCollection context)
 {
     this.sortContext = context;
 }
Пример #14
0
        /// <summary>
        /// Composes an <see cref="EntityQuery" /> for sorting and grouping purposes.
        /// </summary>
        /// <param name="source">The queryable source.</param>
        /// <param name="groupDescriptors">The group descriptors.</param>
        /// <param name="sortDescriptors">The sort descriptors.</param>
        /// <param name="expressionCache">Cache for storing built expressions</param>
        /// <returns>The composed <see cref="EntityQuery" />.</returns>
        public static EntityQuery OrderBy(
            EntityQuery source,
            GroupDescriptorCollection groupDescriptors,
            SortDescriptorCollection sortDescriptors,
            ExpressionCache expressionCache)
        {
            Debug.Assert(source != null, "Unexpected null source");
            Debug.Assert(sortDescriptors != null, "Unexpected null sortDescriptors");
            Debug.Assert(groupDescriptors != null, "Unexpected null groupDescriptors");

            bool hasOrderBy = false;

            // check the GroupDescriptors first
            foreach (GroupDescriptor groupDescriptor in groupDescriptors)
            {
                if (groupDescriptor != null && groupDescriptor.PropertyPath != null)
                {
                    Debug.Assert(expressionCache.ContainsKey(groupDescriptor), "There should be a cached group expression");

                    // check to see if we sort by the same parameter in desc order
                    bool sortAsc = true;
                    foreach (SortDescriptor sortDescriptor in sortDescriptors)
                    {
                        if (sortDescriptor != null)
                        {
                            string sortDescriptorPropertyPath = sortDescriptor.PropertyPath;
                            string groupDescriptorPropertyPath = groupDescriptor.PropertyPath;

                            if (sortDescriptorPropertyPath != null &&
                                sortDescriptorPropertyPath.Equals(groupDescriptorPropertyPath))
                            {
                                if (sortDescriptor.Direction == ListSortDirection.Descending)
                                {
                                    sortAsc = false;
                                }

                                break;
                            }
                        }
                    }

                    string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy");
                    if (!sortAsc)
                    {
                        orderMethodName += "Descending";
                    }

                    source = OrderBy(source, orderMethodName, expressionCache[groupDescriptor]);
                    hasOrderBy = true;
                }
            }

            // then check the SortDescriptors
            foreach (SortDescriptor sortDescriptor in sortDescriptors)
            {
                if (sortDescriptor != null)
                {
                    Debug.Assert(expressionCache.ContainsKey(sortDescriptor), "There should be a cached sort expression");

                    string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy");
                    if (sortDescriptor.Direction == ListSortDirection.Descending)
                    {
                        orderMethodName += "Descending";
                    }

                    source = OrderBy(source, orderMethodName, expressionCache[sortDescriptor]);
                    hasOrderBy = true;
                }
            }

            return source;
        }
 /// <summary>
 /// Resets the <paramref name="sortDescriptors"/> collection to match the <paramref name="sortDescriptions"/> collection.
 /// </summary>
 /// <param name="sortDescriptions">The collection to match</param>
 /// <param name="sortDescriptors">The collection to reset</param>
 private static void ResetToSortDescriptions(SortDescriptionCollection sortDescriptions, SortDescriptorCollection sortDescriptors)
 {
     sortDescriptors.Clear();
     foreach (SortDescription description in sortDescriptions)
     {
         sortDescriptors.Add(SortCollectionManager.GetDescriptorFromDescription(description));
     }
 }
        /// <summary>
        /// Determines whether the <paramref name="sortDescriptions"/> are equivalent to the <paramref name="sortDescriptors"/>.
        /// </summary>
        /// <param name="sortDescriptions">The descriptions to compare</param>
        /// <param name="sortDescriptors">The descriptors to compare</param>
        /// <returns><c>true</c> if the collections are equivalent</returns>
        public static bool AreEquivalent(SortDescriptionCollection sortDescriptions, SortDescriptorCollection sortDescriptors)
        {
            Debug.Assert((sortDescriptions != null) && (sortDescriptors != null), "Both should be non-null.");

            if (sortDescriptions.Count != sortDescriptors.Count)
            {
                return false;
            }

            for (int i = 0, count = sortDescriptions.Count; i < count; i++)
            {
                if (!SortCollectionManager.AreEquivalent(sortDescriptions[i], sortDescriptors[i]))
                {
                    return false;
                }
            }

            return true;
        }
Пример #17
0
 public CustomComparer(SortDescriptorCollection sortDescriptors)
 {
     this.sortDescriptors = sortDescriptors;
 }
        public void CollectionManagerCollatesSortDescriptorEvents()
        {
            SortDescriptorCollection collection = new SortDescriptorCollection();
            SortDescriptionCollection descriptionCollection = new SortDescriptionCollection();
            ExpressionCache cache = new ExpressionCache();
            SortDescriptor descriptor = null;

            this.CollectionManagerCollatesTemplate(
                (validationAction) =>
                {
                    return new SortCollectionManager(collection, descriptionCollection, cache, sd => validationAction());
                },
                () =>
                {
                    collection.Add(new SortDescriptor());
                },
                () =>
                {
                    collection[0].PropertyPath = "First";
                },
                () =>
                {
                    collection.Add(new SortDescriptor());
                },
                () =>
                {
                    collection[1].PropertyPath = "Second";
                },
                () =>
                {
                    collection[1] = new SortDescriptor();
                },
                () =>
                {
                    descriptor = collection[0];
                    collection.Remove(descriptor);
                },
                () =>
                {
                    descriptor.PropertyPath = "Removed";
                });
        }
Пример #19
0
 public GridViewRowInfoEventComparer(SortDescriptorCollection context)
     : base(context)
 {
 }
Пример #20
0
        public bool Sort(RadSortOrder sortOrder, bool multiSortMode)
        {
            if (!this.CanSort || this.ownerTemplate == null)
            {
                return(false);
            }
            SortDescriptor           descriptor      = new SortDescriptor(this.Name, GridViewHelper.GetSortDirection(sortOrder));
            SortDescriptorCollection sortDescriptors = this.ownerTemplate.SortDescriptors;
            bool flag = !multiSortMode && sortDescriptors.Count > 1;

            if (flag)
            {
                if (sortOrder == RadSortOrder.None)
                {
                    descriptor = (SortDescriptor)null;
                }
                if (this.RaiseSortingChanging(descriptor))
                {
                    return(false);
                }
                sortDescriptors.BeginUpdate();
                sortDescriptors.Clear();
            }
            int index = sortDescriptors.IndexOf(this.Name);

            if (index >= 0)
            {
                if (sortOrder == RadSortOrder.None)
                {
                    sortDescriptors.RemoveAt(index);
                    return(true);
                }
                if (sortOrder == GridViewHelper.GetSortDirection(sortDescriptors[index].Direction))
                {
                    return(false);
                }
                sortDescriptors[index].Direction = GridViewHelper.GetSortDirection(sortOrder);
                return(true);
            }
            if (sortOrder == RadSortOrder.None)
            {
                if (flag)
                {
                    sortDescriptors.EndUpdate();
                }
                return(false);
            }
            if (!multiSortMode && sortDescriptors.Count == 1)
            {
                sortDescriptors[0] = descriptor;
            }
            else
            {
                sortDescriptors.Add(descriptor);
            }
            if (flag)
            {
                sortDescriptors.EndUpdate();
            }
            return(true);
        }