private void listBoxDestinos_DoubleClick(object sender, EventArgs e) { model get = new model(); DtoLatLong latlgn = get.getLatLngId(listBoxDestinos.Text); //center map gMapControl1.Position = new PointLatLng(Convert.ToDouble(latlgn.latitude, CultureInfo.InvariantCulture), Convert.ToDouble(latlgn.longitude, CultureInfo.InvariantCulture)); //set zoom gMapControl1.Zoom = 15; }
public void ArquivoTXT(string[] theLines) { progressBar1.Maximum = theLines.Count(); progressBar1.Minimum = 0; for (int i = 0; i < theLines.Count(); i++) { progressBar1.Value = i; DtoDestino destino = new DtoDestino(); destino.transportadora = theLines[0]; if (theLines[i].Contains("NF:")) { if (theLines[i].Substring(3).Length > 30) { destino.documento = theLines[i].Substring(3, 30); } else { destino.documento = theLines[i].Substring(3); } destino.nome = theLines[i + 1]; model get = new model(); Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora); if (!existeDocumento) { int posicao = theLines[i + 2].IndexOf("-"); string bairro = theLines[i + 2].Substring(posicao + 2); int posicaofinal = bairro.IndexOf("-"); destino.bairro = bairro.Substring(0, 7); destino.endereco = theLines[i + 2].Replace('-', ','); model m = new model(); DtoLatLong latlong = m.GetLatLongGoogle(destino.endereco); try { destino.latitude = double.Parse(latlong.latitude, CultureInfo.InvariantCulture); destino.longitude = double.Parse(latlong.longitude, CultureInfo.InvariantCulture); destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture); destino.duracao = latlong.duracao; } catch (Exception) { destino.status = "E"; } destino.status = "I"; model post = new model(); post.set(destino); } } } }
private List <DtoRota> RouteGoogle(string origem, string destino, string rota) { var requestUri = string.Format("https://maps.googleapis.com/maps/api/directions/xml?origin=" + origem + "&destination=" + destino + "&waypoints=optimize:true" + rota + "|&key=AIzaSyAwjnJzF57fQddVy_dL8yTC01Zw7ufVuY8", Uri.EscapeDataString(rota)); WebRequest request = WebRequest.Create(requestUri); List <DtoRota> list = new List <DtoRota>(); using (WebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { DataSet dsResult = new DataSet(); dsResult.ReadXml(reader); for (int i = 0; i < dsResult.Tables["leg"].Rows.Count; i++) { DtoRota r = new DtoRota(); string startEndereco = dsResult.Tables["leg"].Rows[i]["start_address"].ToString(); string endEndereco = dsResult.Tables["leg"].Rows[i]["end_address"].ToString(); r.start_address = startEndereco; r.end_address = endEndereco; //r.waypoint_order = i; DtoLatLong latlongstart = GetLatLongGoogle(startEndereco); //DtoLatLong latlongstart = GetLatLongBD(startEndereco); try { r.start_latitude = latlongstart.latitude; r.start_longitude = latlongstart.longitude; } catch (Exception) { throw; } DtoLatLong latlongend = GetLatLongGoogle(endEndereco); try { r.end_latitude = latlongend.latitude; r.end_longitude = latlongend.longitude; } catch (Exception) { throw; } list.Add(r); } } } return(list); }
private void btnConsultar_Click(object sender, EventArgs e) { model get = new model(); DtoLatLong latlong = get.GetLatLongGoogle(textBoxEndereco.Text); try { textBoxLatitude.Text = latlong.latitude; textBoxLongitude.Text = latlong.longitude; } catch (Exception) { throw; } }
public DtoLatLong GetLatLongGoogle(string text) { Context db = new Context(); string origin = string.Empty; try { origin = db.empresa.SingleOrDefault().endereco; } catch (Exception) { origin = "Rua Carlos DallAgnolo 121,Toledo, PR"; } string requestUriCordenadas = string.Format("https://maps.googleapis.com/maps/api/geocode/xml?address=" + text + "&key=AIzaSyAwjnJzF57fQddVy_dL8yTC01Zw7ufVuY8", Uri.EscapeDataString(text)); string requestUriDistancia = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" + origin + "&destinations=" + text + "&key=AIzaSyCNiXQqjhm3GQ83i2FmXXo835XUOfylz6c"; string duration; string distance; WebRequest requestCordenadas = WebRequest.Create(requestUriCordenadas); using (WebResponse response = (HttpWebResponse)requestCordenadas.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { DataSet dsResult = new DataSet(); dsResult.ReadXml(reader); string lati = dsResult.Tables["location"].Rows[0]["lat"].ToString(); string longi = dsResult.Tables["location"].Rows[0]["lng"].ToString(); WebRequest requestDistancia = WebRequest.Create(requestUriDistancia); using (WebResponse responseDistancia = (HttpWebResponse)requestDistancia.GetResponse()) { using (StreamReader readerDistancia = new StreamReader(responseDistancia.GetResponseStream(), Encoding.UTF8)) { DataSet dsResultDistancia = new DataSet(); dsResultDistancia.ReadXml(readerDistancia); duration = dsResultDistancia.Tables["duration"].Rows[0]["text"].ToString() + " - " + dsResultDistancia.Tables["distance"].Rows[0]["text"].ToString();; distance = dsResultDistancia.Tables["distance"].Rows[0]["value"].ToString(); } } DtoLatLong i = new DtoLatLong(); i.latitude = lati; i.longitude = longi; i.distancia = distance; i.duracao = duration; return(i); } } }
private void CarregarMapa() { //use google provider //gMapControl1.MapProvider = BingMapProvider.Instance; gMapControl1.MapProvider = GoogleMapProvider.Instance; //get tiles from server only gMapControl1.Manager.Mode = AccessMode.ServerOnly; //not use proxy GMapProvider.WebProxy = null; //center map on toledo model get = new model(); DtoLatLong latlgn = get.getLatlgnEmpresa(); gMapControl1.Position = new PointLatLng(Convert.ToDouble(latlgn.latitude, CultureInfo.InvariantCulture), Convert.ToDouble(latlgn.longitude, CultureInfo.InvariantCulture)); //zoom min/max; default both = 2 gMapControl1.MinZoom = 1; gMapControl1.MaxZoom = 100; //set zoom gMapControl1.Zoom = 13; }
private void CarregarMapa() { try { Provider(); //get tiles from server only gMapControl1.Manager.Mode = AccessMode.ServerOnly; //center map on toledo model get = new model(); DtoLatLong latlgn = get.getLatlgnEmpresa(); gMapControl1.Position = new PointLatLng(Convert.ToDouble(latlgn.latitude, CultureInfo.InvariantCulture), Convert.ToDouble(latlgn.longitude, CultureInfo.InvariantCulture)); //zoom min/max; default both = 2 gMapControl1.MinZoom = 1; gMapControl1.MaxZoom = 100; //set zoom gMapControl1.Zoom = 13; } catch (Exception ex) { throw ex; } }
private void Jadlog(string[] theLines) { try { progressBar1.Maximum = theLines.Count(); progressBar1.Minimum = 0; for (int i = 0; i < theLines.Count(); i++) { progressBar1.Value = i; if (theLines[i].Contains("Nome") && theLines[i].Contains("Cep")) { DtoDestino destino = new DtoDestino(); destino.transportadora = "JADLOG"; if (theLines[i].Contains("NomeNome")) { destino.documento = theLines[i].Substring(9, 14); } else { destino.documento = theLines[i].Substring(5, 14); } model get = new model(); Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora); if (!existeDocumento) { destino.nome = theLines[i + 1].Substring(0, 29); int posicao = theLines[i + 1].IndexOf("-"); int posicaobairro = (theLines[i - 1].IndexOf("-")) + 1; string bairro = theLines[i - 1].Substring(posicaobairro); destino.bairro = bairro; destino.endereco = theLines[i + 1].Substring(posicao + 1).Replace('/', ',') + "," + bairro + ",Toledo, PR"; model m = new model(); DtoLatLong latlong = m.GetLatLongGoogle(destino.endereco); try { destino.latitude = double.Parse(latlong.latitude, CultureInfo.InvariantCulture); destino.longitude = double.Parse(latlong.longitude, CultureInfo.InvariantCulture); destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture); destino.duracao = latlong.duracao; } catch (Exception) { destino.status = "E"; } destino.status = "I"; model post = new model(); post.set(destino); } } } CarregarDestinos(); progressBar1.Visible = false; } catch (Exception ex) { } }
private void TotalExpress(string[] theLines) { try { progressBar1.Maximum = theLines.Count(); progressBar1.Minimum = 0; int linha = 0; foreach (var l in theLines) { linha++; progressBar1.Value = linha; if (linha >= 15 && linha < 48) { string theLine = l.ToLower(); DtoDestino destino = new DtoDestino(); destino.transportadora = "TotalExpress"; string nrLinha = theLine.Substring(0, 2); if (nrLinha.Trim().Length == 1) { destino.documento = theLine.Substring(20, 9); destino.nome = theLine.Substring(35); int posicao = theLine.IndexOf("/") + 2; if (theLine.Substring(posicao).Length > 30) { destino.bairro = theLine.Substring(posicao, 30).ToUpper(); } else { destino.bairro = theLine.Substring(posicao).ToUpper(); } model get = new model(); Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora); if (!existeDocumento) { if (theLine.Contains("avenida")) { int posicaoAvenia = theLine.IndexOf("avenida"); destino.endereco = theLine.Substring(posicaoAvenia).Replace('/', ',') + ",Toledo, PR"; } else if (theLine.Contains("rua")) { int posicaoRua = theLine.IndexOf("rua"); destino.endereco = theLine.Substring(posicaoRua).Replace('/', ',') + ",Toledo, PR"; } else { destino.endereco = theLine.Substring(61).Replace('/', ',') + ",Toledo, PR"; } try { model getlatlng = new model(); DtoLatLong latlong = getlatlng.GetLatLongGoogle(destino.endereco); destino.latitude = Convert.ToDouble(latlong.latitude, CultureInfo.InvariantCulture); destino.longitude = Convert.ToDouble(latlong.longitude, CultureInfo.InvariantCulture); destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture); destino.duracao = latlong.duracao; } catch (Exception ex) { destino.status = "E"; } } } else { destino.documento = theLine.Substring(20, 9); destino.nome = theLine.Substring(36); int posicao = theLine.IndexOf("/") + 2; if (theLine.Substring(posicao).Length > 30) { destino.bairro = theLine.Substring(posicao, 30).ToUpper(); } destino.documento = theLine.Substring(20, 9); model get = new model(); Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora); if (!existeDocumento) { if (theLine.Contains("avenida")) { int posicaoAvenia = theLine.IndexOf("avenida"); destino.endereco = theLine.Substring(posicaoAvenia).Replace('/', ',') + ",Toledo, PR"; } else if (theLine.Contains("rua")) { int posicaoRua = theLine.IndexOf("rua"); destino.endereco = theLine.Substring(posicaoRua).Replace('/', ',') + ",Toledo, PR"; } else if (theLine.Contains("rodovia")) { int posicaoRua = theLine.IndexOf("rodovia"); destino.endereco = theLine.Substring(posicaoRua).Replace('/', ',') + ",Toledo, PR"; } else { destino.endereco = theLine.Substring(61).Replace('/', ',') + ",Toledo, PR"; } try { model getlatlng = new model(); DtoLatLong latlong = getlatlng.GetLatLongGoogle(destino.endereco); destino.latitude = Convert.ToDouble(latlong.latitude, CultureInfo.InvariantCulture); destino.longitude = Convert.ToDouble(latlong.longitude, CultureInfo.InvariantCulture); destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture); destino.duracao = latlong.duracao; } catch (Exception) { destino.status = "E"; } } } destino.status = "I"; model post = new model(); post.set(destino); } } CarregarDestinos(); progressBar1.Visible = false; } catch (Exception ex) { throw ex;; } }
private void DIALOGO(string[] theLines) { try { progressBar1.Maximum = theLines.Count(); progressBar1.Minimum = 0; for (int i = 0; i < theLines.Count(); i++) { progressBar1.Value = i; if (i >= 19) { DtoDestino destino = new DtoDestino(); destino.transportadora = "DIALOGO"; destino.documento = Regex.Match(theLines[i].Substring(11, 9), @"\d+").Value; if (theLines[i + 1].Contains("CENTRO")) { destino.bairro = "CENTRO"; } else if (theLines[i + 1].Contains("VILA INDUSTRIAL")) { destino.bairro = "VILA INDUSTRIAL"; } else if (theLines[i + 1].Contains("JARDIM PORTO ALEGRE")) { destino.bairro = "JARDIM PORTO ALEGRE"; } else if (theLines[i + 1].Contains("JARDIM POR")) { destino.bairro = "JARDIM PORTO ALEGRE"; } else if (theLines[i + 1].Contains("JD PTO ALEGRE")) { destino.bairro = "JARDIM PORTO ALEGRE"; } else if (theLines[i + 1].Contains("JD PORTO ALEGRE")) { destino.bairro = "JARDIM PORTO ALEGRE"; } else if (theLines[i + 1].Contains("SANTA CLARA 4")) { destino.bairro = "SANTA CLARA IV"; } else if (theLines[i + 1].Contains("SANTA CLARA IV")) { destino.bairro = "SANTA CLARA IV"; } else if (theLines[i + 1].Contains("JARDIM EUR")) { destino.bairro = "JARDIM EUROPA"; } else if (theLines[i + 1].Contains("JD EUROPA")) { destino.bairro = "JARDIM EUROPA"; } else if (theLines[i + 1].Contains("VILA PIONEIRO")) { destino.bairro = "VILA PIONEIRO"; } else if (theLines[i + 1].Contains("Vila Pioneiro")) { destino.bairro = "VILA PIONEIRO"; } else if (theLines[i + 1].Contains("VILA PIONE")) { destino.bairro = "VILA PIONEIRO"; } else if (theLines[i + 1].Contains("VL PIONEIRO")) { destino.bairro = "VILA PIONEIRO"; } else if (theLines[i + 1].Contains("JARDIM PAULISTA")) { destino.bairro = "JARDIM PAULISTA"; } else if (theLines[i + 1].Contains("JARDIM PAU")) { destino.bairro = "JARDIM PAULISTA"; } else if (theLines[i + 1].Contains("JARDIM PANORAMA")) { destino.bairro = "JARDIM PANORAMA"; } else if (theLines[i + 1].Contains("JARDIM PAN")) { destino.bairro = "JARDIM PANORAMA"; } else if (theLines[i + 1].Contains("JARDIM BRESSAN")) { destino.bairro = "JARDIM BRESSAN"; } else if (theLines[i + 1].Contains("JARDIM BRE")) { destino.bairro = "JARDIM BRESSAN"; } else if (theLines[i + 1].Contains("JARDIM PARIZZOTTO")) { destino.bairro = "JARDIM PARIZZOTTO"; } else if (theLines[i + 1].Contains("SAO FRANCISCO")) { destino.bairro = "SAO FRANCISCO"; } else if (theLines[i + 1].Contains("SAO FRANCI")) { destino.bairro = "SAO FRANCISCO"; } else if (theLines[i + 1].Contains("BOA ESPERANCA")) { destino.bairro = "BOA ESPERANCA"; } else if (theLines[i + 1].Contains("JARDIM CONCORDIA")) { destino.bairro = "JARDIM CONCORDIA"; } else if (theLines[i + 1].Contains("JARDIM CON")) { destino.bairro = "JARDIM CONCORDIA"; } else if (theLines[i + 1].Contains("JARDIM COOPAGRO")) { destino.bairro = "JARDIM COOPAGRO"; } else if (theLines[i + 1].Contains("MARACANA")) { destino.bairro = "MARACANA"; } else if (theLines[i + 1].Contains("INDEPENDENCIA")) { destino.bairro = "INDEPENDENCIA"; } else if (theLines[i + 1].Contains("VILA OPERARIA")) { destino.bairro = "VILA OPERARIA"; } else if (theLines[i + 1].Contains("JARDIM GISELA")) { destino.bairro = "JARDIM GISELA"; } else if (theLines[i + 1].Contains("VILA NOVA")) { destino.bairro = "VILA NOVA"; } else { destino.bairro = "Não encontrado"; } model get = new model(); Boolean existeDocumento = get.getDestinoDocumento(destino.documento, destino.transportadora); if (!existeDocumento) { if (theLines[i + 1].Contains("-")) { int posicao = theLines[i + 1].IndexOf("-") + 3; destino.nome = theLines[i + 1].Substring(posicao, 25); } else { destino.nome = theLines[i + 1].Substring(0, 30); } int posicaoDacte = theLines[i + 2].IndexOf("DACTE") - 5; destino.endereco = theLines[i + 2].Substring(3, posicaoDacte).Replace('/', ',') + ",Toledo, PR"; try { model m = new model(); DtoLatLong latlong = m.GetLatLongGoogle(destino.endereco); destino.latitude = Convert.ToDouble(latlong.latitude, CultureInfo.InvariantCulture); destino.longitude = Convert.ToDouble(latlong.longitude, CultureInfo.InvariantCulture); destino.distancia = Convert.ToDouble(latlong.distancia, CultureInfo.InvariantCulture); destino.duracao = latlong.duracao; } catch (Exception) { destino.status = "E"; } destino.status = "I"; model post = new model(); post.set(destino); i++; } i++; } } CarregarDestinos(); progressBar1.Visible = false; } catch (Exception ex) { } }