Ejemplo n.º 1
0
        public static void AddRow(GridForm grid)
        {
            ++grid.dataGridView.RowCount;

            OnGridMathCellsProvider.InitEmptyCells(grid);

            HeadersUpdater headersUpdater = new HeadersUpdater(grid, new UpdateRows());

            headersUpdater.Update();
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
0
        public static void InsertRow(GridForm grid)
        {
            int rowIndex = grid.dataGridView.CurrentCell.RowIndex;

            grid.dataGridView.Rows.Insert(rowIndex);

            OnGridMathCellsProvider.InitEmptyCells(grid);

            MathCellsShifter mathCellsShifter = new MathCellsShifter(new ShiftAfterRowInsert(), rowIndex, grid);

            mathCellsShifter.Shift();

            HeadersUpdater headersUpdater = new HeadersUpdater(grid, new UpdateRows());

            headersUpdater.Update();
        }
Ejemplo n.º 4
0
        private void InitialGridSetup()
        {
            MathCellsProvider.GetInstance.ResetMathCells();
            ClearGrid();
            ClearOutputBoxes();

            const int initN = 10;
            const int initM = 10;

            dataGridView.RowCount    = initN;
            dataGridView.ColumnCount = initM;

            HeadersUpdater headersUpdater = new HeadersUpdater(this, new UpdateRows(), new UpdateColumns());

            headersUpdater.Update();

            OnGridMathCellsProvider.InitEmptyCells(this);
        }
Ejemplo n.º 5
0
        public static void InsertColumn(GridForm grid)
        {
            int colIndex = grid.dataGridView.CurrentCell.ColumnIndex;

            DataGridViewTextBoxColumn dummyCol = new DataGridViewTextBoxColumn
            {
                HeaderText = "dummyColText"
            };

            grid.dataGridView.Columns.Insert(colIndex, dummyCol);

            OnGridMathCellsProvider.InitEmptyCells(grid);

            MathCellsShifter mathCellsShifter = new MathCellsShifter(new ShiftAfterColumnInsert(), colIndex, grid);

            mathCellsShifter.Shift();

            HeadersUpdater headersUpdater = new HeadersUpdater(grid, new UpdateColumns());

            headersUpdater.Update();
        }
Ejemplo n.º 6
0
        public static void DeleteColumn(GridForm grid)
        {
            if (grid.dataGridView.ColumnCount <= 1)
            {
                return;
            }

            int colIndex = grid.dataGridView.CurrentCell.ColumnIndex;

            bool isDeletionAllowed = true;

            if (IsColumnHasValue(grid, colIndex))
            {
                isDeletionAllowed = IsDeletionAllowed("column");
            }

            if (isDeletionAllowed)
            {
                foreach (DataGridViewRow row in grid.dataGridView.Rows)
                {
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        if (cell.ColumnIndex == colIndex)
                        {
                            MathCell delCell = MathCellsProvider.GetMathCell(cell);
                            delCell.UpdateDependentsBeforeDelete();
                            MathCellsProvider.GetInstance.RemoveCell(delCell);
                        }
                    }
                }

                grid.dataGridView.Columns.RemoveAt(colIndex);

                MathCellsShifter mathCellsShifter = new MathCellsShifter(new ShiftAfterColumnDeletion(), colIndex, grid);
                mathCellsShifter.Shift();

                HeadersUpdater headersUpdater = new HeadersUpdater(grid, new UpdateColumns());
                headersUpdater.Update();
            }
        }
Ejemplo n.º 7
0
        public static void DeleteRow(GridForm grid)
        {
            if (grid.dataGridView.RowCount <= 1)
            {
                return;
            }

            int rowIndex = grid.dataGridView.CurrentCell.RowIndex;

            bool isDeletionAllowed = true;

            if (IsRowHasValue(grid, rowIndex))
            {
                isDeletionAllowed = IsDeletionAllowed("row");
            }

            if (isDeletionAllowed)
            {
                DataGridViewRow deletionRow = grid.dataGridView.Rows[rowIndex];

                foreach (DataGridViewCell cell in deletionRow.Cells)
                {
                    MathCell delCell = MathCellsProvider.GetMathCell(cell);
                    delCell.UpdateDependentsBeforeDelete();
                    MathCellsProvider.GetInstance.RemoveCell(delCell);
                }

                grid.dataGridView.Rows.RemoveAt(rowIndex);

                MathCellsShifter mathCellsShifter = new MathCellsShifter(new ShiftAfterRowDeletion(), rowIndex, grid);
                mathCellsShifter.Shift();

                HeadersUpdater headersUpdater = new HeadersUpdater(grid, new UpdateRows());
                headersUpdater.Update();
            }
        }