public Vehiculo BuscarVehiculo(int?id) { this.error = ""; Vehiculo unVehiculo = null; SqlCommand comando = new SqlCommand(); comando.Connection = this.conexion; comando.CommandText = "SELECT * FROM VEHICULO WHERE ID=" + id; try { SqlDataReader registro = comando.ExecuteReader(); if (registro.Read()) { unVehiculo = new Vehiculo(); unVehiculo.id = Convert.ToInt32(registro.GetDecimal(0)); unVehiculo.placa = registro.GetString(1); Linea linea = new Linea(); linea.id = registro.GetDecimal(2); unVehiculo.idLinea = linea; unVehiculo.modelo = registro.GetString(3); unVehiculo.numeroMotor = registro.GetString(4); unVehiculo.color = registro.GetString(5); ClaseVehiculo clase = new ClaseVehiculo(); clase.id = registro.GetDecimal(6); unVehiculo.idClaseVehiculo = clase; TipoServicio tipo = new TipoServicio(); tipo.id = registro.GetDecimal(7); } registro.Close(); } catch (Exception ex) { this.error = ex.Message; } return(unVehiculo); }
private void button2_Click(object sender, EventArgs e) { Vehiculo objVehiculo = new Vehiculo(); objVehiculo.placa = txtPlaca.Text; Prueba2.Modelo.Linea objLinea = new Prueba2.Modelo.Linea(); objLinea.id = long.Parse(cbLinea.SelectedValue.ToString()); objVehiculo.idLinea = objLinea; objVehiculo.modelo = txtModelo.Text; objVehiculo.numeroMotor = txtNumeroMotor.Text; objVehiculo.color = txtColor.Text; ClaseVehiculo objClaseVeh = new ClaseVehiculo(); objClaseVeh.id = long.Parse(cbClaseVehiculo.SelectedValue.ToString());; objVehiculo.idClaseVehiculo = objClaseVeh; TipoServicio objTipoSer = new TipoServicio(); objTipoSer.id = long.Parse(cbTipoSer.SelectedValue.ToString());; objVehiculo.idTipoServicio = objTipoSer; bool agregado = controllerVehiculo.agregarVehiculo(objVehiculo); if (agregado) { MessageBox.Show("SE HA REALIZADO CON EXITO EL VEHICULO", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Error", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); } }