Exemple #1
0
        public FilterCriteria AddSelectionCriterion(SelectionCriterion newSelectionCriterion)
        {
            SelectionCriterion selectionCriterion = new SelectionCriterion(newSelectionCriterion);

            m_Criteria.AddCriteria(selectionCriterion);
            ValidateCriteria(m_Criteria);
            return(this);
        }
Exemple #2
0
        public FilterCriteria AddXmlFilter(Type type, Type dataType, Int32 length, string xmlPath, OperandType combineInstruction, string propertyName, string workTypeName, ComparisonMethod compareMethod, object value)
        {
            // Create a new SelectionCriterion object.
            SelectionCriterion selectionCriterion = new SelectionCriterion(combineInstruction, type, dataType, length, xmlPath, propertyName, workTypeName, compareMethod, value);

            m_Criteria.AddCriteria(selectionCriterion);
            ValidateCriteria(m_Criteria);
            return(this);
        }
        /// <summary>
        /// Adds the criteria.
        /// </summary>
        /// <param name="criterion">The criterion.</param>
        public void AddCriteria(SelectionCriterion criterion)
        {
            // Make sure criterion isn't null
            VerifyCriteria(criterion);

            // Add type to typelist if doesn't exist
            if (Types.IndexOf(criterion.Type) == -1)
            {
                Types.Add(criterion.Type);
            }

            // Add the criteria
            m_Criteria.Add(criterion);
        }
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns></returns>
        public PersistentCriteria Clone()
        {
            // Create empty Persistent Criteria
            PersistentCriteria newCriteria = new PersistentCriteria();

            // Set Operand Type
            newCriteria.OperandType = OperandType;

            // Add all the types.
            foreach (Type t in Types)
            {
                newCriteria.Types.Add(t);
            }

            // Add a clone of each Criteria contained
            foreach (object criteria in Criteria)
            {
                // Try as SelectionCriterion
                SelectionCriterion sc = criteria as SelectionCriterion;
                if (sc != null)
                {
                    // Add a copy of the selection criterion
                    newCriteria.AddCriteria((SelectionCriterion)sc.Clone());
                    continue;
                }

                // Try as IPersistentCriteria
                PersistentCriteria pc = criteria as PersistentCriteria;
                if (pc != null)
                {
                    // Add a copy of the persistent criteria.
                    newCriteria.AddCriteria((PersistentCriteria)pc.Clone());
                    continue;
                }

                // Neither valid type, throw execption.
                InvalidCriteriaObject(criteria);
            }

            return(newCriteria);
        }
Exemple #5
0
        /// <summary>
        /// Columns the alias.
        /// </summary>
        /// <param name="selectionCriterion">The selectionCriterion.</param>
        /// <returns></returns>
        private string ColumnAlias(SelectionCriterion selectionCriterion)
        {
            string str = string.Empty;

            if ((selectionCriterion == null) || (selectionCriterion.Property == null))
            {
                throw new NullReferenceException("SelectionCriterion cannot be null!");
            }
            if (selectionCriterion.DataType == null)
            {
                str = selectionCriterion.PropertyAlias;
            }
            else
            {
                char[]   delimiterChars     = { '.' };
                string[] xmlColumn          = selectionCriterion.OriginalPropertyName.Split(delimiterChars);
                string   persistentTypeName = AppInfo.GetTableName(selectionCriterion.Type);
                str = m_DataObjectBroker.ConnectionInfo.GetColumnAlias(persistentTypeName, xmlColumn, selectionCriterion.XmlPath, GetDataType(selectionCriterion), selectionCriterion);
            }
            return(str);
        }
        /// <summary>
        /// Adds the types.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        private void AddTypes(PersistentCriteria criteria)
        {
            foreach (object o in criteria.Criteria)
            {
                SelectionCriterion sc = o as SelectionCriterion;
                if (sc != null)
                {
                    if (Types.IndexOf(sc.Type) == -1)
                    {
                        Types.Add(sc.Type);
                    }
                    continue;
                }
                PersistentCriteria pc = o as PersistentCriteria;
                if (pc != null)
                {
                    AddTypes(pc);
                    continue;
                }

                // Neither valid type, throw execption.
                InvalidCriteriaObject(o);
            }
        }
Exemple #7
0
 private string GetDataType(SelectionCriterion selectionCriterion)
 {
     return(m_DataObjectBroker.ConnectionInfo.GetDataType(selectionCriterion));
 }
Exemple #8
0
        /// <summary>
        /// Selections the clause.
        /// </summary>
        /// <param name="selectionCriterion">The selectionCriterion.</param>
        /// <returns></returns>
        private string SelectionClause(SelectionCriterion selectionCriterion, bool forParameters)
        {
            string result = string.Empty;

            if (selectionCriterion.Expression == Expression.None)
            {
                if (selectionCriterion == null)
                {
                    throw new NullReferenceException("SelectionCriterion cannot be null!");
                }
                if (!m_Types.Contains(selectionCriterion.Type))
                {
                    m_Types.Add(selectionCriterion.Type);
                }
                selectionCriterion.PropertyAlias = AppInfo.GetTableName(selectionCriterion.Type) + ".";
                if (selectionCriterion.OriginalPropertyName != "ObjectKey")
                {
                    selectionCriterion.PropertyAlias += selectionCriterion.OriginalPropertyName;
                }
                else
                {
                    selectionCriterion.PropertyAlias += AppInfo.GetTableName(selectionCriterion.Type) + "Key";
                }
                string expression = string.Empty;
                if (m_PreviousSelectionCriterion != null && m_PreviousSelectionCriterion.Expression == Expression.Begin)
                {
                    expression = "(";
                }
                if (forParameters)
                {
                    object value = selectionCriterion.Value;
                    if (selectionCriterion.ComparisonMethod == ComparisonMethod.In || selectionCriterion.ComparisonMethod == ComparisonMethod.NotIn)
                    {
                        if (value != null)
                        {
                            object   obj   = value;
                            Array    array = obj as Array;
                            object[] objs  = new object[array.Length];
                            int      i     = 0;
                            foreach (var item in array)
                            {
                                objs[i++] = item;
                            }
                            value = objs;
                        }
                        else
                        {
                            throw new InvalidOperationException("ComparisonMethod.In/ComparisonMethod.NotIn cannot have a null object value");
                        }
                    }
                    string text = ComparisonTextForParameters(m_DataObjectBroker, selectionCriterion.ComparisonMethod, ref value, m_Parameters.Count);
                    if (value != null)
                    {
                        if (selectionCriterion.ComparisonMethod != ComparisonMethod.In && selectionCriterion.ComparisonMethod != ComparisonMethod.NotIn)
                        {
                            m_Parameters.Add(value);
                        }
                        else
                        {
                            for (int i = 0; i < ((object[])value).Length; i++)
                            {
                                m_Parameters.Add(((object[])value)[i]);
                            }
                        }
                    }
                    result = OperandText(selectionCriterion.OperandType) + " " + expression + ColumnAlias(selectionCriterion) + " " + text + " ";
                }
                else
                {
                    result = OperandText(selectionCriterion.OperandType) + " " + expression +
                             ColumnAlias(selectionCriterion) + " " +
                             ComparisonText(m_DataObjectBroker, selectionCriterion.ComparisonMethod, selectionCriterion.Value, selectionCriterion.Property.PropertyType) + " ";
                }
            }
            else if (selectionCriterion.Expression == Expression.Begin)
            {
                result = string.Empty;
            }
            else if (selectionCriterion.Expression == Expression.End)
            {
                result = ") ";
            }
            else
            {
                throw new ApplicationException("Could not generate where clause!");
            }
            m_PreviousSelectionCriterion = selectionCriterion;
            return(result);
        }
Exemple #9
0
        public void EndExpression()
        {
            SelectionCriterion selectionCriterion = new SelectionCriterion(Expression.End);

            m_Criteria.AddCriteria(selectionCriterion);
        }
Exemple #10
0
        public void BeginExpression()
        {
            SelectionCriterion selectionCriterion = new SelectionCriterion(Expression.Begin);

            m_Criteria.AddCriteria(selectionCriterion);
        }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistentCriteria"/> class.
 /// </summary>
 /// <param name="operandType">Type of the operand.</param>
 /// <param name="criterion">The criterion.</param>
 public PersistentCriteria(OperandType operandType, SelectionCriterion criterion)
 {
     Initialize(operandType);
     AddCriteria(criterion);
 }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistentCriteria"/> class.
 /// </summary>
 /// <param name="criterion">The criterion.</param>
 public PersistentCriteria(SelectionCriterion criterion)
 {
     Initialize(OperandType.None);
     AddCriteria(criterion);
 }
Exemple #13
0
 public SelectionCriterion(SelectionCriterion sc)
 {
     m_OriginalPropertyName = sc.OriginalPropertyName;
     Initialize(sc.OperandType, sc.Type, sc.DataType, sc.Length, sc.XmlPath, sc.Property, sc.ComparisonMethod, sc.Value, true, sc.Expression);
 }