Example #1
0
        private async void Graph_Confirm_Create(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Graph_exist)
                {
                    msgdi = new MessageDialog("Não pode existir mais de um Grafo ainda!");
                    await msgdi.ShowAsync();

                    return;
                }
                else
                {
                    Graph                  = new Grafo(isDigraph.IsOn);
                    Graph.name             = label_box_graph.Text;
                    Graph_exist            = true;
                    GraphCreate.Visibility = Visibility.Collapsed;
                    myConsole.AddStringToConsole($"\nGrafo {label_box_graph.Text} foi adicionado.");
                    myConsole.Update();
                    Add_Graph.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                msgdi = new MessageDialog($"Erro: {ex.Message}");
                await msgdi.ShowAsync();
            }
            label_box_graph.Text = "";
        }
Example #2
0
        /// <summary>
        /// Checks Add-combobox and confirms the operation
        /// </summary>
        /// <param name="sender">Button Confirm</param>
        /// <param name="e">Routed Event</param>
        private async void Confirm_add_item(object sender, RoutedEventArgs e)
        {
            try
            {
                if (selected_item_name == "Grafo")
                {
                    if (Graph_exist)
                    {
                        msgdi = new MessageDialog("Não pode existir mais de um Grafo ainda!");
                        await msgdi.ShowAsync();

                        return;
                    }
                    else
                    {
                        Graph       = new Grafo(isDigraph.IsChecked.Value);
                        Graph.name  = label_box.Text;
                        Graph_exist = true;
                    }
                }
                if (Graph_exist)
                {
                    switch (selected_item_name)
                    {
                    case "Vértice":
                    {
                        Vertice vertice_aux = new Vertice(label_box.Text, Graph.NumVertices() + 1);

                        Graph.AddVertice(vertice_aux);
                        Debug.WriteLine(Graph.NumVertices());
                        Debug.WriteLine(Graph.NumArestas());
                        v1_box.Items.Add(vertice_aux.Label);
                        v2_box.Items.Add(vertice_aux.Label);
                        break;
                    }

                    case "Aresta":
                    {
                        Aresta aresta_aux = new Aresta(float.Parse(weigth_Aresta_box.Text), Graph.BuscaVertice(v1_box.SelectedItem.ToString()), Graph.BuscaVertice(v2_box.SelectedItem.ToString()), Graph.isDigraph);
                        Graph.AddAresta(aresta_aux);
                        break;
                    }
                    }
                    if (selected_item_name != "")
                    {
                        myConsole.AddStringToConsole($"\n{selected_item_name} {label_box.Text} foi adicionado.");
                    }
                }
                else
                {
                    msgdi = new MessageDialog("Não existe Grafo ainda!");
                    await msgdi.ShowAsync();
                }
            }catch (Exception ex) {
                msgdi = new MessageDialog($"Erro {ex.Message}");
                await msgdi.ShowAsync();
            }

            clear_ui_add();
            Add_scene.Visibility      = Visibility.Collapsed;
            ComboAdd_box.SelectedItem = "";
            myConsole.Update();
            graphStats.Update();
        }