Beispiel #1
0
 public void DoUpdate(GridForm ownerGrid)
 {
     for (int i = 0; i < ownerGrid.dataGridView.RowCount; ++i)
     {
         ownerGrid.dataGridView.Rows[i].HeaderCell.Value = $"{i}";
     }
 }
Beispiel #2
0
 public static void UpdateValuesOnGrid(List <MathCell> mCells, GridForm ownerGrid)
 {
     foreach (MathCell mCell in mCells)
     {
         mCell.EvaluateFormula();
         PutMathCellOnGrid(mCell, ownerGrid);
     }
 }
        public void DoShift(int delimiterIndex, MathCell mCell, GridForm ownerGrid)
        {
            int rowIndex = mCell.RowIndex;

            if (rowIndex > 0 && rowIndex > delimiterIndex && rowIndex <= ownerGrid.dataGridView.RowCount)
            {
                --mCell.RowIndex;
            }
        }
        public void DoShift(int delimiterIndex, MathCell mCell, GridForm ownerGrid)
        {
            int rIndex = mCell.RowIndex;

            if (rIndex >= delimiterIndex && rIndex < ownerGrid.dataGridView.RowCount)
            {
                ++mCell.RowIndex;
            }
        }
Beispiel #5
0
        private static bool IsRowHasValue(GridForm grid, int rowIndex)
        {
            DataGridViewRow deletionRow = grid.dataGridView.Rows[rowIndex];
            var             hasValue    = (from DataGridViewCell cell in deletionRow.Cells
                                           select cell.Value != null && !string.IsNullOrEmpty(cell.Value.ToString()))
                                          .Any(r => r);

            return(hasValue);
        }
Beispiel #6
0
 public void DoUpdate(GridForm ownerGrid)
 {
     for (int j = 0; j < ownerGrid.dataGridView.ColumnCount; ++j)
     {
         ownerGrid.dataGridView.Columns[j].SortMode         = DataGridViewColumnSortMode.NotSortable;
         ownerGrid.dataGridView.Columns[j].MinimumWidth     = 100;
         ownerGrid.dataGridView.Columns[j].HeaderCell.Value = $"{j}";
     }
 }
        public void DoShift(int delimiterIndex, MathCell mCell, GridForm ownerGrid)
        {
            int colIndex = mCell.ColumnIndex;

            if (colIndex > 0 && colIndex > delimiterIndex && colIndex <= ownerGrid.dataGridView.ColumnCount)
            {
                --mCell.ColumnIndex;
            }
        }
        public void DoShift(int delimiterIndex, MathCell mCell, GridForm ownerGrid)
        {
            int cIndex = mCell.ColumnIndex;

            if (cIndex >= delimiterIndex && cIndex < ownerGrid.dataGridView.ColumnCount)
            {
                ++mCell.ColumnIndex;
            }
        }
Beispiel #9
0
 public static void UpdateDependentsOnGrid(MathCell mCell, GridForm ownerGrid)
 {
     for (int i = 0; i < mCell.Dependents.Count; ++i)
     {
         MathCell dependentCell = mCell.Dependents[i];
         dependentCell.EvaluateFormula();
         PutMathCellOnGrid(dependentCell, ownerGrid);
         UpdateDependentsOnGrid(dependentCell, ownerGrid);
     }
 }
Beispiel #10
0
        public static void AddRow(GridForm grid)
        {
            ++grid.dataGridView.RowCount;

            OnGridMathCellsProvider.InitEmptyCells(grid);

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

            headersUpdater.Update();
        }
Beispiel #11
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();
            }
        }
Beispiel #12
0
        private static bool HasInvalidIndexing(string formula)
        {
            List <string> formulaAddresses = AddressesHandler.GetAddresses(formula);
            GridForm      ownerGrid        = MathCellsProvider.GetInstance.OwnerGrid;

            foreach (string address in formulaAddresses)
            {
                var(rowIndex, colIndex) = AddressesHandler.GetIndexes(address);
                if (rowIndex >= ownerGrid.dataGridView.RowCount || colIndex >= ownerGrid.dataGridView.ColumnCount)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #13
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();
        }
Beispiel #14
0
 public static void InitEmptyCells(GridForm ownerGrid)
 {
     foreach (DataGridViewRow row in ownerGrid.dataGridView.Rows)
     {
         foreach (DataGridViewCell cell in row.Cells)
         {
             if (cell.Tag == null)
             {
                 cell.Tag = new MathCell("")
                 {
                     RowIndex    = cell.RowIndex,
                     ColumnIndex = cell.ColumnIndex
                 };
             }
         }
     }
 }
Beispiel #15
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();
        }
Beispiel #16
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();
            }
        }
Beispiel #17
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();
            }
        }
Beispiel #18
0
 public static void PutMathCellOnGrid(MathCell mCell, GridForm ownerGrid)
 {
     ownerGrid.dataGridView[mCell.ColumnIndex, mCell.RowIndex].Value = mCell.Value;
 }
Beispiel #19
0
 public HeadersUpdater(GridForm grid, params IHeadUpdate[] updates)
 {
     _ownerGrid = grid;
     _updates   = updates.ToList();
 }
Beispiel #20
0
 public void SetGridForm(GridForm initGrid)
 {
     OwnerGrid = initGrid;
 }
 public MathCellsShifter(IShift shiftWay, int delimiterIndex, GridForm ownerGrid)
 {
     _shiftWay       = shiftWay;
     _delimiterIndex = delimiterIndex;
     _ownerGrid      = ownerGrid;
 }