Example #1
0
        public bool UpdateCells(MyCell cell, DataGridView dataGridView1)
        {
            cell.new_depends.Clear();

            string new_exp = ConvertDepends(cell.RowNameCell, cell.ColNameCell, cell.Exp);

            GetResult(new_exp, cell.RowNameCell, cell.ColNameCell, dataGridView1);

            return(true);
        }
Example #2
0
        public void Clear()
        {
            for (int i = 0; i < sz; i++)
            {
                for (int j = 0; j < sz; j++)
                {
                    string name = FullName(i, j);
                    TableCells[i, j] = new MyCell(name, i, j);
                }
            }

            dictionary.Clear();
            RowCount = 0;
            ColCount = 0;
        }
Example #3
0
        public bool DeleteColumn(DataGridView dgv)
        {
            if (ColCount == 1)
            {
                MessageBox.Show("You can't delete column", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            List <MyCell> notEmptyCells = new List <MyCell>();
            List <MyCell> dependsCells  = new List <MyCell>();

            for (int i = 0; i < RowCount; i++)
            {
                string name = FullName(i, ColCount - 1);
                if (dictionary[name] != "0" && dictionary[name] != "")
                {
                    notEmptyCells.Add(TableCells[i, ColCount - 1]);
                }
                if (TableCells[i, ColCount - 1].dependsOnMe.Count != 0)
                {
                    dependsCells.AddRange(TableCells[i, ColCount - 1].dependsOnMe);
                }
            }

            if (notEmptyCells.Count != 0 || dependsCells.Count != 0)
            {
                string errorMessage = "";
                if (notEmptyCells.Count != 0)
                {
                    errorMessage += "There is not empty cells : ";
                    foreach (MyCell cell in notEmptyCells)
                    {
                        string str = cell.NameCell + "; ";
                        errorMessage += str;
                    }

                    errorMessage += "\n";
                }

                if (dependsCells.Count != 0)
                {
                    errorMessage += "There is cells, thats depends from cells in this row : ";
                    foreach (MyCell cell in dependsCells)
                    {
                        string str = cell.NameCell + "; ";
                        errorMessage += str;
                    }

                    errorMessage += "\n";
                }

                errorMessage += "Are you sure to delete this column? ";
                DialogResult result = MessageBox.Show(errorMessage, "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.No)
                {
                    return(false);
                }
            }

            List <MyCell> new_dependCells = new List <MyCell>();

            new_dependCells.AddRange(dependsCells);
            foreach (MyCell cell in dependsCells)
            {
                for (int i = 0; i < RowCount; i++)
                {
                    if (cell.NameCell == TableCells[i, ColCount - 1].NameCell)
                    {
                        new_dependCells.Remove(cell);
                    }
                }
            }

            for (int i = 0; i < RowCount; i++)
            {
                string name = FullName(i, ColCount - 1);
                dictionary.Remove(name);
            }

            for (int i = 0; i < RowCount; i++)
            {
                if (dgv[ColCount - 1, i].Value == null)
                {
                    continue;
                }
                TableCells[i, ColCount - 1].DellDependsOnMeAndDepends();
            }

            foreach (MyCell cell in new_dependCells)
            {
                UpdateCells(cell, dgv);
            }

            for (int i = 0; i < RowCount; i++)
            {
                string name = FullName(ColCount - 1, i);
                TableCells[i, ColCount - 1] = new MyCell(name, i, ColCount - 1);
            }

            ColCount--;
            return(true);
        }