Metziop

Untitled

Jul 27th, 2022
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9.  
  10. namespace Ubar4.Datos
  11. {
  12.     public class datosViaje
  13.     {
  14.         public static bool Agendar(Ubar4.Modelo.Viaje viaje) {
  15.             try {
  16.                 Conexion conn= new Conexion();
  17.                 string sql= "INSERT INTO `ubar`.`viajes`(`origenLat`, `origenLon`, `destinoLat`, `destinoLon`, `fecha`, `hora`, `idUsuario`, `distancia`, `tiempoEst`,`horaLlegada`, `costo`, `direccion`) VALUES('"+viaje.OrigenLat+"', '"+viaje.OrigenLon+"', '"+viaje.DestinoLat+"', '"+viaje.DestinoLon+"', '"+viaje.Fecha+"', '"+viaje.Tiempo+"', '"+viaje.IdUser+"', '"+viaje.Distancia+"', '"+viaje.TiempoEstimado+"', '"+viaje.HoraLlegada+"', '"+viaje.Costo+"', '"+viaje.Distancia+"')";
  18.                 MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
  19.                 int filasAfectadas = command.ExecuteNonQuery();
  20.                 if (filasAfectadas == 1)
  21.                 {
  22.                     MessageBox.Show("Viaje agendado");
  23.                     conn.Desconectar();
  24.                     return true;
  25.  
  26.                 }
  27.                 else { conn.Desconectar();
  28.                     MessageBox.Show("Error, se pudo agendar el viaje, revise la informacion proporcionada");
  29.                     return false;
  30.                 }
  31.             } catch (Exception ex) {
  32.                 MessageBox.Show("Error al establecer la conexion"+ex.Message);
  33.                 return false;
  34.             }
  35.         }
  36.         public static void llenarTabla(int idUsuario, DataGridView gr)
  37.         {
  38.             try {
  39.                 Conexion conn= new Conexion();
  40.                 string sql = "SELECT `idViaje`, `origenLat`, `origenLon`, `destinoLat`, `destinoLon`, `fecha`, `hora`,`distancia`, `costo` FROM `ubar`.`viajes` WHERE idUsuario='"+idUsuario+"'";
  41.                 MySqlCommand cm = new MySqlCommand(sql, conn.Conectar());
  42.                 MySqlDataAdapter adapter = new MySqlDataAdapter(cm);
  43.                 DataTable dt = new DataTable();
  44.                 adapter.Fill(dt);
  45.                 gr.DataSource = dt;
  46.             } catch (Exception ex) {
  47.                 MessageBox.Show("error"+ex);
  48.             }
  49.            
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment