コード例 #1
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 (Graph_exist)
                {
                    switch (selected_item_name)
                    {
                    case "Vértice":
                    {
                        Vertice vertice_aux = new Vertice(label_box.Text, Graph.NumVertices());
                        Graph.AddVertice(vertice_aux);

                        v1_box.Items.Add(vertice_aux.Label);
                        v2_box.Items.Add(vertice_aux.Label);
                        v1_rem_box.Items.Add(vertice_aux.Label);
                        v2_rem_box.Items.Add(vertice_aux.Label);
                        if (Graph.Vertices.Count > 0)
                        {
                            Vertex_list.ItemsSource = Graph.VerticeToListString();
                        }
                        else
                        {
                            Vertex_list.ItemsSource = null;
                        }
                        IsNotRendered = true;
                        break;
                    }

                    case "Aresta":
                    {
                        if (Graph.Vertices.Count > 0)
                        {
                            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.");
                    }
                    myConsole.Update();
                }
                else
                {
                    msgdi = new MessageDialog("Não existe Grafo ainda!");
                    await msgdi.ShowAsync();
                }
            }catch (Exception ex) {
                msgdi = new MessageDialog($"Erro {ex.Message}");
                await msgdi.ShowAsync();
            }
        }
コード例 #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();
        }
コード例 #3
0
        //public static void CarregarGrafoPeloArquivo(IDado[,] matriz)
        //{
        //    for (int i = 0; i < matriz.GetLength(0); i++)
        //    {
        //        Vertice disc = new Vertice(matriz[i, 0]);
        //        Vertice prof = new Vertice(matriz[i, 1]);
        //        Vertice peri = new Vertice(matriz[i, 2]);

        //        grade.AddVertice(disc);
        //        grade.AddVertice(prof);
        //        grade.AddVertice(peri);

        //        grade.AddAresta(new Aresta(disc, prof));
        //        grade.AddAresta(new Aresta(disc, peri));
        //    }
        //}

        public static void CarregarGrafoPeloBanco()
        {
            DataTable disciplinas = (new TDisciplina()).SelectAll();
            DataTable horarios    = (new THorario()).SelectAll();
            DataTable alocacao    = (new TAlocacao()).SelectAll();

            grade = new Grafo();

            foreach (DataRow linha in disciplinas.Rows)
            {
                // DISCIPLINA

                Disciplina d           = new Disciplina(linha[2].ToString(), int.Parse(linha[3].ToString()), int.Parse(linha[1].ToString()));
                Vertice    vDisciplina = new Vertice(d);
                grade.AddVertice(vDisciplina);

                // PERIODO

                Periodo p        = new Periodo(int.Parse(linha[1].ToString()));
                Vertice vPeriodo = grade.GetVerticePorDado(p);

                if (vPeriodo == null)
                {
                    vPeriodo = new Vertice(p);
                    grade.AddVertice(vPeriodo);
                }

                // PROFESSOR

                DataRow linhap = (new TProfessor()).Select(linha[3].ToString()); //uma consulta por inserção de disciplina é muito. Otimizar isso depois

                Professor f          = new Professor(int.Parse(linhap[0].ToString()), int.Parse(linhap[1].ToString()));
                Vertice   vProfessor = grade.GetVerticePorDado(f);

                if (vProfessor == null)
                {
                    vProfessor = new Vertice(f);
                    grade.AddVertice(vProfessor);
                }

                grade.AddAresta(new Aresta(vDisciplina, vPeriodo));
                grade.AddAresta(new Aresta(vDisciplina, vProfessor));
            }

            foreach (DataRow linha in horarios.Rows)
            {
                // HORARIO

                Horario h = new Horario(
                    (DiaSemana)int.Parse(linha[3].ToString()),
                    DateTime.Parse(linha[1].ToString()) == DateTime.Parse("19:00:00") ? Hora._19h00 : Hora._20h50);

                Vertice vHorario = new Vertice(h);

                grade.AddVertice(vHorario);

                foreach (DataRow linhaAloc in alocacao.Rows)
                {
                    if (linhaAloc[2].ToString() == linha[0].ToString())
                    {
                        Disciplina disc = new Disciplina(int.Parse(linhaAloc[1].ToString()));

                        Vertice vDisciplina = grade.GetVerticePorDado(disc);
                        Vertice vPeriodo    = grade.GetVerticePorDado(new Periodo(disc.Periodo));

                        grade.AddAresta(new Aresta(vHorario, vDisciplina));
                        grade.AddAresta(new Aresta(vHorario, vPeriodo));
                    }
                }
            }
        }