Ejemplo n.º 1
0
        protected virtual void OnCellArrayPasting(CellArrangePastingEventArgs e)
        {
            var handler = base.Events[TimeSheetGridView.EVENT_CELLARRAYPASTING] as EventHandler <CellArrangePastingEventArgs>;

            if (handler != null && !base.IsDisposed)
            {
                handler(this, e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pastes from clip board.
        /// </summary>
        public void PasteFromClipBoard(bool onlySelectedCells = true)
        {
            if (this.SelectedCells.Count > 0)
            {
                var clipboardDataObject = (DataObject)Clipboard.GetDataObject();
                if (clipboardDataObject.GetDataPresent(typeof(TimeSheetDayCopiedArray)))
                {
                    var clipboardTimeSheetDayArray = clipboardDataObject.GetData(typeof(TimeSheetDayCopiedArray)) as TimeSheetDayCopiedArray;
                    if (clipboardTimeSheetDayArray != null)
                    {
                        int minRow, minCol, maxRow, maxCol;
                        if (TimeSheetDayCopiedArray.FindArrayBound(this.SelectedCells,
                                                                   out minRow, out minCol, out maxRow, out maxCol))
                        {
                            // Before pasting a array cell, control needs to notify user to handle other business
                            var cellArrangePastingEventArgs = new CellArrangePastingEventArgs(clipboardTimeSheetDayArray, this.Rows[minRow].Cells[minCol]);
                            OnCellArrayPasting(cellArrangePastingEventArgs);

                            if (cellArrangePastingEventArgs.Cancel == true)
                            {
                                Debug.WriteLine("User has just canceled pasting action");
                                return;
                            }

                            // Only fill on selected cells
                            // Case 1: copied array is equal selected cells
                            // Case 2: copied array is inside selected cells
                            // Case 3: copied array is outside selected cells
                            int deltaRow, deltaCol;
                            if (onlySelectedCells)
                            {
                                deltaRow = maxRow - minRow + 1;
                                deltaCol = maxCol - minCol + 1;
                            }
                            else
                            {
                                // Only use a presented selected cell
                                // Case 1: enough range to fill from copied array
                                // Case 2: not enough range to fill from copied array

                                deltaRow = this.Rows.Count - minRow;
                                deltaCol = this.Columns.Count - minCol - this.ColumnHeaderCount;
                            }

                            // Get max bound
                            if (clipboardTimeSheetDayArray.MaxRow < deltaRow)
                            {
                                maxRow = minRow + clipboardTimeSheetDayArray.MaxRow;
                            }
                            if (clipboardTimeSheetDayArray.MaxCol < deltaCol)
                            {
                                maxCol = minCol + clipboardTimeSheetDayArray.MaxCol;
                            }

                            for (int i = minRow; i <= maxRow; i++)
                            {
                                for (int j = minCol; j <= maxCol; j++)
                                {
                                    var selectedCell = this.Rows[i].Cells[j];

                                    int rowIndex = i - minRow;
                                    int colIndex = j - minCol;

                                    // Check index inbound of copied array
                                    if (rowIndex < clipboardTimeSheetDayArray.MaxRow &&
                                        colIndex < clipboardTimeSheetDayArray.MaxCol)
                                    {
                                        var clipboardValue = clipboardTimeSheetDayArray[rowIndex, colIndex];

                                        var cellPastingEventArgs = new CellPastingEventArgs(selectedCell, clipboardValue);

                                        // Perform before cell is pasted
                                        OnCellPasting(cellPastingEventArgs);
                                        if (!cellPastingEventArgs.Cancel)
                                        {
                                            CopyAndPasteCell(selectedCell, clipboardValue);

                                            // Perform after cell is pasted
                                            OnCellPasted(new CellPastedEventArgs(selectedCell));
                                        }
                                    }// Check index inbound of copied array
                                }
                            }
                        }
                    }
                } // Clipboard present TimeSheetDayCopiedArray
            }     // Check SelectedCells
        }