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> </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>0cm</Left> <Height>1.2cm</Height> <Width>7.5cm</Width> <Style> <Border> <Style>None</Style> </Border> </Style> </Tablix>"; } } return TableStr; }
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> " + GenerateTextBox("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 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; }
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; }
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 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 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; }
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 += GetTextBox(headerTxt[i].Name, null, headerTxt[i].ValueOrExpression); } strHeader += @" </ReportItems> <Style /> </PageHeader>"; return strHeader; }
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("Images") + "\\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) + @" <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 void GenerateReportImage(ReportBuilder reportBuilder) { }
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++) { strFooter += GetTextBox(footerTxt[i].Name, null, footerTxt[i].ValueOrExpression); } strFooter += @"</ReportItems> <Style /> </PageFooter>"; return strFooter; }
public static Stream GenerateReport(ReportBuilder reportBuilder) { Stream ret = new MemoryStream(Encoding.UTF8.GetBytes(GetReportData(reportBuilder))); return ret; }
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; }
private void btnRechargeCardView_Click(object sender, EventArgs e) { if (!ValidateDataCardInput()) { return; } dgvRechargeCardHistory.DataSource = null; DateTime date_begin = new DateTime(dtpSaleGasBegin.Value.Year, dtpSaleGasBegin.Value.Month, dtpSaleGasBegin.Value.Day, 0, 0, 0); DateTime date_end = new DateTime(dtpSaleGasEnd.Value.Date.Year, dtpSaleGasEnd.Value.Month, dtpSaleGasEnd.Value.Day, 23, 59, 59); String customerId = (cboRechargeCardCustomer.SelectedItem as ComboboxItem).Value.ToString(); Task<String> task = SGM_WaitingIdicator.WaitingForm.waitingFrm.progressReporter.RegisterTask( () => { return m_service.SGMSaleGas_GetCardReport(customerId, date_begin, date_end, txtRechargeCardID.Text.Trim()); }); SGM_WaitingIdicator.WaitingForm.waitingFrm.progressReporter.RegisterContinuation(task, () => { String stResponse = task.Result as String; DataTransfer dataResponse = JSonHelper.ConvertJSonToObject(stResponse); if (dataResponse.ResponseCode == DataTransfer.RESPONSE_CODE_SUCCESS) { if (dataResponse.ResponseDataSet != null) { dgvRechargeCardHistory.DataSource = dataResponse.ResponseDataSet.Tables[0]; cardReportViewer.Reset(); String tableName = dataResponse.ResponseDataSet.Tables[0].TableName; DataTable data = dataResponse.ResponseDataSet.Tables[0]; cardReportViewer.LocalReport.DataSources.Add(new ReportDataSource(tableName, data)); ReportBuilder reportBuilder = new ReportBuilder(); reportBuilder.DataSource = dataResponse.ResponseDataSet; reportBuilder.Page = new ReportPage(); ReportSections reportHeader = new ReportSections(); reportHeader.Size = new ReportScale(); reportHeader.Size.Height = 0.1; ReportItems reportHeaderItems = new ReportItems(); ReportTextBoxControl[] headerTxt = new ReportTextBoxControl[1]; headerTxt[0] = new ReportTextBoxControl() { Name = "txtReportTitle", ValueOrExpression = new string[] { string.Format("Sales Report: {0}", DateTime.Now) } }; reportHeaderItems.TextBoxControls = headerTxt; reportHeader.ReportControlItems = reportHeaderItems; reportBuilder.Page.ReportHeader = reportHeader; cardReportViewer.LocalReport.LoadReportDefinition(ReportEngine.GenerateReport(reportBuilder)); cardReportViewer.RefreshReport(); } else frmMsg.ShowMsg(SGMText.SGM_INFO, SGMText.REPORT_NO_DATA, SGMMessageType.SGM_MESSAGE_TYPE_INFO); } else { frmMsg.ShowMsg(SGMText.SGM_ERROR, dataResponse.ResponseErrorMsg, SGMMessageType.SGM_MESSAGE_TYPE_ERROR); } }, SynchronizationContext.Current); }