} //оновлення клітин, що залежать від даної public bool RecurrenceCheck(MyCell Current, MyCell Initial) { if (Current.IDependOn.Contains(Initial.Name)) { return(false); //pominyav } foreach (string cellName in Current.IDependOn) { if (RecurrenceCheck(dictionary[cellName], Initial)) { return(true); } } return(false); } //перевірка на наявність рекурсії
} //створює таблицю private void AddRow_Click(object sender, EventArgs e) { DataGridViewRow A = new DataGridViewRow(); A.HeaderCell.Value = rowNum.ToString(); dgv.Rows.Add(A); ++rowNum; for (int j = 0; j < dgv.ColumnCount; ++j) { string cellName = SetCellName(j, rowNum - 1); MyCell cell = new MyCell(cellName); cell.Value = 0; cell.Exp = "0"; cell.Column = j; cell.Row = A.Index; dictionary.Add(cellName, cell); } }
} //конструктор форми private void CreateDataGridView(int columns, int rows) { for (int i = 0; i < columns; ++i) { DataGridViewColumn A = new DataGridViewColumn(); A.HeaderText = SetColumnName(i); A.Name = A.HeaderText; MyCell cellA = new MyCell(); A.CellTemplate = cellA; dgv.Columns.Add(A); ++columnNum; } for (int i = 0; i < rows; ++i) { DataGridViewRow A = new DataGridViewRow(); A.HeaderCell.Value = i.ToString(); dgv.Rows.Add(A); ++rowNum; } } //створює таблицю
private void AddColumn_Click(object sender, EventArgs e) { DataGridViewColumn A = new DataGridViewColumn(); A.HeaderText = SetColumnName(columnNum); A.Name = A.HeaderText; MyCell cellA = new MyCell(); A.CellTemplate = cellA; dgv.Columns.Add(A); ++columnNum; for (int j = 0; j < dgv.RowCount; ++j) { string cellName = SetCellName(columnNum - 1, j); MyCell cell = new MyCell(cellName); cell.Value = 0; cell.Exp = "0"; cell.Row = j; cell.Column = A.Index; dictionary.Add(cellName, cell); } }
public Form1() { InitializeComponent(); openFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"; saveFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"; CreateDataGridView(Measures, Measures); for (int i = 0; i < rowNum; ++i) { for (int j = 0; j < columnNum; ++j) { string cellName = SetCellName(j, i); MyCell cell = new MyCell(cellName); cell.Value = 0; cell.Exp = "0"; cell.Column = j; cell.Row = i; dictionary.Add(cellName, cell); } } this.ActiveControl = dgv; } //конструктор форми
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { int columns = 0; int rows = 0; if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } string filename = openFileDialog1.FileName; StreamReader streamReader = new StreamReader(filename); columns = Convert.ToInt32(streamReader.ReadLine()); rows = Convert.ToInt32(streamReader.ReadLine()); Clear(dgv); CreateDataGridView(columns, rows); dictionary.Clear(); try { for (int i = 0; i < columns; ++i) { for (int j = 0; j < rows; ++j) { string cellName = SetCellName(i, j); MyCell cell = new MyCell(cellName); cell.Value = 0; cell.Exp = streamReader.ReadLine(); cell.Column = i; cell.Row = j; dictionary.Add(cellName, cell); } } for (int i = 0; i < columns; ++i) { for (int j = 0; j < rows; ++j) { string cellName = SetCellName(i, j); string input = dictionary[cellName].AddressToValue(ref dictionary); var output = Calculator.Evaluate(input); dictionary[cellName].Value = output; if (output != 0) { dgv[i, j].Value = output; } } } for (int i = 0; i < columns; ++i) { for (int j = 0; j < rows; ++j) { string cellName = SetCellName(i, j); RefreshCells(dictionary[cellName].Name); } } } catch (Exception) { MessageBox.Show("An error occurred while writing the file."); } finally { streamReader.Close(); } }