We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

jgoodale
jgoodale asked
on
Medium Priority
607 Views
Last Modified: 2012-05-11
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.
Comment
Watch Question

Commented:
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;
        }        
    }




}

Author

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.
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.