|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Techniques PowerBuilder Web Reporting From Scratch in Minutes
Using DataWindow.NET and Visual Studio
By: Berndt Hamboeck
Jan. 26, 2006 06:45 PM
A week ago one of my customers asked me to do a presentation on Sybase DataWindow.NET. We discussed what they would like to see (besides all the standard stuff all PowerBuilder shops want to see, such as a Master/Detail DataWindow in a client/server environment and, in a second step, these DataWindows within a browser), and they asked me to talk a little bit about distributing such a Web application in a production environment.
The Idea
The Implementation
We don't need to talk about the helper pages since how to create a common look and feel is completely up to you or your company, so let's take a look at the page where users are able to upload a library. The requirements for an HTML form to be able to upload files are very simple (see the full source code in Listing 1), as we have to use a form with a multipart/form-data encryption: <form id="Form1" enctype="multipart/form-data" runat="server"> The HTML input control that is used to upload the file has a simple type of file: <input id="uplTheFile" type="file" runat="server" style="width: 300px"/> This is all that needs to be done to the HTML form for a client to be able to submit a file to an ASP.NET application. The more interesting part is receiving the file on the server side, which is done in the server-side script for the upload button. The line: uplTheFile.PostedFile.SaveAs(strFullFileOnServer); saves the file on the physical directory on the server. I decided to use a directory within my virtual Web directory, called PBL, so that all the libraries can be found in one place by the administrator. The second page needs to read all the available (uploaded) PowerBuilder libraries from the PBL directory. As you can see in Listing 2, I used a GridView component that I have bound to a DirectoryInfo object (see Listing 3) that holds all the available files. Again, nothing really spectacular here. Let's have a look at the page that reads the contents of the library. Once again I used a GridView (see Listing 4) that I have bound to an array of DataWindowObjectEntry objects. This class is provided by DataWindow.NET and is part of the utility classes. Just one line is needed to get all the existing DataWindow objects from a physical file on your Web server (for the full server-side code, look at Listing 5).
DataWindowObjectEntry[] dwEntries = Now we have just two more pages to go. Let's start with the easier of these two, the page that includes just a StreamImageContainer. As a PowerBuilder developer you know that we have DataWindows displaying data in text format or in a graphical format. Within a browser these graph DataWindows can be displayed as a standalone image file or in an image stream embedded into the Web page. The disadvantage in using an image file is that the file is stored on the Web server and needs to be removed somehow (it will not be removed automatically), the StreamImageContainer does not have this drawback, but it needs more memory on the server side to serve the image to the client. Simply create a new page to put a StreamImageContainer object on and save it (see Listing 6). Our last step will be to create the heart of our application, the page where the report is displayed (and the page containing the StreamImageContainer might be used) (see Listing 7). I placed the following objects on this page:
If you prefer to get real physical images, use ImageFile, so the rendering of the graph object is saved into a file on the Web server and an image URL is generated automatically to a reference of this image file within the page. Also the physical directory in which the temporary image file is stored and the URL path need to be specified in the GraphDynamicImageFileUrlPath property. This property must specify a URL path in the Web application virtual directory (I used the images directory). The last step is to choose how to render the graph (the file format). To select the image format, set the ImageFormat property to GIF, JPEG, or PNG. The default image format is PNG, which provides superior rendering and a smaller footprint than JPEG, whereas GIF is the way to go to reduce the footprint to a minimum (of course, at the cost of some loss of quality). We also want our users to be able to export the WebDataWindow's content to a PDF file on the server and then stream the result to the browser. This can easily be done by using the SaveAs function on the server side (after installing the GNU AFPL Ghostscript driver on the Web server) - you'll find the complete source code in Listing 8: dwReport.SaveAs(pdfFileName, Sybase.DataWindow.FileSaveAsType.Pdf); ASP.NET pages are inherently stateless, which means that when we come back to the server to save the WebDataWindow's content as a PDF, we need to get the current state of the data visible to the user. This can easily be done by setting the following properties to true:
This small project was created for demo purposes and lacks some functionality, which can be built in easily, and some points that you might build in to bring it in into a production-ready state:
DataWindow.NET and Visual Studio are a good combination when it comes to development on the Windows platform. For PowerBuilder developers it's easy to start development after learning the basics about the .NET Framework. EAServer developers will miss a well-defined component model, but will be happy to see that the original HTML DataWindow has made it into the .NET world and will not have any problems with the client event model. In my simple example I showed (as you have seen all of these pages can be written within a few minutes) that we now have a foot in the Microsoft world, and we, as a PowerBuilder community, are no longer limited to the Java and PowerBuilder world anymore. Sybase DataWindow.NET brings us closer to the world of Microsoft. I wish you happy coding with Sybase DataWindow.NET. Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||