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 }
private void btnOK_Click(object sender, RoutedEventArgs e) { try { if (!(string.IsNullOrEmpty(to)) && !(string.IsNullOrEmpty(from)) && !(string.IsNullOrEmpty(txtWeight.Text))) { var regx = new Regex(@"^[0-9]+$"); if (regx.IsMatch(txtWeight.Text) || txtWeight.Text.Trim().ToLower().Equals("inf")) { int ifrom = findVetex(from); int ito = findVetex(to); if (ifrom != -1 && ito != -1) { graph.Records[ifrom].Edges[ito] = txtWeight.Text; GPH.SetGraph(graph); this.Close(); } else { throw new Exception("Wrong input! from or destination vertex has a problem!"); } } else { throw new Exception("invalid input as weight."); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Warning"); } }