private void BuildQuery(string filterName, FilterClauseEnum clause, FilterConditionEnum condition, string filterValue) { FilterName = filterName; Clause = clause; Condition = condition; FilterValue = filterValue; foreach (FilterClauseEnum val in Enum.GetValues(typeof(FilterClauseEnum))) { var isSelected = val == clause; Clauses.Add(new FilterEnumContainer { Name = val.ToString(), Value = (int)val, Selected = isSelected }); } foreach (FilterConditionEnum val in Enum.GetValues(typeof(FilterConditionEnum))) { var isSelected = val == condition; Conditions.Add( new FilterEnumContainer { Name = val.ToString(), Value = (int)val, Selected = isSelected }); } }
public ColumnFilterCondition(string fieldName, FilterConditionEnum condition, object value, string displayText) { this.fieldName = fieldName; this.condition = condition; this.value = value; this.displayText = displayText; }
/// <summary> /// Возвращает шаблон условия /// </summary> /// <param name="type"></param> /// <param name="fieldName"></param> /// <returns></returns> private string GetConditionTemplate(FilterConditionEnum type, string fieldName) { var res = ""; switch (type) { case FilterConditionEnum.Contains: res = $"{fieldName}.Contains(@0)"; break; case FilterConditionEnum.Equal: res = $"{fieldName} == @0"; break; case FilterConditionEnum.GreaterThan: res = $"{fieldName} > @0"; break; case FilterConditionEnum.LesserThan: res = $"{fieldName} < @0"; break; default: throw new Exception("Неизвестное условие."); } return(res); }
private void RemoveConditionFromList(FilterConditionEnum condition) { int index = cbeFilterConditions.Properties.Items.IndexOf(Enum.GetName(typeof(FilterConditionEnum), condition)); if (index != -1) { cbeFilterConditions.Properties.Items.RemoveAt(index); } }
public FilterQuery(string filterName, FilterClauseEnum clause, FilterConditionEnum condition, string filterValue) { BuildQuery(filterName, clause, condition, filterValue); }
public static void ShowFilter( TreeList treeList, bool readOnly, string idField, string idParent, FilterConditionEnum filterCondition) { object prevalue = null; TreeListColumn currentColumn = null; bool Flag = false; Dictionary<string, object> preValue = new Dictionary<string, object>(); Dictionary<string, int> indexCondition = new Dictionary<string, int>(); //Chèn row filter vào treelist DataTable dtSource = (DataTable)treeList.DataSource; DataRow filterRow = dtSource.NewRow(); foreach (DataColumn column in dtSource.Columns) { try { if (column.ColumnName != idField && column.ColumnName != idParent) { try { filterRow[column.ColumnName] = ""; } catch { filterRow[column.ColumnName] = DBNull.Value; } } } catch (Exception ex) { PLException.AddException(ex); } } filterRow[idField] = long.MinValue; filterRow[idParent] = long.MinValue; dtSource.Rows.InsertAt(filterRow, 0); treeList.OptionsBehavior.EnableFiltering = true; treeList.OptionsBehavior.AutoSelectAllInEditor = false; treeList.OptionsBehavior.Editable = false; treeList.OptionsBehavior.EnterMovesNextColumn = true; treeList.ExpandAll(); if (readOnly) { treeList.AfterFocusNode += delegate(object sender, NodeEventArgs e) { if (e.Node.Id == 0) treeList.OptionsBehavior.Editable = true; else treeList.OptionsBehavior.Editable = false; }; } else treeList.OptionsBehavior.Editable = true; treeList.FocusedNodeChanged += delegate(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { try { if (e.Node.Id == 0) treeList.OptionsBehavior.Editable = true; else treeList.OptionsBehavior.Editable = false; } catch { } }; treeList.FocusedColumnChanged += delegate(object sender, DevExpress.XtraTreeList.FocusedColumnChangedEventArgs e) { if (Flag) { Flag = false; treeList.FocusedColumn = currentColumn; treeList.ShowEditor(); } }; treeList.ValidateNode += delegate(object sender, ValidateNodeEventArgs e) { try { if (e.Node.Id == 0) e.Valid = true; } catch { } }; treeList.CellValueChanged += delegate(object sender, DevExpress.XtraTreeList.CellValueChangedEventArgs e) { try { if (e.Node.Id == 0) { Flag = true; currentColumn = e.Column; object value; int index; preValue.TryGetValue(e.Column.FieldName, out value); indexCondition.TryGetValue(e.Column.FieldName, out index); treeList.FilterConditions[index].Value1 = prevalue; treeList.FilterConditions[index].Visible = true; treeList.FilterConditions[index].Value1 = e.Value; treeList.FilterConditions[index].Visible = false; e.Node[e.Column.FieldName] = e.Value; //treeList.ShowEditor(); //SendKeys.Send("{END}"); if (preValue.ContainsKey(e.Column.FieldName)) { preValue[e.Column.FieldName] = e.Value; } else { preValue.Add(e.Column.FieldName, e.Value); } } } catch { } }; treeList.FilterNode += delegate(object sender, FilterNodeEventArgs e) { try { if (e.Node.Id == 0) e.Handled = true; else if (e.Node.Level == 0) e.Handled = true; } catch { } }; //Gán điều kiện lọc cho các column int numColumn = treeList.Columns.Count; try { for (int i = 0; i < numColumn; i++) { TreeListColumn tc = treeList.Columns[i]; treeList.FilterConditions.Add(new FilterCondition(filterCondition, tc, null, null, true)); try { indexCondition.Add(tc.FieldName, i); preValue.Add(tc.FieldName, null); } catch { } } } catch { } }