public void SetUp(IActivateItems activator, IAggregateBuilderOptions options, AggregateConfiguration aggregate) { //record new states so we don't accidentally erase names of stuff SetItemActivator(activator); _options = options; _countColumnRequirement = _options.GetCountColumnRequirement(aggregate); _aggregate = aggregate; _availableColumns.Clear(); _includedColumns.Clear(); olvSelectColumns.ClearObjects(); _availableColumns.AddRange(_options.GetAvailableSELECTColumns(_aggregate)); _includedColumns.AddRange(_aggregate.AggregateDimensions); //add count option unless it cannot have one if (_options.GetCountColumnRequirement(_aggregate) != CountColumnRequirement.CannotHaveOne) { AggregateCountColumn countCol; if (!string.IsNullOrEmpty(_aggregate.CountSQL)) { countCol = new AggregateCountColumn(_aggregate.CountSQL); _includedColumns.Add(countCol); } else { countCol = new AggregateCountColumn("count(*) as CountColumn"); _availableColumns.Add(countCol); } countCol.SetQuerySyntaxHelper(_querySyntaxHelper, true); } olvSelectColumns.AddObjects(_includedColumns); olvSelectColumns.AddObjects(_availableColumns); }
void olvSelectColumns_CellClick(object sender, CellClickEventArgs e) { if (e.Column == olvAddRemove) { var countColumn = e.Model as AggregateCountColumn; var importableColumn = e.Model as ExtractionInformation; var dimensionColumn = e.Model as AggregateDimension; if (countColumn == null && importableColumn == null && dimensionColumn == null) { throw new Exception("Object in list view of type that wasn't IColumn, it was " + e.Model.GetType().Name); } //if it is an add if (_availableColumns.Contains(e.Model)) { //count column added if (countColumn != null) { if (_options.GetCountColumnRequirement(_aggregate) == CountColumnRequirement.CannotHaveOne) { WideMessageBox.Show("Cohort Sets cannot have count columns", "A count column is a SELECT column with an aggregate function (count(*), sum(x) etc). The SELECT component for cohort identification must be the patient id column only."); } else { Save(countColumn); } } //regular column added if (importableColumn != null) { var dimension = new AggregateDimension(Activator.RepositoryLocator.CatalogueRepository, importableColumn, _aggregate); _availableColumns.Remove(importableColumn); _includedColumns.Add(dimension); olvSelectColumns.RemoveObject(importableColumn); olvSelectColumns.AddObject(dimension); olvSelectColumns.EnsureModelVisible(dimension); Save(dimension); //object doesn't exist, that might cause problems return; } } else { //it is a removal //user is trying to remove count column if (countColumn != null) { if (_options.GetCountColumnRequirement(_aggregate) == CountColumnRequirement.MustHaveOne) { return; //leave it checked - removal is forbidden } _aggregate.CountSQL = ""; _aggregate.SaveToDatabase(); _includedColumns.Remove(countColumn); _availableColumns.Add(countColumn); olvSelectColumns.RemoveObject(countColumn); olvSelectColumns.AddObject(countColumn); olvSelectColumns.EnsureModelVisible(countColumn); Activator.RefreshBus.Publish(this, new RefreshObjectEventArgs(_aggregate)); } //user is trying to remove a dimension if (dimensionColumn != null) { dimensionColumn.DeleteInDatabase(); //get the master it was based on var extractionInformation = dimensionColumn.ExtractionInformation; try { dimensionColumn.DeleteInDatabase(); } catch (Exception ex) { //couldn't delete it so don't update the UI just tell the user why ExceptionViewer.Show(ex); return; } //remove it from the inclusion list _includedColumns.Remove(dimensionColumn); olvSelectColumns.RemoveObject(dimensionColumn); //add the master importable version it was based on into available columns again _availableColumns.Add(extractionInformation); olvSelectColumns.AddObject(extractionInformation); Save(extractionInformation); } } } }