private void btnOK_Click(object sender, RoutedEventArgs e) { try { string vertexName = txtVertextName.Text.Trim().ToUpper(); var graph = GPH.GetGraph(); if (!(graph.Header.Vertices.Exists(x => x.ToLower().Equals(vertexName.ToLower())))) { graph.Header.AddVertex(vertexName); List <string> edges = new List <string>(); for (int i = 0; i < graph.Records.Count; i++) //reset the edges weights(doesn't have a path to any vertices) { edges.Add("Inf"); graph.Records[i].AddEdge("Inf"); } edges.Add("0"); graph.AddRecord(new GraphRecord() { VertexName = vertexName, Edges = edges }); GPH.SetGraph(graph); //write it to file and save. } else { throw new Exception("this vertex already exist."); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Warning!"); } this.Close(); //close the app }
public AddEdge() { InitializeComponent(); GPH = new GraphFile(); graph = GPH.GetGraph(); from = to = string.Empty; }
public MainWindow() { InitializeComponent(); GPH = new GraphFile(); var graph = GPH.GetGraph(); GenerateGraph(graph); RefreshList(); }
private void RefreshList() { var graph = GPH.GetGraph(); DataTable dt = new DataTable(); //design columns for (int i = -1; i < graph.Header.Vertices.Count; i++) { if (i == -1) { dt.Columns.Add(new DataColumn("Matrix")); } else { dt.Columns.Add(new DataColumn($"{graph.Header.Vertices[i]}")); } } for (int i = 0; i < graph.Records.Count; i++) { var row = dt.NewRow(); for (int j = -1; j < graph.Records.Count; j++) { if (j == -1) { row["Matrix"] = graph.Records[i].VertexName; } else { row[$"{graph.Header.Vertices[j]}"] = graph.Records[i].Edges[j]; } } dt.Rows.Add(row); } lst_matrix.AutoGenerateColumns = true; lst_matrix.ItemsSource = dt.DefaultView; }