public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
        {
            GridViewGroupFooterCell      cell           = container as GridViewGroupFooterCell;
            GridViewGroupFooterRow       groupFooterRow = cell.ParentRow as GridViewGroupFooterRow;
            QueryableCollectionViewGroup group          = groupFooterRow.Group as QueryableCollectionViewGroup;

            if (group != null)
            {
                AggregateFunction f = cell.Column.AggregateFunctions.FirstOrDefault();
                if (f != null)
                {
                    AggregateResult result = group.AggregateResults[f.FunctionName];

                    if (result != null && result.Value != null && object.Equals(result.Value.GetType(), typeof(double)) && (double)result.Value > 5)
                    {
                        return(this.GroupFooterCellStyle);
                    }
                    else
                    {
                        return(this.DefaultGroupFooterCellStyle);
                    }
                }
            }

            return(new Style(typeof(GridViewGroupFooterCell)));
        }
コード例 #2
0
        /// <summary>
        /// Get Aggregates Function
        /// </summary>
        /// <param name="group"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        private string GetAggregates(QueryableCollectionViewGroup group, GridViewDataColumn column)
        {
            List <string> aggregates = new List <string>();

            foreach (AggregateFunction function in column.AggregateFunctions)
            {
                foreach (AggregateResult result in group.AggregateResults)
                {
                    if (function.FunctionName == result.FunctionName && result.FormattedValue != null)
                    {
                        aggregates.Add(result.FormattedValue.ToString());
                    }
                }
            }
            return(String.Join(",", aggregates.ToArray()));
        }
コード例 #3
0
        /// <summary>
        /// Helper method for Export PDF
        /// </summary>
        /// <param name="table"></param>
        /// <param name="group"></param>
        /// <param name="columns"></param>
        /// <param name="grid"></param>
        private static void AddGroupRow(Table table, QueryableCollectionViewGroup group, IList <GridViewBoundColumnBase> columns
                                        , RadGridView grid, List <int> visibleAggregateIndex, Func <int, int, object, object, object> cellValueOverwrite)
        {
            TableRow row = new TableRow();

            int level = GetGroupLevel(group);

            TableCell groupHeaderCell = new TableCell();

            groupHeaderCell.TextAlignment     = RadTextAlignment.Center;
            groupHeaderCell.VerticalAlignment = RadVerticalAlignment.Center;
            groupHeaderCell.Padding           = new Padding(0, 5, 5, 0);
            groupHeaderCell.Background        = level > 0 ? Color.FromArgb(255, 228, 229, 229) : Color.FromArgb(255, 198, 200, 200);
            groupHeaderCell.ColumnSpan        = columns.Count();// +(grid.GroupDescriptors.Count() > 0 ? 1 : 0) - (level > 0 ? 1 : 0);
            AddCellValue(groupHeaderCell, group.Key != null ? group.Key.ToString() : string.Empty);
            row.Cells.Add(groupHeaderCell);

            table.Rows.Add(row);

            if (group.HasSubgroups)
            {
                for (int i = 0; i < group.Subgroups.Count(); i++)
                {
                    AddGroupRow(table, group.Subgroups[i] as QueryableCollectionViewGroup, columns, grid, visibleAggregateIndex, cellValueOverwrite);
                }
            }
            else
            {
                AddDataRows(table, group.Items, columns, grid, cellValueOverwrite);
            }

            TableRow headerRow = new TableRow();

            for (int i = 0; i < columns.Count(); i++)
            {
                TableCell cell = new TableCell()
                {
                    VerticalAlignment = RadVerticalAlignment.Center
                };
                cell.TextAlignment = RadTextAlignment.Right;
                cell.Background    = Color.FromArgb(255, 228, 229, 229);
                AddCellValue(cell, columns[i].UniqueName);
                cell.PreferredWidth = new TableWidthUnit((float)columns[i].ActualWidth);
                headerRow.Cells.Add(cell);
            }
        }
コード例 #4
0
        private void ElementExporting(object sender, GridViewElementExportingEventArgs e)
        {
            e.Width *= 1.4;
            if (e.Element == ExportElement.HeaderRow || e.Element == ExportElement.FooterRow ||
                e.Element == ExportElement.GroupFooterRow)
            {
                e.Background = HeaderBackground;
                e.Foreground = HeaderForeground;
                e.FontSize   = 16;
                e.FontWeight = FontWeights.Bold;
            }
            else if (e.Element == ExportElement.Row)
            {
                e.Background = RowBackground;
                e.Foreground = RowForeground;
            }
            else if (e.Element == ExportElement.Cell &&
                     e.Value != null && e.Value.Equals("Chocolade"))
            {
                e.FontFamily = new FontFamily("Verdana");
                e.Background = Colors.LightGray;
                e.Foreground = Colors.Blue;
            }
            else if (e.Element == ExportElement.GroupHeaderRow)
            {
                e.FontFamily = new FontFamily("Verdana");
                e.Background = Colors.LightGray;
                e.Height     = 24;
            }
            else if (e.Element == ExportElement.GroupHeaderCell &&
                     e.Value != null && e.Value.Equals("Chocolade"))
            {
                e.Value = "MyNewValue";
            }
            else if (e.Element == ExportElement.GroupFooterCell)
            {
                GridViewDataColumn           column   = e.Context as GridViewDataColumn;
                QueryableCollectionViewGroup qcvGroup = e.Value as QueryableCollectionViewGroup;

                if (column != null && qcvGroup != null && column.AggregateFunctions.Count > 0)
                {
                    e.Value = GetAggregates(qcvGroup, column);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// adding group rows to exported pdf
        /// </summary>
        /// <param name="table"></param>
        /// <param name="group"></param>
        /// <param name="columns"></param>
        /// <param name="grid"></param>
        private void AddGroupRow(Table table, QueryableCollectionViewGroup group, IList <GridViewBoundColumnBase> columns, RadGridView grid)
        {
            TableRow row = new TableRow();

            int level = GetGroupLevel(group);

            if (level > 0)
            {
                TableCell cell = new TableCell();
                cell.PreferredWidth = new TableWidthUnit(level * 20);
                cell.Background     = Colors.White;
                row.Cells.Add(cell);
            }

            TableCell aggregatesCell = new TableCell();

            aggregatesCell.Background = Colors.White;
            aggregatesCell.ColumnSpan = columns.Count() + (grid.GroupDescriptors.Count() > 0 ? 1 : 0) - (level > 0 ? 1 : 0);

            AddCellValue(aggregatesCell, group.Key != null ? group.Key.ToString() : string.Empty);

            foreach (AggregateResult result in group.AggregateResults)
            {
                AddCellValue(aggregatesCell, result.FormattedValue != null ? result.FormattedValue.ToString() : string.Empty);
            }

            row.Cells.Add(aggregatesCell);

            table.Rows.Add(row);

            if (group.HasSubgroups)
            {
                for (int i = 0; i < group.Subgroups.Count(); i++)
                {
                    AddGroupRow(table, group.Subgroups[i] as QueryableCollectionViewGroup, columns, grid);
                }
            }
            else
            {
                for (int i = 0; i < group.ItemCount; i++)
                {
                    AddDataRows(table, group.Items, columns, grid);
                }
            }
        }
コード例 #6
0
        private void ExportWorkbook(RadGridView grid, Stream stream)
        {
            IList <GridViewBoundColumnBase> columns = (from c in grid.Columns.OfType <GridViewBoundColumnBase>()
                                                       orderby c.DisplayIndex
                                                       select c).ToList();

            using (IWorkbookExporter workbook = SpreadExporter.CreateWorkbookExporter(this.selectedExportFormat, stream))
            {
                using (IWorksheetExporter worksheet = workbook.CreateWorksheetExporter("Sheet1"))
                {
                    this.SetWidthOfColumns(worksheet, grid.GroupDescriptors.Count, columns);

                    int rowIndex = 0;
                    if (grid.ShowColumnHeaders)
                    {
                        this.AddHeaderRow(worksheet, grid.GroupDescriptors.Count, columns);
                        rowIndex = 1;
                    }

                    if (grid.Items.Groups != null)
                    {
                        for (int i = 0; i < grid.Items.Groups.Count; i++)
                        {
                            QueryableCollectionViewGroup group = (QueryableCollectionViewGroup)grid.Items.Groups[i];
                            rowIndex = this.AddGroupRow(worksheet, 1, rowIndex, grid.GroupDescriptors.Count, group, columns);
                        }
                    }
                    else
                    {
                        this.AddDataRows(worksheet, 0, 0, grid.Items, columns);
                    }

                    foreach (CellRange range in this.mergedCells)
                    {
                        worksheet.MergeCells(range.FromRowIndex, range.FromColumnIndex, range.ToRowIndex, range.ToColumnIndex);
                    }
                }
            }
        }
コード例 #7
0
ファイル: GroupRecord.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Adds new aggregate result to collection.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="result">The aggregate result.</param>
        /// <param name="func">The aggregate function.</param>
        private static void AddAggregateResult(QueryableCollectionViewGroup group, Veyron.SharedTypes.AggregateResult result, AggregateFunction func)
        {
            var aggregateResult = new AggregateResult(result.Value, func);

            var r = result;
            var columnAggregates = group.AggregateResults
                .SkipWhile(x => !x.FunctionName.StartsWith(r.ColumnName, StringComparison.Ordinal))
                .TakeWhile(x => x.FunctionName.StartsWith(r.ColumnName, StringComparison.Ordinal))
                .ToList();

            if (!columnAggregates.Any())
                group.AggregateResults.Add(aggregateResult);
            else
            {
                var index = columnAggregates.TakeWhile(x =>
                        AggregateHelper.GetAttribute(
                            AggregateHelper.GetTypeByFullName(x.Caption.Replace(":", null))).Order <
                        AggregateHelper.GetAttribute(result.SummaryType).Order).Count();

                if (columnAggregates.Count <= index)
                {
                    var lastItemIndex = group.AggregateResults.IndexOf(columnAggregates.Last());

                    if (lastItemIndex == group.AggregateResults.Count - 1)
                        group.AggregateResults.Add(aggregateResult);
                    else
                        group.AggregateResults.Insert(lastItemIndex + 1, aggregateResult);
                }
                else
                {
                    var itemIndex = group.AggregateResults.IndexOf(columnAggregates[index]);
                    group.AggregateResults.Insert(itemIndex, aggregateResult);
                }
            }
        }
コード例 #8
0
ファイル: GroupRecord.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Invalidates aggregate results by assigning <see cref="Constants.AggregateCalculatingPlaceHolder"/> value.
        /// </summary>
        /// <param name="group">The <see cref="Telerik.Windows.Data.IGroup"/> instance.</param>
        /// <param name="aggregateDefinitions">The collection of aggregate definitions.</param>
        public void InvalidateAggregateResults(QueryableCollectionViewGroup group = null, IList<AggregateDefinition> aggregateDefinitions = null)
        {
            if (!IsAttached ||
                (!IsExpanded && !IsPopulated))
                return;

            if (group == null)
                group = (QueryableCollectionViewGroup)_groupInfo.Target;

            if (aggregateDefinitions == null)
            {
                foreach (var aggregateResult in group.AggregateResults)
                {
                    aggregateResult.FormattedValue = Constants.AggregateCalculatingPlaceHolder;
                }
            }
            else
            {
                foreach (var aggregateDefinition in aggregateDefinitions)
                {
                    var aggregateResult = group.AggregateResults.FirstOrDefault(
                        x => x.FunctionName == aggregateDefinition.FunctionName);

                    if (aggregateResult != null)
                        aggregateResult.FormattedValue = Constants.AggregateCalculatingPlaceHolder;
                }
            }

            RefreshGroupFooter();
        }
コード例 #9
0
        private int AddGroupRow(IWorksheetExporter worksheet, int outlineLevel, int rowIndex, int numberOfIndentCells,
                                QueryableCollectionViewGroup group, IList <GridViewBoundColumnBase> columns)
        {
            int startColumnIndex = this.GetGroupLevel(group);

            this.mergedCells.Add(new CellRange(rowIndex, startColumnIndex, rowIndex, numberOfIndentCells + columns.Count - 1));

            SpreadCellFormat format = new SpreadCellFormat();

            format.Fill = SpreadPatternFill.CreateSolidFill(ColorToSpreadColor(this.GroupHeaderRowColor));
            format.HorizontalAlignment = SpreadHorizontalAlignment.Left;

            using (IRowExporter row = worksheet.CreateRowExporter())
            {
                row.SetOutlineLevel(outlineLevel - 1);

                row.SkipCells(startColumnIndex);

                for (int i = startColumnIndex; i < numberOfIndentCells + columns.Count - 1; i++)
                {
                    using (ICellExporter cell = row.CreateCellExporter())
                    {
                        cell.SetFormat(format);

                        if (group.Key is int)
                        {
                            cell.SetValue((int)group.Key);
                        }
                        else if (group.Key is double)
                        {
                            cell.SetValue((double)group.Key);
                        }
                        else
                        {
                            string cellValue = group.Key != null?group.Key.ToString() : string.Empty;

                            cell.SetValue(cellValue);
                        }
                    }
                }
            }

            rowIndex++;
            startColumnIndex++;

            if (group.HasSubgroups)
            {
                foreach (IGroup subGroup in group.Subgroups)
                {
                    int newRowIndex = this.AddGroupRow(worksheet, outlineLevel + 1, rowIndex, numberOfIndentCells, subGroup as QueryableCollectionViewGroup, columns);
                    rowIndex = newRowIndex;
                }
            }
            else
            {
                this.AddDataRows(worksheet, outlineLevel, startColumnIndex, group.Items, columns);
                rowIndex += group.Items.Count;
            }

            return(rowIndex);
        }
コード例 #10
0
        private int AddGroupRow(Worksheet worksheet, int rowIndex, int numberOfIndentCells, QueryableCollectionViewGroup group, IList<GridViewBoundColumnBase> columns)
        {
            int startColumnIndex = this.GetGroupLevel(group);

            CellSelection groupHeaderRow = worksheet.Cells[rowIndex, startColumnIndex, rowIndex, numberOfIndentCells + columns.Count - 1];
            groupHeaderRow.Merge();

            IFill fill = new PatternFill(PatternType.Solid, this.GroupHeaderRowColor, Colors.Transparent);
            groupHeaderRow.SetFill(fill);

            string cellValue = group.Key != null ? group.Key.ToString() : string.Empty;
            groupHeaderRow.SetValue(cellValue);
            groupHeaderRow.SetHorizontalAlignment(RadHorizontalAlignment.Left);

            rowIndex++;
            startColumnIndex++;

            if (group.HasSubgroups)
            {
                foreach (var subGroup in group.Subgroups)
                {
                    int newRowIndex = this.AddGroupRow(worksheet, rowIndex, numberOfIndentCells, subGroup as QueryableCollectionViewGroup, columns);
                    rowIndex = newRowIndex;
                }
            }
            else
            {
                this.AddDataRows(worksheet, rowIndex, startColumnIndex, group.Items, columns);
                rowIndex += group.Items.Count;
            }

            return rowIndex;
        }
コード例 #11
0
        private void AddGroupRow(Table table, QueryableCollectionViewGroup group, IList<GridViewBoundColumnBase> columns, int groupDescriptorsCount)
        {
            int level = this.GetGroupLevel(group);
            TableRow row = table.Rows.AddTableRow();

            if (level > 0)
            {
                this.AddIndentCell(row, level, new ThemableColor(this.DataRowColor));
            }

            TableCell cell = row.Cells.AddTableCell();
            cell.Shading.BackgroundColor = new ThemableColor(this.GroupHeaderRowColor);
            cell.ColumnSpan = columns.Count + (groupDescriptorsCount > 0 ? 1 : 0) - (level > 0 ? 1 : 0);
            this.AddCellValue(cell, group.Key);

            if (group.HasSubgroups)
            {
                foreach (var g in group.Subgroups)
                {
                    this.AddGroupRow(table, g as QueryableCollectionViewGroup, columns, groupDescriptorsCount);
                }
            }
            else
            {
                this.AddDataRows(table, group.Items, columns, groupDescriptorsCount);
            }
        }
コード例 #12
0
        private int AddGroupRow(IWorksheetExporter worksheet, int outlineLevel, int rowIndex, int numberOfIndentCells,
            QueryableCollectionViewGroup group, IList<GridViewBoundColumnBase> columns)
        {
            int startColumnIndex = this.GetGroupLevel(group);
            this.mergedCells.Add(new CellRange(rowIndex, startColumnIndex, rowIndex, numberOfIndentCells + columns.Count - 1));

            SpreadCellFormat format = new SpreadCellFormat();
            format.Fill = SpreadPatternFill.CreateSolidFill(ColorToSpreadColor(this.GroupHeaderRowColor));
            format.HorizontalAlignment = SpreadHorizontalAlignment.Left;

            using (IRowExporter row = worksheet.CreateRowExporter())
            {
                row.SetOutlineLevel(outlineLevel - 1);

                row.SkipCells(startColumnIndex);

                for (int i = startColumnIndex; i < numberOfIndentCells + columns.Count - 1; i++)
                {
                    using (ICellExporter cell = row.CreateCellExporter())
                    {
                        cell.SetFormat(format);

                        if (group.Key is int)
                        {
                            cell.SetValue((int)group.Key);
                        }
                        else if (group.Key is double)
                        {
                            cell.SetValue((double)group.Key);
                        }
                        else
                        {
                            string cellValue = group.Key != null ? group.Key.ToString() : string.Empty;
                            cell.SetValue(cellValue);
                        }
                    }
                }
            }

            rowIndex++;
            startColumnIndex++;

            if (group.HasSubgroups)
            {
                foreach (IGroup subGroup in group.Subgroups)
                {
                    int newRowIndex = this.AddGroupRow(worksheet, outlineLevel + 1, rowIndex, numberOfIndentCells, subGroup as QueryableCollectionViewGroup, columns);
                    rowIndex = newRowIndex;
                }
            }
            else
            {
                this.AddDataRows(worksheet, outlineLevel, startColumnIndex, group.Items, columns);
                rowIndex += group.Items.Count;
            }

            return rowIndex;
        }
コード例 #13
0
        /// <summary>
        /// Handles RadGridView Element Export in predefined prameterized details
        /// </summary>
        /// <param name="exportElement">GridViewElementExportingEventArgs - custom argument received in RadGridView Element_Exporting event</param>
        /// <param name="cellValueConverter">Function to convert cell values to customed values</param>
        /// <param name="headerCellValueConverter">Function to convert header cell values to customed values</param>
        /// <param name="isGroupFootersVisible">True to display group footers in export</param>
        /// <param name="hideColumnIndex">List of column indexes to be hide in export</param>
        /// <param name="aggregatedColumnIndex">aggregated column indexes</param>
        public static void ElementExporting(GridViewElementExportingEventArgs exportElement, Func <object> cellValueConverter = null,
                                            Func <object> headerCellValueConverter = null, bool isGroupFootersVisible       = true
                                            , List <int> hideColumnIndex           = null, List <int> aggregatedColumnIndex = null)
        {
            ExportElementOptions element = ExportElementOptions.Where(t => t.ExportElementType == exportElement.Element).FirstOrDefault();

            if (element != null)
            {
                exportElement.Background        = element.ExportElementBackground;
                exportElement.Foreground        = element.ExportElementForeground;
                exportElement.FontFamily        = element.ExportElementFontFamily;
                exportElement.FontSize          = element.ExportElementFontSize;
                exportElement.Height            = element.ExportElementFontSize + 5;
                exportElement.Width             = 100;
                exportElement.VerticalAlignment = VerticalAlignment.Center;
                exportElement.FontWeight        = element.ExportElementFontWeight;
                exportElement.TextAlignment     = element.ExportElementTextAlignment;
            }


            if (hideColumnIndex != null)
            {
                GridViewDataColumn column = exportElement.Context as GridViewDataColumn;

                if (column != null)
                {
                    if (exportElement.Element == ExportElement.Cell || exportElement.Element == ExportElement.FooterCell ||
                        exportElement.Element == ExportElement.GroupFooterCell || exportElement.Element == ExportElement.GroupHeaderCell ||
                        exportElement.Element == ExportElement.GroupIndentCell || exportElement.Element == ExportElement.HeaderCell)
                    {
                        if (hideColumnIndex.Contains(column.DisplayIndex))
                        {
                            exportElement.Cancel = true;
                        }
                    }
                }
            }

            if (exportElement.Element == ExportElement.HeaderCell)
            {
                if (headerCellValueConverter != null)
                {
                    exportElement.Value = headerCellValueConverter();
                }
            }

            if (exportElement.Element == ExportElement.GroupFooterRow || exportElement.Element == ExportElement.GroupFooterCell)
            {
                if (isGroupFootersVisible == false)
                {
                    exportElement.Cancel = true;
                    return;
                }
            }

            if (exportElement.Element == ExportElement.Cell)
            {
                if (cellValueConverter != null)
                {
                    exportElement.Value = cellValueConverter();
                }
            }

            if (exportElement.Element == ExportElement.Row)
            {
                if (cellValueConverter != null)
                {
                    exportElement.Value = cellValueConverter();
                }
            }

            if (exportElement.Element == ExportElement.FooterCell)
            {
                if (cellValueConverter != null)
                {
                    exportElement.Value = cellValueConverter();
                }
            }

            else if (exportElement.Element == ExportElement.GroupFooterCell)
            {
                GridViewDataColumn           column   = exportElement.Context as GridViewDataColumn;
                QueryableCollectionViewGroup qcvGroup = exportElement.Value as QueryableCollectionViewGroup;

                if (column != null && qcvGroup != null && column.AggregateFunctions.Count > 0)
                {
                    exportElement.Value = GetAggregates(qcvGroup, column);
                }
                else
                {
                    exportElement.Value = "";
                }
            }
        }