Пример #1
0
        public MathCell ProcessCellInput(DataGridViewCell inputCell)
        {
            string newFormula = string.Empty;

            if (inputCell.Value != null)
            {
                newFormula = inputCell.Value.ToString();
            }

            MathCell mCell = GetMathCell(inputCell);

            mCell.Formula     = newFormula;
            mCell.RowIndex    = inputCell.RowIndex;
            mCell.ColumnIndex = inputCell.ColumnIndex;

            object prevValue = mCell.Value;

            mCell.EvaluateFormula();
            object currentValue = mCell.Value;

            if (prevValue != null && prevValue.ToString() == "RecursiveReference" ||
                currentValue.ToString() == "RecursiveReference")
            {
                foreach (MathCell usedCell in UsedCells)
                {
                    usedCell.RemoveFromBoundedCells();
                    OnGridMathCellsProvider.UpdateValuesOnGrid(UsedCells, OwnerGrid);
                }
            }

            OnGridMathCellsProvider.UpdateDependentsOnGrid(mCell, OwnerGrid);

            return(mCell);
        }
Пример #2
0
        public static void OpenFile(GridForm grid)
        {
            if (grid.openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filePath = grid.openFileDialog.FileName;

                DataSet dataSet = InstanceDataSet(filePath);
                if (dataSet == null)
                {
                    return;
                }

                MathCellsProvider.GetInstance.ResetMathCells();
                grid.ClearGrid();
                grid.ClearOutputBoxes();

                DataTable dataTable = dataSet.Tables[0];
                grid.dataGridView.ColumnCount = dataTable.Columns.Count;
                grid.dataGridView.RowCount    = dataTable.Rows.Count;

                foreach (DataGridViewRow row in grid.dataGridView.Rows)
                {
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        MathCell newCell = new MathCell(dataTable.Rows[cell.RowIndex][cell.ColumnIndex].ToString())
                        {
                            RowIndex = cell.RowIndex, ColumnIndex = cell.ColumnIndex
                        };

                        if (!string.IsNullOrWhiteSpace(newCell.Formula))
                        {
                            MathCellsProvider.GetInstance.AddCell(newCell);
                        }

                        cell.Tag = newCell;
                    }
                }

                List <MathCell> addedCells = MathCellsProvider.GetInstance.GetUsedCells();
                OnGridMathCellsProvider.UpdateValuesOnGrid(addedCells, grid);

                // first value reevalutes because it can be calculated with non proper references
                addedCells.First().EvaluateFormula();
                OnGridMathCellsProvider.PutMathCellOnGrid(addedCells.First(), grid);

                HeadersUpdater headersUpdater = new HeadersUpdater(grid, new UpdateRows(), new UpdateColumns());
                headersUpdater.Update();
            }
        }
Пример #3
0
        public void Shift()
        {
            foreach (DataGridViewRow row in _ownerGrid.dataGridView.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    MathCell mCell = MathCellsProvider.GetMathCell(cell);
                    _shiftWay.DoShift(_delimiterIndex, mCell, _ownerGrid);
                }
            }

            List <MathCell> usedMathCells = MathCellsProvider.GetInstance.GetUsedCells();

            foreach (MathCell usedCell in usedMathCells)
            {
                usedCell.ShiftReferences();
            }

            OnGridMathCellsProvider.UpdateValuesOnGrid(usedMathCells, _ownerGrid);
        }