DevExpress's Xtrareport Learning notes

Source: Internet
Author: User
Tags border color microsoft sql server crosstab

Xtrareport first, the basic concept:

Each report in Xtrareports is represented by an instance of the Xtrarepot class, or is represented by subclasses of the class (this is more common). Therefore, each report is used as a container for the zone, and the report control is included in each stripe. Each report in the Xtrareports can be bound to data or unbound. To create a bound report, you first bind the report to a data source, and then specify the data-binding options for each report control. All sizes and locations for report controls, bands, and reports themselves are measured in the same units within the report. The unit of measure is specified by the report's Xtrareport.reportunit property and can be set to one of the following types: 1% inches: When the reportunit property value is set to Reportunit.hundredthsofaninch is used. One-tenth mm: Used when the Reportunit property value is set to Reportunit.tenthsofamillimeter. Ii. events to be used when the page is built

before Print:

During a preview/print/Export report, the Xrcontrol.beforeprint event occurs before the Xrcontrol object creates its image, primarily for programmatically changing the properties of the report, the striped properties, and the properties of the controls that are stored in the Detailband detail band.

Most tasks can be performed in this event (such as changing xrcontrol.visible, Xrcontrol.backcolor, Xrcontrol.bordercolor, and other attributes) and can be performed easily without writing code, just using the Formatting rules. In addition, thebeforeprint event can be taken over to reassign the control's style and adjust its xrcontrol.locationf properties.

In the beforeprint event, you can use the Xtrareportbase.getcurrentcolumnvalue method to get the current value of the data column for the data-bound control. Note that in this event, it is too late to modify the binding information for the control. Therefore, for data-bound controls, you can adjust only their static text.

Sample code:

private void Xrlabel1_beforeprint (object sender, PrintEventArgs e)

{

If Convert.todouble (this. Getcurrentcolumnvalue ("UnitPrice")) > 30) {

Xrcontrol control = this. FindControl ("XrLabel1", true);

Control. locationf = new PointF (15F, 15F);

Control. Styles.style = this. STYLESHEET[0];

}

}

III. Structure of the report

The entire report consists of a number of binding bands, with the binding bands as follows:

Binding bands

Description

Topmarginband

Blank ( Header/Footer ) displayed on each page, above Pageheaderband or Reportheaderband

Reportheaderband

At the start of the report ( Report Header ), this band is designed to display some overview information, such as a cover page for a report.

Pageheaderband

On top of each page ( header ), below Topmarginband or Reportheaderband

Groupheaderband

At the start of each group, or at the top of the group ( grouped headers ), sometimes across multiple pages. This band specifies the grouping criteria and is used to display information about the starting position of each group of records

Detailband

Between all other bands on the page ( details ). Each row in this stripe displays only one record in the bound data source, or it simply holds the unbound control when no data source is specified for the report.

Detailreportband

Below the Detailband ( from the table ), is designed to hold the from report when creating a master/from report

Groupfooterband

At the end of each group, or at the bottom of the group ( grouped footnotes ), sometimes across multiple pages. This band is primarily designed to display summary information for each group.

Reportfooterband

At the end of the report ( Report footer ). This band is designed to display certain ultimate information, such as report summaries.

Pagefooterband

Below each page ( footer ) above Reportfooterband and Bottomfooterband, this band is designed for page numbers or footer from previous pages

Bottommarginband

The Blank (foot) at the bottom of each page, below the Pagefooterband.

Common properties of reports

Property

Description

BackColor

Set the background color of a report control

Bands

The bands that the report contains to place various controls (collections)

BorderColor

Control border color in report

Borderdashstyle

Control border Style in report

Borders

Control border in Report

BorderWidth

Border width

Calculatedfiled

Calculated fields, mainly used in Data-aware (data-aware) reports (collections)

DataAdapter

Data source Adapter Object

DataMember

Concrete tables for binding reports in the data source

DataSource

Report Data source

Datasourceschema

Specify the data source framework file (xml/xsd file)

Designeroptions

Showdesignerhints (BOOL): Display tips at design time

Showdesignerwarnings (BOOL): Display warning tips at design time

Showprintingwarnings (BOOL): Print Tips

Detailprintcount

Set the number of pages to print

Detailprintcountonemptydatasource

Number of times the data source is printed when it is empty

DrawGrid (BOOL)

Set whether you want to draw the snap grid

Exportoptions

Used to set the related properties (collection) When the report is exported

Filterstring

Report Data Filter string

Pagecolor

Report page Color

Formattingrules

Set formatting styles

Formattingsheet

Formatting a collection of styles

Pagerkind

Set Paper Type

Parameters

Set Report Parameters

Printonemptydatasource (BOOL)

Sets whether to print when the data source is empty

Requestparameters (BOOL)

Set whether to create a report after a parameter is submit

Snapgridsize

To set the report snap grid size

Snappingmodel

Set alignment mode (Snaptolines&snaptogrid)

SnapToGrid (BOOL)

Set whether to snap to grid

StyleSheet

To set the style of a control reference

Stylesheetpath

Set reference external style file

TextAlignment

Set the report font alignment

Watermark

(property collection) to set up a watermark for a report, including pictures and text

Xmldatapath

To set the data source path for the data source as an XML file

Five, report controls

Report controls are divided into Web page controls and report design controls 1 in a Web application . Web Page Control

Control

Description

Reportdocumentmap

Used to display a bookmark in a report on a Web page, you need to specify the ReportViewer property of the control.

Reportparameterpanel

For Web page pass parameters to the report, you need to specify the ReportViewer property of the control.

ReportViewer

For a Web page rendering report, you specify that the report property for the control is an instance of the statement to display.

Reporttoolbar

With the ReportViewer control to use, to achieve paging, printing, export and other functions.

2. Report Design-Time Controls:

Control

Description

Xrlabel

A Label control that allows you to insert single or multiple lines of text into a report. This text may be static, or it may be dynamic binding.

Xrcheckbox

A check box control that is designed to display true/false or checked/unchecked/indeterminate status in a report.

Xrrichtext

A rich text control that is designed to display, enter, and manipulate text formatted for formatting.

Xrpicturebox

A picture box control that displays the images in a report.

Xrpanel

Panel control, which can contain other report controls.

Xrtable

A table control that inserts a table (including rows and cells).

Xrline

A line control used to draw vertical lines, horizontal lines, or slashes in a report.

Xrshape

A shape control that is used to embed simple graphics into a report.

Xrbarcode

Barcode controls, which allow you to insert many different barcode types into the report.

Xrzipcode

Zip Code control that allows you to insert a number that represents a postal code into the report.

Xrchart

A chart control that can be used to render data in a graphical view.

Xrpivotgrid

A pivot Grid control that is used to render data from a lower data source in a crosstab form, creating a crosstab report.

Xrpageinfo

A control that displays some of the secondary information. Use this control to display page numbers, current dates, or user information in a report.

Xrpagebreak

Page break control, which is used as a markup report to start a new page.

Xrcrossbandline

A line control that can span multiple bands.

Xrcrossbandbox

A box control that can span multiple bands.

Xrsubreport

Subreport control, which is used to display subreports.

vi. report type A static report is a report that simply renders some static information. Such reports are typically not tied to a data source, and a single control or set of controls is displayed on a page. Use the Xtrareportbase.detailprintcount property if you need to repeat the same report content multiple times. A tabular report is a report that renders information in tabular form. This information is stored in the report's bound data source (which can also be read from the database at run time) and is usually not hierarchical (for example, contains only one datasheet). Use the Xrtable control and bind the cells of the table to render the data in the data source; If a report is used to display data from a hierarchical-level data source, it is often referred to as a master/slave report. Two main ways to create a master/from report. The first approach is to use this method, based on a report band (using a Detailreportband band), when the data source contains a primary instance and a ado.net relationship from the instance. The second method is to create two different report classes and merge the report as a subreport into the main report (using the Xrsubreport control, specify that the control's ReportSource property is a subreport). A multiple-column report is a report that renders data with multiple columns or rows, depending on the current multiple-column setting. This report is useful, for example, when each detail band displays only a small amount of data and needs to print the appearance of the next detail stripe on the right side of a column, so that the entire width of the page is fully utilized. In addition, multiple-column reports are useful when you create cards or mailing addresses that have the same content, and you need to print a large number of cards of the same size on many report pages.

Because the multiple-column layout primarily affects the detail bands of the report, you can specify a Detail pattern by using the Detailband.multicolumn attribute of the band area. To enable the multiple-column mode, set the Multicolumn.mode property to remove any values other than None

The column number is fixed, the column width is the same and is calculated automatically.
To do this, you should set the Multicolumn.mode property to Multicolumnmode.usecolumncount and set the Multicolumn.columncount property to the number of columns you want.

Automatically calculates the number of columns, with the width of all columns being the same fixed width.
To do this, you should set the Multicolumn.mode property to Multicolumnmode.usecolumnwidth and set the Multicolumn.columnwidth property to the column width you want. A crosstab report is a report that renders information in a crosstab form. A crosstab (or pivot table) is similar to a simple plain data-binding table, but instead renders a multidimensional hierarchical level of information in a single table and contains automatic sorting, counting, totals, and cumulation for each row and column. Using the Xrpivotgrid control, and specifying a data source, bound field, and column for the control, and ensuring that the report's data source is null, if both use the same data source, the Xrpivotgrid control will be printed the same number of times as the number of rows in the data source. 6. side-by-side reports display two columns of the same or different information in a report, depending primarily on the Xrsubreport control. 7. A Drill-through report is similar to a master-slave report, but a subreport is accessed through hyperlinks. The settings for hyperlinks are described in the data binding section below. 8. a mail merge report often encounters difficulties when trying to create an e-mail template. In these templates, some of the text is invariant, and some fields, often surrounded by predefined tags, should populate the data from the database when the document is created. This feature is also known as mail merge and can be easily implemented using Xtrareports.

Basically, to create an embedded field, you need to insert the name of the data field enclosed in parentheses into the text of the control, and if the field is valid in the current data context, it will be replaced with an appropriate data value when the report is previewed or exported. 9. Label report This report is similar to a multiple-column report. vii. report Data Sources 1. Data source

It is bound to a data source by the Xtrareportbase.datasource property of the Xtrareport object, regardless of the specific data source type and the data binding method used. The only exception is when you are working with an XML data source, you need to assign to the Xtrareportbase.xmldatapath property and require the Xtrareportbase.datasource property to be set to null. 2. Methods for binding Data 2.1. To bind a report using a. NET Data provider

This approach means that the data is stored in the database. You can bind a report to this data by using one of the two data adapter components that you have provided:

OleDbDataAdapter, using OLE DB to access the exposed data source;

SqlDataAdapter, which is designed to use a data source that is provided by Microsoft SQL Server 7.0 or later.

These data adapters use connection objects to bind data and to generate a DataSet object that contains a datasheet. They can then be bound to the report by assigning the datasheet (or the Data view bound to the table) directly to the Xtrareportbase.datasource property. You can also assign the generated dataset object to the Xtrareportbase.datasource property and use the Xtrareportbase.dataadapter property to specify the name of the data adapter. 2.2. Bind the report to the List

Data objects created at run time must support the IList, itypedlist, or IBindingList interfaces and are assigned to the Xtrareportbase.datasource attribute. Note that you do not need to create a custom data source object. For example, you can use a DataTable object that is populated with data at run time. 2.3. Bind the report to XML data

This method uses the data stored in the XML file. You can access this data in one of two ways. Set the Xtrareportbase.datasource property value to a dataset created from an XML file, and assign the XML file directly to the Xtrareportbase.xmldatapath property. Viii. Data binding and report preview 1. Design-Time Binding

When you bind a data source at design time, you need to add the appropriate data source to your application, that is, to add the dataset assembly to your application, and then, in the report design interface, assign the report's data source to the appropriate dataset, and open the field list. Drag the corresponding field with the mouse to the appropriate control. Click Preview to preview the report. 2. Run-time bindings

Binding the data source at run time is more flexible, and it can be rendered on the report by reading useful data from the database as needed. For a run-time bound data source, its data-binding operations are completed in the report's constructor. In Report Designer, just place the appropriate controls. There is a DataBindings property in the report control, and this property's Add method can bind data to the control.

Sample code:

Void DataBind ()

{

DATASOURCE=TB//TB is a DataTable

XRLABEL1.DATABINDS.ADD ("Text", NULL, "Column1");

XRLABEL2.DATABINDS.ADD ("Text", NULL, "Column2", "formatstring:{0}");

}

Call the above method in the report's constructor to bind the data to Xrlabel, where the Add method has two overloads:

CONTROL.DATABINDS.ADD (Control properties, data sources, bound fields)

CONTROL.DATABINDS.ADD (Control properties, data sources, bound fields, formatting settings)

The properties that can be bound by each control may be different and can be viewed through the control's Databinds property. 3. Chart Control Binding

Both the chart control and the Pivotgrid control need to specify the data source independently, and if the two controls are placed detail, the report cannot specify the data source, or the control will display the same number of rows as the report data source.

For data binding to a chart control, bind the corresponding field to the corresponding series, argumentdatamember to the X-axis bound field, and valuedatamembersserializable to the Y-axis field.

You can have more than one series in a chart, you can find the series set in the corresponding Series.chart control by series index or name, and the titles collection is the title of the corresponding series.

Sample code:

protected void DataBind ()

{

String sqlstr = "Select Unitprice,productname from ProductSales Group by Productname,unitprice";

This.xrChart1.DataSource = helper.getdatatable (SQLSTR);

This.xrchart1.series[0]. Argumentdatamember = "ProductName";

This.xrchart1.series[0]. valuedatamembersserializable = "UnitPrice";

This.xrchart1.series[0]. Name = "Price";

This.xrchart1.series[0]. Legendpointoptions.pointview = pointview.argument;

His.xrChart1.Legend.Visible = false;

}

ix. presentation of data

Because data sources are provided in a design-time and run-time manner, data rendering is also different. For reports that provide data sources at run time, grouping and sorting needs to be added to the report through code, while the design-time provisioning of data sources can be set directly through the graphical interface. 1. Data grouping and sorting

Run-time groupings need to include the following code in the data-binding function:

This. GROUPHEADER1.GROUPFIELDS.ADD (New GroupField ("StudentID", xrcolumnsortorder.descending));

The two parameters of GroupField are grouped fields, sorted by type. 2. Data filtering 2.1. Filtering at the report level

Add a filter parameter to the Parameters property in the report and set the filter criteria, and the list of parameters in Parameters on the Web page will be displayed in the Reportparameterpanel control, and after you add parameters to the report, Default Status Preview report The report is created after you click Submit, and you need to set the report's Requestparameters property to False to create a report without providing parameters. 2.2. Filtering at the data source level

Filtering data at the data level, mainly through the where condition of the SQL statement, to pass the parameters of the Where condition to the report class, can be done through the report's constructor, other ways to be studied. At the same time, combined with data filtering at the report level, it is convenient to display the required data on the page.

3. Data Formatting

The FormatString property of the control allows you to set the appropriate formatted output style as needed. Sets various statistical functions through the Summary property of the control.

10. Appearance setting 1. Appearance Properties

The appearance properties are shown in the following table:

the

Properties

Description

BackColor

Gets or sets the background color of the report element and its child controls

bordercolor

Get or set the edge of a report element and its child controls Box color.

Borderdashstyle

to get or set the border dashed style of a report element and its child controls.

Borders

Gets or sets the visible border (top, right, bottom, left) of a report element and its child controls.

borderwidth

Gets or sets the border width of the report element and its child controls.

Font

Gets or sets the font options (font name, size, and so on) for the report element and its child controls.

ForeColor

Gets or sets the foreground color of the report element and its child controls.

Padding

Gets or sets the amount of indentation used to draw the content of a report element and its child controls.

textalignment

Gets or sets the text alignment of a report element and its child controls.

2. Style 2.1 odd-even line style

It allows for visually dividing consecutive data fields in a report for better readability. To apply these styles to a control, you should use its Xrcontrol.oddstylename and Xrcontrol.evenstylename properties. 2.2. Style sheet

You can use the Styles Editor (style editor) at design time to manage report style sheets, custom style sheets, store to files, and load from files. As a result, you can create multiple style sheets and load them at design time or at run time. There are two ways to save a report's style sheet. The first approach is to save as an external file (with a repss extension), and then use the Xtrareport.stylesheetpath property to load into the report in read-only mode, described in how to: Create and store report style sheet topics. The second way is to store the style sheet inside the report (using the Xtrareport.stylesheet property), so you can modify it as needed and save it with the report itself. 3. Attach conditional formatting settings

The formatting rule is set through the Formattingruls property of the control, and when the rule is met, the row data is displayed in a defined style. The formattingrules of the same report is placed in the Formattingrulessheet property. 11, interactive navigation 1. Hyperlinks

Sample code:

Add a hyperlink to a Xrlabel

XRLABEL.DATABINDS.ADD ("NavigateUrl", NULL, "COLUNM", "http://www.quantacn.com?id={0}");

Explanation: When a report has specified a data source (at design time or at run time), you can bind the control to the NavigateUrl property using the above methods, while formatting the URL address and the parameters you want to wear. 2. Document Map

If you set the Bookmark property in the report, the report generates a document map, which is displayed in the Web page with the Reportdocumentmap control.

Sample code:

Add a Document Map to Xrpanel

XRPANEL.DATABINDS.ADD ("Bookmark", NULL, "Column", "formatstring:{0}"); 12. Other

Do not use Reporttoolbar to print, export reports.

Steps:

1. Set the Clientinstancename property of the ReportViewer control on a Web page (for example, viewer)

2. Add a Aspxbutton control to a Web page

3. Click Aspxbutton control's smart tag, cancel AutoPostBack, click client-side-events;

4. Add the following code in the Click event

function (S, e) {

Viewer. Savetodisk (' PDF '); Save to PDF format

Viewer. Print (); Print a report

13, application Deployment

After the Web application is published, the DLL files in the applied devexpress are not built into the application's Bin folder, so you must manually go to the developer Express installation directory in the source folder, the DLL files referenced in the application are copied to the Bin folder in the application before the application is deployed to the server. Otherwise, the report will not display correctly, and note that when you design the report, do not specify the type of printer to prevent errors when printing (someone on the internet has encountered this problem). The test is normal when you deploy the application to IIS on this computer.


Original address: http://www.cnblogs.com/Happly/articles/2541453.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.