Beispiel #1
0
        // Every time the selection changes, this method is called with the
        // Spreadsheet as its parameter.  We display the current time in the cell.

        private void displaySelection(SpreadsheetPanel ss)
        {
            int    row, col;
            String value;

            ss.GetSelection(out col, out row);
            ss.GetValue(col, row, out value);
            if (value == "")
            {
                ss.SetValue(col, row, DateTime.Now.ToLocalTime().ToString("T"));
                ss.GetValue(col, row, out value);
            }
        }
Beispiel #2
0
        // Every time the selection changes, this method is called with the
        // Spreadsheet as its parameter.  We display the current time in the cell.

        private void displaySelection(SpreadsheetPanel ss)
        {
            int row, col;
            String value;
            ss.GetSelection(out col, out row);
            ss.GetValue(col, row, out value);
            if (value == "") 
            {
                ss.SetValue(col, row, DateTime.Now.ToLocalTime().ToString("T"));
                ss.GetValue(col, row, out value);
                MessageBox.Show("Selection: column " + col + " row " + row + " value " + value);
            }
        }
Beispiel #3
0
        // Every time the selection changes, this method is called with the
        // Spreadsheet as its parameter.  We display the current time in the cell.

        private void displaySelection(SpreadsheetPanel ss)
        {
            int    row, col;
            String value;

            ss.GetSelection(out col, out row);
            ss.GetValue(col, row, out value);
            if (value == "")
            {
                ss.SetValue(col, row, DateTime.Now.ToLocalTime().ToString("T"));
                ss.GetValue(col, row, out value);
                MessageBox.Show("Selection: column " + col + " row " + row + " value " + value);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Called when a cell on the spreadsheet is selected.
        /// </summary>
        /// <param name="ss">Spreadsheet that called the method.</param>
        private void cellSelected(SpreadsheetPanel ss)
        {
            int row, col;

            ss.GetSelection(out col, out row);
            String _cellName = "" + ((char)('A' + col)) + (row + 1);

            if (shiftPressed) //If shift is pressed we are only adding the cell name to the contents box.
            {
                int selectionStart = contentsBox.SelectionStart;
                contentsBox.Text = contentsBox.Text.Insert(selectionStart, _cellName);
                contentsBox.Select(selectionStart + _cellName.Length, 0);
                ss.SetSelection(previousCellX, previousCellY);
                return;
            }
            if (contentButton.Enabled) // If we click away submit what we've got if there has been a change.
            {
                contentButton_Click(null, null);
            }
            previousCellX = col;
            previousCellY = row;
            cellName.Text = _cellName;
            String contents = ourSpreadsheet.GetCellContents(_cellName).ToString();
            String value    = ourSpreadsheet.GetCellValue(_cellName).ToString();

            contentsBox.Text = contents;
            previousContents = contents;
            if (value == "SpreadsheetUtilities.FormulaError")
            {
                value = "!FORMULA_ERROR"; //Change the name to something more readable
                if (heroMode)             // HERO MODE Stuff
                {
                    HeroModeReset();
                }
            }
            toolTip.SetToolTip(valueBox, value); //Set the tooltip to be the full value
            if (value.Length > 16)               // Trim it down to fit in the contents box
            {
                value = value.Substring(0, 15);
            }
            valueBox.Text = value;

            //Pretty Colorized stuff
            //colorizeDependencies(_cellName);

            contentButton.Enabled = false;//Keep the contents button disabled
        }
        /// <summary>
        /// Helper method for updating the cell's value boxes when the selection changes
        /// This method correctly sets the value textboxes: cellNameValue, columnValue, rowValue, cellContentsValue, and the cellValueBox textboxes
        /// </summary>
        /// <param name="sheet"></param>
        private void displaySelection(SpreadsheetPanel sheet)
        {
            // Create variables for holding the row, column, and cell values
            int    row;
            int    col;
            String value;

            // Get the current selection
            sheet.GetSelection(out col, out row);
            // Get the cell's value once the selection is obtained
            sheet.GetValue(col, row, out value);

            // Add ascii offset to the column number
            int asciiCol = col + 65;

            // Convert the ascii value into a char and set it as the columnValue text box
            columnValue.Text = Char.ConvertFromUtf32(asciiCol);

            // Add 1 to the row number since rows and columns starting index is 0
            int actualRow = row + 1;

            // Convert row number to a string and store it in the rowValue text box
            rowValue.Text = actualRow.ToString();

            // Combine the column and row values as a string and set them as the cellNameValue text box
            cellNameValue.Text = Char.ConvertFromUtf32(asciiCol) + actualRow.ToString();

            // Get the contents of the cell and convert it to a string
            String cellContents = spreadSheet.GetCellContents(cellNameValue.Text).ToString();

            // Set the cell's contents in the cellContentsValue text box
            cellContentsValue.Text = cellContents;

            // Get the vlaue of the cell and convert it to a string
            String cellValue = spreadSheet.GetCellValue(cellNameValue.Text).ToString();

            // Set the clel's value in the cellValueBox textbox
            cellValueBox.Text = cellValue;
        }
        private void DisplayUpdate(SpreadsheetPanel ss)
        {
            if (_spreadsheet == null) return;
            int col, row;
            ss.GetSelection(out col, out row);
            // Convert col, row index to spreadsheet cell names.
            var cellName = ((char)(col + 65)) + (row + 1).ToString(CultureInfo.InvariantCulture);

            // Displays selected cell's name
            CellNameBox.Invoke(new Action(() => { CellNameBox.Text = cellName; }));
            // No need to fetch the value from the spreadsheet again, just copy it from
            // the spreadsheetpanel. This avoids reworking the FormulaError message.
            string value;
            ss.GetValue(col, row, out value);
            ValueBox.Invoke(new Action(() => { ValueBox.Text = value; }));
        }
        /// <summary>
        /// </summary>
        /// <param name="ss">The SpreadsheetPanel in the current Form1</param>
        private void DisplaySelection(SpreadsheetPanel ss)
        {
            if (_spreadsheet == null) return;
            int col, row;
            ss.GetSelection(out col, out row);
            // Convert col, row index to spreadsheet cell names.
            var cellName = ((char) (col + 65)) + (row + 1).ToString(CultureInfo.InvariantCulture);

            // Displays selected cell's name
            CellNameBox.Invoke(new Action(() => { CellNameBox.Text = cellName; }));
            var content = _spreadsheet.GetCellContents(cellName);
            // If content is a formula, prepend "=" before displaying
            var f = content as Formula;
            if (f != null)
            {
                ContentBox.Invoke(new Action(() => { ContentBox.Text = "=" + f; }));
            }
                // Otherwise just display the content.
            else
            {
                ContentBox.Invoke(new Action(() => { ContentBox.Text = content.ToString(); }));
            }
            // No need to fetch the value from the spreadsheet again, just copy it from
            // the spreadsheetpanel. This avoids reworking the FormulaError message.
            string value;
            ss.GetValue(col, row, out value);
            ValueBox.Invoke(new Action(() => { ValueBox.Text = value; }));
        }
Beispiel #8
0
        /// <summary>
        /// Updates the panel display, cellDisplayTextBox, contentsTextBox, valueTextBox, and all non-empty Cells
        ///  Every time the selection changes, this method is called with the Spreadsheet as its parameter. 
        /// </summary>
        /// <param name="ss"></param>
        private void displaySelection(SpreadsheetPanel ss)
        {
            // Get col and row of cell.
            int row, col;
            ss.GetSelection(out col, out row);

            string nameOfCell = "" + GetExcelColumnName(col) + (row + 1); // get cell name

            // Cell Display
            cellDisplayBox.Text = nameOfCell;

            // Set the valueTextBox if there is a formula error make the error message be "###########"
            var valueOfCell = spreadsheet.GetCellValue(nameOfCell); // get value of cell
            string valueOfCellString;

            if (valueOfCell is SpreadsheetUtilities.FormulaError)
            {
                //clientCommunication.
                // If it is an FormulaError we don't do anytyhing here.
                valueOfCellString = "##########";
            }
            else
            {
                /**If is isn't a FormulaError, we send "CHANGE VERSION #\n" to the server.
                 * The state of the client’s local spreadsheet should remain unchanged until approved by the server.
                 Socket.BeginSend("message", SendCallback, null/whatever);
                 Socket.BeginReceive(ReceiveCallback, null/whatever);
                 probably a loop with thread.sleep in it while we wait for the message.
                 */
                valueOfCellString = valueOfCell.ToString();
            }

            valueTextBox.Text = valueOfCellString;
            ss.SetValue(col, row, valueOfCellString); // update panel

            var contentsOfCell = spreadsheet.GetCellContents(nameOfCell);
            // Set the contentsTextBox, append the '=' for convience
            if (contentsOfCell is SpreadsheetUtilities.Formula)
            {
                contentsTextBox.Text = "=" + contentsOfCell.ToString();
            }
            else
            {
                contentsTextBox.Text = contentsOfCell.ToString();
                ss.SetSelection(col, row);
            }

            // update all non empty cells
            IEnumerable<string> nonEmptyCells = spreadsheet.GetNamesOfAllNonemptyCells();
            foreach (var name33 in nonEmptyCells)
            {
                Match m = Regex.Match(name33, @"^([A-Z]+) *(\d)$");// separate cell name
                if (m.Success)
                {
                    // get the column letter and convert it to a number
                    string translated = m.Groups[1].Value;
                    int column = TranslateColumnNameToIndex(translated);
                    int rowNumber = Int32.Parse(m.Groups[2].Value) - 1;

                    string valueOfDependentCellString;
                    var valueOfDependentCell = spreadsheet.GetCellValue(name33);

                    // Set the value if there is a formula error
                    if (valueOfDependentCell is SpreadsheetUtilities.FormulaError)
                    {
                        valueOfDependentCellString = "##########";

                    }
                    else
                    {
                        valueOfDependentCellString = valueOfDependentCell.ToString();
                    }
                    ss.SetValue(column, rowNumber, valueOfDependentCellString); // update panel
                }
            }

            // put cursor in contents text box
            contentsTextBox.Focus();
            contentsTextBox.Select(contentsTextBox.Text.Length, 0);
        }
Beispiel #9
0
        // Every time the selection changes, this method is called with the
        // Spreadsheet as its parameter.  We display the current time in the cell.

        private void displaySelection(SpreadsheetPanel ss)
        {
            bool succesfull = true;
            int newRow, newCol;
            //String value;
            // if a cell has been updated then add it to the model and
            //update the gui
            if(cellChanged)
            {
                succesfull = updateModel(row, col);
            }
            //if model was succesfully changed than make changes to the GUI
            if (succesfull)
            {
                //get the newly selected cell
                ss.GetSelection(out newCol, out newRow);
                displayCurrentCell(newCol, newRow);

                //save cells' postion
                row = newRow;
                col = newCol;
            }
            //model was not succesfull updated keep user on the incorrect cell
            else
            {
                spreadsheetPanel1.SetSelection(col, row);
            }
        }
Beispiel #10
0
 //A helper method to convert the currently selected cell in the panel to the currect cell name for use in Spreadsheet.
 private string SelectionToCell(SpreadsheetPanel panel)
 {
     int row, col;
     string cell;
     panel.GetSelection(out col, out row);
     cell = char.ConvertFromUtf32(col + 65) + (row + 1);
     return cell;
 }
Beispiel #11
0
        /// <summary>
        /// updates the display of the GUI.
        /// </summary>
        /// <param name="ss"></param>
        private void update_display(SpreadsheetPanel ss)
        {
            contents_box.Select();
            //stores where the user has selected on the spreadsheetpanel.
            int col, row;
            ss.GetSelection(out col, out row);
            //converts the col row location on the spreadsheetpanel to a usable name such as A1 for (0,0).
            string cell_name = (char)(65 + col) + (row + 1).ToString();
            //if the contents of the highlighted cell is a double or a string this and the contents are longer than
            //0(meaning they aren't "" then this sets the contents box back to what the user entered before, otherwise
            //sets the contents box to empty.
            if (my_spread_sheet.GetCellContents(cell_name) is double || my_spread_sheet.GetCellContents(cell_name) is string)
            {
                if(my_spread_sheet.GetCellContents(cell_name).ToString().Length >=1)
                {
                    contents_box.Text = my_spread_sheet.GetCellContents(cell_name).ToString();
                }
                else
                {
                    contents_box.Text = "";
                }
            }
            //if the cell names contents are not a double or a string then it must be a formula so an = is prepended.
            else
            {
                contents_box.Text = "=" + my_spread_sheet.GetCellContents(cell_name).ToString();
            }
            //if the cell name has a value then it is displayed in the value box.
            if (my_spread_sheet.GetCellValue(cell_name)!= null)
            {
                value_box.Text = my_spread_sheet.GetCellValue(cell_name).ToString();
            }
            //if the cell name does not have a value then the value box is cleared.
            else
            {
                value_box.Clear();
            }

            //this shows the current cell name selected along with value appended in the value label next to the value box.
            value_label.Text = cell_name + " Value";
            contents_box.SelectAll();
        }