public CustomSelection(DataTableBackedList<ControlRow> templateTable, CustomSelectionOperator termCombiningOperator) { this.SearchTerms = new List<SearchTerm>(); this.TermCombiningOperator = termCombiningOperator; // generate search terms for all relevant controls in the template (in control order) foreach (ControlRow control in templateTable) { // skip hidden controls as they're not normally a part of the user experience // this is potentially problematic in corner cases; an option to show terms for all controls can be added if needed if (control.Visible == false) { continue; } // create search term for the control SearchTerm searchTerm = new SearchTerm(); searchTerm.ControlType = control.Type; searchTerm.DataLabel = control.DataLabel; searchTerm.DatabaseValue = control.DefaultValue; searchTerm.Operator = Constant.SearchTermOperator.Equal; searchTerm.Label = control.Label; searchTerm.List = control.GetChoices(); searchTerm.UseForSearching = false; this.SearchTerms.Add(searchTerm); switch (searchTerm.ControlType) { case Constant.Control.Counter: searchTerm.DatabaseValue = "0"; searchTerm.Operator = Constant.SearchTermOperator.GreaterThan; // Makes more sense that people will test for > as the default rather than counters break; case Constant.DatabaseColumn.DateTime: // the first time the CustomViewSelection dialog is popped CarnassialWindow calls SetDateTime() to changes the default date time to the date time // of the current image searchTerm.DatabaseValue = DateTimeHandler.ToDatabaseDateTimeString(Constant.ControlDefault.DateTimeValue); searchTerm.Operator = Constant.SearchTermOperator.GreaterThanOrEqual; // support querying on a range of datetimes by giving the user two search terms, one configured for the start of the interval and one // for the end SearchTerm dateTimeLessThanOrEqual = new SearchTerm(searchTerm); dateTimeLessThanOrEqual.Operator = Constant.SearchTermOperator.LessThanOrEqual; this.SearchTerms.Add(dateTimeLessThanOrEqual); break; case Constant.Control.Flag: searchTerm.DatabaseValue = Boolean.FalseString; break; case Constant.DatabaseColumn.UtcOffset: // the first time it's popped CustomViewSelection dialog changes this default to the date time of the current image searchTerm.SetDatabaseValue(Constant.ControlDefault.DateTimeValue.Offset); break; default: // default values above break; } } }
public SearchTerm(SearchTerm other) { this.ControlType = other.ControlType; this.DatabaseValue = other.DatabaseValue; this.DataLabel = other.DataLabel; this.Label = other.Label; if (other.List == null) { this.List = null; } else { this.List = new List<string>(other.List); } this.Operator = other.Operator; this.UseForSearching = other.UseForSearching; }