private void button6_Click(object sender, EventArgs e) //клік на read directly from file { if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { StreamReader strrd = new StreamReader(openFileDialog1.FileName); int num_of_vertex = Convert.ToInt32(strrd.ReadLine()); MatrixElement[,] matrix = new MatrixElement[num_of_vertex, num_of_vertex]; for (int i = 0; i < num_of_vertex; i++) { string[] temp = strrd.ReadLine().Split(' '); for (int j = 0; j < num_of_vertex; j++) { if (temp[j] == "&") { matrix[i, j] = new MatrixElement(int.MaxValue); } else { matrix[i, j] = new MatrixElement(Convert.ToInt32(temp[j])); } } } strrd.Close(); DoIt(matrix); } catch { MessageBox.Show("You have choosed incorrect file!"); } } }
private void button3_MouseClick(object sender, MouseEventArgs e) //клік на start { try { int num_of_vertex = dataGridView1.Columns.Count; MatrixElement[,] matrix = new MatrixElement[num_of_vertex, num_of_vertex]; for (int i = 0; i < num_of_vertex; i++) { for (int j = 0; j < num_of_vertex; j++) { if (dataGridView1.Rows[i].Cells[j].Value.ToString() == "&") { matrix[i, j] = new MatrixElement(int.MaxValue); } else { matrix[i, j] = new MatrixElement(Convert.ToInt32(dataGridView1.Rows[i].Cells[j].Value.ToString())); } } } DoIt(matrix); } catch { MessageBox.Show("Something went wrong. Maybe you entered wrong values into table or left it empty. Please enter only numbers or \"&\" and don't left cells empty."); } }