private void btnRegistrar_Click(object sender, EventArgs e) { try { String matricula = textBoxMatricula.Text.Trim(); String marca = textBoxMarca.Text.Trim(); String modelo = textBoxModelo.Text.Trim(); Cliente cliente = (Cliente)comboCliente.SelectedItem; if ((matricula.Length > 0) && (marca.Length > 0) && (modelo.Length > 0) && (cliente != null)) { if (vehiculoSeleccionado == null) { fachada.crearVehiculo(matricula, modelo, marca, cliente); MessageBox.Show("El vehículo ha sido creado"); borrarDatos(); } else { fachada.editarVehiculo(vehiculoSeleccionado, (Cliente)comboCliente.SelectedItem, textBoxMarca.Text, textBoxModelo.Text, textBoxMatricula.Text); MessageBox.Show("Se ha editado el elemento seleccionado de forma correcta!"); } listaVehiculos.Items.Clear(); foreach (Vehiculo v in fachada.getListaVehiculos()) { listaVehiculos.Items.Add(v); } listaVehiculos.Show(); } else { MessageBox.Show("Valores incorrectos.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (MiExcepcion es) { MessageBox.Show(es.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error en los datos", MessageBoxButtons.OK, MessageBoxIcon.Error); } vehiculoSeleccionado = null; listaVehiculos.SelectedItem = null; }