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 static bool TryCreateOrOpen(string filePath, TemplateDatabase templateDatabase, bool orderFilesByDate, CustomSelectionOperator customSelectionTermCombiningOperator, out FileDatabase fileDatabase) { // check for an existing database before instantiating the databse as SQL wrapper instantiation creates the database file bool populateDatabase = !File.Exists(filePath); fileDatabase = new FileDatabase(filePath); if (populateDatabase) { // initialize the database if it's newly created fileDatabase.OnDatabaseCreated(templateDatabase); } else { // if it's an existing database check if it needs updating to current structure and load data tables if (fileDatabase.OnExistingDatabaseOpened(templateDatabase) == false) { return false; } } // ensure all tables have been loaded from the database if (fileDatabase.ImageSet == null) { fileDatabase.GetImageSet(); } if (fileDatabase.Markers == null) { fileDatabase.GetMarkers(); } fileDatabase.CustomSelection = new CustomSelection(fileDatabase.Controls, customSelectionTermCombiningOperator); fileDatabase.OrderFilesByDateTime = orderFilesByDate; fileDatabase.PopulateDataLabelMaps(); return true; }