예제 #1
0
        private Cell GetCell(string CellName)
        {
            CellCoordinates GetCellCoordinates = cellsCoordinates.Find(x => x.Name == CellName);

            //check if cell exist
            if (GetCellCoordinates.Name != null)
            {
                //get class cell from tag
                Cell cell;
                if (dataGridView1.Rows[GetCellCoordinates.Y].Cells[GetCellCoordinates.X].Tag != null && dataGridView1.Rows[GetCellCoordinates.Y].Cells[GetCellCoordinates.X].Tag is Cell)
                {
                    cell = (Cell)dataGridView1.Rows[GetCellCoordinates.Y].Cells[GetCellCoordinates.X].Tag;
                }

                //or create new
                else
                {
                    cell = new Cell(GetCellCoordinates);
                    dataGridView1.Rows[GetCellCoordinates.Y].Cells[GetCellCoordinates.X].Tag = cell;
                }

                return(cell);
            }

            return(null);
        }
예제 #2
0
        private List <CellCoordinates> GetExpressionUsedCells(string ValidExpression)
        {
            List <CellCoordinates> UsedCells = new List <CellCoordinates>();
            string cellName = null;

            for (int i = 0; i < ValidExpression.Length; i++)
            {
                if (!Char.IsNumber(ValidExpression[i]))
                {
                    while (i < ValidExpression.Length && ValidExpression[i] != '+' && ValidExpression[i] != '-' && ValidExpression[i] != '*' && ValidExpression[i] != '/')

                    {
                        cellName = cellName + ValidExpression[i];
                        i++;
                    }

                    if (cellName != null)
                    {
                        CellCoordinates cell = cellsCoordinates.Find(x => x.Name == cellName);
                        if (cell.Name == null)
                        {
                            cell = new CellCoordinates(0, 0, cellName);
                        }

                        UsedCells.Add(cell);
                    }
                    cellName = null;
                }
            }

            return(UsedCells);
        }
예제 #3
0
 public Cell(CellCoordinates coordinates)
 {
     this.coordinates = coordinates;
     this.expression  = null;
     this.display     = null;
     usedToСells      = new List <CellCoordinates>();
     usedСells        = new List <CellCoordinates>();
 }
예제 #4
0
        private void AddRows()
        {
            DataGridViewRow row       = new DataGridViewRow();
            int             rowHeader = dataGridView1.RowCount;

            row.HeaderCell.Value = rowHeader.ToString();
            dataGridView1.Rows.Add(row);

            //save new cells when added row
            for (int i = 0; i <= dataGridView1.ColumnCount - 1; i++)
            {
                CellCoordinates coordinates = new CellCoordinates(i, rowHeader, GetColumnHeader(i) + (rowHeader + 1));
                cellsCoordinates.Add(coordinates);
            }
        }
예제 #5
0
        private void AddColumns()
        {
            DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();

            string columnHeader = GetColumnHeader(dataGridView1.ColumnCount);

            column.Name = columnHeader;
            dataGridView1.Columns.Add(column);

            //save new cells when added column
            for (int i = 0; i <= dataGridView1.RowCount; i++)
            {
                CellCoordinates coordinates = new CellCoordinates(dataGridView1.ColumnCount - 1, i, columnHeader + (i + 1).ToString());
                cellsCoordinates.Add(coordinates);
            }
        }
예제 #6
0
        private void CellAddFieldUsedCell(ref Cell cell, string usedCellName)
        {
            CellCoordinates UsedCell = cell.usedСells.Find(x => x.Name == usedCellName);

            //check if UsedCell already added
            if (UsedCell.Name == null)
            {
                CellCoordinates FindUsedCell = cellsCoordinates.Find(x => x.Name == usedCellName);
                cell.usedСells.Add(FindUsedCell);

                //find used cell and add usedToCell
                Cell findCell = GetCell(usedCellName);
                if (findCell != null)
                {
                    CellAddFieldUsedToCell(ref findCell, cell.Coordinates.Name);
                }
            }
        }