Exemplo n.º 1
0
        /// <summary>
        /// If set button is clicked, add cell contents to sheet,
        /// give the GUI the value of the cell to display
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            int row;
            int col;

            //gets current location of selected cell
            spreadsheetPanel1.GetSelection(out col, out row);
            //gets name of associated cell
            string name = ConvertColRowIntoName(col, row);

            ContentsBox.Focus();
            //recalculates any cells that are dependent on current cell
            try
            {
                ContentsInitial = ContentsBox.Text;
                HashSet <string> CellsRecalculate = (HashSet <string>)sheet.SetContentsOfCell(name, ContentsBox.Text);
                foreach (string cell in CellsRecalculate)
                {
                    int vertical;
                    int horizontal;
                    ConvertStringToRowAndColumn(cell, out vertical, out horizontal);
                    ContentsBox.Text = sheet.GetCellContents(cell).ToString();

                    string content = this.sheet.GetCellContents(cell).ToString();

                    string value = sheet.GetCellValue(cell).ToString();
                    //sets error message to box and value lebel if error in formula
                    if (value == "SpreadsheetUtilities.FormulaError")
                    {
                        spreadsheetPanel1.SetValue(vertical, horizontal, "Formula Error");
                        ValueBox.Text = "Formula Error";
                    }
                    else if (value != null && value != "")
                    {
                        if (content.Equals(value))
                        {
                            Networking.Send(this.server, "3\t" + this.docID.ToString() + "\t" + name + "\t" + value + "\n");
                        }
                        else
                        {
                            Networking.Send(this.server, "3\t" + this.docID.ToString() + "\t" + name + "\t=" + content + "\n");
                        }
                        spreadsheetPanel1.SetValue(vertical, horizontal, value);
                        ValueBox.Text = value;
                    }
                }
            }
            //creates message box with error message
            catch (SpreadsheetUtilities.FormulaFormatException)
            {
                DialogResult dialogResult = MessageBox.Show("Invalid formula syntax.", "Warning", MessageBoxButtons.OK);
            }
            catch (SS.CircularException)
            {
                DialogResult dialogResult = MessageBox.Show("Circular Dependency", "Warning", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event method called when a cell is clicked on the spreadsheet panel object
        /// </summary>
        /// <param name="p"></param>
        private void onCellClicked(SpreadsheetPanel p)
        {
            int row, col;

            p.GetSelection(out col, out row);
            string cellName     = GetCellName(col, row);
            object cellContents = spreadsheet.GetCellContents(cellName);

            if (cellContents is Formula)
            {
                cellContents = "=" + cellContents;
            }

            ContentsBox.Text      = cellContents.ToString();
            cellValueTextBox.Text = spreadsheet.GetCellValue(cellName).ToString();

            ContentsBox.Focus();
        }
Exemplo n.º 3
0
        /// <summary>
        /// event that deels with selecting a cell, if cell already has contents it populates the approperiate labels with content information
        /// </summary>
        /// <param name="sender">spreadsheetPanel</param>
        private void SpreadsheetPanel1_Selection(SpreadsheetPanel sender)
        {
            //clears previous content
            ContentsBox.Clear();
            ValueBox.Clear();
            int row;
            int col;

            //used to get letter portion of cell name.
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            spreadsheetPanel1.GetSelection(out col, out row);
            //adds 1 to row to set name in spreadsheet cell to match panel labels.
            row += 1;
            AddressLabel.Text = "" + alpha[col] + row + ":";
            //sets name for cell using row and col integers
            string name = "" + alpha[col] + row;

            string contents = sheet.GetCellContents(name).ToString();
            string value    = sheet.GetCellValue(name).ToString();

            //checks if formula is an error if so sets cell contents to error message and error label.

            if (value == "SpreadsheetUtilities.FormulaError")
            {
                spreadsheetPanel1.SetValue(col, row - 1, "Formula Error");
                ValueBox.Text = "Formula Error";
            }
            //otherwise sets the value and proper content to appropreiate labels and cell.
            else
            {
                ValueBox.Text = value;
                spreadsheetPanel1.SetValue(col, row - 1, value);
            }
            //sets the contents of input box to what is in the current cell.
            ContentsBox.Focus();
            ContentsBox.Text = contents;
        }