Ejemplo n.º 1
0
        /// <summary>
        /// Fires when Spreadsheet Cells are Changed
        /// </summary>
        /// <param name="sender">Spreadsheet Class</param>
        /// <param name="e">Event arguments</param>
        private void UpdateFormUI(object sender, PropertyChangedEventArgs e)
        {
            // Update the Cell Values at UI Level
            if (e.PropertyName == "CellChanged")
            {
                CptS321.SpreadsheetCell cellChanged = sender as CptS321.SpreadsheetCell;

                this.dataGridView.Rows[(int)cellChanged.RowIndex].Cells[(int)cellChanged.ColumnIndex].Value = cellChanged.CellValue;
            }
            // Update the Cell Colors at UI Level
            else if (e.PropertyName == "BGColorChanged")
            {
                CptS321.SpreadsheetCell cellChanged = sender as CptS321.SpreadsheetCell;

                if (cellChanged != null)
                {
                    uint cellRow    = cellChanged.RowIndex;
                    uint cellColumn = cellChanged.ColumnIndex;

                    uint cellColor             = cellChanged.BGColor;
                    System.Drawing.Color color = System.Drawing.Color.FromArgb((int)cellColor);

                    dataGridView.Rows[(int)cellRow].Cells[(int)cellColumn].Style.BackColor = color;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fires when User Starts Editing Cells in Data Grid
        /// </summary>
        /// <param name="sender">UI Data Grid View</param>
        /// <param name="e">Event arguments</param>
        private void dataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            uint cellRow    = (uint)e.RowIndex;
            uint cellColumn = (uint)e.ColumnIndex;

            CptS321.SpreadsheetCell cellToUpdate = this.spreadsheet.GetCell(cellRow, cellColumn);

            if (cellToUpdate != null)
            {
                this.dataGridView.Rows[(int)cellRow].Cells[(int)cellColumn].Value = cellToUpdate.CellText;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fires when Cell Editing Finished
        /// </summary>
        /// <param name="sender">UI Data Grid</param>
        /// <param name="e">Event arguments</param>
        private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            // Get Cell Index
            uint cellRow    = (uint)e.RowIndex;
            uint cellColumn = (uint)e.ColumnIndex;

            // Get Cell Instance
            CptS321.SpreadsheetCell cellToUpdate = this.spreadsheet.GetCell(cellRow, cellColumn);
            string oldText = cellToUpdate.CellText;

            // If Valid Cell
            if (cellToUpdate != null)
            {
                try
                {
                    // Update Cell Text at Index with new Value
                    cellToUpdate.CellText = this.dataGridView.Rows[(int)cellRow].Cells[(int)cellColumn].Value.ToString();
                }
                catch (NullReferenceException)
                {
                    // Catch Empty Values and set as Empty
                    cellToUpdate.CellText = string.Empty;
                }

                // Update Grid View
                if (cellToUpdate.CellText != string.Empty)
                {
                    this.dataGridView.Rows[(int)cellRow].Cells[(int)cellColumn].Value.ToString();
                }

                // Create Undo Command for Text Change and add to List
                List <SpreadsheetEngine.ICommand> textUndoCommand = new List <SpreadsheetEngine.ICommand>();
                textUndoCommand.Add(new SpreadsheetEngine.RestoreTextCommand(cellToUpdate, oldText, cellToUpdate.CellText));

                // Add the Undo Command List to the Undo Stack
                this.spreadsheet.AddUndo(textUndoCommand);

                // Enable the Undo Button for the Created Command
                this.undoToolStripMenuItem.Enabled = true;

                // Clear any Pending Redo's Since a new Command was Pushed
                this.spreadsheet.ClearRedoStack();
            }

            // Update Menu Text
            UpdateToolStripMenu();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fires when Cell Demo Button Clicked
        /// </summary>
        /// <param name="sender">Demo Button</param>
        /// <param name="e">Event arguments</param>
        private void demoButton_Click(object sender, EventArgs e)
        {
            Random RNGenerator = new Random();

            for (uint i = 0; i < 50; ++i)
            {
                uint randomRow    = Convert.ToUInt32(RNGenerator.Next(0, 50));
                uint randomColumn = Convert.ToUInt32(RNGenerator.Next(0, 26));

                CptS321.SpreadsheetCell randomCell = this.spreadsheet.GetCell(randomRow, randomColumn);
                randomCell.CellText = "C++ or C#?";
            }

            for (uint i = 0; i < 50; ++i)
            {
                this.spreadsheet.GetCell(i, 1).CellText = "This is Cell B" + (i + 1);
                this.spreadsheet.GetCell(i, 0).CellText = "=B" + (i + 1);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fires when Background Color Clicked
        /// </summary>
        /// <param name="sender">UI Color Menu</param>
        /// <param name="e">Event arguments</param>
        private void BackgroundColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Open Color Dialog box for user to select a new color
            ColorDialog colorDialog = new ColorDialog();

            // Store a list of commands for undo / redo
            List <SpreadsheetEngine.ICommand> restoreBGColorCommands = new List <SpreadsheetEngine.ICommand>();

            // When the user selects a new color
            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                // Iterate through each of the selected cells
                foreach (DataGridViewCell cell in dataGridView.SelectedCells)
                {
                    // Covert to spreadsheetCell location
                    CptS321.SpreadsheetCell spreadsheetCell = spreadsheet.GetCell((uint)cell.RowIndex, (uint)cell.ColumnIndex);
                    uint oldColor = spreadsheetCell.BGColor;
                    uint newColor = (uint)colorDialog.Color.ToArgb();
                    spreadsheetCell.BGColor = newColor;

                    // Create the undo command
                    SpreadsheetEngine.RestoreBGColorCommand restoreColor = new SpreadsheetEngine.RestoreBGColorCommand(spreadsheetCell, oldColor, newColor);
                    restoreBGColorCommands.Add(restoreColor);
                }

                // Add command list to the stack
                spreadsheet.AddUndo(restoreBGColorCommands);
                this.undoToolStripMenuItem.Enabled = true;

                // Check redo stack, clear if not already empty
                if (!this.spreadsheet.RedoStackIsEmpty())
                {
                    this.spreadsheet.ClearRedoStack();
                }
            }

            // Update button labels and enabled state
            UpdateToolStripMenu();
        }