Windows WF is the programming model, engine, and toolset for quickly building workflow-enabled applications on Windows. It consists of .NET classes, an in-process workflow engine, and designers for Visual Studio. IBM Database Add-ins for Visual Studio workflow control allows users to easily create Windows workflow applications without knowledge of workflow or deep knowledge of IBM databases. In this article, you'll walk you through the process of creating your own workflow application to access relational data in an IBM database.
In order to create WF applications using IBM's workflow component, you will need the following:
- Visual Studio 2008 Professional Edition installed
- IBM database Add-ins for Visual Studio Version 9.5 FP2 installed
- IBM database Client 9.5 FP2 installed
- Access to a DB2 or Informix database
You should have general familiarity with the IBM Database Add-ins for Visual Studio. To become more familiar with the general features of the IBM Database Add-ins for Visual Studio, read the "Overview of IBM Database Add-ins for Visual Studio 2005" and the Develop proof-of-concepts .NET applications tutorial series.
New users to Windows WF concepts and .NET Framework 3.0 can get acquainted to the this new technology by following these useful articles:
- "Windows Workflow Foundation on Microsoft .NET Framework"
- "Windows Workflow Foundation on MSDN .NET Framework Developer Center"
Use IBMDatabaseActivity component in a sequential workflow
Sequential workflow is a flow of events that run in a specific order. This means that each event occurs after another certain event has taken place. Now look at a simple example to illustrate a sequential workflow.
Assume that a customer places an order that needs to be shipped. This order can be processed after checking the inventory. This order receipt, verifying inventory to process the order and then shipping the order, is one of the simplest workflows. In real life, the workflow may include complex conditions as defined in if blocks. Events need to happen based on the outcome of the conditions defined in the if block. If the product in stock is less than the quantity ordered, the product needs to be reordered. Otherwise, the order can be processed and inventory updated.
The following steps illustrate a simple example for beginners and provide an introduction to the Windows workflow console application. You can create more complex applications after becoming familiar with this technology.
- Launch Visual Studio 2008 and create a connection to the database.
Select Add Connection from the Server Explorer pop-up menu,
which will launch the Add Connection dialog, as shown in Figure 1.
Figure 1. Add Connection
- In the Data Source field, select IBM DB2, IDS and U2 Servers (IBM
DB2, IDS, and U2 Data Provider for .NET Framework), and
provide a server name, user ID, and password. Click Test
Connection to verify whether the connection has been made
successfully. Click OK.
Figure 2. Add Connection
- To create a workflow console application, from the main menu, select
File > New Project. In the New Project window,
expand the Visual C# node, then select Workflow. There
are different workflow type applications. However, for this example
create a state machine application by selecting the Sequential
Workflow Console Application and naming it
OrderWorkflow. Then click OK.
Figure 3. Create the Sequential Workflow Console Application
This creates a new Sequential Workflow Console Application project.
Figure 4. New Sequential Workflow Console Application project
- Drag and drop the IBMDatabase component from the Toolbox to the
designer to start creating the workflow application.
Figure 5. Adding the IBMDatabase component
Note: If you can't see Workflow1.cs[Design] or IBMDatabase is not being shown with the steps here, check the prerequisites again. It is possible that some of the prerequisites are missing.
- Select ibmDatabase1 on the designer and rename it to
IBMCheckInventory, using the property window.
Figure 6. Setting properties for the IBMDatabase component
- Add an IfElseActivity and two more IBMDatabase activities into each
IfElse branch, rename these to IBMOrderStock and
IBMProcessCustomerOrder. Finally, add one more IBMDatabase
activity after IfElseActivity and name it IBMUpdateInventory.
Figure 7. Adding conditions to the project
- To configure these activities (IBMCheckInventory, IBMOrderStock,
IBMProcessCustomerOrder, and IBMUpdateInventory), select each
activity, go to the Properties page, and set properties as illustrated here.
For IBMCheckInventory, set CommandText to include the SQL (for example, select stockonhand from stocks), set CommandType to Text, ConnectString should include the connection information (this information is also available from the Advanced Properties dialog. Select the Modify Connection pop-up menu on the connection in Server Explorer, and click Advanced to launch the Advanced Properties dialog). Select the Source Table to get the data. Under Events properties, set the CommandExecuted property to include the method name.
Figure 8. Setting properties for IBMCheckInventory
- Click IBMOrderStock, IBMProcessCustomerOrder, and
IBMUpdateInventory and update the properties as you did for
IBMCheckInventory.
Figure 9. Setting properties for IBMOrderStock
Figure 10. Setting properties for IBMProcessCustomerOrder
Figure 11. Setting properties for IBMUpdateInventory
- In the Workflow1.cs class, add these private variables:
private int _stockcounter; private int _ordercounter;
Figure 12. Adding variables
- In design view, click the IBMCheckInventory activity, and in
the Properties window, type CheckInv in the CommandExecuted field:
Figure 13. Set property name -- IBMCheckInventory
- This will take you to the Code View window. There, add the code
snippet below:
private void CheckInv (object sender, EventArgs e) { Console.WriteLine("Cheking Inventory..."); _stockcounter = (int) this.IBMCheckInventory.DataSet.Tables[0].Rows[0]["stockonhand"]; Console.WriteLine("Stock on hand: " + _stockcounter.ToStrig()); Console.ReadLine(); }
Figure 14. Adding code
- Go back to the Design View, and click ifElseBranchActivity1. In
the Properties window, click the Condition row and select
Declarative Rule Condition. Expand the row and set the
condition name as LessThan. Click Expression, and in the
Rule Condition Editor window, enter the following code:
this._stockcounter < 1
- Do the same for the other branch and name it GreaterThan and
give the expression:
this._stockcounter >= 1
- In Design View, click IBMOrderStock, and in Properties window,
type OrderStock in the CommandExecuted field:
Figure 15. Set the property name -- IBMOrderStock
- This takes you to the Code View window. There, add the code snippet below:
private void CheckInv (object sender, EventArgs e) { Console.WriteLine("Out of stock. Item reordered..."); } - In Design View, click IBMProcessCustomerOrder and in Properties
window, type ProcessCustomerOrder in the CommandExecuted field:
Figure 16. Set the property name -- IBMProcessCustomerOrder
- This takes you to the Code View window. There, add the code snippet
below:
private void ProcessCustomerOrder (object sender, EventArgs e) { Console.WriteLine("Order Processed..."); } - In Design View, click IBMUpdateInventory and in the Properties
window, type UpdateInventory in the CommandExecuted field:
Figure 17. Set the property name -- IBMUpdateInventory
This takes you to the Code View window. There, add the code snippet below:
private void UpdateInventory (object sender, EventArgs e) { Console.WriteLine("Inventory updated..."); }
Press F5, or click Run, in order to run the project. You will get different outputs. However, two possible outputs for value 1 and 0 are shown in Figures 18 and 19:
Figure 18. Displaying output
Figure 17. Displaying output 2
Conclusion
As illustrated in this article, it is fairly easy to create a sequential workflow application that executes a series of predefined steps to accomplish a certain task. You can define complex business rules using other available components. IBM Database Add-ins has included the IBMDatabase component to simplify the creation of a WF application with IBM database servers. Windows WF applications support dynamic business situations and complex requirements that are the need of the day and handling these requirements with ease of use can help users meet business challenges effectively.
Learn
-
Develop
proof-of-concept .NET applications
tutorial series (developerWorks): Create proof-of-concept applications to
access relational and XML data in IBM DB2 9, using Microsoft Visual Studio
.NET 2005.
-
"Overview of IBM Database Add-ins for
Visual Studio 2005"
(developerWorks, December 2005): Get a summary of the functionality in the
IBM Database Add-is for Visual Studio.
- Windows Workflow Foundation on Microsoft .NET
Framework:
Learn more about Windows Workflow Foundation on Microsoft .NET
Framework.
- Windows Workflow
Foundation on MSDN .NET Framework Developer Center:
Find out more about the Windows WF concepts and .NET Framework
3.0.
- DB2
9.5 Information Center for Linux, UNIX, and Windows:
Find information describing how to use the DB2 family of products and
features, as well as related WebSphere Information Integration products
and features.
- IBM Database Add-Ins for Visual Studio Overview: Read more about the features that are available in the IBM Database Add-ins.
-
developerWorks IBM Information
Management and Visual Studio .NET:
Find more resources for DB2 .NET developers.
-
DB2 for .NET:
Innovate with Visual Studio. Find more information on the IBM Database
Add-Ins for .NET.
-
developerWorks Information Management zone:
Learn more about Information Management. Find technical documentation,
how-to articles, education, downloads, product information, and
more.
- Stay current with
developerWorks technical events and webcasts.
Get products and technologies
- Download
IBM product evaluation versions
and get your hands on application development tools and middleware
products from IBM Information Management, Lotus®, Rational®,
Tivoli®, and WebSphere®.
Discuss
- Participate in the discussion forum.
- Check out
developerWorks
blogs
and get involved in the
developerWorks community.
Comments (Undergoing maintenance)







