static string GetTableColumns(ReportBuilder reportBuilder, ReportTable table) { ReportColumns[] columns = table.ReportDataColumns; ReportTextBoxControl ColumnCell = new ReportTextBoxControl(); if (columns == null) { return(""); } string strColumnHeirarchy = ""; strColumnHeirarchy = @" <TablixColumns>"; for (int i = 0; i < columns.Length; i++) { ColumnCell = columns[i].ColumnCell; strColumnHeirarchy += @" <TablixColumn> <Width>" + ColumnCell.Size.Width.ToString() + @"cm</Width> </TablixColumn>"; } strColumnHeirarchy += @"</TablixColumns>"; return(strColumnHeirarchy); }
static string GenerateTableRow(ReportBuilder reportBuilder, ReportTable table) { ReportColumns[] columns = table.ReportDataColumns; ReportTextBoxControl ColumnCell = new ReportTextBoxControl(); ReportScale colHeight = ColumnCell.Size; ReportDimensions padding = new ReportDimensions(); if (columns == null) { return(""); } string strTableRow = ""; strTableRow = @"<TablixRow> <Height>0.6cm</Height> <TablixCells>"; for (int i = 0; i < columns.Length; i++) { ColumnCell = columns[i].ColumnCell; padding = ColumnCell.Padding; strTableRow += @"<TablixCell> <CellContents> " + GenerateTableRowTextBox(reportBuilder, "txtCell_" + table.ReportName + "_", ColumnCell.Name, "", true, padding) + @" </CellContents> </TablixCell>"; } strTableRow += @"</TablixCells></TablixRow>"; return(strTableRow); }
static string GetHeaderTextBox(ReportBuilder reportBuilder, ReportTextBoxControl reportHeader, ReportDimensions padding = null) { string strTextBox = ""; strTextBox = @" <Textbox Name=""" + reportHeader.Name + @"""> <CanGrow>true</CanGrow> <KeepTogether>true</KeepTogether> <Paragraphs> <Paragraph> <TextRuns>"; for (int i = 0; i < reportHeader.ValueOrExpression.Length; i++) { strTextBox += GetHeaderTextRun(reportBuilder, reportHeader.ValueOrExpression[i].ToString()); } strTextBox += @"</TextRuns> <Style> <TextAlign>Center</TextAlign> </Style> </Paragraph> </Paragraphs> <rd:DefaultName>" + reportHeader.Name + $@"</rd:DefaultName> <Top>{reportHeader.Size.Top}cm</Top> <Left>{reportHeader.Size.Left}cm</Left> <Height>{reportHeader.Size.Height}cm</Height> <Width>{reportHeader.Size.Width}cm</Width> <ZIndex>2</ZIndex> <Style> <Border> <Style>None</Style> </Border>"; strTextBox += GetDimensions(padding) + @"</Style> </Textbox>"; return(strTextBox); }
public void PrintRdlcDataGrid(HttpResponse httpResponse, DataGridHtml dataGridHtml, DomainUtility.ReportExportType reportExportType) { DataView dataView = dataGridHtml.MakeDataView(); //Report Viewer, Builder and Engine ReportViewer reportViewer = new ReportViewer(); reportViewer.Reset(); DataSet DS = new DataSet(); DS.Tables.Add(dataView.ToTable()); ReportBuilder reportBuilder = new ReportBuilder(); reportBuilder.DataSource = DS; reportBuilder.Page = new ReportPage(); reportBuilder.TableRows = dataView.Table.Rows.Count; string fontFamily = new ConfigurationService(base.UnitOfWork).GetValue(sysBpmsConfiguration.e_NameType.DefaultReportFontFamily.ToString()); if (!string.IsNullOrWhiteSpace(fontFamily)) { reportBuilder.FontFamily = fontFamily; } if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridHeaderColor)) { reportBuilder.TableHeaderColor = "#" + dataGridHtml.ReportGridHeaderColor.ToStringObj(); } if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridFooterColor)) { reportBuilder.TableFooterColor = "#" + dataGridHtml.ReportGridFooterColor.ToStringObj(); } if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridEvenColor)) { reportBuilder.TableRowEvenColor = "#" + dataGridHtml.ReportGridEvenColor.ToStringObj(); } if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridOddColor)) { reportBuilder.TableRowOddColor = "#" + dataGridHtml.ReportGridOddColor.ToStringObj(); } //report size switch (dataGridHtml.ReportPaperSize) { case "A2": reportBuilder.Page.PageSize = new ReportScale() { Width = 59.4, Height = 42 }; break; case "A3": reportBuilder.Page.PageSize = new ReportScale() { Width = 42, Height = 29.7 }; break; case "A4": reportBuilder.Page.PageSize = new ReportScale() { Width = 29.7, Height = 21 }; break; case "A5": reportBuilder.Page.PageSize = new ReportScale() { Width = 21, Height = 14.8 }; break; default: reportBuilder.Page.PageSize = new ReportScale() { Width = 29.7, Height = 21 }; break; } ReportSections reportFooter = new ReportSections(); ReportItems reportFooterItems = new ReportItems(); ReportTextBoxControl[] footerTxt = new ReportTextBoxControl[3]; string footer = string.IsNullOrWhiteSpace(dataGridHtml.ReportFooter) ? $" page {ReportGlobalParameters.CurrentPageNumber} of {ReportGlobalParameters.TotalPages}" : dataGridHtml.ReportFooter; footerTxt[0] = new ReportTextBoxControl() { Name = "txtCopyright", ValueOrExpression = new string[] { footer } }; reportFooterItems.TextBoxControls = footerTxt; reportFooter.ReportControlItems = reportFooterItems; reportBuilder.Page.ReportFooter = reportFooter; ReportSections reportHeader = new ReportSections(); reportHeader.Size = new ReportScale(); reportHeader.Size.Height = 0.56849; ReportItems reportHeaderItems = new ReportItems(); List <ReportTextBoxControl> headerTxt = new List <ReportTextBoxControl>() { }; headerTxt.Add(new ReportTextBoxControl() { Name = "txtReportTitle", Size = new ReportScale() { Height = 0.6, Width = 5, Left = (reportBuilder.Page.PageSize.Width - 5) / 2, Top = 0.5 }, ValueOrExpression = new string[] { dataGridHtml.Label } }); if (dataGridHtml.ReportShowDate) { headerTxt.Add(new ReportTextBoxControl() { Name = "txtReportDateTitle", Size = new ReportScale() { Height = 0.6, Width = 2, Left = 0.5, Top = 1 }, ValueOrExpression = new string[] { DateTime.Now.ToString("yyyy/MM/dd") } }); } reportHeaderItems.TextBoxControls = headerTxt.ToArray(); reportHeader.ReportControlItems = reportHeaderItems; reportBuilder.Page.ReportHeader = reportHeader; reportViewer.LocalReport.LoadReportDefinition(ReportBuilderEngine.GenerateReport(reportBuilder)); dataView.Table.Columns.Cast <DataColumn>().ToList().ForEach(c => c.ColumnName = c.ColumnName.Replace(" ", "_")); reportViewer.LocalReport.DataSources.Add( new ReportDataSource(dataView.Table.TableName, dataView.Table)); reportViewer.LocalReport.DisplayName = "WastageReport"; Warning[] warnings; string[] streamids; string mimeType; string encoding; string filenameExtension; byte[] bytes = reportViewer.LocalReport.Render(reportExportType.ToString(), null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); string caption = string.IsNullOrWhiteSpace(dataGridHtml.Label) ? new DynamicFormService(base.UnitOfWork).GetInfo(dataGridHtml.DynamicFormID).Name : dataGridHtml.Label; this.Response(httpResponse, bytes, reportExportType, caption, mimeType); }