QueryBuilder
Namespace: Wisej.Web
Assembly: Wisej.Framework (4.2.0.0)
Edits nested, typed AND/OR query rules with an optional expression preview.
- C#
- VB.NET
public class QueryBuilder : Control
Public Class QueryBuilder
Inherits Control
Fields use the reusable FilterField model. All accepted edits are validated on the server. The expression is a display DSL, not executable SQL. Translate the model to parameterized queries in application code. Root depth is zero; MaxDepth counts child levels.
Example:
var builder = new QueryBuilder { Dock = DockStyle.Fill };
builder.Fields.Add(new FilterField("CPU", "CPU", FilterFieldType.Number));
builder.Root.Rules.Add(new QueryRule("CPU", QueryOperator.GreaterThan, "80"));
builder.QueryChanged += (sender, e) => Console.WriteLine(builder.ToExpression());
Controls.Add(builder);
Constructors
QueryBuilder()
Creates an empty AND query with up to three nested group levels.
Properties
AddGroupText
String: Gets or sets the localized override for the "+ Group" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
AddRuleText
String: Gets or sets the localized override for the "+ Rule" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
AllText
String: Gets or sets the localized override for the "ALL" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
AnyText
String: Gets or sets the localized override for the "ANY" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
ComparisonAccessibleText
String: Gets or sets the localized override for the "Comparison" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
ContainsText
String: Gets or sets the localized override for the "contains" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
DefaultSize
Size: Returns the default size of the control.
Value: The default Size of the control.
EqualText
String: Gets or sets the localized override for the "is" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
FalseText
String: Gets or sets the localized override for the "false" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
FieldAccessibleText
String: Gets or sets the localized override for the "Field" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
Fields
FilterFieldCollection: Gets the shared field metadata. Removing a field used by a rule is rejected.
GroupConditionText
String: Gets or sets the localized override for the "of the following are true" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
IsEmptyText
String: Gets or sets the localized override for the "is empty" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
IsNotEmptyText
String: Gets or sets the localized override for the "is not empty" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
MaxDepth
Int32: Gets or sets the maximum child-group depth, from zero to sixteen. The root has depth zero. (Default: 3)
NestedGroupText
String: Gets or sets the localized override for the "nested group" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
NoRulesText
String: Gets or sets the localized override for the "No rules" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
NotEqualText
String: Gets or sets the localized override for the "is not" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
RemoveGroupText
String: Gets or sets the localized override for the "Remove group" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
RemoveRuleText
String: Gets or sets the localized override for the "Remove rule" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
Root
QueryGroup: Gets or sets the live query tree.
Attached edits notify automatically. Invalid assignments and edits are rolled back. A group or rule cannot be shared between trees or occur twice in a tree. Replacing Root raises RuleRemoved for old rules and RuleAdded for new rules before QueryChanged.
ShowPreview
Boolean: Gets or sets whether to display the read-only expression preview. (Default: True)
StartsWithText
String: Gets or sets the localized override for the "starts with" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
TrueText
String: Gets or sets the localized override for the "true" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation.
ValueAccessibleText
String: Gets or sets the localized override for the "{0} value" text. (Default: null)
The default is null, which selects the built-in translation for the current UI culture. The getter returns the configured override. An empty string suppresses the text without changing the operation. {0} is the field caption. Literal braces can be written as {{ and }}.
Methods
Dispose(disposing)
Disposes the control.
| Parameter | Type | Description |
|---|---|---|
| disposing | Boolean | true when this method is called by the application rather than a finalizer. |
FromJson(json)
Atomically replaces the query with a validated JSON tree.
| Parameter | Type | Description |
|---|---|---|
| json | String | JSON previously produced by ToJson, or the equivalent documented structure. |
Configure Fields before importing. Unknown fields, invalid operators and literals, extra properties, more than 512 nodes, and excess nesting are rejected. The existing query is preserved on failure. Payloads are limited to 1 MB of characters.
Example:
string savedQuery = builder.ToJson();
builder.FromJson(savedQuery);
OnQueryChanged(e)
Raises the QueryChanged event.
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs | Event data. |
OnRuleAdded(e)
Raises the RuleAdded event.
| Parameter | Type | Description |
|---|---|---|
| e | QueryRuleEventArgs | Event data. |
OnRuleRemoved(e)
Raises the RuleRemoved event.
| Parameter | Type | Description |
|---|---|---|
| e | QueryRuleEventArgs | Event data. |
OnWebEvent(e)
Dispatches client edit events to server validation.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs | Client event. |
OnWebRender(config)
Renders first-level widget properties and wires the edit event unconditionally.
| Parameter | Type | Description |
|---|---|---|
| config | Object | Client configuration. |
ToExpression()
Formats the query as a human-readable expression, omitting empty groups.
Returns: String. The display expression.
Field keys are bracketed with closing brackets escaped by doubling. Text, choice, and date literals are single-quoted with quotes doubled. Numeric and boolean literals are invariant. CONTAINS and STARTS WITH are display operators. An empty query returns an empty string. This is not a SQL, LINQ, or executable expression generator.
ToJson()
Serializes the rule tree using stable field keys and invariant string literals.
Returns: String. A JSON object with logic, rules, and groups arrays; metadata is not included.
Events
QueryChanged
EventHandler Occurs after an accepted query or field metadata change.
RuleAdded
EventHandler<QueryRuleEventArgs> Occurs for each rule entering the query, including rules in a newly added group.
RuleRemoved
EventHandler<QueryRuleEventArgs> Occurs for each rule leaving the query, including rules in a removed group.
Implements
| Name | Description |
|---|---|
| IUserData | Provides access to the UserData and Tag properties associated to the component implementing this interface. |
| IBindableComponent | Bindable components implement this interface. |
| IDropTarget | Controls that support drag & drop operations implement this interface. |
| IWisejComponent | All wisej components implement this interface. |
| IWisejControl | All wisej controls derived from the Control class must implement this interface. |
| IWisejSerializable | Allows an object to serialize itself. |