Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
    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);
    }