Sams Microsoft SQL Server 2008- P4

50 471 0
Sams Microsoft SQL Server 2008- P4

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ptg 131 Generating Reports with Visual Studio 8 Design Screen After selecting your data, the next step is to design the presentation for the data. Layout assistance is provided by the Toolbox, Report Data, and Design dockable windows. Design view is a default that BIDS displays after you add a report (see Figure 8.11). The Toolbox (shown in Figure 8.11) is accessible by selecting Toolbox from the View menu. This has all the report item controls you might use while authoring reports. The simplest way to use them is to drag the control you want onto the body of a report. Data can be inserted from the Report Data window. (Just choose Report Data from the View menu.) The Report Data window contains a tree list of available fields to use from the data sets. If you drag a field onto the report body, BIDS creates a text box to contain the field. Any item on the report can be modified through the Properties window. The Properties window can be accessed by pressing F4 or by selecting Properties Window from the View menu. Figure 8.11 shows the Properties window for a report object. Categorized Alphabetical Property pages Properties window Properties toolbar Toolbox Report data Main menu Design tab Preview tab Report body Context help/tip for a property Error List window Report items Dataset fields Output window Report object (page, code, etc.) Toolbar Solution Explorer FIGURE 8.11 Report Design view. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 132 CHAPTER 8 Report Designer(s) At this point in the report development process, you need to take the results of your query and apply a layout and format to them. Let’s make a simple tabular report and add a few bells and whistles. Complete the following steps using the Sales by Territory by Salesperson report: 1. Drag a text box from the Toolbox to the report body. In the Properties window (F4), select the text box. (Most likely, the text box you just added is already selected.) Enter Sales by Territory by Salesperson in the text box and change the follow- ing property values to those specified here: Name: ReportTitle Location: Top = 0, Left = 0 Size: Height = .5in, Width = 4.5in Color: DarkBlue Font: FontFamily = Tahoma, FontSize = 18pt, FontWeight = Bold 2. Drag a table and place it on the report’s body under the report title that you have just created. By default, the table comes with three columns, which are all 1-inch wide. Click the bar above each column; if selected successfully, the entire column should be selected. After a column is selected, you can use the Properties window and change the Width property to fit the information you are going to display. You can do this for each column individually or select columns you want to change to the same size by pressing and holding Ctrl key and selecting multiple columns. NOTE In SSRS 2008, the Table report item is actually represented by a new Tablix data region. Tablix represents both Table and Matrix report items. This is why some of the menu items and dialog boxes use Tablix even though we work with the Table report item. 3. From the Report Data window, drag the AdventureWorkDataset fields (CountryRegionName, TerritoryName, and FirstName) to the first three columns of the table. Note that when you drag a field over a column the entire column is selected. Report Designer will add a value of a field to a data row of the table and the name of a field to the header of the table. When adding a field name to table’s header, the Report Designer will also insert spaces before each capital letter in the field’s name. 4. To add more columns to the table, you can select the rightmost column of the table, right-click the column, and select Insert Column, Right (see Figure 8.12). Repeat three times. The table should now have six columns. 5. Alternatively you can continue dragging fields from the data set to the table, posi- tioning your cursor where you want the column to be added, similar to Figure 8.13 where we add a column to the end of the table. Note how the cursor changes to indicate an addition to the table. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 133 Generating Reports with Visual Studio 8 FIGURE 8.12 Adding columns to a table. 6. Click the button next to the report header row. After the row is selected, use the Properties window to set the following properties: FIGURE 8.13 Adding columns to a table by dragging data fields. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 134 CHAPTER 8 Report Designer(s) BackgroundColor: #1c3a70 Color: White Font: FontFamily = Tahoma, FontSize = 11pt, FontWeight = Bold 7. Click the button at the upper-left corner of the table. When you do this, the entire table should now be selected. The Properties window now should reflect the table’s properties. You can modify table properties as you consider appropriate. For example, you can change table’s BorderStyle property to Solid to display a border around the table. 8. Click the Preview tab to see what the report looks like. We should fix some formatting to make a report more visually appealing. You may have noticed that country and territory names are not ordered, and Sales columns are not formatted as currency. 9. Click the Design tab. Holding the Ctrl key, select cells that contain sales data. For the format, enter C . (The single letter C is a formatting for currency.) 10. Click anywhere on the table, and then right-click the button at the upper-left corner of the table. 11. Select Tablix Properties from the context menu. 12. Now display the Sorting tab. 13. Click the Add button three times to add three columns to sorting. Select the follow- ing columns for sorting: CountryRegionName, TerritoryName, and LastName. Leave the default sorting order A to Z (see Figure 8.14). FIGURE 8.14 Adding columns for sorting. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 135 Summary 8 14. Click OK to complete the sorting assignment, and display the Preview tab to see what the report looks like (see Figure 8.15). This concludes the starter report. Preview mode has full report-viewing capabilities and allows navigating multipage reports and exporting a report to a different format (such as XML, Word, and Excel). Preview mode also has print capabilities (such as print preview and page setup). Summary BIDS is nothing more than the shell of Visual Studio. Both products house the main report development tool from Microsoft: SQL Server Report Designer. Over the next several chapters, you will see how to use Report Designer to develop powerful and visually appealing reports for all kinds of end users. You’ll learn more about client-side ad hoc reporting in Chapter 18. Find control: text to find, find first, find next Zoom Printing control: print, print preview, page setup Export report in a different format (such as XML) Multipage report control: first, previous, go to page, next, last Browsing control: back, cancel, refresh Report Viewer toolbar FIGURE 8.15 Completed report in Preview mode. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg This page intentionally left blank From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg CHAPTER 9 Report Definition Language IN THIS CHAPTER . Language: A Way to Communicate . Use of XML . Declarative Programming . Report Elements T he preceding chapter introduced you to Report Designer and Report Builder. This chapter takes a look at the output from these tools. SSRS is unique in that it uses Extensible Markup Language (XML) to generate reports. This chapter provides an insight into why Microsoft uses XML as their report-generation language, and then delves into the structure of the result- ing document. Language: A Way to Communicate At first glance, the name Report Definition Language (RDL) might appear to be a misnomer. As you’ve already seen, it is nothing more than an XML document, just like any other XML document. Why would they call this a language? After all, there is no compiler necessary, and the syntax is nothing like C++, C#, or any other programming language. To answer this, you need to think of things at a bit higher level than most programming paradigms allow. Remember, one of the goals of SSRS is to remain an open- ended environment. Likewise, as you have already seen, SSRS is composed of many different components: There is the database server, the Windows Service, the Report Server Web Service, and so on. Most important, at least from an end-user perspective, are the report designers and the rendering engine. As you have seen, Microsoft already offers three designers: Report Designer and Report Builder 1.0 and 2.0. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 138 CHAPTER 9 Report Definition Language All designers use the same rendering engine, and even within this engine there are multi- ple formats. For all of this to work together seamlessly, all these components need to communicate with the same underlying principles. This is where the common language comes in to play; it is just a common way to communicate instructions between the various entities. Use of XML Most enterprise reporting solutions use proprietary binary formats. This locks developers into using that vendor’s tools to generate and deploy reports. Obviously, this runs counter to the SSRS design goal of generating open standards. The other thing to note about SSRS is the idea to keep report designers and generators separate. This poses the fundamental challenge of what open format allows such disparate things to communicate. Thankfully, the answer already existed: XML. XML is already in use throughout the Web and even in many non-Web systems as a communication mechanism. It easily allows anyone with a text editor to create an XML file. XML is similar to Hypertext Markup Language (HTML) in that it is a form of markup language. There are a few major differences. With XML, a document has to be well formed, meaning every beginning markup tag (called a node) has to have a corresponding ending tag. Second, HTML only has a few keywords that can be used to mark up text. XML doesn’t have any such limitation because the end user is the one responsible for the creation of tags. The tags are used to describe the data encompassed by them. This is in stark contrast to HTML, which describes how to handle presentation of data. This makes XML an ideal communication medium or language. The one drawback about such a flexible medium is, ironically enough, its flexibility. Immediately, you might wonder the following: If any node can be in any place, and any node can have any attribute, how can this be effective? There have to be some rules. To solve this problem, you need to create an XML schema. An XML schema allows the creation of a contract to adhere to between different systems by defining when and where in the document a set of XML nodes should appear, and which nodes should have attrib- utes describing them. The RDL specification is the XML schema that describes the layout of the XML used to create reports. The XML itself basically becomes the programming language of the report. Declarative Programming Just as a programming language lets a programmer tell a computer how and what to produce to the end user, the RDL tells the Report Server what data to use and how to lay it out. Now, there is a little trick here: Most programming languages communicate a what From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 139 Report Elements 9 and a how to do something. There is no way to tell ASP.NET to produce a web page just by giving it a template. However, that is what the RDL does. The RDL communicates what the output is to look like and where the source data is to come from. This leaves the appli- cation free to decide how to generate the defined look and feel, regardless of the program- ming language or underlying architecture. This model is called the declarative model. A producer application is an application that is used to generate RDL files. Business Intelligence Development Studio (BIDS) and Report Builder fall into this category. For most users, it is helpful to have a graphical user interface (GUI), although you can develop a report purely in your favorite text editor. A consumer application is simply one that takes the RDL from the producer and creates the desired output. In its simplest form, it queries for the data and displays the results in the specified format. This is where a lot of the custom elements come in. Using the custom elements, it is possible to send instructions for one output format, which could then be ignored by all others. Report Elements To create a report, you need to know a few things: . Where and what is your source data? . What is the report layout? . Are there any other properties, such as external images or parameters? To cover this much information, the RDL schema has many elements. The RDL specifica- tion (schema) itself is an open schema, and Microsoft fully expects third parties to add onto it to extend it. In the scope of this book, it would be time-consuming and arduous to cover every element, so this book covers just a few key elements. You can find more infor- mation about the RDL schema on the Microsoft website at http://schemas.microsoft.com/ sqlserver/reporting/2008/01/reportdefinition/ReportDefinition.xsd. If you’d prefer to see the RDL’s elements in a graphical form, you can find it in the Books Online or in its web version at http://msdn.microsoft.com/en-us/library/ms153957.aspx or by simply searching for “Report Definition XML Diagrams” at http://www.microsoft.com. You can also view the XML of any report by opening the report in BIDS and selecting the Code from the View menu while in Design view. Alternatively, you can view a report’s XML by right-clicking the report in Solution Explorer and selecting View Code from a drop-down menu. Let’s examine several SSRS elements. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 140 CHAPTER 9 Report Definition Language Report Element The Report element is the highest-level element in the RDL’s XML hierarchy. The Report element contains all the information needed to process the report. There can be only one Report element in every report. In fact, every other element is a child node of the Report element. Examples of these child elements include PageHeader , Body , PageFooter , DataSources , DataSets , and Parameters . The following code listing shows an example of the Report element. The RDL is of an empty report with a Line report item: <?xml version=”1.0” encoding=”utf-8”?> <Report xmlns:rd=”http://schemas.microsoft.com/SQLServer/reporting/reportdesigner” xmlns=”http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition”> <Body> <ReportItems> <Line Name=”Line1”> <Top>0.0175in</Top> <Height>0.25in</Height> <Width>1in</Width> <Style> <Border> <Style>Solid</Style> </Border> </Style> </Line> </ReportItems> <Height>2in</Height> <Style /> </Body> <Width>6.5in</Width> <Page> <Style /> </Page> <rd:ReportID>a045101c-aa05-4334-940f-b728efb81635</rd:ReportID> <rd:ReportUnitType>Inch</rd:ReportUnitType> </Report> ReportParameters Element For the ReportParameters element, there are following entries in the RDL schema: . <xsd:element name=”Report”> <xsd:complexType> <xsd:choice minOccurs=”1” maxOccurs=”unbounded”> From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... used only in headers and footers ReportFolder String The virtual path to the folder containing the report This does not include the ReportServerName ReportName String The name of the report from the Report Server s catalog ReportServerUrl String The URL of the Report Server from which the report is being processed TotalPages Integer The value for the total number of pages in a report This parameter can... dialog box Armed with an understanding of the RDL, you can write your own graphical report designers if you so choose SQL Server Books Online have an example of such a generator under the title “Tutorial: Generating RDL Using the NET Framework,” which is also available online at http://msdn .microsoft. com/en-us/library/ms170667.aspx The RDL generator in the example simply uses NET’s System.Xml.XmlTextWriter... Language Runtime In fact, three of them are already referenced for you: Microsoft. VisualBasic, System.Math, and System.Convert In addition, SSRS enables you to write your own functions using custom code blocks (in VB.NET) Visual Basic Runtime Functions Runtime functions are provided through Microsoft NET library’s namespaces: Microsoft. VisualBasic, System.Math, and System.Convert Aggregate (for example,... IsMissing The extended properties have to be supported by a provider to contain values; otherwise, those properties are Nothing (or Null) An example of a provider that supports extended properties is the SQL Server Analysis Services (SSAS) data-processing extension The thought behind extended properties is to have a consistent formatting of the data no matter what tool a user uses NOTE 10 The extended properties... item If omitted, the value defaults to the width of the containing object minus the Left value PageBreakAtStart Optional Boolean Instructs the Report Server to put a page break before a report item PageBreakAtEnd Optional Boolean Instructs the Report Server to put a page break after a report item Visibility Optional Element Specifies the initial visibility of an item and a toggle trigger item for the... the data You can do so by assigning a text box the following value: =DataSets(“ProductsDataSet”).CommandText This proves helpful for debugging, especially if you are generating a SQL statement at the runtime (using dynamic SQL statements) So that you do not distract users with the CommandText information, you can set a Color property of the text box where you are displaying CommandText to the same color... The schema definition element for a DataSet is in the following listing To shorten the listing, we have skipped several child elements for a DataSet that determine how a Report Server sorts data: AccentSensitivity (when text is accent sensitive, the character ’a’ is not equal to the character ’ã’), WidthSensitivity (determines whether single-byte and double-byte representation... even though invisible it is still available in a report’s Hypertext Markup Language (HTML) Therefore, it might highlight a query’s vulnerabilities, especially if the query contains parameters or dynamic SQL You can use RewrittenCommandText for a similar purpose, to view a query with its parameters expanded However, because only a limited number of providers fill this member with data, the usability of... Collection Items Properties Property Type Description DataSourceReference String The relative path of the data source Example: /DataSources/AdventureWorks Type String The type of a data provider Example: SQL Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark From the Library of STEPHEN EISEMAN 160 CHAPTER 10 Expressions Members of this collection are Nothing (or Null) if the data... expression =First(Fields!FirstName.Value, “DataSet1”) is required Because data regions have an associated data set, this association provides scope resolution for fields within a data region In SSRS 2008, Microsoft added extended (New in 2008) properties to the Fields collection Table 10.4 shows a complete list of properties TABLE 10.4 Fields Collection Items Member Properties Property Type Description . <Report xmlns:rd=”http://schemas .microsoft. com/SQLServer/reporting/reportdesigner” xmlns=”http://schemas .microsoft. com/sqlserver/reporting/2008/01/reportdefinition”>. find more infor- mation about the RDL schema on the Microsoft website at http://schemas .microsoft. com/ sqlserver/reporting/2008/01/reportdefinition/ReportDefinition.xsd.

Ngày đăng: 28/10/2013, 17:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan