Exemplo n.º 1
0
        /// <summary>
        /// This static method combines 2 where statements with eachother to form a new statement
        /// </summary>
        /// <param name="statement1"></param>
        /// <param name="statement2"></param>
        /// <returns></returns>
        //public static WhereStatement CombineStatements(WhereStatement statement1, WhereStatement statement2)
        //{
        //    // statement1: {Level1}((Age<15 OR Age>=20) AND (strEmail LIKE 'e%') OR {Level2}(Age BETWEEN 15 AND 20))
        //    // Statement2: {Level1}((Name = 'Peter'))
        //    // Return statement: {Level1}((Age<15 or Age>=20) AND (strEmail like 'e%') AND (Name = 'Peter'))

        //    // Make a copy of statement1
        //    WhereStatement result = WhereStatement.Copy(statement1);

        //    // Add all clauses of statement2 to result
        //    for (int i = 0; i < statement2.ClauseLevels; i++) // for each clause level in statement2
        //    {
        //        List<WhereClause> level = statement2[i];
        //        foreach (WhereClause clause in level) // for each clause in level i
        //        {
        //            for (int j = 0; j < result.ClauseLevels; j++)  // for each level in result, add the clause
        //            {
        //                result.AddWhereClauseToLevel(clause, j);
        //            }
        //        }
        //    }

        //    return result;
        //}

        public static WhereStatement Copy(WhereStatement statement)
        {
            WhereStatement result = new WhereStatement();

            foreach (WhereClause clause in statement)
            {
                WhereClause clauseCopy = null;
                if (clause is GeneralWhereClause)
                {
                    GeneralWhereClause gClause = (GeneralWhereClause)clause;
                    clauseCopy = new GeneralWhereClause(gClause.LogicalOperator, gClause.FieldName, gClause.ComparisonOperator, gClause.Value, gClause.Level);
                }
                else if (clause is BetweenWhereClause)
                {
                    BetweenWhereClause bClause = (BetweenWhereClause)clause;
                    clauseCopy = new BetweenWhereClause(bClause.LogicalOperator, bClause.FieldName, bClause.FromValue, bClause.ToValue, bClause.Level);
                }
                //foreach (WhereClause.SubClause subClause in clause.SubClauses)
                //{
                //    WhereClause.SubClause subClauseCopy = new WhereClause.SubClause(subClause.LogicOperator, subClause.ComparisonOperator, subClause.Value);
                //    clauseCopy.SubClauses.Add(subClauseCopy);
                //}
                result.Add(clauseCopy);
            }
            return(result);
        }