How to Join a AndCondition and a OrCondition in one?

Answered How to Join a AndCondition and a OrCondition in one?

  • Wednesday, June 18, 2008 4:32 PM
     
     
    Hi 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 ?

All Replies