devxlogo

Sybase DataWindow .NET 2.0—Easy, Powerful, and Flexible

Sybase DataWindow .NET 2.0—Easy, Powerful, and Flexible

ybase recently released DataWindow .NET 2.0, a powerful object used to build data-driven .NET applications. The DataWindow offers nearly identical capabilities for both Windows Forms and Web (ASP.NET) Forms, and it’s versatile and easy to use, suitable for reporting, graphs, tree views or data entry. You can create multi-user data entry forms with only four lines of code (excluding standard try-catch blocks). Sybase’s DataWindow technology, used by client-server developers since the early 1990’s, integrates well into the Visual Studio environment.

Installation
DataWindow .NET 2.0 works with the full release version of Visual Studio 2005. Installation did not work with the Visual Studio 2005 beta or with the C# Express Edition. I tested the installation and development on both Windows XP Professional and Windows XP Home Editions.

Installation is simple and straightforward. Sybase uses InstallShield to guide users through the installation. There are several installation options (see Figure 1). Of those, you must install DataWindow .NET and the DataWindow Designer. The DataWindow .NET option installs the DataWindow components into Visual Studio’s toolbox. DataWindow Designer is the tool for designing reports, graphs and data entry forms. I recommend installing the DataWindow Reference for additional help files and examples. Installing Adaptive Server Anywhere (ASA) is optional; selecting it installs Sybase’s ASA database. However, new users should strongly consider this option, because ASA is required to view the DataWindow samples.

?
Figure 1. Installation Options: You must install the DataWindow .NET and DataWindow Designer options. The Reference is useful and the Adaptive Server Anywhere option is required for viewing the DataWindow samples.
?
Figure 2. Windows Forms Toolbox Additions: The figure shows the new Sybase DataWindow 2.0 category and sub-items created by installing the DataWindow.
?
Figure 3. Web Forms Toolbox Additions: The figure shows the new Sybase DataWindow 2.0 category and sub-items created by installing the DataWindow.

After you complete the installation, Visual Studio’s Toolbox will display a new category labeled “Sybase DataWindow 2.0.” Figure 2 shows the Toolbox addition as it appears in a Windows Forms project, while Figure 3 shows the addition as it appears in an ASP.NET project. The Web Form Toolbox installation appears to have a slight error. The Transaction component was not present on the toolbox, so I had to manually create and code the Transaction object for Web-based applications.

Overview of Building a DataWindow Application
You build Windows Form and Web-based applications the same way, using the following steps:

  • Create a DataWindow library using the data designer. The library holds all reports, graphs, labels, and data entry forms. During development, you save the library as a .PBL file, but you can (and should) compile the library to a .PBD file for distribution with your application.
  • ?
    Figure 4. Transaction Properties: The figure shows the Properties pane for the Transaction object.
  • Use the data designer to build reports, graphs, labels, and data entry forms. The objects you create using the data designer are referred to as DataWindow objects.
  • Use Visual Studio to add a Transactions object to your form (either Windows or Web Form). The Transaction object, added as a hidden control, contains data connection properties.
  • Use Visual Studio to add a DataWindow control to the form. Use the VS toolbox to add the visible control to you form. The DataWindowControl is a visual data driven control comparable to the data grid, but with many additional features.
  • Set the properties for the Transaction object (see Figure 4).
  • Set the DBParameter property to connect to your database. Figure 4 shows the connection string for SQL Server when using integrated security.
  • Set the Dbms property.
  • Set the properties for the DataWindow control (see Figure 5).
  • Set the library list to your .PBL or .PBD library.
  • Set the DataWindowObject property to the object you created using the data designer.
?
Figure 5. DataWindow Properties: Here are some of the property settings for the DataWindow control used in the sample application.

Add the lines in your program to retrieve the data:

      transaction1.Connect();   dataWindowControl1.SetTransaction(transaction1);   dataWindowControl1.Retrieve();

The first line connects to the database. This command should be issued only once in the entire application.

Using the DataWindow Designer 2.0
You use the data designer to build reports, graphs and data entry forms. The creation process is quick and simple. The designer performs very fast?perhaps no faster than prior releases, but it feels more responsive. Although Sybase does not refer to the Designer interface as a Wizard, most of the process feels like a Wizard.

The designer uses a three-step process for creating a DataWindow object, and walks you through the process.

First, you select the type of DataWindow object you want to create (see Figure 6). Then it prompts you to select the data source (see Figure 7). This new designer version supports ADO Datasets as a data source. Finally, you create the SQL for data retrieval (see Figure 8), using a “query painter,” which provides a visual interface including drag-and-drop table and column selections as well as the sort command (ORDER BY clause).

?
Figure 6. DataWindow Object Types. To create a DataWindow object, first select the type of object you want to create from this dialog.
?
Figure 7. Selecting a Data Source: During the second step to build a DataWindow object, you select a data source from a set of possible choices.
?
Figure 8. Query Painter: The DataWindow Designer includes a query painter, that lets you drag and drop database tables and columns from a selected data source.

You can add calculation columns or even manually enter the entire SQL string exactly as you want it. The Wizard-like three-step process makes it easy to create the basic layout for your forms, after which the designer takes on a typical multi-pane interface (see Figure 9). After selecting the object type, the table(s), and the column(s), you have a basic form allowing unlimited customization.

The designer truly shines with customization capabilities. The three major panes let you control the look-and-feel by sliding columns and labels, then setting appropriate properties. You can see real-time changes to the presentation in a preview area.

?
Figure 9. Multi-pane Interface: After using a Wizard-like interface that aids in specifying an object type, data source, and query, the DataWindow Designer switches to a familiar multi-pane interface for designing data-input forms and reports visually.

One of the designer’s strongest features is the ability to create both reports and data entry screens using the same banded-style designer. Developers can set a few simple options to create multi-user aware SQL based data entry forms. Configuring these options in the DataWindow object eliminates the need for programming INSERT, UPDATE, and DELETE SQL statements. Whether generating a report or data entry form, the DataWindow provides WYSIWYG output using one line of programming code:

   // print the contents of the DataWindow    // without prompting   dataWindowControl1.Print()       // show the Windows print dialog before printing   dataWindowControl1.PrintDialog() 

The next step is to launch Visual Studio and integrate the reports into your applications.

Author’s Note: The data designer is very similar to the designer used in PowerBuilder. PowerBuilder users will find little if any transition required to build reports using the designer. Non-PowerBuilder users will find the interface intuitive and powerful.

Using DataWindows for Windows Forms
The process to integrate the DataWindow into your .NET application is very simple. Once you understand a few of the key properties of the Transaction object and the DataWindow control, using them is just as simple as using .NET’s native controls.

As stated in the overview, the first step is to connect to the database by adding a non-visual transaction object from the toolbox. You can then drag a DataWindowControl from the toolbox to the form. Figure 10 shows the control prior to setting any properties. Setting two properties provides a link to the DataWindow object you created via the DataWindow designer. Setting the LibraryList and DataWindowObject properties immediately shows a sample outline from your data source, but does not show actual data (see Figure 11). The immediate view provides a nice way to lay out your data and forms.

?
Figure 10. An Empty DataWindow Control: Here’s how a DataWindow control looks at runtime before you set any of its properties.
?
Figure 11. Immediate View: Although the immediate view doesn’t display actual data, it does provide a convenient way to lay out controls on your forms.

As discussed earlier, the following three lines of code allowed the form to connect to the database and retrieve data:

   transaction1.Connect();   dataWindowControl1.SetTransaction(transaction1);   dataWindowControl1.Retrieve();

To save data back to the database requires two additional lines of code:

   dataWindowControl1.UpdateData(true);   transaction1.Commit();

The properties and events available for the DataWindow control are expansive. Figure 12 shows the final window running in a Windows Forms application. One nice feature is the drop-down calendar for dates. You configure this component by setting a DataWindow property in the designer. The drop-down calendar works in both Windows Forms and Web Forms applications.

?
Figure 12. Live DataWindow: The figure shows a configured DataWindow at runtime, with live data. Developers can add features such as the drop-down calendar with no coding, by simply setting DataWindow properties.
?
Figure 13. A TreeView Report: This Windows Forms-only report type provides an expandable hierarchical tree view of the report data.

A new DataWindow type available for Windows forms only is a Treeview report. Using the same Wizard-like interface to select the report type (TreeView), data source and query simplifies creating complex data-driven tree views (see Figure 13). The only coding required is the few lines to retrieve the data.

Using DataWindows for Web Forms
One of the nicest features is the simplicity of creating one object that’s usable in both Windows and Web applications. The programming code shown for the Windows form earlier is the same as that used for Web Forms. Figure 14 shows the form from the Windows sample application in Figure 12 running as a Web Form. There is a price to pay. The Web Form HTML is rather large because it achieves much of its functionality via javascript generated by the DataWindow control. A simple form generates roughly 100K of HTML and JavaScript, so your forms will not be the lightest if you use all the default properties for the DataWindow control. The DataWindow control now provides several properties that control and eliminate unnecessary JavaScript if you don’t use certain DataWindow features. See the documentation for more information about these properties.

?
Figure 14. A Web Forms Version: Here’s a screenshot of the Web Forms version of the sample application running from the same data input form initially designed for the Windows version.

Despite the effort Sybase has put into the Web version of the DataWindow, there are still more differences between the Windows and Web versions in addition to the tree view type mentioned earlier, which isn’t available in the Web version.

One disappointment was that I had to manually code a Transaction object to use it in an ASP.NET application because the control wasn’t available in the Web Toolbox. Fortunately, this appears to be nothing more than an error in the install, and you can add the control in code. Here’s the code I used to overcome the missing Transaction object:

   Sybase.DataWindow.Transaction SQLCA =       new Sybase.DataWindow.Transaction();   transaction1.Dbms = Sybase.DataWindow.DbmsType.Odbc;   transaction1.AutoCommit = false;   transaction1.DbParameter =       "ConnectString='DSN=mySQLServer;UID=;PWD=', " +      "ConnectOption='SQL_INTEGRATED_SECURITY," +       "SQL_IS_ON'";
Author’s Note: The control provides additional DHTML and stylesheet properties for maximum control of the output.

Sybase’s latest upgrade of the DataWindow product is flexible, powerful, easy-to-use and performs very well. The product acts and feels more polished than the initial 1.0 release. The Web Forms capability works well, but imposes a size overhead penalty. DataWindow .NET 2.0 would be a nice addition for anyone developing data-centric applications. The DataWindow object provides one interface for designing reports, nested reports, graphics, labels, and data entry forms?and for the most part, these objects work in both Windows and Web Forms.

DataWindow .NET 2.0 provides a logical migration path for PowerBuilder developers moving to .NET. Developers familiar with PowerBuilder 7.0 or later will immediately recognize the DataWindow designer. The majority of the functions and methods are similar to PowerBuilder, albeit with minor changes to some of the language elements. Still, PowerBuilder developers will find DataWindow .NET 2.0 a fast and easy transition for developing data-driven MDI applications in .NET.

It’s worth noting that since version 1.0 of the DataWindow appeared, Microsoft has closed the gap considerably with regards to designing and implementing grid-based forms. The latest release of Visual Studio 2005 simplifies creating grid-based forms while minimizing programming. Sybase’s DataWindow .NET 2.0 still adds value for those developing data-centric applications.

devx-admin

Share the Post: