Metziop

Untitled

Jul 27th, 2022
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.85 KB | None | 0 0
  1. using Geolocation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Ubar4.Datos;
  12. using Ubar4.Modelo;
  13.  
  14. namespace Ubar4
  15. {
  16.     public partial class Viajes : Form
  17.     {
  18.        
  19.        
  20.         //recibiendo el id y nombre de usuario
  21.         public Viajes(int id, string nombre)
  22.         {
  23.             InitializeComponent();
  24.  
  25.            
  26.             this.idTxt.Text = id.ToString();
  27.             this.lblUser.Text = nombre;
  28.             int Usuario = id;
  29.             //estableciendo los tamaños de la tabla de datos
  30.             dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  31.  
  32.  
  33.         }
  34.  
  35.         private void btnLimpiar_Click(object sender, EventArgs e)
  36.         {
  37.             //limpiando formulario
  38.             borrar();
  39.         }
  40.  
  41.         private void button1_Click(object sender, EventArgs e)
  42.         {
  43.             //checando por cajas vacias
  44.             if (orgLatTxt.Text.Trim() == "" || orgLonTxt.Text.Trim() == "" || desLatTxt.Text.Trim() == "" || desLonTxt.Text.Trim() == "")
  45.             {
  46.                 MessageBox.Show("Favor de llenar todos los campos ");
  47.             }
  48.             else
  49.             {
  50.                //tomando datos de las cajas de texto
  51.                 //definiendo variables para coordenadas
  52.                 double orgLat = Convert.ToDouble(orgLatTxt.Text);
  53.                 double orgLon = Convert.ToDouble(orgLonTxt.Text);
  54.                 double desLat = Convert.ToDouble(desLatTxt.Text);
  55.                 double desLong = Convert.ToDouble(desLonTxt.Text);
  56.                 //variables de la bliblioteca
  57.                 Coordinate origen = new Coordinate(orgLat, orgLon);
  58.                 Coordinate destino = new Coordinate(desLat, desLong);
  59.                 double distancia = GeoCalculator.GetDistance(origen, destino, 4, DistanceUnit.Kilometers);
  60.                 double tiempoEstimado = distancia / 50;
  61.                 string direccion = GeoCalculator.GetDirection(origen, destino);
  62.                 double costo = distancia * 25;
  63.                 //llenando formulario
  64.                 disTxt.Text = distancia.ToString();
  65.                 dirTxt.Text = direccion.ToString();
  66.                 tiempoEstTxt.Text = tiempoEstimado.ToString();
  67.                 //CALCULANDO HORA DE LLEGADA
  68.                 DateTime hora1 = Convert.ToDateTime(timeTxt.Text);
  69.                 DateTime estimado= DateTime.FromOADate(tiempoEstimado);
  70.                 DateTime llegada = hora1.AddMinutes(estimado.Minute);
  71.                 hrLlegadaTxt.Value = llegada;
  72.                 lblPrecio.Text = costo.ToString();
  73.  
  74.  
  75.             }
  76.         }
  77.  
  78.         private void agendarBtn_Click(object sender, EventArgs e)
  79.         {
  80.             //generando viaje
  81.             Viaje viaje = new Viaje();
  82.             viaje.OrigenLat = Convert.ToDouble(orgLatTxt.Text);
  83.             viaje.OrigenLon = Convert.ToDouble(orgLonTxt.Text);
  84.             viaje.DestinoLat = Convert.ToDouble(desLatTxt.Text);
  85.             viaje.DestinoLon = Convert.ToDouble(desLonTxt.Text);
  86.             viaje.Fecha = dateTxt.Text;
  87.             viaje.Tiempo = timeTxt.Text;
  88.             viaje.Distancia = Convert.ToDouble(disTxt.Text);
  89.             viaje.TiempoEstimado = tiempoEstTxt.Text;
  90.             viaje.HoraLlegada = hrLlegadaTxt.Text;
  91.             viaje.Costo = Convert.ToDouble(lblPrecio.Text);
  92.             viaje.Direccion=dirTxt.Text;
  93.             viaje.IdUser = Convert.ToInt32(idTxt.Text);
  94.             //checando por insercion a la base de datos
  95.             if (datosViaje.Agendar(viaje)) {
  96.                 borrar();
  97.                 //refreescando tabla tabla
  98.                 datosViaje.llenarTabla(Convert.ToInt32(idTxt.Text), dataGridView1);
  99.  
  100.             }
  101.         }
  102.         //metodo para salir
  103.         private void salirBtn_Click(object sender, EventArgs e)
  104.         {
  105.             this.Dispose();
  106.         }
  107.         //metodo para borrar
  108.         public void borrar() {
  109.             orgLatTxt.Text = "";
  110.             orgLonTxt.Text = "";
  111.             desLatTxt.Text = "";
  112.             desLonTxt.Text = "";
  113.             dateTxt.Text = "";
  114.             timeTxt.Text = "";
  115.             disTxt.Text = "";
  116.             dirTxt.Text = "";
  117.             tiempoEstTxt.Text = "";
  118.             hrLlegadaTxt.Text = "";
  119.             lblPrecio.Text = "00.00";
  120.         }
  121.  
  122.         //metodo para llenar la tabla al inicio
  123.         private void Viajes_Load(object sender, EventArgs e)
  124.         {
  125.             datosViaje.llenarTabla(Convert.ToInt32(idTxt.Text), dataGridView1);
  126.  
  127.         }
  128.  
  129.         private void orgLatTxt_TextChanged(object sender, EventArgs e)
  130.         {
  131.  
  132.         }
  133.  
  134.         private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  135.         {
  136.  
  137.         }
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment