public SearchProperty GetLowestProperty() { if (Child == null) { return(SelectedProperty); } SearchProperty property = Child.GetLowestProperty(); if (property == null) { return(SelectedProperty); } return(property); }
protected override void OnSelectedIndexChanged(EventArgs e) { Graphics g = CreateGraphics(); Width = (int)g.MeasureString(Text, Font).Width + 20; g.Dispose(); if (!SelectedItem.Equals("")) { SelectedProperty = SelectedItem as SearchProperty; } else { SelectedProperty = null; } if (Child != null) { PropertyBox temp = Child; Child = null; temp.Remove(); } //if listproperties only and subproperties contains other lists or !list if (!ListPropertiesOnly && SelectedProperty != null && (!ListPropertiesOnly && SelectedProperty.SubProperties.Any() || ListPropertiesOnly && SelectedProperty.SubProperties.Count(property => property.SubProperties.Count > 0) > 0)) { Child = new PropertyBox { _parentProperty = this, ParentType = (SelectedItem as SearchProperty).Type, ListPropertiesOnly = ListPropertiesOnly, Location = new Point(Right + 0, Top) }; Parent.Controls.Add(Child); } if (Parent.GetType() == typeof(CriteriaLine)) { (Parent as CriteriaLine).GetComparers(); (Parent as CriteriaLine).ValueSelect.ResetText(); (Parent as CriteriaLine).GetValueOptions(); (Parent as CriteriaLine).ResizeSelf(); } base.OnSelectedIndexChanged(e); }
public void GetComparers() { if (OrderByCriteria) { if (PropertySelect.Child != null && PropertySelect.Child.SelectedProperty != null && PropertySelect.ContainsList() && !PropertySelect.ContainsListLast()) { ComparerSelect.SelectedIndexChanged += ComparerChanged; Controls.AddRange(new Control[] { ComparerSelect, ValueSelect }); ValueSelect.Items.Clear(); ValueSelect.Text = ""; } else { ComparerSelect.SelectedIndexChanged += null; Controls.Remove(ComparerSelect); Controls.Remove(ValueSelect); } } ComparerSelect.Items.Clear(); Type propertyType = PropertySelect.GetLowestPropertyType(); List <QueryComparer> comparers = SearchProperty.GetComparers(propertyType); if (OrderByCriteria && PropertySelect.Child != null && (propertyType == typeof(int) || propertyType == typeof(double) || propertyType.IsGenericType)) { comparers.AddRange(new List <QueryComparer>() { QueryComparer.Min, QueryComparer.Max, QueryComparer.Average, QueryComparer.Sum }); } ComparerSelect.Items.AddRange(comparers.Cast <object>().ToArray()); //foreach (QueryComparer comparer in comparers) // ComparerSelect.Items.Insert(SearchProperty.ComparerToString(comparer)); if (comparers.Count > 0) { ComparerSelect.SelectedIndex = 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); }
public CriteriaLine(bool select, bool search, bool order) { SelectCriteria = select; SearchCriteria = search; OrderByCriteria = order; //BackColor = Color.White; Insert.Text = "Insert"; Insert.Width = 40; Insert.Height = 19; Insert.FlatStyle = FlatStyle.Flat; Insert.Font = new Font("Arial", 6.5f); Insert.FlatAppearance.BorderSize = 0; Remove.Text = "Remove"; Remove.Width = 51; Remove.Height = 19; Remove.FlatStyle = FlatStyle.Flat; Remove.Font = new Font("Arial", 6.5f); Remove.FlatAppearance.BorderSize = 0; QueryOperatorSelect.Items.AddRange(new object[] { QueryOperator.And, QueryOperator.Or }); QueryOperatorSelect.Width = 45; QueryOperatorSelect.DropDownStyle = ComboBoxStyle.DropDownList; QueryOperatorSelect.SelectedIndex = 0; QueryOperatorSelect.SelectedIndexChanged += delegate { GetValueOptions(); object value = ValueSelect.SelectedItem; (Parent as CriteriaPanel).UpdateValueSelects(this); ValueSelect.SelectedItem = value; }; //QueryOperatorSelect.Visible = false; PropertySelect.SelectedIndexChanged += OnPropertyChange; //PropertySelect.FlatStyle = FlatStyle.Flat; ComparerSelect.DropDownStyle = ComboBoxStyle.DropDownList; ComparerSelect.Width = 115; ComparerSelect.ForeColor = Color.Green; //ComparerSelect.FlatStyle = FlatStyle.Popup; //ComparerSelect.Font = new System.Drawing.Font("MS Sans Serif", 8, FontStyle.Bold); ComparerSelect.FormattingEnabled = true; ComparerSelect.Format += delegate(object sender, ListControlConvertEventArgs e) { e.Value = SearchProperty.ComparerToString((QueryComparer)e.Value); }; GetComparers(); //ValueSelect.FlatStyle = FlatStyle.Flat; ValueSelect.Width = 175; ValueSelect.TextChanged += delegate { (Parent as CriteriaPanel).UpdateValueSelects(this); }; ValueSelect.SelectedIndexChanged += delegate { (Parent as CriteriaPanel).UpdateValueSelects(this); }; ValueSelect.FormattingEnabled = true; ValueSelect.Format += delegate(object sender, ListControlConvertEventArgs e) { //if (e.ListItem.GetType() == typeof(DeathCause)) e.Value = e.ListItem.GetDescription(); }; OrderBySelect.Items.AddRange(new object[] { "Ascending", "Descending" }); OrderBySelect.Width = 83; OrderBySelect.DropDownStyle = ComboBoxStyle.DropDownList; OrderBySelect.SelectedIndex = 0; //OrderBySelect.FlatStyle = FlatStyle.Flat; if (OrderByCriteria) { Controls.AddRange(new Control[] { PropertySelect, OrderBySelect, Insert, Remove }); } else { Controls.AddRange(new Control[] { QueryOperatorSelect, PropertySelect, ComparerSelect, ValueSelect, Insert, Remove }); } Height = LineHeight; }
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); }
protected override void OnSelectedIndexChanged(EventArgs e) { Graphics g = this.CreateGraphics(); this.Width = (int)g.MeasureString(this.Text, this.Font).Width + 20; g.Dispose(); if (!SelectedItem.Equals("")) SelectedProperty = SelectedItem as SearchProperty; else SelectedProperty = null; if (Child != null) { PropertyBox temp = Child; Child = null; temp.Remove(); } //if listproperties only and subproperties contains other lists or !list if (!ListPropertiesOnly && SelectedProperty != null && ((!ListPropertiesOnly && SelectedProperty.SubProperties.Any()) || (ListPropertiesOnly && SelectedProperty.SubProperties.Count(property => property.SubProperties.Count > 0) > 0))) { Child = new PropertyBox(); Child.ParentProperty = this; Child.ParentType = (SelectedItem as SearchProperty).Type; Child.ListPropertiesOnly = ListPropertiesOnly; Child.Location = new Point(Right + 0, Top); Parent.Controls.Add(Child); } if (Parent.GetType() == typeof(CriteriaLine)) { (Parent as CriteriaLine).GetComparers(); (Parent as CriteriaLine).ValueSelect.ResetText(); (Parent as CriteriaLine).GetValueOptions(); (Parent as CriteriaLine).ResizeSelf(); } base.OnSelectedIndexChanged(e); }