TryAddSelectedVerticesToGroup ( Microsoft.Office.Interop.Excel.Workbook oWorkbook, Sheet2 oVertexWorksheet ) { Debug.Assert(oWorkbook != null); Debug.Assert(oVertexWorksheet != null); AddSelectedVerticesToGroupDialog oAddSelectedVerticesToGroupDialog = new AddSelectedVerticesToGroupDialog(oWorkbook); if (oAddSelectedVerticesToGroupDialog.ShowDialog() != DialogResult.OK) { return(false); } // First, remove the selected vertices from any groups they belong to. ListObject oGroupTable, oGroupVertexTable; ICollection <String> oSelectedVertexNames; if ( !TryRemoveSelectedVerticesFromGroups(oWorkbook, oVertexWorksheet, out oSelectedVertexNames) || !ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.Groups, TableNames.Groups, out oGroupTable) || !ExcelTableUtil.TryGetTable(oWorkbook, WorksheetNames.GroupVertices, TableNames.GroupVertices, out oGroupVertexTable) ) { return(false); } String sGroupName = oAddSelectedVerticesToGroupDialog.GroupName; if (oAddSelectedVerticesToGroupDialog.IsNewGroup) { // Add the new group to the group table. // // Note that the group table (and the group-vertex table, below) // needs to be activated before being written to. If this isn't // done, the formula written to the group-vertex table below also // mysteriously appears in the vertex table on the vertex // worksheet. // // It's up to the caller to use the ExcelActiveWorksheetRestorer // class to save and restore the active worksheet. ExcelUtil.ActivateWorksheet(oGroupTable); ExcelTableUtil.AddTableRow(oGroupTable, GroupTableColumnNames.Name, sGroupName ); SetVertexAttributesForAllGroups(oGroupTable); } // Add the selected vertices to the group-vertex table. ExcelUtil.ActivateWorksheet(oGroupVertexTable); foreach (String sSelectedVertexName in oSelectedVertexNames) { ExcelTableUtil.AddTableRow(oGroupVertexTable, GroupVertexTableColumnNames.GroupName, sGroupName, GroupVertexTableColumnNames.VertexName, sSelectedVertexName, GroupVertexTableColumnNames.VertexID, GetExcelFormulaForVertexID() ); } return(true); }
SetSettings ( String tableName, String columnName, Decimal selectedMinimum, Decimal selectedMaximum, out String selectedMinimumAddress, out String selectedMaximumAddress ) { Debug.Assert(!String.IsNullOrEmpty(tableName)); Debug.Assert(!String.IsNullOrEmpty(columnName)); Debug.Assert(selectedMaximum >= selectedMinimum); AssertValid(); CheckOpen(); selectedMinimumAddress = selectedMaximumAddress = null; SettingsForOneFilter oSettingsForOneFilter; String sDictionaryKey = GetDictionaryKey(tableName, columnName); Range oSelectedMinimumCell, oSelectedMaximumCell; if (m_oDynamicFilterSettingsDictionary.TryGetValue( sDictionaryKey, out oSettingsForOneFilter)) { // The settings are already in the table. Update the table row. Debug.Assert(m_oDynamicFilterSettingsTable.Parent is Worksheet); Worksheet oWorksheet = (Worksheet)m_oDynamicFilterSettingsTable.Parent; oSelectedMinimumCell = oWorksheet.get_Range( oSettingsForOneFilter.SelectedMinimumAddress, Missing.Value); oSelectedMinimumCell.set_Value(Missing.Value, selectedMinimum); oSelectedMaximumCell = oWorksheet.get_Range( oSettingsForOneFilter.SelectedMaximumAddress, Missing.Value); oSelectedMaximumCell.set_Value(Missing.Value, selectedMaximum); // Update the dictionary entry. oSettingsForOneFilter.SelectedMinimum = selectedMinimum; oSettingsForOneFilter.SelectedMaximum = selectedMaximum; } else { // The settings aren't in the table yet. Add a row to the table. Range oNewRowRange = ExcelTableUtil.AddTableRow( m_oDynamicFilterSettingsTable, DynamicFilterSettingsTableColumnNames.TableName, tableName, DynamicFilterSettingsTableColumnNames.ColumnName, columnName, DynamicFilterSettingsTableColumnNames.SelectedMinimum, selectedMinimum, DynamicFilterSettingsTableColumnNames.SelectedMaximum, selectedMaximum ); oSelectedMinimumCell = (Range)oNewRowRange.Cells[1, GetTableColumnIndex(m_oDynamicFilterSettingsTable, DynamicFilterSettingsTableColumnNames.SelectedMinimum, true)]; oSelectedMaximumCell = (Range)oNewRowRange.Cells[1, GetTableColumnIndex(m_oDynamicFilterSettingsTable, DynamicFilterSettingsTableColumnNames.SelectedMaximum, true)]; // Add a dictionary entry. oSettingsForOneFilter = new SettingsForOneFilter(); oSettingsForOneFilter.SelectedMinimum = selectedMinimum; oSettingsForOneFilter.SelectedMaximum = selectedMaximum; oSettingsForOneFilter.SelectedMinimumAddress = ExcelUtil.GetRangeAddressAbsolute(oSelectedMinimumCell); oSettingsForOneFilter.SelectedMaximumAddress = ExcelUtil.GetRangeAddressAbsolute(oSelectedMaximumCell); m_oDynamicFilterSettingsDictionary.Add(sDictionaryKey, oSettingsForOneFilter); } selectedMinimumAddress = oSettingsForOneFilter.SelectedMinimumAddress; selectedMaximumAddress = oSettingsForOneFilter.SelectedMaximumAddress; Debug.Assert(!String.IsNullOrEmpty(selectedMinimumAddress)); Debug.Assert(!String.IsNullOrEmpty(selectedMaximumAddress)); }