Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Ubar4.Datos
- {
- public class datosViaje
- {
- public static bool Agendar(Ubar4.Modelo.Viaje viaje) {
- try {
- Conexion conn= new Conexion();
- 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+"')";
- MySqlCommand command = new MySqlCommand(sql, conn.Conectar());
- int filasAfectadas = command.ExecuteNonQuery();
- if (filasAfectadas == 1)
- {
- MessageBox.Show("Viaje agendado");
- conn.Desconectar();
- return true;
- }
- else { conn.Desconectar();
- MessageBox.Show("Error, se pudo agendar el viaje, revise la informacion proporcionada");
- return false;
- }
- } catch (Exception ex) {
- MessageBox.Show("Error al establecer la conexion"+ex.Message);
- return false;
- }
- }
- public static void llenarTabla(int idUsuario, DataGridView gr)
- {
- try {
- Conexion conn= new Conexion();
- string sql = "SELECT `idViaje`, `origenLat`, `origenLon`, `destinoLat`, `destinoLon`, `fecha`, `hora`,`distancia`, `costo` FROM `ubar`.`viajes` WHERE idUsuario='"+idUsuario+"'";
- MySqlCommand cm = new MySqlCommand(sql, conn.Conectar());
- MySqlDataAdapter adapter = new MySqlDataAdapter(cm);
- DataTable dt = new DataTable();
- adapter.Fill(dt);
- gr.DataSource = dt;
- } catch (Exception ex) {
- MessageBox.Show("error"+ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment