Example #1
0
        public void SetupComparers(QueryComparer comparer)
        {
            if (this.Next != null)
            {
                if (this.GetSearchType().GetProperty(this.PropertyName).PropertyType.IsGenericType)
                {
                    this.Comparer = QueryComparer.Count;
                }
                else
                {
                    this.Comparer = QueryComparer.Property;
                }
                this.Next.SetupComparers(comparer);
            }
            else
            {
                if (comparer == QueryComparer.Equals || comparer == QueryComparer.NotEqual)
                {
                    if ((this.PropertyName != "Value" && this.GetSearchType().GetProperty(this.PropertyName).PropertyType == typeof(string)) ||
                        (this.PropertyName == "Value" && this.GetSearchType() == typeof(string)))
                    {
                        if (comparer == QueryComparer.Equals)
                        {
                            comparer = QueryComparer.StringEquals;
                        }
                        if (comparer == QueryComparer.NotEqual)
                        {
                            comparer = QueryComparer.StringNotEqual;
                        }
                    }

                    if (this.PropertyName != "Value" && this.GetSearchType().GetProperty(this.PropertyName).PropertyType == typeof(bool))
                    {
                        comparer = QueryComparer.Is;
                    }
                }
                if (this.PropertyName != "Value" && this.GetSearchType().GetProperty(this.PropertyName).PropertyType.IsGenericType)
                {
                    switch (comparer)
                    {
                    case QueryComparer.Equals: comparer = LegendsViewer.Controls.Query.QueryComparer.ListEquals; break;

                    case QueryComparer.GreaterThan: comparer = QueryComparer.ListGreaterThan; break;

                    case QueryComparer.LessThan: comparer = QueryComparer.ListLessThan; break;
                    }
                    this.Next          = SearchInfo.Make(this.GetSearchType().GetProperty(this.PropertyName).PropertyType);
                    this.Next.Operator = QueryOperator.Or;
                    this.Next.Previous = this;
                    this.Next.Comparer = QueryComparer.All;
                }

                this.Comparer = comparer;
            }
        }
Example #2
0
 public void SetupSearchProperties(SearchInfo criteria)
 {
     criteria.PropertyName = SelectedProperty.Name;
     if (Child != null && Child.SelectedProperty != null)
     {
         criteria.Next          = SearchInfo.Make(Child.ParentType);
         criteria.Next.Operator = QueryOperator.Or;
         criteria.Next.Previous = criteria;
         Child.SetupSearchProperties(criteria.Next);
     }
 }
Example #3
0
        public void SetupOrderByComparers(QueryComparer comparer)
        {
            if (this.Next != null)
            {
                if (comparer == QueryComparer.Min || comparer == QueryComparer.Max || comparer == QueryComparer.Average || comparer == QueryComparer.Sum)
                {
                    this.Comparer      = comparer;
                    this.Next.Comparer = this.Comparer;
                }

                if (!this.GetSearchType().GetProperty(this.PropertyName).PropertyType.IsGenericType)
                {
                    this.Comparer = QueryComparer.Property;
                }

                this.Next.SetupOrderByComparers(comparer);
            }
            else
            {
                if (comparer == QueryComparer.All)
                {
                    this.Comparer      = QueryComparer.All;
                    this.Next          = SearchInfo.Make(this.GetSearchType().GetProperty(this.PropertyName).PropertyType);
                    this.Next.Operator = QueryOperator.Or;
                    this.Next.Previous = Next;
                    this.Next.Comparer = QueryComparer.All;
                }
                else
                {
                    if (comparer == QueryComparer.Equals || comparer == QueryComparer.NotEqual)
                    {
                        bool propertyIsString;
                        if (this.PropertyName != "Value")
                        {
                            propertyIsString = this.GetSearchType().GetProperty(this.PropertyName).PropertyType == typeof(string);
                        }
                        else
                        {
                            propertyIsString = this.Previous.GetSearchType().GetProperty(Previous.PropertyName).PropertyType.GetGenericArguments()[0] == typeof(string);
                        }
                        if (propertyIsString && comparer == QueryComparer.Equals)
                        {
                            comparer = QueryComparer.StringEquals;
                        }
                        if (propertyIsString && comparer == QueryComparer.NotEqual)
                        {
                            comparer = QueryComparer.StringNotEqual;
                        }
                    }

                    this.Comparer = comparer;
                }
            }
        }
Example #4
0
        public SearchInfo BuildSearchInfo(bool gettingValuesOnly = false)
        {
            if (!OrderByCriteria && !(PropertySelect.SelectedIndex >= 0 && ComparerSelect.SelectedIndex >= 0))
            {
                return(null);
            }

            if (OrderByCriteria && Controls.Contains(ComparerSelect) && ComparerSelect.SelectedIndex < 0)
            {
                return(null);
            }

            SearchInfo criteria = SearchInfo.Make(PropertySelect.ParentType);

            criteria.Operator = (QueryOperator)QueryOperatorSelect.SelectedItem;

            //build property
            PropertySelect.SetupSearchProperties(criteria);

            //build comparer
            if (OrderByCriteria)
            {
                if (OrderBySelect.Text == "Descending")
                {
                    criteria.OrderByDescending = true;
                }

                if (Controls.Contains(ComparerSelect))
                {
                    criteria.SetupOrderByComparers((QueryComparer)ComparerSelect.SelectedItem);
                }
                else if (PropertySelect.GetLowestPropertyType().IsGenericType)
                {
                    criteria.SetupOrderByComparers(QueryComparer.All);
                }
            }
            else
            {
                criteria.SetupComparers((QueryComparer)ComparerSelect.SelectedItem);//  SearchProperty.StringToComparer(ComparerSelect.Text));
            }

            //build value
            if (PropertySelect.GetLowestPropertyType() == typeof(int) || PropertySelect.GetLowestPropertyType() == typeof(List <int>) || PropertySelect.GetLowestPropertyType().IsGenericType)
            {
                if (Controls.Contains(ValueSelect) && !gettingValuesOnly)
                {
                    try
                    {
                        criteria.SetupValue(Convert.ToInt32(ValueSelect.Text));
                    }
                    catch { return(null); }
                }
                else
                {
                    criteria.SetupValue(0);
                }
            }
            else if (PropertySelect.GetLowestPropertyType() == typeof(double) || PropertySelect.GetLowestPropertyType() == typeof(List <double>))
            {
                if (Controls.Contains(ValueSelect) && !gettingValuesOnly)
                {
                    try
                    {
                        criteria.SetupValue(double.Parse(ValueSelect.Text));// Convert.ToDouble(ValueSelect.Text));
                    }
                    catch { return(null); }
                }
            }
            else if (ValueSelect.DropDownStyle == ComboBoxStyle.DropDownList)
            {
                criteria.SetupValue(ValueSelect.SelectedItem);
            }
            else
            {
                criteria.SetupValue(ValueSelect.Text);
            }

            return(criteria);
        }