예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var filecontend = string.Empty;
            var file        = string.Empty;

            string[] trabalhadores;
            using (OpenFileDialog open = new OpenFileDialog())
            {
                open.InitialDirectory = Path.Combine(Application.StartupPath);
                open.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    file = open.FileName;
                    var filestream = open.OpenFile();
                    using (StreamReader reader = new StreamReader(filestream, Encoding.GetEncoding("iso-8859-1")))
                    {
                        filecontend = reader.ReadToEnd();
                    }
                }
            }
            filecontend   = filecontend.Replace("\r", "");
            trabalhadores = filecontend.Split(',', ';', '\n');
            for (int i = 0; i < trabalhadores.Length; i = i + 5)
            {
                trabalhadores[i + 1] = trabalhadores[i + 1].Replace('.', ',');
                trabalhadores[i + 2] = trabalhadores[i + 2].Replace(".", ",");
            }
            CurrentGraph.AddNode("julio", "-15,836073", "-47,912019", "estudante", true);
            for (int i = 0; i < trabalhadores.Length; i = i + 5)
            {
                if (bool.Parse(trabalhadores[i + 4]) == true)
                {
                    CurrentGraph.AddNode(trabalhadores[i], trabalhadores[i + 1], trabalhadores[i + 2], trabalhadores[i + 3], bool.Parse(trabalhadores[i + 4]));
                }
            }
            for (int i = 0; i < CurrentGraph.Nodes.Count; i++)
            {
                for (int j = 0; j < CurrentGraph.Nodes.Count; j++)
                {
                    if (i != j)
                    {
                        CurrentGraph.AddAdjacency(CurrentGraph.GetNodeById(i), CurrentGraph.GetNodeById(j), converterCord(CurrentGraph.GetNodeById(i).latitude, CurrentGraph.GetNodeById(j).latitude, CurrentGraph.GetNodeById(i).longitude, CurrentGraph.GetNodeById(j).longitude));
                    }
                }
            }
            listView1.Columns.Add("Nome", 121);
            listView1.Columns.Add("Profissão", 121);
            List <string> Adicionado = new List <string>();

            for (int i = 1; i < CurrentGraph.Nodes.Count; i++)
            {
                var item1 = new ListViewItem(new[] { CurrentGraph.GetNodeById(i).Name, CurrentGraph.GetNodeById(i).profissao });
                //var item1 = new ListViewItem(new[] { CurrentGraph.GetNodeById(i).profissao });
                item1.Tag = CurrentGraph.GetNodeById(i);
                var node = (Node)item1.Tag;
                //if (!Adicionado.Contains(node.profissao)) {
                listView1.Items.Add(item1);
                //Adicionado.Add(node.profissao);
                //}
            }
            BaseGraph = CurrentGraph.Copy();
            RefreshGraphDraw();
        }