Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Geolocation;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Ubar4.Datos;
- using Ubar4.Modelo;
- namespace Ubar4
- {
- public partial class Viajes : Form
- {
- //recibiendo el id y nombre de usuario
- public Viajes(int id, string nombre)
- {
- InitializeComponent();
- this.idTxt.Text = id.ToString();
- this.lblUser.Text = nombre;
- int Usuario = id;
- //estableciendo los tamaños de la tabla de datos
- dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
- }
- private void btnLimpiar_Click(object sender, EventArgs e)
- {
- //limpiando formulario
- borrar();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //checando por cajas vacias
- if (orgLatTxt.Text.Trim() == "" || orgLonTxt.Text.Trim() == "" || desLatTxt.Text.Trim() == "" || desLonTxt.Text.Trim() == "")
- {
- MessageBox.Show("Favor de llenar todos los campos ");
- }
- else
- {
- //tomando datos de las cajas de texto
- //definiendo variables para coordenadas
- double orgLat = Convert.ToDouble(orgLatTxt.Text);
- double orgLon = Convert.ToDouble(orgLonTxt.Text);
- double desLat = Convert.ToDouble(desLatTxt.Text);
- double desLong = Convert.ToDouble(desLonTxt.Text);
- //variables de la bliblioteca
- Coordinate origen = new Coordinate(orgLat, orgLon);
- Coordinate destino = new Coordinate(desLat, desLong);
- double distancia = GeoCalculator.GetDistance(origen, destino, 4, DistanceUnit.Kilometers);
- double tiempoEstimado = distancia / 50;
- string direccion = GeoCalculator.GetDirection(origen, destino);
- double costo = distancia * 25;
- //llenando formulario
- disTxt.Text = distancia.ToString();
- dirTxt.Text = direccion.ToString();
- tiempoEstTxt.Text = tiempoEstimado.ToString();
- //CALCULANDO HORA DE LLEGADA
- DateTime hora1 = Convert.ToDateTime(timeTxt.Text);
- DateTime estimado= DateTime.FromOADate(tiempoEstimado);
- DateTime llegada = hora1.AddMinutes(estimado.Minute);
- hrLlegadaTxt.Value = llegada;
- lblPrecio.Text = costo.ToString();
- }
- }
- private void agendarBtn_Click(object sender, EventArgs e)
- {
- //generando viaje
- Viaje viaje = new Viaje();
- viaje.OrigenLat = Convert.ToDouble(orgLatTxt.Text);
- viaje.OrigenLon = Convert.ToDouble(orgLonTxt.Text);
- viaje.DestinoLat = Convert.ToDouble(desLatTxt.Text);
- viaje.DestinoLon = Convert.ToDouble(desLonTxt.Text);
- viaje.Fecha = dateTxt.Text;
- viaje.Tiempo = timeTxt.Text;
- viaje.Distancia = Convert.ToDouble(disTxt.Text);
- viaje.TiempoEstimado = tiempoEstTxt.Text;
- viaje.HoraLlegada = hrLlegadaTxt.Text;
- viaje.Costo = Convert.ToDouble(lblPrecio.Text);
- viaje.Direccion=dirTxt.Text;
- viaje.IdUser = Convert.ToInt32(idTxt.Text);
- //checando por insercion a la base de datos
- if (datosViaje.Agendar(viaje)) {
- borrar();
- //refreescando tabla tabla
- datosViaje.llenarTabla(Convert.ToInt32(idTxt.Text), dataGridView1);
- }
- }
- //metodo para salir
- private void salirBtn_Click(object sender, EventArgs e)
- {
- this.Dispose();
- }
- //metodo para borrar
- public void borrar() {
- orgLatTxt.Text = "";
- orgLonTxt.Text = "";
- desLatTxt.Text = "";
- desLonTxt.Text = "";
- dateTxt.Text = "";
- timeTxt.Text = "";
- disTxt.Text = "";
- dirTxt.Text = "";
- tiempoEstTxt.Text = "";
- hrLlegadaTxt.Text = "";
- lblPrecio.Text = "00.00";
- }
- //metodo para llenar la tabla al inicio
- private void Viajes_Load(object sender, EventArgs e)
- {
- datosViaje.llenarTabla(Convert.ToInt32(idTxt.Text), dataGridView1);
- }
- private void orgLatTxt_TextChanged(object sender, EventArgs e)
- {
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment