AWC.Reporter.Win product object in VB.NET

Creation Data Matrix in VB.NET AWC.Reporter.Win product object

Listing 11.1 AWC.Reporter.Win product object
Data Matrix 2d Barcode Drawer In VB.NET
Using Barcode drawer for .NET framework Control to generate, create ECC200 image in Visual Studio .NET applications.
www.OnBarcode.com
Reading ECC200 In VB.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
namespace AWC.Reporter.Win { public class Product { private string productName; public string ProductName { get{return productName;} set { this.productName = value; } }
Draw Code-128 In Visual Basic .NET
Using Barcode creator for .NET Control to generate, create USS Code 128 image in Visual Studio .NET applications.
www.OnBarcode.com
EAN-13 Generator In VB.NET
Using Barcode generation for .NET framework Control to generate, create EAN13 image in .NET framework applications.
www.OnBarcode.com
USING REPORTVIEWER IN LOCAL MODE
Create 2D Barcode In VB.NET
Using Barcode drawer for .NET Control to generate, create Matrix image in VS .NET applications.
www.OnBarcode.com
Print PDF-417 2d Barcode In VB.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create PDF417 image in VS .NET applications.
www.OnBarcode.com
private string productCategory; public string ProductCategory { get { return productCategory; } set { this.productCategory = value; } } private string productSubCategory; public string ProductSubCategory { get { return productSubCategory; } set { this.productSubCategory = value; } } private decimal productSales; public decimal ProductSales { get { return productSales; } set { this.productSales = value; } } }
Quick Response Code Creator In VB.NET
Using Barcode creator for .NET Control to generate, create QR Code image in VS .NET applications.
www.OnBarcode.com
Printing MSI Plessey In Visual Basic .NET
Using Barcode generator for .NET framework Control to generate, create MSI Plessey image in .NET framework applications.
www.OnBarcode.com
The Product class contains four properties: ProductName, CategoryName, SubCategoryName, and ProductSales. You ll use this object when you set up your dataset for your report. Listing 11.2 shows the code for the ProductInformation class.
Data Matrix ECC200 Reader In Visual Studio .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Create ECC200 In None
Using Barcode generator for Font Control to generate, create DataMatrix image in Font applications.
www.OnBarcode.com
Listing 11.2 The ProductInformation object, which uses .NET generics to return a list of product objects
Barcode Generator In Objective-C
Using Barcode generation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Recognize Data Matrix In VB.NET
Using Barcode scanner for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
public class ProductInformation { public static List<Product> GetProducts() Returns generic list { of Product objects SqlDataReader rdr = null; SqlCommand cmd = null; SqlConnection conn = new SqlConnection (global::AWC.Reporter.Win.Properties.Settings. Default.AdventureWorksConnectionString); List<Product> ProductList = new List<Product>(); try Instantiates a new { Generic object conn.Open(); cmd = new SqlCommand("spGetProductSalesByCategory",conn); cmd.CommandType = CommandType.StoredProcedure; rdr = cmd.ExecuteReader(); Puts returned dataset Product prod = null; into SqlDataReader while (rdr.Read()) { prod = new Product(); prod.ProductName = rdr.GetString (rdr.GetOrdinal("ProductName"));
Encode QR-Code In None
Using Barcode printer for Online Control to generate, create QR-Code image in Online applications.
www.OnBarcode.com
Decode Code39 In Visual C#
Using Barcode scanner for .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
MASTERING THE REPORTVIEWER CONTROLS
PDF417 Reader In VS .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Code-128 Maker In Java
Using Barcode encoder for Java Control to generate, create Code 128 Code Set C image in Java applications.
www.OnBarcode.com
prod.ProductCategory = rdr.GetString (rdr.GetOrdinal("ProductCategory")); prod.ProductSubCategory = rdr.GetString (rdr.GetOrdinal("ProductSubCategory")); prod.ProductSales = rdr.GetDecimal (rdr.GetOrdinal("Sales")); ProductList.Add(prod); Adds product objects to } } catch( SqlException ex) { throw ex; } finally { conn.Close(); } return ProductList; } }
Creating Code 128 Code Set B In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create Code 128 Code Set B image in Reporting Service applications.
www.OnBarcode.com
Scanning Code 3 Of 9 In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
generic ProductList object
UPC-A Supplement 2 Decoder In VS .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Data Matrix Creation In Objective-C
Using Barcode generator for iPad Control to generate, create Data Matrix image in iPad applications.
www.OnBarcode.com
Returns list of product objects to caller
The code here is pretty straightforward. The ProductImport object has a static class called GetProducts() b. You ve created this as a static method so that you can simply call this method without having to instantiate the object first. Note that this method returns a new type of object that is available in the 2.0 version of the .NET Framework. This <List>Product states that you will return a list of objects, but not just any type of object. The only type of object that you ll be able to put in this list is a Product object. This is not a requirement for your objects to work with Reporting Services, but it does provide a level of safety that was not available by using an ArrayList, for example. (For more information on .NET generics, see the Resources section at the end of this book.) The first thing this method does is set up the objects that you ll use to connect to the database. You also instantiate a new generic list (ProductList) that contains your product objects c. This ProductList object is the object that you ll return to the caller. You open a connection to the database and put the result set into a SqlDataReader object d. Once you have your data, you loop through each row of data in your SqlDataReader. Within this loop you set the properties of your Product object and then add the Product object to your list e. Once the loop is finished, you simply return your list to the caller f. Adding and configuring the ReportViewer to use a business object data source As in our previous examples, begin by creating a new Windows Form and this time name it ReportViewerLocalObject.cs. Next, stretch the form to an appropriate size for your report and add a ReportViewer control. From the ReportViewer task smart USING REPORTVIEWER IN LOCAL MODE 403
The Product object is found in the AWC.Reporter.Win namespace.
tag window, choose Design a New Report. From the Data menu select Add New Data Source to open the Data Source Configuration Wizard. Select Object as the Data Source type and click Next. This brings up a screen that lets you select an object from assemblies on your machine as well as objects in your project. Expand the AWReporterWin project and the AWC.Reporter.Win namespace, as shown in figure 11.9. Once you click Next you see a screen that displays the objects that will be added. Click Finish to complete the wizard. You should see the new Product object in the Data Sources Explorer, as shown in figure 11.10. Now you re ready for the next step: creating the report. Creating the report using business object fields Creating a report using fields from a business object is similar to what you ve done in previous chapters using database fields from a dataset. Figure 11.11 shows the report that we created by simply dragging the dataset fields onto a table entity. As long as the properties (fields) are at the top level, you will be able to drag them just as you can with the database datasets. If you have nested objects, you have to set the path to the property by editing the expression at the field level. We show an example of this later on. You are now ready to add your object-based report to your Windows Form. From the ReportViewer smart tag window, select the report that you just created. This not 404
Copyright © OnBarcode.com . All rights reserved.