示例#1
0
 public Facede(Bll.Facede Application)
 {
     column = new Column(Application);
     corporationList = new CorporationList(Application);
     list = new List(Application);
     listColumn = new ListColumn(Application);
     listItem = new ListItem(Application);
     memberList = new MemberList(Application);
 }
        public override ListColumnCollection<ListObject> CreateColumns()
        {
            ListColumn<ListObject> listColumn = new ListColumn<ListObject>("Antivirus", new Converter<ListObject, string>(
                delegate(ListObject listObject)
                {
                    Debug.WriteLine("Getting listObject from ListColumn " + listObject.Id);
                    return GetDataFromYourCache(listObject.Id.ToString());
                }));

            ListColumnCollection<ListObject> columns = new ListColumnCollection<ListObject>();
            columns.Add(listColumn);
            return columns;
        }
示例#3
0
        TryGetTableColumn
        (
            ListObject table,
            String columnName,
            out ListColumn column
        )
        {
            Debug.Assert(table != null);
            Debug.Assert(!String.IsNullOrEmpty(columnName));

            column = null;

            try
            {
                column = table.ListColumns[columnName];

                return (true);
            }
            catch (COMException)
            {
                return (false);
            }
        }
    GetOrAddTableColumn
    (
        ListColumn oSourceColumn,
        ListObject oNewTable
    )
    {
        Debug.Assert(oSourceColumn != null);
        Debug.Assert(oNewTable != null);
        AssertValid();

        String sColumnName = oSourceColumn.Name;

        Range oSourceColumnData = oSourceColumn.DataBodyRange;
        Debug.Assert(oSourceColumnData != null);

        ListColumn oNewColumn;

        if (!ExcelTableUtil.TryGetOrAddTableColumn(oNewTable, sColumnName,
                (Double)oSourceColumnData.ColumnWidth, null,
                out oNewColumn) )
        {
            throw new ExportWorkbookException(
                "A column couldn't be added to the new workbook."
                );
        }

        Range oNewColumnData = oNewColumn.DataBodyRange;

        Debug.Assert(oNewColumnData != null);

        oNewColumnData.NumberFormat = oSourceColumnData.NumberFormat;

        return (oNewColumnData);
    }
        //*************************************************************************
        //  Method: MergeDuplicateEdges()
        //
        /// <summary>
        /// Merges duplicate edges in the edge worksheet given information about
        /// the edges.
        /// </summary>
        ///
        /// <param name="oEdgeTable">
        /// Edge table.
        /// </param>
        ///
        /// <param name="oVertex1NameData">
        /// Data range for the vertex 1 name column.
        /// </param>
        ///
        /// <param name="aoVertex1NameValues">
        /// Data values from the vertex 1 name column.
        /// </param>
        ///
        /// <param name="oVertex2NameData">
        /// Data range for the vertex 2 name column.
        /// </param>
        ///
        /// <param name="aoVertex2NameValues">
        /// Data values from the vertex 2 name column.
        /// </param>
        ///
        /// <param name="oEdgeWeightColumn">
        /// Edge weight column.
        /// </param>
        ///
        /// <param name="oEdgeWeightData">
        /// Data range for the edge weight column.
        /// </param>
        ///
        /// <param name="aoEdgeWeightValues">
        /// Data values from the edge weight column.
        /// </param>
        ///
        /// <param name="bGraphIsDirected">
        /// true if the graph is directed, false if it is undirected.
        /// </param>
        //*************************************************************************
        protected void MergeDuplicateEdges(
            ListObject oEdgeTable,
            Range oVertex1NameData,
            Object [,] aoVertex1NameValues,
            Range oVertex2NameData,
            Object [,] aoVertex2NameValues,
            ListColumn oEdgeWeightColumn,
            Range oEdgeWeightData,
            Object [,] aoEdgeWeightValues,
            Boolean bGraphIsDirected
            )
        {
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oVertex1NameData != null);
            Debug.Assert(aoVertex1NameValues != null);
            Debug.Assert(oVertex2NameData != null);
            Debug.Assert(aoVertex2NameValues != null);
            Debug.Assert(oEdgeWeightColumn != null);
            Debug.Assert(oEdgeWeightData != null);
            Debug.Assert(aoEdgeWeightValues != null);
            AssertValid();

            // This dictionary contains one key/value pair for each unique edge.
            // The key is a vertex name pair and the value is the one-based table
            // row number of the first instance of the edge.  If the edge worksheet
            // contains these rows, for example:
            //
            // 1  X,Y
            // 2  A,B
            // 3  A,B
            // 4  C,D
            // 5  A,B
            // 6  A,B
            //
            // then the dictionary will have three entries: one for X,Y, one for
            // A,B, and one for C,D.  The entry for X,Y will have a value of 1 (the
            // one-based table row number of the first instance of X,Y), the entry
            // for A,B will have a value of 2, and the entry for C,D will have a
            // value of 4.

            Dictionary<String, Int32> oUniqueEdges =
            new Dictionary<String, Int32>();

            // Loop through the table rows.

            Int32 iRows = oVertex1NameData.Rows.Count;

            for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++)
            {
            String sVertex1Name, sVertex2Name;

            if (
                !ExcelUtil.TryGetNonEmptyStringFromCell(aoVertex1NameValues,
                    iRowOneBased, 1, out sVertex1Name)
                ||
                !ExcelUtil.TryGetNonEmptyStringFromCell(aoVertex2NameValues,
                    iRowOneBased, 1, out sVertex2Name)
                )
            {
                continue;
            }

            // Does the row already have an edge weight?

            Double dInitialEdgeWeight = 1;

            Object oInitialEdgeWeight = aoEdgeWeightValues[iRowOneBased, 1];

            if (oInitialEdgeWeight != null && oInitialEdgeWeight is Double)
            {
                // Yes.

                dInitialEdgeWeight = (Double)oInitialEdgeWeight;
            }
            else
            {
                // No.  Set the initial edge weight.

                aoEdgeWeightValues[iRowOneBased, 1] = 1.0;
            }

            // Has an instance of this edge already been found?

            String sVertexNamePair = Edge.GetVertexNamePair(
                sVertex1Name, sVertex2Name, bGraphIsDirected);

            Int32 iFirstInstanceRowOneBased;

            if ( oUniqueEdges.TryGetValue(
                sVertexNamePair, out iFirstInstanceRowOneBased) )
            {
                // Yes.  This row will need to be deleted.  Mark it by nulling
                // its edge weight.

                aoEdgeWeightValues[iRowOneBased, 1] = null;

                // Update the edge weight for the row with the edge's first
                // instance.

                Debug.Assert(aoEdgeWeightValues[iFirstInstanceRowOneBased, 1]
                    is Double);

                aoEdgeWeightValues[iFirstInstanceRowOneBased, 1] =
                    (Double)aoEdgeWeightValues[iFirstInstanceRowOneBased, 1]
                    + dInitialEdgeWeight;
            }
            else
            {
                // No.  Add a dictionary entry.

                oUniqueEdges.Add(sVertexNamePair, iRowOneBased);
            }
            }

            // Save the updated edge weights to the table.

            oEdgeWeightData.set_Value(Missing.Value, aoEdgeWeightValues);

            // Delete the duplicate rows.

            DeleteDuplicateRows(oEdgeTable, oEdgeWeightColumn, oEdgeWeightData,
            aoEdgeWeightValues);
        }
示例#6
0
 private void ColumnRightClickEvent(ListColumn column)
 {
     ColumnRightClick?.Invoke(this, new ColumnClickEventArgs(column));
 }
示例#7
0
        //*************************************************************************
        //  Method: ColumnShouldBeExcluded()
        //
        /// <summary>
        /// Determines whether a table column should be excluded.
        /// </summary>
        ///
        /// <param name="oColumn">
        /// The table column to check.
        /// </param>
        ///
        /// <returns>
        /// true if the column should be excluded.
        /// </returns>
        //*************************************************************************
        private static Boolean ColumnShouldBeExcluded(
            ListColumn oColumn
            )
        {
            Debug.Assert(oColumn != null);

            switch (oColumn.Name)
            {
            case CommonTableColumnNames.ID:

                // It makes no sense to filter on the NodeXL-generated ID
                // column.

                return (true);

            default:

                break;
            }

            Range oColumnData = oColumn.DataBodyRange;

            // Exclude columns with no data or with an empty first data cell.

            if (
            oColumnData == null
            ||
            oColumnData.Rows.Count < 1
            ||
            !(oColumnData.Cells[1, 1] is Range)
            ||
            ( (Range)oColumnData.Cells[1, 1] ).get_Value(Missing.Value) == null
            )
            {
            return (true);
            }

            return (false);
        }
示例#8
0
        GetColumnFormat
        (
            ListColumn column
        )
        {
            Debug.Assert(column != null);

            Range oColumnData = column.DataBodyRange;

            Debug.Assert(oColumnData != null);
            Debug.Assert(oColumnData.Rows.Count > 0);

            // Look at the type of the value in the first cell.

            Debug.Assert(oColumnData.Cells[1, 1] is Range);

            Range oFirstDataCell = (Range)oColumnData.Cells[1, 1];
            Object oFirstDataCellValue = oFirstDataCell.get_Value(Missing.Value);

            Debug.Assert(oFirstDataCellValue != null);

            if (oFirstDataCellValue is DateTime)
            {
                if (CellContainsTime(oFirstDataCell))
                {
                    // Sample: 1/1/2008 3:40 pm.

                    return (ExcelColumnFormat.DateAndTime);
                }
                else
                {
                    // Sample: 1/1/2008.

                    return (ExcelColumnFormat.Date);
                }
            }
            else if (oFirstDataCellValue is Double)
            {
                // Cells formatted as a time are returned as Double.  Another test
                // is required to distinguish times from real Doubles.

                if (CellContainsTime(oFirstDataCell))
                {
                    // Sample: 3:40 pm.

                    return (ExcelColumnFormat.Time);
                }
                else
                {
                    // Sample: 123.

                    return (ExcelColumnFormat.Number);
                }
            }
            else
            {
                return (ExcelColumnFormat.Other);
            }
        }
示例#9
0
        TryAddTableColumnWithRowNumbers
        (
            ListObject table,
            String columnName,
            Double columnWidthChars,
            String columnStyle,
            out ListColumn listColumn
        )
        {
            Debug.Assert(table != null);
            Debug.Assert(!String.IsNullOrEmpty(columnName));

            Debug.Assert(columnWidthChars == AutoColumnWidth ||
                columnWidthChars >= 0);

            listColumn = null;

            if (!TryAddTableColumn(table, columnName, columnWidthChars,
                columnStyle, out listColumn))
            {
                return (false);
            }

            Range oDataBodyRange = listColumn.DataBodyRange;

            if (oDataBodyRange != null)
            {
                // Fill the column with a ROW() formulas.

                oDataBodyRange.set_Value(Missing.Value, "=ROW()");

                // Convert the formulas to static values.

                oDataBodyRange.Copy(Missing.Value);

                PasteValues(oDataBodyRange);
            }

            return (true);
        }
        /// <summary>
        /// Invoked when an unhandled MouseUp routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. The event data reports that the mouse button was released.</param>
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (_resizingColunn != null)
            {
                _resizingColunn = null;
                Mouse.Capture(null);
                e.Handled = true;
                return;
            }

            base.OnMouseUp(e);
        }
        /// <summary>
        /// Invoked when an unhandled MouseDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.</param>
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var position = e.GetPosition(this);

            foreach (var resizeArea in _resizeAreas)
                if (resizeArea.HotArea.Contains(position))
                {
                    Mouse.Capture(this);
                    _resizingColunn = resizeArea.Column;
                    _originalResizeWidth = _resizingColunn.Width.Value;
                    _originalResizeX = position.X;
                    e.Handled = true;
                    return;
                }

            base.OnMouseDown(e);
        }
    GetAttributeColumn
    (
        ListObject oTable,
        String sAttribute,
        out ListColumn oAttributeColumn,
        out Range oAttributeColumnData
    )
    {
        Debug.Assert(oTable != null);
        Debug.Assert( !String.IsNullOrEmpty(sAttribute) );

        if ( !ExcelTableUtil.TryGetTableColumn(oTable, sAttribute,
            out oAttributeColumn) )
        {
            if ( !ExcelTableUtil.TryAddTableColumn(oTable, sAttribute,
                ExcelTableUtil.AutoColumnWidth, null, out oAttributeColumn) )
            {
                goto CannotGetColumn;
            }

            // Wrap the text in the new column's header.

            ExcelTableUtil.WrapTableColumnHeader(oAttributeColumn);

            // This sometimes wraps a single-word header.  Fix it.

            oAttributeColumn.Range.EntireColumn.AutoFit();
        }

        if ( ExcelTableUtil.TryGetTableColumnData(oAttributeColumn,
            out oAttributeColumnData) )
        {
            // Success.

            return;
        }

        CannotGetColumn:

        throw new WorkbookFormatException(
            "The " + sAttribute + " column couldn't be added."
            );
    }
 /// <summary>
 /// Updates the width of the supplied column.
 /// <remarks>Call when changing the ColumnCell text, CellPadding, or text font.</remarks>
 /// </summary>
 /// <param name="col">The RollColumn object to update.</param>
 /// <returns>The new width of the RollColumn object.</returns>
 private int UpdateWidth(ListColumn col)
 {
     col.Width = (col.Text.Length * _charSize.Width) + (CellWidthPadding * 4);
     return(col.Width.Value);
 }
示例#14
0
        GetColumnPairNames
        (
            ListObject table,
            String column1NameBase,
            String column2NameBase
        )
        {
            Debug.Assert(table != null);
            AssertValid();

            List <KeyValuePair <String, String> > oColumnPairNames =
                new List <KeyValuePair <String, String> >();

            Regex oRegex = GetColumnNameRegex(column1NameBase);

            // Loop through all the columns looking for a column name based on
            // column1NameBase.  If such a column is found, look for the
            // corresponding column name based on column2NameBase.

            foreach (ListColumn oColumn1 in table.ListColumns)
            {
                String sColumn1Name = oColumn1.Name;

                ListColumn oColumn2 = null;

                if (String.IsNullOrEmpty(sColumn1Name))
                {
                    continue;
                }

                // Look for an exact match.

                if (sColumn1Name == column1NameBase)
                {
                    // Found column 1.  Look for column 2.

                    if (!ExcelTableUtil.TryGetTableColumn(table, column2NameBase,
                                                          out oColumn2))
                    {
                        oColumn2 = null;
                    }
                }
                else
                {
                    // Look for a "starts with" match.

                    Match oMatch = oRegex.Match(sColumn1Name);

                    Int32 iAppendedNumber;

                    if (
                        oMatch.Success
                        &&
                        Int32.TryParse(
                            oMatch.Groups[AppendedNumberGroupName].Value,
                            out iAppendedNumber)
                        )
                    {
                        // Found column 1.  Look for column 2.

                        if (!ExcelTableUtil.TryGetTableColumn(table,
                                                              column2NameBase + " " + iAppendedNumber.ToString(),
                                                              out oColumn2))
                        {
                            oColumn2 = null;
                        }
                    }
                }

                if (oColumn2 != null)
                {
                    oColumnPairNames.Add(new KeyValuePair <String, String>(
                                             oColumn1.Name, oColumn2.Name));
                }
            }

            return(oColumnPairNames);
        }
示例#15
0
        TryGetOrAddTableColumn
        (
            ListObject table,
            String columnName,
            Double columnWidthChars,
            String columnStyle,
            out ListColumn listColumn
        )
        {
            Debug.Assert(table != null);
            Debug.Assert(!String.IsNullOrEmpty(columnName));

            Debug.Assert(columnWidthChars == AutoColumnWidth ||
                columnWidthChars >= 0);

            return (
                TryGetTableColumn(table, columnName, out listColumn)
                ||
                TryAddTableColumn(table, columnName, columnWidthChars, columnStyle,
                    out listColumn)
                );
        }
        /// <summary>
        /// Renders the header for an individual column
        /// </summary>
        /// <param name="dc">Drawing context</param>
        /// <param name="column">Column</param>
        /// <param name="columnClientRect">The suggested area for the header</param>
        protected virtual void RenderColumnHeader(DrawingContext dc, ListColumn column, Rect columnClientRect)
        {
            dc.DrawLine(GetGridLinePen(), new Point(columnClientRect.Right - .5d, 0d), new Point(columnClientRect.Right - .5d, ActualHeight));

            if (column.IsResizable)
                _resizeAreas.Add(new ResizeAreaWrapper {Column = column, HotArea = new Rect(columnClientRect.Right - 2, columnClientRect.Top, 5, columnClientRect.Height)});

            var header = column.Header.ToString();
            if (!string.IsNullOrEmpty(header) && columnClientRect.Width > 8)
            {
                var ft = new FormattedText(header, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(FontFamily, FontStyle, FontWeight, FontStretches.Normal), FontSize, Foreground) {TextAlignment = column.HeaderTextAlignment, MaxLineCount = 1, MaxTextWidth = columnClientRect.Width - 6, Trimming = TextTrimming.CharacterEllipsis};
                var topOffset = Math.Max((double)(int)(columnClientRect.Height - ft.Height)/2, 0d);
                dc.DrawText(ft, new Point(columnClientRect.X + 3, columnClientRect.Y + topOffset));
            }
        }
示例#17
0
        TryGetTableColumnData
        (
            ListColumn column,
            out Range tableColumnData
        )
        {
            Debug.Assert(column != null);

            tableColumnData = null;

            Debug.Assert(column.Parent is ListObject);

            ListObject oTable = (ListObject)column.Parent;

            Range oDataBodyRange = oTable.DataBodyRange;

            if (oDataBodyRange == null)
            {
                // This happens when the user deletes the first data row of a one-
                // row table.  It looks like an empty row is there, but the
                // DataBodyRange is actually null.

                Int32 iRow;

                // Is there a header row?

                Range oRangeToUse = oTable.HeaderRowRange;

                if (oRangeToUse != null)
                {
                    // Yes.  Use the row after the header row.

                    iRow = oRangeToUse.Row + 1;
                }
                else
                {
                    // No.  Use the first row of the table.

                    oRangeToUse = oTable.Range;

                    iRow = oRangeToUse.Row;
                }

                Debug.Assert(oTable.Parent is Worksheet);

                Worksheet oWorksheet = (Worksheet)oTable.Parent;

                oDataBodyRange = oWorksheet.get_Range(

                    oWorksheet.Cells[iRow, oRangeToUse.Column],

                    oWorksheet.Cells[iRow,
                        oRangeToUse.Column + oRangeToUse.Columns.Count - 1]
                    );
            }

            return (ExcelUtil.TryIntersectRanges(oDataBodyRange, column.Range,
                out tableColumnData));
        }
    MarkRowsForDeletion
    (
        ListObject oEdgeTable,
        Object [,] aoVertex1NameValues,
        Object [,] aoVertex2NameValues,
        Object [,] aoThirdColumnValues,
        Boolean bGraphIsDirected,
        out ListColumn oDeleteIfEmptyColumn,
        out Range oDeleteIfEmptyData,
        out Object [,] aoDeleteIfEmptyValues
    )
    {
        Debug.Assert(oEdgeTable != null);
        Debug.Assert(aoVertex1NameValues != null);
        Debug.Assert(aoVertex2NameValues != null);
        AssertValid();

        HashSet<String> oUniqueEdgeKeys = new HashSet<String>();

        if ( !ExcelTableUtil.TryGetOrAddTableColumn(oEdgeTable,
            DeleteIfEmptyColumnName, ExcelTableUtil.AutoColumnWidth, null,
            out oDeleteIfEmptyColumn, out oDeleteIfEmptyData,
            out aoDeleteIfEmptyValues) )
        {
            throw new InvalidOperationException(
                "Can't add marked for deletion column.");
        }

        Int32 iRows = GetRowCount(aoVertex1NameValues);

        for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++)
        {
            String sEdgeKey;
            Object oDeleteIfEmpty = 1;

            if (
                TryGetEdgeKey(iRowOneBased, aoVertex1NameValues,
                    aoVertex2NameValues, aoThirdColumnValues, bGraphIsDirected,
                    out sEdgeKey)
                &&
                !oUniqueEdgeKeys.Add(sEdgeKey)
                )
            {
                // This is a duplicate that is not the first instance.  It
                // should be deleted.

                oDeleteIfEmpty = null;
            }

            aoDeleteIfEmptyValues[iRowOneBased, 1] = oDeleteIfEmpty;
        }

        oDeleteIfEmptyData.set_Value(Missing.Value, aoDeleteIfEmptyValues);
    }
示例#19
0
        TryInsertTableColumn
        (
            ListObject table,
            String columnName,
            Int32 oneBasedColumnIndex,
            Double columnWidthChars,
            String columnStyle,
            out ListColumn listColumn
        )
        {
            Debug.Assert(table != null);
            Debug.Assert(!String.IsNullOrEmpty(columnName));
            Debug.Assert(oneBasedColumnIndex >= 1);

            Debug.Assert(columnWidthChars == AutoColumnWidth ||
                columnWidthChars >= 0);

            return (TryAddOrInsertTableColumn(table, columnName,
                oneBasedColumnIndex, columnWidthChars, columnStyle,
                out listColumn));
        }
    ShowOrHideColumn
    (
        ListColumn column,
        Boolean show
    )
    {
        Debug.Assert(column != null);

        Range oEntireColumn = column.Range.EntireColumn;
        Boolean bColumnWasVisible = !(Boolean)oEntireColumn.Hidden;

        if (bColumnWasVisible != show)
        {
            oEntireColumn.Hidden = !show;
        }

        return (bColumnWasVisible);
    }
示例#21
0
        TryAddOrInsertTableColumn
        (
            ListObject table,
            String columnName,
            Int32 oneBasedColumnIndex,
            Double columnWidthChars,
            String columnStyle,
            out ListColumn listColumn
        )
        {
            Debug.Assert(table != null);
            Debug.Assert(!String.IsNullOrEmpty(columnName));
            Debug.Assert(oneBasedColumnIndex == -1 || oneBasedColumnIndex >= 1);

            Debug.Assert(columnWidthChars == AutoColumnWidth ||
                columnWidthChars >= 0);

            listColumn = null;

            Object oPosition;
            ListColumns oColumns = table.ListColumns;
            Int32 iColumns = oColumns.Count;
            Double[] adColumnWidthChars = null;

            if (oneBasedColumnIndex == -1)
            {
                oPosition = Missing.Value;
            }
            else
            {
                oPosition = oneBasedColumnIndex;

                // When inserting a column, Excel messes up the widths of the
                // columns after the insertion point.  Save the widths of those
                // columns.

                if (oneBasedColumnIndex <= iColumns)
                {
                    adColumnWidthChars =
                        new Double[iColumns - oneBasedColumnIndex + 1];

                    for (Int32 iOneBasedIndex = oneBasedColumnIndex;
                        iOneBasedIndex <= iColumns; iOneBasedIndex++)
                    {
                        adColumnWidthChars[iOneBasedIndex - oneBasedColumnIndex] =
                            (Double)oColumns[iOneBasedIndex].Range.ColumnWidth;
                    }
                }
            }

            try
            {
                listColumn = oColumns.Add(oPosition);
            }
            catch (COMException oCOMException)
            {
                if (oCOMException.ErrorCode == -2146827284)
                {
                    // This can happen, for example, if adding a table column
                    // would cause a merged cells to unmerge, the user is asked
                    // if he wants to allow the unmerge, and he says no.

                    return (false);
                }

                throw;
            }

            // Set various properties on the new column.

            listColumn.Name = columnName;

            Range oColumnRange = listColumn.Range;

            if (columnWidthChars == AutoColumnWidth)
            {
                oColumnRange.EntireColumn.AutoFit();
            }
            else
            {
                oColumnRange.ColumnWidth = columnWidthChars;
            }

            oColumnRange.Validation.Delete();

            SetRangeStyle(oColumnRange, columnStyle);

            if (adColumnWidthChars != null)
            {
                // Restore the widths of the columns after the insertion point.

                for (Int32 iOneBasedIndex = oneBasedColumnIndex;
                    iOneBasedIndex <= iColumns; iOneBasedIndex++)
                {
                    oColumns[iOneBasedIndex + 1].Range.ColumnWidth =
                        adColumnWidthChars[iOneBasedIndex - oneBasedColumnIndex];
                }
            }

            return (true);
        }
示例#22
0
        //*************************************************************************
        //  Method: DeleteDuplicateRows()
        //
        /// <summary>
        /// Deletes the duplicate rows from the edge table.
        /// </summary>
        ///
        /// <param name="oEdgeTable">
        /// Edge table.
        /// </param>
        ///
        /// <param name="oEdgeWeightColumn">
        /// Edge weight column.
        /// </param>
        ///
        /// <param name="oEdgeWeightData">
        /// Data range for the edge weight column.
        /// </param>
        ///
        /// <param name="aoEdgeWeightValues">
        /// Data values from the edge weight column.
        /// </param>
        ///
        /// <remarks>
        /// All rows for which the edge weight cell is null are deleted.
        /// </remarks>
        //*************************************************************************
        protected void DeleteDuplicateRows(
            ListObject oEdgeTable,
            ListColumn oEdgeWeightColumn,
            Range oEdgeWeightData,
            Object [,] aoEdgeWeightValues
            )
        {
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oEdgeWeightColumn != null);
            Debug.Assert(oEdgeWeightData != null);
            Debug.Assert(aoEdgeWeightValues != null);
            AssertValid();

            Range oDuplicateRows = null;

            // Find the rows with null edge weights, which are the duplicates.  To
            // avoid multiple areas, which can slow things down signficantly, sort
            // the table on the edge weight column.  That forces the duplicates
            // to be contiguous.
            //
            // But first, add a temporary column and set its values to the
            // worksheet row numbers.  This will be used later to restore the
            // original sort order.

            ListColumn oTemporaryColumn;

            if ( !ExcelUtil.TryAddTableColumnWithRowNumbers(oEdgeTable,
            "Temporary for Sort", 5F, null, out oTemporaryColumn) )
            {
            return;
            }

            Sort oSort = oEdgeTable.Sort;
            SortFields oSortFields = oSort.SortFields;
            oSortFields.Clear();

            oSortFields.Add(oEdgeWeightColumn.Range, XlSortOn.xlSortOnValues,
            XlSortOrder.xlAscending, Missing.Value,
            XlSortDataOption.xlSortNormal);

            oSort.Apply();

            if (oEdgeWeightData.Rows.Count != 1)
            {
            try
            {
                oDuplicateRows = oEdgeWeightData.SpecialCells(
                    XlCellType.xlCellTypeBlanks, Missing.Value);
            }
            catch (COMException)
            {
                // There are no such rows.

                oDuplicateRows = null;
            }
            }
            else
            {
            // Range.SpecialCells() can't be used in the one-cell case, for
            // which it behaves in a bizarre manner.  See this posting:
            //
            // http://ewbi.blogs.com/develops/2006/03/determine_if_a_.html
            //
            // ...of which this is an excerpt:
            //
            // "SpecialCells ignores any source Range consisting of only one
            // cell. When executing SpecialCells on a Range having only one
            // cell, it will instead consider all of the cells falling within
            // the boundary marked by the bottom right cell of the source Range
            // sheet's UsedRange."
            //
            // Instead, just check the single row.

            if (aoEdgeWeightValues[1, 1] == null)
            {
                oDuplicateRows = oEdgeWeightData.EntireRow;
            }
            }

            if (oDuplicateRows != null)
            {
            // Delete the duplicate rows, which are contiguous.

            Debug.Assert(oDuplicateRows.Areas.Count == 1);

            oDuplicateRows.EntireRow.Delete(XlDeleteShiftDirection.xlShiftUp);
            }

            // Restore the original sort order by sorting on the temporary column
            // that contains the original worksheet row numbers.

            Debug.Assert(oTemporaryColumn != null);

            oSortFields.Clear();

            oSortFields.Add(oTemporaryColumn.Range, XlSortOn.xlSortOnValues,
            XlSortOrder.xlAscending, Missing.Value,
            XlSortDataOption.xlSortNormal);

            oSort.Apply();
            oSortFields.Clear();

            oTemporaryColumn.Delete();

            oSort.Apply();
        }
示例#23
0
        //*************************************************************************
        //  Method: TryGetNumericRange()
        //
        /// <summary>
        /// Attempts to get the range of values in a numeric column.
        /// </summary>
        ///
        /// <param name="sWorksheetName">
        /// Name of the worksheet containing the table.
        /// </param>
        ///
        /// <param name="oColumn">
        /// The numeric column.
        /// </param>
        ///
        /// <param name="dMinimumCellValue">
        /// Where the minimum value in the column gets stored if true is returned.
        /// </param>
        ///
        /// <param name="dMaximumCellValue">
        /// Where the maximum value in the column gets stored if true is returned.
        /// </param>
        ///
        /// <returns>
        /// true if the column contains a range of numeric values.
        /// </returns>
        //*************************************************************************
        private static Boolean TryGetNumericRange(
            String sWorksheetName,
            ListColumn oColumn,
            out Double dMinimumCellValue,
            out Double dMaximumCellValue
            )
        {
            Debug.Assert( !String.IsNullOrEmpty(sWorksheetName) );
            Debug.Assert(oColumn != null);
            Debug.Assert(oColumn.DataBodyRange != null);

            dMinimumCellValue = dMaximumCellValue = Double.MinValue;

            Application oApplication = oColumn.Application;

            String sFunctionCall = String.Format(

            "=MIN({0}!{1})"
            ,
            sWorksheetName,
            ExcelUtil.GetRangeAddress(oColumn.DataBodyRange)
            );

            if ( !ExcelUtil.TryEvaluateDoubleFunction(oApplication, sFunctionCall,
            out dMinimumCellValue) )
            {
            return (false);
            }

            sFunctionCall = sFunctionCall.Replace("MIN", "MAX");

            if ( !ExcelUtil.TryEvaluateDoubleFunction(oApplication, sFunctionCall,
            out dMaximumCellValue) )
            {
            return (false);
            }

            return (dMaximumCellValue > dMinimumCellValue);
        }
        private Grid GetContentGridForColumn(ListColumn column)
        {
            var grid = new Grid {
                VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, IsHitTestVisible = true, Background = Brushes.Transparent, ClipToBounds = true
            };

            var paddingOffset = new Thickness();

            if (column.CellPadding.Left > 0d || column.CellPadding.Top > 0d || column.CellPadding.Right > 0d || column.CellPadding.Bottom > 0d)
            {
                paddingOffset = new Thickness(column.CellPadding.Left * -1, column.CellPadding.Top * -1, column.CellPadding.Right * -1, column.CellPadding.Bottom * -1);
                grid.Margin   = new Thickness(column.CellPadding.Left, column.CellPadding.Top, column.CellPadding.Right, column.CellPadding.Bottom);
            }

            if (column.CellBackground != null)
            {
                if (column.CellBackgroundOpacity < 1d)
                {
                    grid.Children.Add(new Rectangle
                    {
                        VerticalAlignment   = VerticalAlignment.Stretch,
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        Fill    = column.CellBackground,
                        Opacity = column.CellBackgroundOpacity,
                        Width   = double.NaN,
                        Height  = double.NaN,
                        Margin  = paddingOffset
                    });
                }
                else
                {
                    grid.Background = column.CellBackground;
                }
            }
            else if (!string.IsNullOrEmpty(column.CellBackgroundBindingPath))
            {
                var backgroundBinding = new Binding(column.CellBackgroundBindingPath);
                if (column.CellBackgroundOpacity < 1d)
                {
                    var rect = new Rectangle
                    {
                        VerticalAlignment   = VerticalAlignment.Stretch,
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        Fill    = column.CellBackground,
                        Opacity = column.CellBackgroundOpacity,
                        Width   = double.NaN,
                        Height  = double.NaN,
                        Margin  = paddingOffset
                    };
                    rect.SetBinding(Shape.FillProperty, backgroundBinding);
                    grid.Children.Add(rect);
                }
                else
                {
                    grid.SetBinding(BackgroundProperty, backgroundBinding);
                    grid.Background = column.CellBackground;
                }
            }

            if (Columns.ShowGridLines != ListGridLineMode.Never)
            {
                var cellLines = new Border
                {
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    BorderThickness     = new Thickness(0, 0, 1, 1),
                    BorderBrush         = column.GridLineBrush,
                    Background          = null,
                    Visibility          = Visibility.Collapsed,
                    IsHitTestVisible    = false,
                    Margin = paddingOffset
                };
                SetZIndex(cellLines, 10000);
                if (Columns.ShowGridLines == ListGridLineMode.Always)
                {
                    cellLines.Visibility = Visibility.Visible;
                }
                if (Columns.ShowGridLines == ListGridLineMode.EditOnly)
                {
                    EditModeChanged += (s, e) => { cellLines.Visibility = IsManualEditEnabled ? Visibility.Visible : Visibility.Collapsed; }
                }
                ;
                grid.Children.Add(cellLines);
            }

            if (!double.IsNaN(column.CellContentWidth))
            {
                grid.Width = column.CellContentWidth;
            }
            if (!double.IsNaN(column.CellContentHeight))
            {
                grid.Height = column.CellContentHeight;
            }

            return(grid);
        }