Conditional Activities in C#.NET

Printer DataMatrix in C#.NET Conditional Activities

Conditional Activities
Data Matrix 2d Barcode Creator In Visual C#
Using Barcode creator for VS .NET Control to generate, create Data Matrix ECC200 image in .NET framework applications.
www.OnBarcode.com
Decoding Data Matrix ECC200 In Visual C#
Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
his chapter will introduce the conditional activities that you can use within a workflow. The conditional activities are activities that perform different actions based on criteria, or perform certain actions multiple times. After introducing each activity, I ll show an example of how to use that activity.
Painting Barcode In C#
Using Barcode encoder for .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
Printing Barcode In C#.NET
Using Barcode generation for .NET framework Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
IfElse Activity
GS1 - 13 Generator In C#
Using Barcode generation for VS .NET Control to generate, create UPC - 13 image in Visual Studio .NET applications.
www.OnBarcode.com
USS Code 39 Printer In Visual C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create Code 39 image in Visual Studio .NET applications.
www.OnBarcode.com
The IfElse activity allows you to set up branching within a workflow. Branching within a workflow performs some action (in this case, an activity) based on a condition. You define and evaluate that condition within an IfElseBranch activity within the IfElse activity. When the workflow encounters an IfElse activity, the leftmost IfElseBranch activity is evaluated first. If that branch returns True it s executed; otherwise, the next branch is executed. You don t need to set a condition on the second branch it s considered the Else part. The IfElse activity requires one branch, but the second is optional. You can use the IfElse activity with one branch to be the same as an If . . . EndIf statement. Finally, both a Sequential and a State Machine workflow can use the IfElse activity.
Generate 2D In C#
Using Barcode printer for VS .NET Control to generate, create Matrix Barcode image in VS .NET applications.
www.OnBarcode.com
Generate Identcode In Visual C#
Using Barcode printer for .NET framework Control to generate, create Identcode image in .NET framework applications.
www.OnBarcode.com
IfElse Activity Within Sequential Workflow
ECC200 Generation In Java
Using Barcode creator for Java Control to generate, create Data Matrix image in Java applications.
www.OnBarcode.com
Data Matrix Encoder In None
Using Barcode drawer for Word Control to generate, create DataMatrix image in Word applications.
www.OnBarcode.com
Create a new VB Sequential Workflow Console Application called VBIfElseSequentialExample. Add a private variable to the workflow called IntInputValue, and a public write-only property called InputValue: Private IntInputValue As Integer Public WriteOnly Property InputValue() As Integer Set(ByVal value As Integer) IntInputValue = value End Set End Property
Barcode Printer In Java
Using Barcode drawer for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
ECC200 Creator In Objective-C
Using Barcode drawer for iPad Control to generate, create Data Matrix image in iPad applications.
www.OnBarcode.com
CHAPTER 3 CONDITIONAL ACTIVITIES
2D Barcode Creator In Java
Using Barcode generation for Java Control to generate, create 2D image in Java applications.
www.OnBarcode.com
DataMatrix Encoder In .NET
Using Barcode generator for Reporting Service Control to generate, create Data Matrix 2d barcode image in Reporting Service applications.
www.OnBarcode.com
Open the Module1.vb file and add a dictionary called parms to add parameters, the same as was done in 2. The beginning of Sub Main looks like the following: Shared Sub Main() Dim workflowRuntime As New WorkflowRuntime() AddHandler workflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted AddHandler workflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated Dim parms As Dictionary(Of String, Object) = New Dictionary(Of String, Object) To make this and future examples a little more interactive, add the following two lines: Console.WriteLine("Input value:") parms.Add("InputValue", Cint(Console.ReadLine())) The first line prompts the user for an input value, and the second line reads in the input and adds it to the dictionary with a key of InputValue. The Console.Readline waits for the user s input, so you don t need to worry about pausing. The CInt function call is required to convert the value read from the line on the console to an integer, because the public property InputValue is expecting an integer. If you don t have this CInt function call, the workflow will fail. Finally, add the parms parameter to the CreateWorkflow line: workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parms) Again, this passes the dictionary of parameters to the workflow. The completed Sub Main follows: Shared Sub Main() Dim workflowRuntime As New WorkflowRuntime() AddHandler workflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted AddHandler workflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated Dim parms As Dictionary(Of String, Object) = New Dictionary(Of String, Object) Console.WriteLine("Input value:") parms.Add("InputValue", CInt(Console.ReadLine())) Dim workflowInstance As WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parms) workflowInstance.Start() WaitHandle.WaitOne() End Sub Next, drag and drop an IfElse activity from the Toolbox onto the Workflow1 Workflow Designer. Leave the IfElse activity name as the default, but change the left IfElseBranchActivity to Branch1 and the right to Branch2, so your Workflow Designer looks like Figure 3-1.
Reading GTIN - 13 In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Draw UCC-128 In VS .NET
Using Barcode printer for VS .NET Control to generate, create EAN / UCC - 14 image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 3 CONDITIONAL ACTIVITIES
Barcode Maker In VS .NET
Using Barcode printer for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
EAN128 Maker In Java
Using Barcode drawer for Android Control to generate, create USS-128 image in Android applications.
www.OnBarcode.com
Figure 3-1. New IfElse activity with Branch1 and Branch2 Notice the exclamation point at the top right of the left branch. Remember the left branch is the default and must have an activity inside it. The right branch represents the Else and isn t required. Drop a Code activity within Branch1, and call the Code activity Branch1Code. Rightclick the Branch1Code activity and choose Generate Handlers to create the sub to add your code to. Add a message box that says Branch 1 within the Execute Code sub. When Branch1 (the left side of the IfElse) is evaluated as True, this Code activity will execute. Add a Code activity to Branch2, and call it Branch2Code. Generate Handlers for this Code activity and add a message box with Branch 2 within the Execute Code sub. The code for these two subs follows: Private Sub Branch1Code_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs) MsgBox("Branch 1") End Sub Private Sub Branch2Code_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs) MsgBox("Branch 2") End Sub Now you ve added an activity to perform some action when a branch evaluates to True, but you still need to add a condition to each IfElseBranch activity. This condition is what s evaluated. To add this condition, you need to add a public sub to the workflow code for each branch that will be evaluated. View the code of the Workflow.vb file and add the following lines of code:
Create UPC-A Supplement 2 In None
Using Barcode maker for Software Control to generate, create UPC-A Supplement 5 image in Software applications.
www.OnBarcode.com
Code 3/9 Maker In Java
Using Barcode encoder for BIRT reports Control to generate, create Code 39 image in BIRT reports applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.