Example #1
0
        /// <summary>
        /// Event thrown when Right Arrow is touched
        /// Switch criteria and save current one
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnRightButtonClickedAsync(object sender, EventArgs e)
        {
            SaveCriteria();
            int      index        = CriteriaList.IndexOf(CurrentCriteria);
            Criteria leftCriteria = CriteriaList[index + 1];

            changeCriteria(leftCriteria, index + 1);
        }
Example #2
0
        /// <summary>
        /// Gets a list of records based on criteriaList passed in, using HQL.
        /// Supports OR searches as well.
        /// </summary>
        /// <typeparam name="T">Business entity object type</typeparam>
        /// <typeparam name="criteriaList">list of TypeSafe Criteria objects</typeparam>
        /// <returns>list of Business entity objects</returns>
        private List <T> ExecuteHQLSearch <T>(CriteriaList criteriaList) where T : new()
        {
            List <T> businessEntitiesList;
            T        retObject = new T();

            List <HQLParameterItem> masterHQLParameterItemList = new List <HQLParameterItem>();

            Dictionary <string, object> paramDictionary = new Dictionary <string, object>();

            int i = 0;

            string whereClause = " WHERE ";

            //used when building out where clause.  Need to know index of all entities in the search
            //since parameters are named param0, param1, etc.  Parent entity is always first (index=0)
            List <string> entityNameList = new List <string>();

            //add parent entity type to entityNameList
            entityNameList.Add(retObject.GetType().Name);

            foreach (Criteria criteria in criteriaList)
            {
                criteriaType            TargetOperationalOperator;
                List <HQLParameterItem> HQLParameterItemList = new List <HQLParameterItem>();

                string criteriaHQL = "";

                //if this is not the first criteria in the criteria list, supply the () and correct operator
                if (criteriaList.IndexOf(criteria) > 0)
                {
                    criteriaHQL += " " + criteria.LogicalOperator.ToString() + " (";
                }

                foreach (Criterion criterion in criteria)
                {
                    switch (criterion.RelationalOperator)
                    {
                    case RelationalOperatorType.EQUALS: TargetOperationalOperator = criteriaType.Equal;
                        break;

                    case RelationalOperatorType.STARTSWITH: TargetOperationalOperator = criteriaType.LikeStartsWith;
                        break;

                    case RelationalOperatorType.ENDSWITH: TargetOperationalOperator = criteriaType.LikeEndsWith;
                        break;

                    case RelationalOperatorType.CONTAINS: TargetOperationalOperator = criteriaType.Like;
                        break;

                    case RelationalOperatorType.IN: TargetOperationalOperator = criteriaType.In;
                        break;

                    case RelationalOperatorType.GREATERTHAN: TargetOperationalOperator = criteriaType.GreaterThan;
                        break;

                    case RelationalOperatorType.GREATERTHAN_EQUAL: TargetOperationalOperator = criteriaType.GreaterThanEqual;
                        break;

                    case RelationalOperatorType.LESSTHAN: TargetOperationalOperator = criteriaType.LessThan;
                        break;

                    case RelationalOperatorType.LESSTHAN_EQUAL: TargetOperationalOperator = criteriaType.LessThanEqual;
                        break;

                    default: throw new Exception(String.Format("% is not supported as relation operator", criterion.RelationalOperator));
                    }

                    if (criterion.SubObjectTypeField != null && entityNameList.Contains(criterion.SubObjectTypeField) == false)
                    {
                        entityNameList.Add(criterion.SubObjectTypeField);
                    }

                    HQLParameterItemList.Add(new HQLParameterItem(criterion.FieldName, criterion.FieldValue, TargetOperationalOperator, criterion.LogicalOperator.ToString(), criterion.SubObjectTypeField));
                }


                // build out where clause
                foreach (HQLParameterItem hqlItem in HQLParameterItemList)
                {
                    paramDictionary.Add("param" + i, hqlItem.FieldValue);

                    criteriaHQL = CreateHQLWhereClause(criteriaHQL, i, hqlItem, HQLParameterItemList, entityNameList);
                    i++;
                }

                //if this is not the first criteria in the criteria list, supply the ) to end grouping
                if (criteriaList.IndexOf(criteria) > 0)
                {
                    criteriaHQL += ")";
                }

                whereClause += criteriaHQL;
                masterHQLParameterItemList.AddRange(HQLParameterItemList);
            }


            // HMF Beging Sort Criteria Support

            List <string> sortCriterionSubObjectNameList = new List <String>();

            if (criteriaList.SortCriteria != null && criteriaList.SortCriteria.Count > 0)
            {
                foreach (SortCriterion sortCriterion in  criteriaList.SortCriteria)
                {
                    if (sortCriterion.SubObjectTypeField != null && entityNameList.Contains(sortCriterion.SubObjectTypeField) == false)
                    {
                        entityNameList.Add(sortCriterion.SubObjectTypeField);
                        sortCriterionSubObjectNameList.Add(sortCriterion.SubObjectTypeField);
                    }
                }

                string orderByClause = " ORDER BY ";
                int    x             = 0;

                foreach (SortCriterion sortCriterion in criteriaList.SortCriteria)
                {
                    //determine if sort goes with parent or sub-object
                    if (sortCriterion.SubObjectTypeField == null)
                    {
                        orderByClause += " parent.";
                    }
                    else
                    {
                        orderByClause += " sub" + entityNameList.IndexOf(sortCriterion.SubObjectTypeField) + ".";
                    }

                    if (x > 0)
                    {
                        orderByClause += ",";
                    }
                    if (sortCriterion.SortDirection == SortDirection.Ascending)
                    {
                        orderByClause += sortCriterion.FieldName + " ASC";
                    }
                    else
                    {
                        orderByClause += sortCriterion.FieldName + " DESC";
                    }
                    x++;
                }
                whereClause += orderByClause;
            }

            // HMF End Sort Criteria Support

            if (criteriaList.MaxEntities > 0)
            {
                businessEntitiesList = GetSubObjectFilteredList <T>(masterHQLParameterItemList, paramDictionary, whereClause, criteriaList.MaxEntities, sortCriterionSubObjectNameList);
            }
            else
            {
                businessEntitiesList = GetSubObjectFilteredList <T>(masterHQLParameterItemList, paramDictionary, whereClause, -1, sortCriterionSubObjectNameList);
            }
            return(businessEntitiesList);
        }