public void RemoveColumnAt() { if (COLUMNS > 2) { int ii = dataGridView1.CurrentCell.ColumnIndex; ClassBaseSys sys1 = new ClassBaseSys(); ColumnList.Clear(); for (int i = 0; i < ROWS; ++i) { string res = ""; res = sys1.ToEx(ii); res += i.ToString(); ColumnList.Add(res); } RefreshForColumn(ColumnList); dataGridView1.Columns.RemoveAt(ii); COLUMNS--; int k = 0; foreach (DataGridViewColumn col in dataGridView1.Columns) { ClassBaseSys sys = new ClassBaseSys(); string res = sys.ToEx(k); col.HeaderCell.Value = res; k++; } } else { MessageBox.Show("Подальше видалення неможливе"); } }
public void RemoveRowAt() { if (ROWS >= 2) { int ii = dataGridView1.CurrentRow.Index; ClassBaseSys sys = new ClassBaseSys(); ColumnList.Clear(); for (int i = 0; i < COLUMNS; ++i) { string res = ""; res = sys.ToEx(i); res += (ii).ToString(); ColumnList.Add(res); } RefreshForColumn(ColumnList); dataGridView1.Rows.RemoveAt(ii); ROWS--; int k = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { row.HeaderCell.Value = k.ToString(); k++; } } else { MessageBox.Show("Подальше видалення неможливе"); } }
public void RemoveRowInTheEnd() { bool flag = true; if (dataGridView1.RowCount <= 2) { MessageBox.Show("Неможливо видалити"); flag = false; } ClassBaseSys sys = new ClassBaseSys(); ColumnList.Clear(); if (flag) { for (int i = 0; i < COLUMNS; ++i) { string res = ""; res = sys.ToEx(i); res += (ROWS - 1).ToString(); ColumnList.Add(res); } RefreshForColumn(ColumnList); dataGridView1.Rows.RemoveAt(ROWS - 1); ROWS--; dataGridView1.Rows[ROWS].HeaderCell.Value = ROWS.ToString(); } }
public void RemoveColumnEnd() { bool columnIsEmpty = true; for (int j = 0; j < dataGridView1.RowCount - 1; ++j) { char c = Char.Parse(dataGridView1.Rows[j].Cells[COLUMNS - 1].Value.ToString()); if (COLUMNS <= 2) { columnIsEmpty = false; } } if (columnIsEmpty == false) { MessageBox.Show("Неможливо видалити"); } else { ClassBaseSys sys = new ClassBaseSys(); ColumnList.Clear(); for (int i = 0; i < ROWS; ++i) { string res = ""; res = sys.ToEx(COLUMNS - 1); res += i.ToString(); ColumnList.Add(res); } RefreshForColumn(ColumnList); if (columnIsEmpty == true) { dataGridView1.Columns.RemoveAt(COLUMNS - 1); COLUMNS--; } if (dataGridView1.ColumnCount <= 2) { MessageBox.Show("Подальше видалення неможливе"); return; } } }
public void addNewValue(string exptession, int r, int c) { int uni1 = 64; int uni2 = 91; int uni3 = 47; int uni4 = 58; int LetRow; int LetCol; if (exptession == "" || exptession == " ") { table[r, c].value_1 = exptession; table[r, c].exp = ""; dataGridView1.CurrentCell.Value = exptession; return; } table[r, c].exp = exptession; int h = 0; exptession = exptession.Replace(" ", ""); if (exptession != null) { if (exptession[0] == '=') { int t2; int kk = 0; int k1 = 0; int calc1 = 0; int calc2 = 0; exptession = exptession.Replace(exptession[0], ' '); exptession = exptession.Replace(" ", ""); string test = exptession; while (k1 < test.Length) { if (test[k1] == '(') { calc1++; } if (test[k1] == ')') { calc2++; } k1++; } if (calc1 != calc2) { dataGridView1.Rows[r].Cells[c].Value = "Error"; table[r, c].value_1 = "0"; return; } while (h < test.Length) { int t1 = (int)test[h]; string resultC = ""; string resultR = ""; if ((t1 > uni1) && (t1 < uni2)) { if (kk == 0) { SaveTable[r, c].value_1 = exptession; } resultC += test[h].ToString(); h++; t2 = (int)test[h]; while ((t2 > uni1 && t2 < uni2)) { resultC += test[h]; h++; t2 = (int)test[h]; } while ((t2 > uni3 && t2 < uni4)) { resultR += test[h]; h++; if (h < test.Length) { t2 = (int)test[h]; } else { t2 = 100; } } ClassBaseSys ress = new ClassBaseSys(); int cc = ress.FromEx(resultC); int rr = int.Parse(resultR); if (cc > COLUMNS || rr > ROWS) { table[r, c].value_1 = "error"; table[r, c].exp = ""; dataGridView1.Rows[r].Cells[c].Value = "error"; return; } LetCol = cc; LetRow = rr; string resss = dataGridView1.Rows[rr].Cells[cc].Value.ToString(); table[rr, cc].dependents.Add(table[r, c].getName(c, r)); for (int i = 0; i < table[r, c].dependents.Count; ++i) { table[rr, cc].dependents.Add(table[r, c].dependents[i]); } exptession = exptession.Replace(resultC + resultR, resss); kk++; } h++; } int hh = 0; bool f = false; while (hh < exptession.Length) { if (!Char.IsDigit(exptession[hh]) && exptession != " ") { f = true; break; } hh++; } if (f) { for (int i = 0; i < exptession.Length; ++i) { if (exptession[i] == '/' && exptession[i + 1] == '0') { table[r, c].value_1 = "0"; dataGridView1.Rows[r].Cells[c].Value = "divide by zero"; return; } } ToPolandNotation cur = new ToPolandNotation(); double res = cur.Calculate(exptession); if (circle(table[r, c], r, c)) { if (dataGridView1.Rows[r].Cells[c].Value.ToString() == "#CIRCLE") { dataGridView1.Rows[r].Cells[c].Value = "0"; } table[r, c].value_1 = res.ToString(); dataGridView1.Rows[r].Cells[c].Value = res; ColumnList.Clear(); ClassBaseSys test1 = new ClassBaseSys(); string c1 = test1.ToEx(c); ColumnList.Add(c1 + r.ToString()); RefreshForColumn(ColumnList); } else { MessageBox.Show("NO"); return; } } else { if (exptession == " " || exptession == "") { table[r, c].value_1 = "0"; dataGridView1.Rows[r].Cells[c].Value = "0"; table[r, c].exp = ""; } else { if (dataGridView1.Rows[r].Cells[c].Value.ToString() == "#CIRCLE") { table[r, c].dependents.Clear(); dataGridView1.Rows[r].Cells[c].Value = "0"; } table[r, c].value_1 = exptession; dataGridView1.Rows[r].Cells[c].Value = exptession; } if (circle(table[r, c], r, c)) { ColumnList.Clear(); ClassBaseSys test1 = new ClassBaseSys(); string c1 = test1.ToEx(c); ColumnList.Add(c1 + r.ToString()); RefreshForColumn(ColumnList); } } } else { table[r, c].value_1 = exptession; table[r, c].exp = exptession; dataGridView1.Rows[r].Cells[c].Value = exptession; ColumnList.Clear(); ClassBaseSys test1 = new ClassBaseSys(); string c1 = test1.ToEx(c); ColumnList.Add(c1 + r.ToString()); RefreshForColumn(ColumnList); } } }
public void RefreshForColumn(List <string> curList) { int uni1 = 64; int uni2 = 91; int uni3 = 47; int uni4 = 58; for (int i = 0; i < st1; ++i) { for (int j = 0; j < st1; ++j) { if (SaveTable[i, j].value_1 != "0") { int t2; string exptession = SaveTable[i, j].value_1; int h = 0; while (h < exptession.Length) { int t1 = (int)exptession[h]; string resultC = ""; string resultR = ""; if ((t1 > uni1) && (t1 < uni2)) { resultC += exptession[h].ToString(); h++; t2 = (int)exptession[h]; while ((t2 > uni1 && t2 < uni2)) { resultC += exptession[h]; h++; t2 = (int)exptession[h]; } while ((t2 > uni3 && t2 < uni4)) { resultR += exptession[h]; h++; if (h < exptession.Length) { t2 = (int)exptession[h]; } else { t2 = 100; } } ClassBaseSys ress = new ClassBaseSys(); int cc = ress.FromEx(resultC); int rr = int.Parse(resultR); foreach (string str in curList) { if (str == resultC + resultR) { if (curList.Count == 1) { if (circle(table[i, j], i, j)) { string str1 = ""; str1 = table[i, j].exp.ToString(); addNewValue(str1, i, j); return; } else { return; } } else { dataGridView1.Rows[i].Cells[j].Value = 0; table[i, j].value_1 = "0"; table[i, j].exp = "0"; } } } } h++; } } } } }