Exemplo n.º 1
0
        /// <summary>
        /// Constructor for the Spreadsheet.
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            sheet = new Spreadsheet(s => true, s => s.ToUpper(), "ps6");

            spreadsheetPanel1.SelectionChanged += displaySelection;



            spreadsheetPanel1.SetSelection(0, 0);
            displaySelection(spreadsheetPanel1);
            spreadsheetPanel1.SendToBack();
            spreadsheetPanel1.Focus();
            ContentField.BringToFront();
            ContentField.Focus();
            this.Hide();
        }
Exemplo n.º 2
0
        public Form1(Spreadsheet sheet)
        {
            InitializeComponent();
            this.sheet = sheet;

            foreach (String cellName in sheet.GetNamesOfAllNonemptyCells())
            {
                updateCell(cellName, spreadsheetPanel1);
            }

            spreadsheetPanel1.SelectionChanged += displaySelection;

            spreadsheetPanel1.SetSelection(0, 0);
            displaySelection(spreadsheetPanel1);
            spreadsheetPanel1.SendToBack();
            spreadsheetPanel1.Focus();
            ContentField.BringToFront();
            ContentField.Focus();
        }
Exemplo n.º 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)
        {
            // Used for periodically checking for cirular dependencies
            //if (Stopwatch.IsRunning == false)
            //    Stopwatch.Start();

            //if(Stopwatch.ElapsedMilliseconds  60000)
            //{
            //    PeriodicCircCheck(ss);
            //    Stopwatch.Reset();
            //}

            int    row, col;
            String value;

            if (connected == true)
            {
                Model.Model.Unfocus();
            }

            ss.GetSelection(out col, out row);
            ss.GetValue(col, row, out value);

            CellNameField.Text = (((Char)((65) + (col))) + "" + (row + 1));

            if (connected == true)
            {
                Model.Model.Focus(CellNameField.Text);
            }

            spreadsheetPanel1.GetFirstSelection(out int fcol, out int frow);

            int xpos = LABEL_COL_WIDTH + (col - fcol) * DATA_COL_WIDTH + 1;
            int ypos = LABEL_ROW_HEIGHT + (row - frow) * DATA_ROW_HEIGHT + 1;

            ContentField.Location = new Point(xpos, ypos);
            ContentField.BringToFront();
            ContentField.Focus();
            ContentsBar.Text = ContentField.Text;

            if (sheet.GetCellValue(CellNameField.Text) is FormulaError err)
            {
                ss.SetValue(col, row, "#REF ");
                CellValueField.Text = "#REF ";
            }

            else
            {
                ss.SetValue(col, row, sheet.GetCellValue(CellNameField.Text) + "");
                CellValueField.Text = sheet.GetCellValue(CellNameField.Text) + "";
            }



            if (sheet.GetCellContents(((Char)((65) + (col))) + "" + (row + 1)) is Formula form)
            {
                ContentField.Text = "=" + sheet.GetCellContents(((Char)((65) + (col))) + "" + (row + 1));
            }
            else
            {
                ContentField.Text = "" + sheet.GetCellContents(((Char)((65) + (col))) + "" + (row + 1));
            }

            //CS3505 changes///////////////////////////////////////////////////

            //Checks to see if a circular dependency was found and display #REF in the selected cell on update if it was
            if (isCircular == true)
            {
                MessageBox.Show("The formula you entered results in a circular exception.");
                ss.SetValue(col, row, "#REF ");
                CellValueField.Text = "#REF ";
                isCircular          = false;
            }

            //end//////////////////////////////////////////////////////////////
            ContentField.Focus();
        }