void InitTotalSummaries(MVCxGridViewState gridViewState) { if (gridViewState.TotalSummary.Count > 0) { report.Bands.Add(new ReportFooterBand() { HeightF = bandHeight }); foreach (MVCxSummaryItemState item in gridViewState.TotalSummary) { GridViewDataColumnState col = gridViewState.Columns[item.ShowInColumn == string.Empty ? item.FieldName : item.ShowInColumn]; if (col != null) { if (detailsInfo.Contains(col)) { XRLabel label = new XRLabel(); label.LocationF = ((XRTableCell)detailsInfo[col]).LocationF; label.SizeF = ((XRTableCell)detailsInfo[col]).SizeF; label.DataBindings.Add("Text", null, col.FieldName); label.Summary = new XRSummary() { Running = SummaryRunning.Report }; label.Summary.FormatString = item.DisplayFormat; label.Summary.Func = GetSummaryFunc(item.SummaryType); report.Bands[BandKind.ReportFooter].Controls.Add(label); } } } } }
void InitGroupHeaders(MVCxGridViewState gridViewState) { GridViewDataColumnStateCollection groupedColumns = gridViewState.GroupedColumns; for (int i = groupedColumns.Count - 1; i >= 0; i--) { { GridViewDataColumnState groupedColumn = groupedColumns[i]; GroupHeaderBand gb = new GroupHeaderBand(); gb.Height = bandHeight; XRLabel l = new XRLabel { Text = groupedColumn.FieldName + ": [" + groupedColumn.FieldName + "]", LocationF = new PointF(initialGroupOffset + i * 10, 0), BackColor = Color.Beige, SizeF = new SizeF((report.PageWidth - (report.Margins.Left + report.Margins.Right)) - (initialGroupOffset + i * subGroupOffset), bandHeight) }; gb.Controls.Add(l); gb.RepeatEveryPage = shouldRepeatGroupHeadersOnEveryPage; GroupField gf = new GroupField(groupedColumn.FieldName, groupedColumn.SortOrder == ColumnSortOrder.Ascending ? XRColumnSortOrder.Ascending : XRColumnSortOrder.Descending); gb.GroupFields.Add(gf); report.Bands.Add(gb); } } }
public XtraReport GenerateMVCReport(MVCxGridViewState gridViewState, object model) { report = new XtraReport { Landscape = true, PaperKind = System.Drawing.Printing.PaperKind.Letter }; InitDataSource(model); InitDetailsAndPageHeader(gridViewState); InitSortings(gridViewState); InitGroupHeaders(gridViewState); InitFilters(gridViewState); InitTotalSummaries(gridViewState); return(report); }
void InitSortings(MVCxGridViewState gridViewState) { GridViewDataColumnStateCollection columns = gridViewState.Columns; GridViewDataColumnStateCollection groupedColumns = gridViewState.GroupedColumns; for (int i = 0; i < columns.Count; i++) { if (!groupedColumns.Contains(columns[i])) { if (columns[i].SortOrder != ColumnSortOrder.None) { ((DetailBand)report.Bands[BandKind.Detail]).SortFields.Add(new GroupField(columns[i].FieldName, columns[i].SortOrder == ColumnSortOrder.Ascending ? XRColumnSortOrder.Ascending : XRColumnSortOrder.Descending)); } } } }
private List <MVCxColumnInfo> GetColumnsInfo(MVCxGridViewState gridViewState, int pagewidth) { List <MVCxColumnInfo> columns = new List <MVCxColumnInfo>(); GridViewDataColumnStateCollection visibleColumns = gridViewState.Columns; foreach (GridViewDataColumnState dataColumn in visibleColumns) { MVCxColumnInfo column = new MVCxColumnInfo(dataColumn) { ColumnCaption = string.IsNullOrEmpty(dataColumn.Caption) ? dataColumn.FieldName : dataColumn.Caption, ColumnWidth = ((int)pagewidth / visibleColumns.Count), FieldName = dataColumn.FieldName, IsVisible = true }; columns.Add(column); } return(columns); }
public ActionResult Export() { var model = Session["Results"]; MVCxGridViewState gridViewState = (MVCxGridViewState)Session["gridViewState"]; if (gridViewState != null) { MVCReportGeneratonHelper generator = new MVCReportGeneratonHelper(); generator.CustomizeColumnsCollection += new CustomizeColumnsCollectionEventHandler(CustomizeColumnsCollection); generator.CustomizeColumn += new CustomizeColumnEventHandler(CustomizeColumn); XtraReport report = generator.GenerateMVCReport(gridViewState, model); generator.WritePdfToResponse(Response, "iws.xlsx", System.Net.Mime.DispositionTypeNames.Attachment.ToString()); return(null); } else { return(View("Index")); } }
void InitDetailsAndPageHeader(MVCxGridViewState gridViewState) { GridViewDataColumnStateCollection groupedColumns = gridViewState.GroupedColumns; int pagewidth = (report.PageWidth - (report.Margins.Left + report.Margins.Right)) - groupedColumns.Count * subGroupOffset; List <MVCxColumnInfo> columns = GetColumnsInfo(gridViewState, pagewidth); CustomizeColumnsCollection(report, new ColumnsCreationEventArgs(pagewidth) { ColumnsInfo = columns }); report.Bands.Add(new DetailBand() { HeightF = bandHeight }); report.Bands.Add(new PageHeaderBand() { HeightF = bandHeight }); XRTable headerTable = new XRTable(); XRTableRow row = new XRTableRow(); XRTable detailTable = new XRTable(); XRTableRow row2 = new XRTableRow(); for (int i = 0; i < columns.Count; i++) { if (columns[i].IsVisible) { XRTableCell cell = new XRTableCell(); cell.Width = columns[i].ColumnWidth; cell.Text = columns[i].FieldName; row.Cells.Add(cell); XRTableCell cell2 = new XRTableCell(); cell2.Width = columns[i].ColumnWidth; ControlCustomizationEventArgs cc = new ControlCustomizationEventArgs() { FieldName = columns[i].FieldName, IsModified = false, Owner = cell2 }; CustomizeColumn(report, cc); if (cc.IsModified == false) { cell2.DataBindings.Add("Text", null, columns[i].FieldName); } detailsInfo.Add(columns[i].GridViewColumn, cell2); row2.Cells.Add(cell2); } } headerTable.Rows.Add(row); headerTable.Width = pagewidth; headerTable.LocationF = new PointF(groupedColumns.Count * subGroupOffset, 0); headerTable.Borders = BorderSide.Bottom; detailTable.Rows.Add(row2); detailTable.LocationF = new PointF(groupedColumns.Count * subGroupOffset, 0); detailTable.Width = pagewidth; report.Bands[BandKind.PageHeader].Controls.Add(headerTable); report.Bands[BandKind.Detail].Controls.Add(detailTable); }
void InitFilters(MVCxGridViewState gridViewState) { report.FilterString = gridViewState.FilterExpression; }