static string GenerateTableHeaderRow(ReportBuilder reportBuilder, ReportTable table) { ReportColumns[] columns = table.ReportDataColumns; ReportTextBoxControl ColumnCell = new ReportTextBoxControl(); 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 = columns[i].HeaderColumnPadding; strTableRow += @"<TablixCell> <CellContents> " + GenerateHeaderTableTextBox("txtHeader_" + table.ReportName + "_", ColumnCell.Name, columns[i].HeaderText == null || columns[i].HeaderText.Trim() == "" ? ColumnCell.Name : columns[i].HeaderText, false, padding) + @" </CellContents> </TablixCell>"; } strTableRow += @"</TablixCells></TablixRow>"; return(strTableRow); }
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 GetSortingDetails(ReportBuilder reportBuilder) { return(""); ReportTable[] tables = reportBuilder.Body.ReportControlItems.ReportTable; ReportColumns[] columns = reportBuilder.Body.ReportControlItems.ReportTable[0].ReportDataColumns; ReportTextBoxControl sortColumn = new ReportTextBoxControl(); if (columns == null) { return(""); } string strSorting = ""; strSorting = @" <SortExpressions>"; for (int i = 0; i < columns.Length; i++) { sortColumn = columns[i].ColumnCell; strSorting += "<SortExpression><Value>=Fields!" + sortColumn.Name + @".Value</Value>"; if (columns[i].SortDirection == ReportSort.Descending) { strSorting += "<Direction>Descending</Direction>"; } strSorting += @"</SortExpression>"; } strSorting += "</SortExpressions>"; return(strSorting); }
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> " + GenerateTextBox("txtCell_" + table.ReportName + "_", ColumnCell.Name, "", true, padding) + @" </CellContents> </TablixCell>"; } strTableRow += @"</TablixCells></TablixRow>"; return(strTableRow); }
private static string GetFooter(ReportBuilder reportBuilder) { string strFooter = ""; if (reportBuilder.Page == null || reportBuilder.Page.ReportFooter == null) { return(""); } strFooter = @"<PageFooter> <Height>0.68425in</Height> <PrintOnFirstPage>true</PrintOnFirstPage> <PrintOnLastPage>true</PrintOnLastPage> <ReportItems>"; ReportTextBoxControl[] footerTxt = reportBuilder.Page.ReportFooter.ReportControlItems.TextBoxControls; if (footerTxt != null) { for (int i = 0; i < footerTxt.Count(); i++) { if (footerTxt[i] != null) { strFooter += GetFooterTextBox(footerTxt[i].Name, null, footerTxt[i].ValueOrExpression); } } } strFooter += @"</ReportItems> <Style /> </PageFooter>"; return(strFooter); }
static string GenerateTable(ReportBuilder reportBuilder) { string TableStr = ""; if (reportBuilder != null && reportBuilder.DataSource != null && reportBuilder.DataSource.Tables.Count > 0) { ReportTable table = new ReportTable(); for (int i = 0; i < reportBuilder.Body.ReportControlItems.ReportTable.Length; i++) { table = reportBuilder.Body.ReportControlItems.ReportTable[i]; TableStr += @"<Tablix Name=""table_" + table.ReportName + @"""> <TablixBody> " + GetTableColumns(reportBuilder, table) + @" <TablixRows> " + GenerateTableHeaderRow(reportBuilder, table) + GenerateTableRow(reportBuilder, table) + @" </TablixRows> </TablixBody>" + GetTableColumnHeirarchy(reportBuilder, table) + @" <TablixRowHierarchy> <TablixMembers> <TablixMember> <KeepWithGroup>After</KeepWithGroup> <RepeatOnNewPage>true</RepeatOnNewPage> <KeepTogether>true</KeepTogether> </TablixMember> <TablixMember> <Group Name=""" + table.ReportName + "_Details" + @""" /> </TablixMember> </TablixMembers> </TablixRowHierarchy> <RepeatColumnHeaders>true</RepeatColumnHeaders> <RepeatRowHeaders>true</RepeatRowHeaders> <DataSetName>" + table.ReportName + @"</DataSetName>" + GetSortingDetails(reportBuilder) + @" <Top>0.07056cm</Top> <Left>1cm</Left> <Height>1.2cm</Height> <Width>7.5cm</Width> <ZIndex>1</ZIndex> <Style> <Border> <Style>None</Style> </Border> </Style> </Tablix>"; } } return(TableStr); }
static ReportBuilder InitAutoGenerateReport(ReportBuilder reportBuilder) { if (reportBuilder != null && reportBuilder.DataSource != null && reportBuilder.DataSource.Tables.Count > 0) { DataSet ds = reportBuilder.DataSource; int _TablesCount = ds.Tables.Count; ReportTable[] reportTables = new ReportTable[_TablesCount]; if (reportBuilder.AutoGenerateReport) { for (int j = 0; j < _TablesCount; j++) { DataTable dt = ds.Tables[j]; ReportColumns[] columns = new ReportColumns[dt.Columns.Count]; ReportScale ColumnScale = new ReportScale(); ColumnScale.Width = 4; ColumnScale.Height = 1; ReportDimensions ColumnPadding = new ReportDimensions(); ColumnPadding.Default = 2; for (int i = 0; i < dt.Columns.Count; i++) { columns[i] = new ReportColumns() { ColumnCell = new ReportTextBoxControl() { Name = dt.Columns[i].ColumnName, Size = ColumnScale, Padding = ColumnPadding }, HeaderText = dt.Columns[i].ColumnName, HeaderColumnPadding = ColumnPadding }; } reportTables[j] = new ReportTable() { ReportName = dt.TableName, ReportDataColumns = columns }; } } reportBuilder.Body = new ReportBody(); reportBuilder.Body.ReportControlItems = new ReportItems(); reportBuilder.Body.ReportControlItems.ReportTable = reportTables; } return(reportBuilder); }
private static string GetPageHeader(ReportBuilder reportBuilder) { string strHeader = ""; if (reportBuilder.Page == null || reportBuilder.Page.ReportHeader == null) { return(""); } ReportSections reportHeader = reportBuilder.Page.ReportHeader; strHeader = @"<PageHeader> <Height>" + reportHeader.Size.Height.ToString() + @"in</Height> <PrintOnFirstPage>" + reportHeader.PrintOnFirstPage.ToString().ToLower() + @"</PrintOnFirstPage> <PrintOnLastPage>" + reportHeader.PrintOnLastPage.ToString().ToLower() + @"</PrintOnLastPage> <ReportItems>"; ReportTextBoxControl[] headerTxt = reportBuilder.Page.ReportHeader.ReportControlItems.TextBoxControls; if (headerTxt != null) { for (int i = 0; i < headerTxt.Count(); i++) { strHeader += GetHeaderTextBox(headerTxt[i].Name, null, headerTxt[i].ValueOrExpression); } } strHeader += @" <Image Name=""Image1""> <Source>Embedded</Source> <Value>Logo</Value> <Sizing>FitProportional</Sizing> <Top>0.05807in</Top> <Left>1cm</Left> <Height>0.4375in</Height> <Width>1.36459in</Width> <ZIndex>1</ZIndex> <Style /> </Image> </ReportItems> <Style /> </PageHeader>"; return(strHeader); }
static string GetTableColumnHeirarchy(ReportBuilder reportBuilder, ReportTable table) { ReportColumns[] columns = table.ReportDataColumns; if (columns == null) { return(""); } string strColumnHeirarchy = ""; strColumnHeirarchy = @" <TablixColumnHierarchy> <TablixMembers>"; for (int i = 0; i < columns.Length; i++) { strColumnHeirarchy += "<TablixMember />"; } strColumnHeirarchy += @"</TablixMembers> </TablixColumnHierarchy>"; return(strColumnHeirarchy); }
static string GetReportData(ReportBuilder reportBuilder) { reportBuilder = InitAutoGenerateReport(reportBuilder); string rdlcXML = ""; rdlcXML += @"<?xml version=""1.0"" encoding=""utf-8""?> <Report xmlns=""http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"" xmlns:rd=""http://schemas.microsoft.com/SQLServer/reporting/reportdesigner""> <Body>"; string _tableData = GenerateTable(reportBuilder); if (_tableData.Trim() != "") { rdlcXML += @"<ReportItems>" + _tableData + @"</ReportItems>"; } byte[] imgBinary = File.ReadAllBytes(HttpContext.Current.Server.MapPath("img") + "\\logo.png"); rdlcXML += @"<Height>2.1162cm</Height> <Style /> </Body> <Width>20.8cm</Width> <Page> " + GetPageHeader(reportBuilder) + GetFooter(reportBuilder) + GetReportPageSettings() + @" <Style /> </Page> <AutoRefresh>0</AutoRefresh> " + GetDataSet(reportBuilder) + @" <EmbeddedImages> <EmbeddedImage Name=""Logo""> <MIMEType>image/png</MIMEType> <ImageData>" + System.Convert.ToBase64String(imgBinary) + @"</ImageData> </EmbeddedImage> </EmbeddedImages> <Language>it-IT</Language> <ConsumeContainerWhitespace>true</ConsumeContainerWhitespace> <rd:ReportUnitType>Cm</rd:ReportUnitType> <rd:ReportID>17efa4a3-5c39-4892-a44b-fbde95c96585</rd:ReportID> </Report>"; return(rdlcXML); }
static string GetDataSet(ReportBuilder reportBuilder) { string dataSetStr = ""; if (reportBuilder != null && reportBuilder.DataSource != null && reportBuilder.DataSource.Tables.Count > 0) { string dsName = "rptCustomers"; dataSetStr += @"<DataSources> <DataSource Name=""" + dsName + @"""> <ConnectionProperties> <DataProvider>System.Data.DataSet</DataProvider> <ConnectString>/* Local Connection */</ConnectString> </ConnectionProperties> <rd:DataSourceID>944b21fd-a128-4363-a5fc-312a032950a0</rd:DataSourceID> </DataSource> </DataSources> <DataSets>" + GetDataSetTables(reportBuilder.Body.ReportControlItems.ReportTable, dsName) + @"</DataSets>"; } return(dataSetStr); }
public void DataBind(DataSet ds) { int count = 0; foreach (DataTable dt in ds.Tables) { count++; var report_name = "Report" + count; DataTable dt1 = new DataTable(report_name.ToString()); dt1 = ds.Tables[count - 1]; dt1.TableName = report_name.ToString(); } ReportViewerMaster.Reset(); for (int i = 0; i < ds.Tables.Count; i++) { ReportViewerMaster.LocalReport.DataSources.Add(new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i])); } ReportViewerMaster.LocalReport.EnableHyperlinks = true; ReportBuilder reportBuilder = new ReportBuilder(); reportBuilder.DataSource = ds; reportBuilder.Page = new ReportPage(); ReportSections reportFooter = new ReportSections(); ReportItems reportFooterItems = new ReportItems(); ReportTextBoxControl[] footerTxt = new ReportTextBoxControl[3]; //string footer = string.Format("Copyright {0} Report Generated On {1} Page {2}", DateTime.Now.Year, DateTime.Now, ReportGlobalParameters.CurrentPageNumber); string footer = string.Format("Copyright {0} Report Generated On {1} Page {2} of {3} ", DateTime.Now.Year, DateTime.Now, ReportGlobalParameters.CurrentPageNumber, ReportGlobalParameters.TotalPages); 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; reportHeader.Size.Height = 0.7; ReportItems reportHeaderItems = new ReportItems(); ReportTextBoxControl[] headerTxt = new ReportTextBoxControl[1]; headerTxt[0] = new ReportTextBoxControl() { Name = "txtReportTitle", ValueOrExpression = new string[] { ReportTitle } }; reportHeaderItems.TextBoxControls = headerTxt; reportHeader.ReportControlItems = reportHeaderItems; reportBuilder.Page.ReportHeader = reportHeader; ReportViewerMaster.LocalReport.LoadReportDefinition(ReportEngine.GenerateReport(reportBuilder)); ReportViewerMaster.LocalReport.DisplayName = ReportName; ReportViewerMaster.LocalReport.EnableHyperlinks = true; }
public static Stream GenerateReport(ReportBuilder reportBuilder) { Stream ret = new MemoryStream(Encoding.UTF8.GetBytes(GetReportData(reportBuilder))); return(ret); }
static void GenerateReportImage(ReportBuilder reportBuilder) { }