Ejemplo n.º 1
0
        private static void lerPlanilhaDeCoordenadasExcel()
        {
            using (ExcelPackage xlPackage = new ExcelPackage(arquivoExcel))
            {
                ExcelWorksheet myWorksheet  = xlPackage.Workbook.Worksheets.LastOrDefault(); //select sheet here
                int            totalRows    = myWorksheet.Dimension.End.Row;
                int            totalColumns = myWorksheet.Dimension.End.Column;

                lojasEmPlanilhaExcel = new List <LojaImportacao>();

                StringBuilder sb = new StringBuilder();             //this is your your data
                for (int rowNum = 2; rowNum <= totalRows; rowNum++) //selet starting row here
                {
                    Loja                 lojasDaPlanilha = new Loja();
                    LojaImportacao       li  = new LojaImportacao();
                    IEnumerable <string> row = myWorksheet.Cells[rowNum, 1, rowNum, totalColumns].Select(c => c.Value == null ? string.Empty : c.Value.ToString());

                    string s = string.Join(",", row);
                    //Console.WriteLine(s);
                    li.Nome          = row.ToList()[0];
                    li.Cidade        = row.ToList()[1];
                    li.CoordenadaKml = row.ToList()[2];

                    lojasDaPlanilha.preparaCoordenandaPoligono(li.CoordenadaKml);
                    lojasDaPlanilha.preparaCoordenandaMapa(li.CoordenadaKml);


                    li.CoordenadaPoligono = lojasDaPlanilha.CoordenadaPoligono.ToString();
                    li.CoordenadaMapa     = lojasDaPlanilha.CoordenadaMapa.ToString();
                    li.lojaComProblema    = lojasDaPlanilha.lojaComProblema;


                    lojasEmPlanilhaExcel.Add(li);
                }

                lojasSemFim = lojasEmPlanilhaExcel.Where(x => x.lojaComProblema == true).ToList();
            }
        }
Ejemplo n.º 2
0
        private static void lerXml()
        {
            /*
             #pragma warning disable CS0618 // Type or member is obsolete
             * XmlDataDocument kmlDoc = new XmlDataDocument();
             #pragma warning restore CS0618 // Type or member is obsolete
             * FileStream fs = new FileStream(@"C:\Users\thiago.hpereira\Documents\Visual Studio 2017\Projects\Teco\Lojas com menos pontos - V_Final.kml", FileMode.Open, FileAccess.Read);
             * kmlDoc.Load(fs);
             */

            //XmlReader reader = XmlReader.Create(@"C:\Users\thiago.hpereira\Documents\Visual Studio 2017\Projects\Teco\4 - Zona Sul - BELO HORIZONTE.kml");
            XmlReader reader = XmlReader.Create(arquivoKml);
            string    cidade = string.Empty;

            while (reader.Read())
            {
                reader.Read();
                Loja loja = new Loja();



                while (!(string.Equals(reader.Name.Trim('\t', '\r', '\n'), "Placemark") && reader.NodeType == XmlNodeType.EndElement))
                {
                    if (string.Equals(reader.Name.Trim('\t', '\r', '\n'), String.Empty) && reader.NodeType == XmlNodeType.None)
                    {
                        break;
                    }

                    if (string.Equals(reader.Name.Trim('\t', '\r', '\n'), "Placemark") && reader.NodeType == XmlNodeType.Element)
                    {
                        loja.Cidade = cidade;
                    }

                    if (reader.Name == "Document")
                    {
                        do
                        {
                            reader.Read();
                            if (!string.IsNullOrEmpty(reader.Value.Trim('\t', '\r', '\n')))
                            {
                                cidade      = reader.Value;
                                loja.Cidade = reader.Value;
                            }

                            if ((string.Equals(reader.Name.Trim('\t', '\r', '\n'), "kml") && reader.NodeType == XmlNodeType.EndElement))
                            {
                                break;
                            }
                        } while (loja.Cidade == null);
                    }

                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Placemark"))
                    {
                        do
                        {
                            reader.Read();
                            if (!string.IsNullOrEmpty(reader.Value.Trim('\t', '\r', '\n')))
                            {
                                loja.Nome = reader.Value;
                            }
                        } while (loja.Nome == null);
                    }
                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "coordinates"))
                    {
                        do
                        {
                            reader.Read();
                            if (!string.IsNullOrEmpty(reader.Value.Trim('\t', '\r', '\n')))
                            {
                                loja.CoordenadaKml = reader.Value.Trim('\t', '\r', '\n');
                                loja.preparaCoordenandaPoligono(loja.CoordenadaKml);
                                loja.preparaCoordenandaMapa(loja.CoordenadaKml);
                            }
                        } while (loja.CoordenadaKml == null);
                    }
                    reader.Read();
                }

                if (string.Equals(reader.Name.Trim('\t', '\r', '\n'), String.Empty) && reader.NodeType == XmlNodeType.None)
                {
                    break;
                }

                lojas.Add(loja);

                //Console.WriteLine($"loja:  {lojas.IndexOf(loja) + 1} \n Nome: {loja.Nome} \n Cidade: {loja.Cidade} \n coordenada: {loja.CoordenadaKml.Substring(0, 80)}... \n");
            }
        }