/// <summary> /// Обробка події натискання кнопки Суміжності /// </summary> /// <param name="sender">Відправник</param> /// <param name="e">Подія</param> private void ABSToolStripMenuItem_Click(object sender, EventArgs e) { this.isOrtogonal = mainForm.ISOrtogonal(); this.N = draw.MaxVertexValue(); this.M = draw.CountOfNodes(); this.dataGridView1.Columns.Clear(); this.dataGridView1.Rows.Clear(); if (N > 0) { this.columns = new DataGridViewTextBoxColumn[N + 1]; for (int i = 0; i < N + 1; i++) { this.columns[i] = new DataGridViewTextBoxColumn(); if (i != 0) { this.columns[i].HeaderText = (i).ToString(); } this.columns[i].Width = 30; this.columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } this.dataGridView1.Columns.AddRange(this.columns); this.dataGridView1.Rows.Add(N); for (int i = 0; i < N; i++) { this.dataGridView1.Rows[i].Cells[0].Value = i + 1; } for (int i = 0; i < N; i++) { for (int j = 1; j < N + 1; j++) { this.dataGridView1.Rows[i].Cells[j].Value = "-"; } } for (int i = 0; i < draw.Nodes.Count; i++) { dataGridView1.Rows[draw.Nodes[i].First.Number - 1].Cells[draw.Nodes[i].Second.Number].Value = draw.Nodes[i].Weight; if (!isOrtogonal) { dataGridView1.Rows[draw.Nodes[i].Second.Number - 1].Cells[draw.Nodes[i].First.Number].Value = draw.Nodes[i].Weight; } } } }
/// <summary> /// Обробка події натиснення кнопки Зберегти граф до файлу /// </summary> /// <param name="sender">Відправник</param> /// <param name="e">Подія</param> private void toolStripButton5_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "txt files (*.txt)|*.txt"; var save = saveFileDialog1.ShowDialog(); if (save == System.Windows.Forms.DialogResult.OK && saveFileDialog1.FileName.Length > 0) { isSaved = true; using (StreamWriter write = new StreamWriter(saveFileDialog1.OpenFile())) { write.WriteLine(draw.CountOfVertex() + " " + draw.CountOfNodes() + " " + (isOrtogonal ? 1 : 0)); for (int i = 0; i < draw.Nodes.Count; i++) { write.WriteLine(draw.Nodes[i].First.Number + " " + draw.Nodes[i].Second.Number + " " + draw.Nodes[i].Weight); } } } else if (save == System.Windows.Forms.DialogResult.Cancel) { isSaved = false; } }