öþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþpment Environment Overview
Order entry systems are the most commonly requested database applications for businesses. In this chapter we will look at building one as a Web site. Using the advanced database connectivity features of Microsoft Internet Information Server 3.0 and Visual InterDev, building an online order entry system is a snap.
Web site development with Visual InterDev requires software on both client and server. On the client side you have the Visual InterDev development environment, while on the server side you have the Visual InterDev server extensions (also required are the other server applications, such as Internet Information Server 3.0 running the FrontPage Server Extensions and Active Server Pages). Both client and server sides of Visual InterDev work together to help organize your Web sites. The server side of Visual InterDev is transparent to the developer and requires no maintenance, so from here on, when we use the name "InterDev" we are referring to the Visual InterDev development environment, unless otherwise noted.
InterDev itself runs on the Microsoft Developer Studio 97 (version 5.0 of Developer Studio) environment. This development environment is also used with other Microsoft Visual tools, including Visual Basic, Visual C++, and Visual J++.
Another tool that ships with InterDev is the Visual Database Tools. The Visual Database Tools are seamlessly integrated into InterDev, so you have a single workspace for building complex Web sites as well as database applications, and more importantly, you can easily integrate these two technologies together, thus building either data-driven Web sites or database applications using standard Internet protocols.
InterDev organizes your Web sites and databases by means of projects and workspaces. A project is simply an individual database or Web site. A workspace is InterDev's method of storing multiple projects together, such as a Web site and database.
When you create a new Web site project in InterDev, you have the option of adding to an existing workspace or creating a new one. If you choose to create a new one, InterDev will create a directory on both the server and your local InterDev workstation with the same name as your project. On the local workstation this directory will be a subdirectory of \DevStudio\MyProjects.
On the server it will be a subdirectory of your \inetsvr\wwwroot directory. On the server it will also create a virtual directory using the name of the project and will point that directory to the new \inetsvr\wwwroot\myprojectname subdirectory (where myprojectname is the name of your project). Within this directory on the server, it will also create an \images subdirectory as a default to store the sites images. On the client workstation, it will duplicate the server directory structure and use it when bringing local copies of the files down for editing.
Workspace information is stored in a .DSW (Developer Studio Workspace) file within a project directory on the client side. The project directory used will be the one that was created at the time the workspace was created. If you create an empty workspace (using the Blank Workspace Wizard) with no projects in it, you'll still be asked for a name, and this name will be used to create a subdirectory in the \DevStudio\MyProjects subdirectory.
Within a workspace you can create multiple projects. This does present a slight
dilemma in that you can delete projects from a workspace. If you delete a workspace's
original project, the project directory will remain there, since it still has a workspace
(.DSW) file in it.
CAUTION:
Be aware that if you delete a workspace's original project, that project's directory will not be deleted from the \DevStudio\MyProjects directory.
Project information is stored in a .DSP (Developer Studio Project) file within the project's directory. You can create both Web site and database projects. Just as a Web site project points to a single Web site, a database project points to a single database. If you need to work on more than one Web site or database concurrently, you can add multiple projects to a workspace. You can add database projects to your workspace by either using the New Database Project wizard or by simply adding a data connection to your Web site using the Data Connection Wizard.
As you load a Web page into the Visual InterDev developer environment for editing, a copy of the page is made locally. Then, as you make changes to this page, you are working with a local copy. Whenever you save any changes, InterDev detects this and updates the server's copy.
The advantage of this is that because the page is copied locally, you can then edit it with the editor of your choice. For example, you may want to use Adobe Photoshop to edit images, instead of Microsoft Composer. After setting up Photoshop as a content editor for images, you can then double-click the image to open it, InterDev will copy it locally, and then Photoshop can work with the image. As you save it from Photoshop, InterDev will detect the save and update the copy of the image on the server.
The development process falls into the following three parts:
When the last two steps are finished, your Web site will be finished, because
you're working directly with your live Web site.
Create a Workspace with Projects
If you run the Insert Data Connection Wizard to create a database project, it
will create a GLOBAL.ASA file specifying the database connection for the site. The advantages of the Visual InterDev architecture include the following:
As mentioned earlier, Visual InterDev is built within the Developer Studio 97
(DevStudio) environment. Developer Studio is now in its fifth iteration, having been
used for many years with Microsoft's Visual C++. It offers advanced editing tools,
organizational features, and documentation support. Figure 5.1 illustrates the main
features of the DevStudio environment. As with most Microsoft Windows 97 programs, the menus are fully customizable and
located on floating toolbars. The main workspace is split between the different docked
and document windows. Docked windows, as the name implies, are usually docked to
a border of the application. The docked windows of Visual InterDev include the Project
window and the Output window for debugging. Document windows are loaded as needed
for editing a particular type of content or database object. You make a docked window
a floating window by dragging off the border its currently docked to.
Docking Windows TIP: To convert a docked window to a floating window, double-click its
title bar.
TIP: You can customize the Project window by right-clicking any of the
tabs.
Author the Content
Program Scripts and ComponentsAdvantages of the Visual InterDev Architecture
The Developer Studio Integrated Development Environment
FIG. 5.1
The main components of the Developer Studio 97 environment.
Windows and Toolbars
Document Windows
FIG. 5.2
Visual InterDev supports in-place activation via OLE 2.
A few of the document editors Visual InterDev has built in are as follows:
The Dockable Windows used by Visual InterDev include the following:
Menus and Toolbars
Developer Studio's default configuration displays the Standard toolbar just below the menu bar. Other toolbars appear automatically as you open different editors. Based on your workspace preferences and the size of your screen, you can display as many toolbars as necessary or none at all. You can resize a toolbar, add a menu to it, enlarge its buttons, or move it to a different location.
The menu bar acts as a normal toolbar with a few exceptions: it always fills a complete row when docked horizontally, and you cannot hide it unless you are in full-screen mode. If you do hide it while in full-screen mode, you still have access to the menus by using keyboard shortcuts.
By double-clicking a document or database object in the project workspace, an
editor is automatically loaded. There are two main types of editors: content editors
and object editors. Content editors are typically code editors or WYSIWIG editors,
while with object editors you are typically filling out properties in a dialog box.
Content Editors
FIG. 5.3
The FrontPage Editor allows WYSIWIG editing of HTML documents.
CAUTION:
Open only .HTM files with the FrontPage Editor for Visual InterDev editor. If you use it to open .ALX, .ASA, or .ASP files, you may damage them.
You can see the organization of your site in the Project workspace window of Visual InterDev. It offers a hierarchical view of Web sites, databases, and online documentation. This "explorer" view lets you create, delete, and edit most objects in a Web site or database. The Project workspace has the following three views:
File View
When you load a document for editing, Visual InterDev copies the file from the
server to your local development workstation's \DevStudio\MyProjects\ProjectName
subdirectory. You now have what is called a working copy. If a document's
icon is ghosted, it means you don't have working copy of it (see Figure 5.5).
There are many commands and options available from the pop-up menu when you right-click
in the File View window.
FIG. 5.6
FIG. 5.5
Notice the documents that we have working copies of are not ghosted.
Data View
This workspace has two database connections: one to an Access .DBF file, and one
to a SQL Server database.
NOTE: Microsoft Visual Data Tools are also available in Microsoft Visual C++ 5.0 Enterprise Edition, and as an add-in for Microsoft Visual Basic 5.0 Enterprise Edition.
A key aspect to Visual InterDev environment is the Visual Database Tools component. It allows you to create, edit, and administer any ODBC (Open Database Connectivity) compatible database. Currently ODBC features work with all leading database management systems on the market, including SQL Server, Access, FoxPro, Oracle, Sybase, Informix, IBM DB2, Borland dBASE, and others. The Visual Database Tools are integrated right into the InterDev environment, facilitating the creation of fully dynamic, database-driven Web sites.
A Data view in the project workspace displays all the objects related to any database
project or data connection assigned to your workspace (see Figure 5.8).
FIG. 5.8
The Data view organizes all of your database objects in a hierarchical view.
By using VBScript and JavaScript development you can easily develop powerful database
Web applications. Many of the design-time controls and wizards that ship with InterDev
will generate most of this code for you. For connectivity, you can use the Microsoft
Active Data Objects (ADO), Microsoft Advanced Data Connector (ADC), or any of the
many existing HTML-ODBC connectivity products currently on the market. Within Visual
InterDev, you can connect to multiple databases and pull data from multiple sources
into a single Web page.
Another impressive capability of the Visual Database Tools is that InterDev performs almost every action via SQL (Script Query Language), and you always have the option of viewing or altering this code before letting InterDev execute it. Listing 5.1 shows a sample SQL script generated automatically by simply adding, deleting, and editing fields as well as setting up a few constraints. True, you could write all of this by hand, but why bother when it's so easy with Visual InterDev!
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.sales
DROP CONSTRAINT FK__sales__title_id__1BA8264C
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.sales
DROP CONSTRAINT FK__sales__stor_id__1AB40213
GO
COMMIT
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_sales
(
stor_id char(4) NOT NULL,
ord_num varchar(20) NOT NULL,
ord_date datetime NOT NULL,
payterms varchar(12) NOT NULL,
title_id tid NOT NULL,
New_Field char(20) NULL
) ON "default"
GO
12345678901234567890123456789012345678901234567890123456789012345678
IF EXISTS(SELECT * FROM dbo.sales)
EXEC('INSERT INTO dbo.Tmp_sales(stor_id, ord_num, ord_date,payterms, title_id)
SELECT stor_id, ord_num, ord_date, payterms, title_id FROM dbo.sales TABLOCKX')
GO
DROP TABLE dbo.sales
GO
EXECUTE sp_rename 'dbo.Tmp_sales', 'sales'
GO
ALTER TABLE dbo.sales ADD CONSTRAINT
titleidind UNIQUE NONCLUSTERED
(
title_id
) ON "default"
GO
ALTER TABLE dbo.sales ADD CONSTRAINT
UPKCL_sales PRIMARY KEY CLUSTERED
(
stor_id,
ord_num,
title_id
) ON "default"
GO
ALTER TABLE dbo.sales ADD CONSTRAINT
CK_sales CHECK ((New_Field <> 'Bad Data'))
GO
ALTER TABLE dbo.sales ADD CONSTRAINT
FK__sales__stor_id__1AB40213 FOREIGN KEY
(
stor_id
) REFERENCES dbo.stores
(
stor_id
)
GO
ALTER TABLE dbo.sales WITH NOCHECK ADD CONSTRAINT
FK__sales__title_id__1BA8264C FOREIGN KEY
(
title_id
) REFERENCES dbo.titles
(
title_id
)
GO
GRANT REFERENCES ON dbo.sales TO guest
GRANT SELECT ON dbo.sales TO guest
GRANT INSERT ON dbo.sales TO guest
GRANT DELETE ON dbo.sales TO guest
GRANT UPDATE ON dbo.sales TO guest
COMMIT
The Query Designer is an advanced visual SQL query tool for creating Select,
Delete, Update, and Insert queries. You can type straight SQL code into the Query
Designer, or let InterDev generate it for you by dragging and dropping tables and
fields (see Figure 5.9).
FIG. 5.9
The Query Designer offers simple drag-and-drop query editing.
The Database Designer offers a visual way to create entity relationships between
tables in Microsoft SQL Server databases. It allows you easily to set up triggers,
constraints, foreign keys, and much more (see Figure 5.10).
FIG. 5.10
Within the Database Designer, you can set up relationships and table properties.
You can create new database tables and views from scratch within InterDev. For
table creation you can simply right-click the Tables folder and choose New
Table. After choosing a name, you'll be able to create fields for the new table (see
Figure 5.11).
FIG. 5.11
Here we have clicked the Save Change Script button in the toolbar during the creation
of a new table.
Visual Database Tool supports both Oracle and Microsoft SQL Server stored procedures
(see Figure 5.12). As with tables, you can create a new stored procedure by right-clicking
the Stored Procedure folder and choosing New Stored Procedure.
FIG. 5.12
You can view a stored procedure's variables by opening it in the Data View window.
You can create triggers in your database by means of the Insert,
New Database Item menu option. Figure 5.13 shows a new trigger being
created and the dialog box that appears after choosing Insert New Database Item.
FIG. 5.13
Notice that in the New Database Item dialog box, you can create new items in any
database you currently have access to.
As you have seen, the Developer Studio is a very flexible environment. However, you can customize it even further by altering its menus, toolbars, and keystrokes. You can organize commands the way you want them, so you can find and use them quickly. You can add and remove menus and buttons, change the image or text for a button, and even create your own custom menus. Previous versions of Developer Studio allowed only buttons on toolbars, but with Developer Studio 97 toolbars can contain menus and buttons.
You will often have a header you would like included on every page of your site. This might be HTML code or it might simply be copyright notices placed in comment tags within the HTML. The Server-Side Include (SSI) #INCLUDE directive is a simple way to do this. It will insert the contents of other files at the location of the directive. The line of code would read:
<!-- #INCLUDE FILE="Header.inc" -->
Because this will need to be inserted on every page, we are going to make a macro to accomplish this, and then assign that macro to a button on the toolbar and a keystroke sequence. Developer Studio supports VBA (Visual Basic for Applications) just as Microsoft Office does. Applications that support VBA expose all of the internal objects, methods, and properties, so that you can automate virtually any task by writing a simple Visual Basic program. The latest buzzword for this is Automation (OLE Automation). We'll take a shortcut and use Developer Studio's macro recordinöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþöþL>
FIG. 5.14
Recording a macro is the easiest way to get started with VBA programming.
TIP: To figure out quickly the VBA syntax for a particular command for a function in InterDev, use the Macro Record command and then go back and edit the resulting VBA code later.
FIG. 5.15
While recording a macro, Stop and Pause buttons appear on the screen.
'------------------------------------------------------------------------------
'FILE DESCRIPTION: New Macro File
'------------------------------------------------------------------------------
Sub InsertHeader()
'DESCRIPTION: Insert the include directive
'Begin Recording
ActiveDocument.Selection = "<!-- #INCLUDE FILE=""Header.inc""
-->"
ActiveDocument.Selection.NewLine
'End Recording
End Sub
To test this macro, choose Tools, Macro to display
the Macro dialog box and double-click the InsertHeader macro to run it.
Our next step is to assign this macro to a keystroke and a button on the toolbar. To create a button on the toolbar for this macro, take the following steps:
FIG. 5.17
The Button Appearance dialog box allows you to assign an icon to your custom toolbar
command.
Now you'll see a new button on the standard InterDev toolbar (see Figure 5.18). You
can test it by clicking it while the cursor is in a source code window.
FIG. 5.18
Notice the new button at the right edge of the Standard toolbar.
It's a simple process to assign the same macro to a shortcut key. Choose Tools,
Customize again, but this time click the Keyboard tab. In the Customize
dialog box, choose Macros as the Category, and press Ctrl+Shift+H. You should see
that this shortcut key is unassigned. Now just click Assign and it will be assigned
to the macro (see Figure 5.19). Finally, click Close to close the Customize dialog
box.
FIG. 5.19
When assigning a macro to a shortcut key, make sure you watch the Currently Assigned
To: setting to make sure you don't overwrite an important shortcut key.
You can test the new shortcut key by pressing it while in a Visual InterDev Source
Editor.
In this chapter, we've covered the Visual InterDev integrated development environment, explained it's architecture, outlined the development process, and demonstrated ways of customizing it to suit your needs. For further information on these topics, see the following chapters: