How to Join a AndCondition and a OrCondition in one?
-
Wednesday, June 18, 2008 4:32 PMHi there,
I'm building a Notification Services(NS) Application, and i have a web based interface to add subscriptions to my NS instance. But i'm having a problem with the definition of the UserCondition.
Here is the problem:
I want to add some complex conditions both with "and" or "or" but it only seems to let me have one type of condition.
Here is some code i made:
public Subscription AddConditions(int index, Subscription s, string subscriber,
ArrayList tipos, ArrayList campos, ArrayList condicoes, ArrayList valores)
{
s = new Subscription(subscriber);
AndCondition and = new AndCondition();
OrCondition or = new OrCondition();
ConditionTree c;
string op;
for (int i = 0; i < campos.Count; i++)
{
op = condicoes[i].ToString();
Condition cond;
if (tipos[i].ToString() == "AND")
{
switch (op)
{
case "=": cond = new AndCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.Equals, valores[i].ToString()
));
and.Children.Add(cond);
break;
case "<>": cond = new AndCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.NotEquals, valores[i].ToString()
));
and.Children.Add(cond);
break;
case "<": cond = new AndCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.LessThan, valores[i].ToString()
));
and.Children.Add(cond);
break;
case "<=": cond = new AndCondition(new nsr.SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.LessThanOrEqualTo, valores[i].ToString()
));
and.Children.Add(cond);
break;
case ">": cond = new AndCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.GreaterThan, valores[i].ToString()
));
and.Children.Add(cond);
break;
case ">=": cond = new AndCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.GreaterThanOrEqualTo, valores[i].ToString()
));
and.Children.Add(cond);
break;
default:
break;
}
}
else
{
switch (op)
{
case "=": cond = new OrCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.Equals, valores[i].ToString()
));
or.Children.Add(cond);
break;
case "<>": cond = new OrCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.NotEquals, valores[i].ToString()
));
or.Children.Add(cond);
break;
case "<": cond = new OrCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.LessThan, valores[i].ToString()
));
or.Children.Add(cond);
break;
case "<=": cond = new OrCondition(new nsr.SimpleLeafCondition(
new nsr.FieldValue(campos[i].ToString()), SimpleOperator.LessThanOrEqualTo, valores[i].ToString()
));
or.Children.Add(cond);
break;
case ">": cond = new OrCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.GreaterThan, valores[i].ToString()
));
or.Children.Add(cond);
break;
case ">=": cond = new OrCondition(new SimpleLeafCondition(
new FieldValue(campos[i].ToString()), SimpleOperator.GreaterThanOrEqualTo, valores[i].ToString()
));
or.Children.Add(cond);
break;
default:
break;
}
}
}
if(and.Children.Count>0)
c.Children.Add(and);
if (or.Children.Count > 0)
c.Children.Add(or);
s.UserCondition = c;
return s;
}
The problem is that the ConditionTree needs to be initialized or i get a runtime error when i try to add ( c.Children.Add(and);), but it only lets me initialize it with AndCondition or OrCondition, like ConditionTree c = new AndCondition(); or ConditionTree c= new OrCondition(); !
Does anyone know a way to add this two types of Conditions in one?
Thanks in advance for any help :)
Life.Meaning = null ?- Moved by Peter RitchieMVP, Moderator Thursday, June 19, 2008 8:14 PM off-topic
All Replies
-
Thursday, June 19, 2008 8:14 PMModerator
For questions and sicussions about how to develop .NET applications using workflow functionality provided by Windows Workflow Foundation, please see http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=122&SiteID=1
http://www.peterRitchie.com/blog- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Moderator Friday, May 11, 2012 3:22 AM
Friday, May 11, 2012 3:22 AMModerator
This thread was moved into the Off Topic forum. I can move it into a specific forum for you if you want.
Thanks!
Ed Price (a.k.a User Ed), SQL Server Experience Program Manager (Blog, Twitter, Wiki)
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Moderator Friday, May 11, 2012 3:23 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Moderator Friday, May 11, 2012 3:23 AM