Example #1
0
        public List <SearchInfo> BuildQuery(CriteriaLine breakCriteria = null)
        {
            List <SearchInfo> query = new List <SearchInfo>();

            if (breakCriteria != null && breakCriteria.QueryOperatorSelect.Text == "OR")
            {
                for (int i = Criteria.IndexOf(breakCriteria); i >= 0; i--)
                {
                    if (Criteria[i].QueryOperatorSelect.Text == "AND" || i == 0)
                    {
                        breakCriteria = Criteria[i];
                        break;
                    }
                }
            }

            foreach (CriteriaLine line in Criteria.Where(line => line.IsComplete() || line == breakCriteria))
            {
                if (line == breakCriteria)
                {
                    break;
                }
                SearchInfo criteria = line.BuildSearchInfo();
                if (criteria != null)
                {
                    query.Add(criteria);
                    //criteria.Operator = QueryOperator.And;
                }
            }
            if (query.Count > 0)
            {
                query.First().Operator = QueryOperator.Or;
            }
            return(query);
        }
Example #2
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 #3
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 #4
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 #5
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 #6
0
        private List <SearchInfo> BuildQuery(List <CriteriaLine> inputCriteria)
        {
            List <SearchInfo> criteria = new List <SearchInfo>();
            Type genericSearch         = typeof(SearchInfo <>);

            foreach (CriteriaLine line in inputCriteria.Where(line => line.IsComplete()))
            {
                PropertyBox currentProperty = line.PropertySelect;
                Type        searchType      = genericSearch.MakeGenericType(line.PropertySelect.ParentType);
                SearchInfo  newCriteria     = Activator.CreateInstance(searchType) as SearchInfo;
                if (line == inputCriteria.First(line1 => line1.IsComplete()))
                {
                    newCriteria.Operator = QueryOperator.Or;
                }
                else
                {
                    newCriteria.Operator = QueryOperator.And;
                }
                criteria.Add(newCriteria);
                if (line.OrderByCriteria)
                {
                    if (line.OrderBySelect.Text == "Descending")
                    {
                        newCriteria.OrderByDescending = true;
                    }
                }

                while (currentProperty != null)
                {
                    if (currentProperty.Child == null || currentProperty.Child.SelectedProperty == null)
                    {
                        if (currentProperty.SelectedProperty != null)
                        {
                            newCriteria.PropertyName = currentProperty.SelectedProperty.Name;
                        }
                        if (currentProperty.SelectedProperty != null && currentProperty.SelectedProperty.Type.IsGenericType && currentProperty.SelectedProperty.Type.GetGenericTypeDefinition() == typeof(List <>))
                        {
                            newCriteria.Comparer = QueryComparer.Count;
                            newCriteria.Value    = 0;
                            SearchInfo temp           = newCriteria;
                            Type       nextSearchType = genericSearch.MakeGenericType(currentProperty.SelectedProperty.Type.GetGenericArguments()[0]);
                            newCriteria          = Activator.CreateInstance(nextSearchType) as SearchInfo;
                            temp.Next            = newCriteria;
                            newCriteria.Previous = temp;
                            if (line.OrderByCriteria)
                            {
                                newCriteria.Comparer = QueryComparer.All;
                            }
                        }

                        if (newCriteria.Comparer != QueryComparer.All)
                        {
                            newCriteria.Comparer = SearchProperty.StringToComparer(line.ComparerSelect.Text);
                        }
                        if (currentProperty.SelectedProperty != null && currentProperty.SelectedProperty.Type == typeof(string))
                        {
                            if (newCriteria.Comparer == QueryComparer.Equals)
                            {
                                newCriteria.Comparer = QueryComparer.StringEquals;
                            }
                            else if (newCriteria.Comparer == QueryComparer.NotEqual)
                            {
                                newCriteria.Comparer = QueryComparer.StringNotEqual;
                            }
                        }

                        if (currentProperty.SelectedProperty != null && (currentProperty.SelectedProperty.Type == typeof(int) || currentProperty.SelectedProperty.Type == typeof(List <int>)))
                        {
                            newCriteria.Value = Convert.ToInt32(line.ValueSelect.Text);
                        }
                        else
                        {
                            newCriteria.Value = line.ValueSelect.Text;
                        }
                    }
                    else
                    {
                        newCriteria.Comparer     = QueryComparer.Count;
                        newCriteria.PropertyName = currentProperty.SelectedProperty.Name;
                        SearchInfo temp = newCriteria;
                        Type       nextSearchType;
                        if (currentProperty.Child.ParentType.IsGenericType)
                        {
                            nextSearchType = genericSearch.MakeGenericType(currentProperty.Child.ParentType.GetGenericArguments()[0]);
                        }
                        else
                        {
                            nextSearchType = genericSearch.MakeGenericType(currentProperty.Child.ParentType);
                        }
                        newCriteria          = Activator.CreateInstance(nextSearchType) as SearchInfo;
                        temp.Next            = newCriteria;
                        newCriteria.Previous = temp;
                    }
                    if (newCriteria.Previous != null)
                    {
                        newCriteria.Operator = QueryOperator.Or;
                    }
                    currentProperty = currentProperty.Child;
                }
            }
            return(criteria);
        }
Example #7
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 #8
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);
        }
Example #9
0
        public void GetValueOptions()
        {
            object previousSelection = ValueSelect.SelectedItem;

            ValueSelect.Items.Clear();
            ValueSelect.DropDownStyle = ComboBoxStyle.DropDown;
            Type           selectedType = PropertySelect.GetLowestPropertyType();
            SearchProperty selected     = PropertySelect.GetLowestProperty();

            if (selected == null)
            {
                return;
            }

            if (selectedType == typeof(bool))
            {
                ValueSelect.Items.Add(true);
                ValueSelect.Items.Add(false);
            }
            //else if (selectedType == typeof(DeathCause))
            //{
            //ValueSelect.Items.AddRange(Enum.GetValues(typeof(DeathCause)).Cast<object>().ToArray());
            //    ValueSelect.Items.AddRange(World.DeathCauses.Cast<object>().ToArray());
            //}
            //else if (selectedType == typeof(SiteConqueredType))
            //{
            //    ValueSelect.Items.AddRange(Enum.GetValues(typeof(SiteConqueredType)).Cast<object>().OrderBy(type => type.GetDescription()).ToArray());
            //}
            //else if (selectedType == typeof(BattleOutcome))
            //{
            //    ValueSelect.Items.AddRange(Enum.GetValues(typeof(BattleOutcome)).Cast<object>().OrderBy(outcome => outcome.GetDescription()).ToArray());
            //}
            //else if (selectedType == typeof(HFState))
            //{
            //    ValueSelect.Items.AddRange(Enum.GetValues(typeof(HFState)).Cast<object>().OrderBy(state => state.GetDescription()).ToArray());
            //}
            else //if (!selected.Type.IsGenericType)// && selected.Type != typeof(int) && selected.Type != typeof(double))// && PropertySelect.GetLowestProperty().Name != "Name")
            {
                IEnumerable <object> options;
                if (SelectCriteria)
                {
                    options = (Parent.Parent as QueryControl).SearchSelection(this);
                }
                else
                {
                    options = (Parent.Parent as QueryControl).Search(this);
                }

                SearchInfo available = BuildSearchInfo(true);
                if (available != null)
                {
                    options = available.Select(options);
                    options = options.GroupBy(option => option).Select(option => option.Key);
                    if (options.FirstOrDefault() != null && (options.First().GetType() == typeof(int) || options.First().GetType() == typeof(double)))
                    {
                        options = options.OrderBy(option => option);
                    }
                    else
                    {
                        options = options.OrderBy(option => option.GetDescription()).ToList();
                    }

                    ValueSelect.Items.AddRange(options.ToArray());
                }
            }

            if (selectedType == typeof(bool) || selectedType.IsEnum)
            {
                ValueSelect.DropDownStyle = ComboBoxStyle.DropDownList;
                if (ValueSelect.Items.Count > 0)
                {
                    ValueSelect.SelectedIndex = 0;
                }
            }

            if (PropertySelect.GetLowestProperty().Name == "Name")
            {
                ValueSelect.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                ValueSelect.AutoCompleteSource = AutoCompleteSource.ListItems;
            }
            else
            {
                ValueSelect.AutoCompleteMode = AutoCompleteMode.None;
            }

            if (previousSelection != null && ValueSelect.Items.Contains(previousSelection))
            {
                ValueSelect.SelectedItem = previousSelection;
            }
            (Parent as CriteriaPanel).UpdateValueSelects(this);
        }
Example #10
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);
     }
 }