Microsoft Excel

Even when not working with data-driven applications, I've long believed that there is no better reporting tool than a well-written stored procedure and a copy of Excel. When used properly, a report writer is just a data-formatting tool. All the intelligence is (or at least should be, in my opinion) stored in the stored procedure, or business class, that feeds raw data to the reporting tool. The stored procedure should provide the detail data in the format it will appear in, minus any totals and...

Decompiling Source Code

Although Reflection allows you to drill down into the structure of your assemblies, it doesn't take you as far as the source-code level. When a .NET program is compiled, the source code you write is compiled to Intermediate Language (IL) code. This IL is executed by the Common Language Runtime (CLR) when the application is run. Microsoft directly provides a way for you to see this IL code in the form of the Intermediate Language Disassembler (ILDASM) that ships with the .NET Framework SDK. You...

Code Generation

Probably the most commonly used data-driven applications on the market today are code generators. A substantial amount of software development involves the creation of class wrappers, SQL statements, data-access methods, and variable initializations, and property accessors. Writing this code is a repetitive task that you can easily automate, because the code is a reflection of existing data structures. Code-generation tools attach to data tables and, using the RDBMS's metadata, use data-driven...

Building a Filter Screen

One of the most useful, data-driven applications you can create is a filter screen. These can be used to filter data on a grid control or pass parameters to a report. Suppose you wish to present the user with a screen that offers a myriad of controls to allow filtering of data. When the user makes their selections, these choices should be persisted to a data source and then restored the next time the form is loaded. Examine the filter screen in Figure 4-4. XML is an ideal storage medium for...

Saving Grid Settings

One complaint users often have about applications is the inability to persist their data-grid adjustments. Users have different needs, even for the same screen. You may have a grid on a screen that shows customer information arranged as company name, address, city, state, zip, phone number, terms, CEO name, and accounts payable contact. This much information likely requires left right scrolling, because it's too much to fit in the grid's visible display area. The sales manager may need to know...

Adding References

When you provide a code window for your users, you may wish to allow them to add references to their project much as developers do in the Visual Studio IDE. Figure 3-5 shows the Add Reference dialog. net i com I Projects I Brome Recent M icrosof t. VisualC. VS CodeProvider M icrosof t. VisualS tudio. CommandB ars M icrosof t. VisualS tudio. CommandB ars M icrosof t. VisualS tudio. D ebuggerVisualizers M icrosof t. VisualS tudio. Q uality T ools. UnitT estFramework M icrosof t.VisualS tudio. S...

Connecting Event Code

Note that the Button object in Listing 4-8 is checking for the presence of code for the event specified by the enumeration reference. You need to determine which events you plan to support for your controls. Then, create an enumeration hat defines them, as shown in Listing 4-10. Listing 4-10. ControlEvent Enumeration If you find code associated with a particular event, then you can associate it with a common event handler. The code in Listing 4-11 shows how to retrieve the event code and name a...

Pro Dynamic NET 40 Applications

Data-Driven Programming for the .NET Pro Dynamic .NET 4.0 Applications Data-Driven Programming for the .NET Framework All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 pbk 978-1-4302-2519-5 ISBN-13 electronic 978-1-4302-2520-1 Printed and bound...

Mixing Normalized and Inverted Tables

If you wish to employ a traditional normalized database design in your data-driven application, you may certainly do so. In the personnel-management system example, you've likely created a series of data-collection fields for the employee's personal information that you store in a series of normalized tables. Yet you realize that you can't possibly anticipate all the data elements a user may wish to collect. To remedy this, you can create a one-to-many table that stores an unlimited number of...

Understanding the Page Life Cycle

Before you can appreciate how dynamic and static controls work within the framework of a Page object, you must first understand the life cycle of a web page. When users post back a web page, they normally do so via a button or link object. This object may have JavaScript code attached to it which may contain some validation routines. There's no point in even attempting an expensive full-page postback unless the data being posted back is valid. Then, a series of postback events trigger, most of...

System CodeDom Compiler Namespace

The System.CodeDom.Compiler namespace contains all the functionality you need to compile source code dynamically. There are several reasons you may wish to do this. In systems where users can define their own data-entry fields, you may also wish to let them define their own validation logic. You can accomplish this by building a user interface to a rules-based engine that checks for a predetermined number of scenarios. This can be presented as a wizard that prompts the user for, say, a range of...

Repeater Controls

A Repeater control is a data-bound list that repeats a customized template for every row in a data source. A DataGrid control is like a repeater control in that it displays a row of data for each row in its data source. Although you could build the functionality of a grid in a repeater control, it's best to take advantage of its data-driven nature to display a series of edit fields for each row of data. Listing 5-16 shows the basics of a Repeater control. lt form id form1 runat server gt lt div...

Data Driven Menus

Menus have labyrinthine hierarchies that map perfectly to XML. You can store an application's menu structure in XML, much like a sitemap file in ASP.NET. You may wish to build a menu that is fully or partially data-driven to allow add-on features for an application. Suppose you wish to allow your users to write their own assemblies and link this functionality into the application. The assembly may be an entire subsystem that needs to be made an option on the menu. Or, you may wish to let users...

Dynamic WPF

The introduction of Windows Presentation Foundation WPF in the .NET 3.0 Framework presented a major paradigm shift for the development of both desktop and web-based applications. Over the years, the user interface development community has largely split into two camps desktop and web developers. Although the database access and business layer code is the same, the technologies used to develop the interfaces are vastly different, each requiring its own level of expertise. WPF attempts to bridge...

Syncfusions Essential PDF

Syncfusion's Essential PDF www.syncfusion. com is distributed either as an individual tool or bundled with its Essential BackOffice Studio. Unlike iTextSharp, it comes with full documentation and technical support. And, as you'd expect in a licensed product, it has many more features. To display a DataTable dynamically in PDF, you use the PdfLightTable object, which is designed precisely for that purpose. The code shown in Listing 7-16 performs the same task in Essential PDF that the code in...

Instantiating Classes

All managed code in a .NET application is compiled into assemblies, be they EXEs or DLLs. The key difference is that an EXE has an entry point from the operating system and a DLL doesn't. In all other respects, they're the same. You may need to access an assembly's internal structures at runtime, having had no knowledge of the names of the cases, properties, or methods available to you at compile time. Examine the Invoice class shown in Listing 2-1. This class would obviously have no real...

Converting Inverted Data to a Normalized Structure

The first is the structure of the data itself so you can create the DataTable object to receive the normalized data. The second is the inverted data. Because the traditional approach uses one row for every entity here, employee , it makes sense to convert the inverted structure to a normalized structure that can be more easily manipulated. Because you never know what the structure will be at any given point in time, you can't create classes to encapsulate...

Reportviewer Rdl Headertype

One option for creating dynamic SQL Server Reporting Services reports is to use a third-party library called Dynamic Rdl, which you can find on the Web at www.dynamicrdl. com. This tool provides a class wrapper around the RDL object model as described in the previous section. Dynamic Rdl objects are transformed into their XML-based RDL representations automatically, so you don't need to create and validate RDL manually. Suppose you've constructed the following SQL based on user selections...

IText Sharp

ITextSharp is an open source freeware library available at http sourceforge. net projects itextsharp . The tool consists of one .NET assembly called iTextSharp .DLL. You can use iTextSharp to create free-form text documents, multicolumn newsletters, and just about anything else you can think of. The sample code shown in Listing 7-14 illustrates how to export a DataTable to a columnar report. Listing 7-14. Creating a Report Using iTextSharp Document oDocument new Document PdfWriter oPdfWriter...

Instantiating Forms

When you lay out a form in the Visual Studio IDE, the code for the form and all its composite controls is automatically generated and executed in a data-driven fashion. Look at the code behind any form and its associated designer file, and you'll see this to be true. Examine the form in Figure 4-1. Figure 4-1. A very simple data-entry form Here is a simple screen that has a group box with two child controls a Label and a TextBox. In addition, there is a Button owned directly by the form itself....

Soft Artisans Office Writer for Excel

SoftArtisans' www. softartisans.com OfficeWriter for Excel tool produces native Excel files Office 97, 2000, XP, 2003, and 2007 without instantiating Excel. For use on high-request web server environments, OfficeWriter is a lean tool designed specifically to generate Excel and Word documents on a server. There are two versions of this product the Enterprise Edition and the Standard Edition. The application object in the Enterprise product offers an unlimited number of spreadsheets with full...

SQL Server Extended Properties

SQL Server offers a feature called extended propertiesthat you can use to add metadata to your data objects. You can do this visually by right-clicking the object, as shown in Figure 7-1. Select the Extended Properties entry on the left side of the tab, and you see a simple data-entry form where you can name properties and enter values for them in a key value pair relationship. Figure 7-1. Creating extended properties Figure 7-1. Creating extended properties this same task programmatically via...

Syncfusions Essential XlsIO

Syncfusion's www.syncfusion.com Essential XlsIO is written completely in .NET code C and optionally comes with the source code. This product offers PageSetup objects, row height settings, page breaks, document property settings, data validation, conditional formatting, comments, rich text, autofilters, charts, hyperlinks, PivotTables, and images. Essential XlsIO offers everything but macros, but it preserves them if they're present in template spreadsheets. Listing 7-9 shows how to create a...

Namespaces Classes and Fields

Suppose you want to generate a simple abstract class named MyClass, contained within a namespace called CodeDOM, which has one private field called _szCustomerName. The goal is to generate a simple class declaration with one field, like that in Listing 1-9. Listing 1 -9. Generated Code This code was generated by a tool. Runtime Version 2.0.50727.1433 Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. lt auto-generated gt Name of the customer private...

Dynamic Win Forms

In this chapter, you look at how to create data-driven WinForms applications. This chapter is longer than those for web and WPF applications because most of the principles of data-driven development are the same for all three, and these principles are covered in detail here. You learn how to dynamically instantiate forms and controls, wire events, and link them to runtime compiled code to validate the input. Then, you examine a number of practical examples of how data-driven WinForms...

Using RDL

Simply generating a report showing last name and first name requires some 483 line of RDL. Listing 7-23 shows a small segment of the RDL for this report. lt TableRow gt lt TableCells gt lt TableCell gt lt ReportItems gt lt Textbox Name LastName_Header gt lt Value gt Last Name lt Value gt lt CanGrow gt true lt CanGrow gt lt UserSort gt lt UserSort gt lt Style gt lt BorderColor gt lt BorderStyle gt lt Default gt Solid lt Default gt lt BorderStyle gt lt Language gt en-US...

Dynamic Crystal Reports

Viewer Crystall Report 2008 Net

There are two ways to create Crystal reports dynamically using preset columns and using the Crystal SDK. Both have their advantages and disadvantages, which you learn in the sections that follow. Using preset columns is the easier way to create a data-driven Crystal report. It's also cruder. By creating a report file and binding it to a typed DataSet with, say, ten columns, you can bind up to ten selected data elements chosen by the user. You need to create ten parameter fields as well to serve...