• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

Creating an If, Elseif, Else condition in Workflow .Net 4.0

I'm new to windows workflow foundation and I'm trying to create a new flowchart item that works just like a FlowDecision but has a third branch that has a test for null. This is the login in C# I'm trying to create:

If (condition=="Y") then

ElseIf (condition=="N") then

Else (this is null)

Ideally I would like a generic item that is added to my toolbox that I can drag and drop that will create the 3 branches.

Thanks,

James.
0
jgoodale
Asked:
jgoodale
  • 2
1 Solution
 
twhaightCommented:
try this

if(item == condition)
{
   //code here
}
else if (item == condition2)
{
 //code here
}
else
{
//code here
}


If you have more a simple if then else, a switch/case statement would be better

switch(condition)
{
  case "condition1":
    item = "1";
   break;
 case "condition2":
  item="2";
  break;
 case "condition3"
  item="3";
  break;

Here is an example I used based on the day selected from a calendar to format the date in objects based on the day of the week (the date is on Oracle date format)

protected void DefaultDay()
    {
        /*
         * Puts default work week in txtWeekBeginning and txtWeekEnd
        */

        DateTime today;
        String DayofWeek;
        String strSelectedDay;

        today = System.DateTime.Today;
        txtSelectedDay.Text = today.DayOfWeek.ToString();
        strSelectedDay = txtSelectedDay.Text;

        switch (strSelectedDay)
        {
            case "Sunday":
                txtWeekBeginning.Text = today.ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.AddDays(6).ToString("dd-MMM-yyyy");
                break;
            case "Monday":
                txtWeekBeginning.Text = today.AddDays(-1).ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.AddDays(5).ToString("dd-MMM-yyyy");
                break;
            case "Tuesday":
                txtWeekBeginning.Text = today.AddDays(-2).ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.AddDays(4).ToString("dd-MMM-yyyy");
                break;
            case "Wednesday":
                txtWeekBeginning.Text = today.AddDays(-3).ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.AddDays(3).ToString("dd-MMM-yyyy");
                break;
            case "Thursday":
                txtWeekBeginning.Text = today.AddDays(-4).ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.AddDays(2).ToString("dd-MMM-yyyy");
                break;
            case "Friday":
                txtWeekBeginning.Text = today.AddDays(-5).ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.AddDays(1).ToString("dd-MMM-yyyy");
                break;
            case "Saturday":
                txtWeekBeginning.Text = today.AddDays(-6).ToString("dd-MMM-yyyy");
                txtWeekEnd.Text = today.ToString("dd-MMM-yyyy");
                break;
        }        
    }




}

0
 
jgoodaleAuthor Commented:
twhaight: I'm looking for a solution using the workflow objects in .Net 4.0. I have my code working using flowswitches but I'm not sure if this is the right solution for what I want.. I will paste some code in my next post.
0
 
askanilkrisCommented:
I think I understand where you are going as i have had spend day and night thinking about this solution where in  I can have multiple branch from a activitiy
This is by default not possible in WF4 as i tried all ways to override all the classes that .net expose from flownode to flowdecison but all in vain coz they are protected internal and cannot be overridden

Then offlate i came to know that WF4 patch has been released with some thing called statemachine
which will allow you to manipulate different states your systems is in

if you search on this over the net you would get lots of forum where this question have been asked but not leading anywhere..

This link has video tutorial to start with
http://code.msdn.microsoft.com/Windows-Workflow-b4b808a8
you have to install Vs2010 SP1 and one more patch to have start with (more info can be found in the video)
you can refer the below link to go with statemachine
http://blogs.msdn.com/b/endpoint/archive/2011/04/20/wf4-state-machine-user-experience.aspx

Thanks
Kris
0
 
jgoodaleAuthor Commented:
Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now