Example #1
0
 private void btnAgregar_Click(object sender, EventArgs e)
 {
     if (txtMarca.Text == string.Empty && txtModel.Text == string.Empty && nudPrecio.Value == 0)
     {
         MessageBox.Show("Todos los campos son obligatorios.");
         txtMarca.Focus();
     }
     else if (txtMarca.Text == string.Empty)
     {
         MessageBox.Show("La marca es un campo obligatorio.");
         txtMarca.Focus();
     }
     else if (txtModel.Text == string.Empty)
     {
         MessageBox.Show("El modelo es un campo obligatorio.");
         txtModel.Focus();
     }
     else if (nudPrecio.Value == 0)
     {
         MessageBox.Show("El precio es un campo obligatorio");
         nudPrecio.Focus();
     }
     else if (!rdoCarro.Checked && !rdoCamion.Checked && !rdoMicrobus.Checked)
     {
         MessageBox.Show("Elija el tipo de vehiculo.");
     }
     else if (rdoCarro.Checked)
     {
         if (txtPuertas.Text == string.Empty)
         {
             MessageBox.Show("La cantidad de puertas es un campo obligatorio");
             txtPuertas.Focus();
         }
         else
         {
             Carro carro = new Carro(txtMarca.Text, Convert.ToInt32(nudMillas.Value), txtModel.Text, Convert.ToDouble(nudPrecio.Value), Convert.ToInt32(txtPuertas.Text));
             dataGridView1.Rows.Add(carro.Marca, carro.Modelo, carro.Millaje, carro.Precio.ToString("C2"), rdoCarro.Text, carro.Puertas);
             txtMarca.Clear();
             txtModel.Clear();
             nudMillas.Value = 0;
             txtModel.Clear();
             nudPrecio.Value  = 0;
             rdoCarro.Checked = false;
             txtPuertas.Clear();
             txtMarca.Focus();
         }
     }
     else if (rdoCamion.Checked)
     {
         if (txtCapacidad.Text == string.Empty)
         {
             MessageBox.Show("La capacidad de carga es un campo obligatorio");
             txtCapacidad.Focus();
         }
         else if (txtTanque.Text == string.Empty)
         {
             MessageBox.Show("La capacidad del tanque de combustible es un campo obligatorio");
         }
         else
         {
             Camion camion = new Camion(txtMarca.Text, Convert.ToInt32(nudMillas.Value), txtModel.Text, Convert.ToDouble(nudPrecio.Value), Convert.ToInt32(txtCapacidad.Text), Convert.ToInt32(txtTanque.Text));
             dataGridView1.Rows.Add(camion.Marca, camion.Modelo, camion.Millaje, camion.Precio.ToString("C2"), rdoCamion.Text, "", camion.CapacidadCarga, camion.TanqueCombustible);
             txtMarca.Clear();
             txtModel.Clear();
             nudMillas.Value = 0;
             txtModel.Clear();
             nudPrecio.Value   = 0;
             rdoCamion.Checked = false;
             txtCapacidad.Clear();
             txtTanque.Clear();
             txtMarca.Focus();
         }
     }
     else if (rdoMicrobus.Checked)
     {
         if (txtPasajeros.Text == string.Empty)
         {
             MessageBox.Show("El nĂºmero de pasajeros es un campo obligatorio.");
             txtPasajeros.Focus();
         }
         else
         {
             Microbus microbus = new Microbus(txtMarca.Text, Convert.ToInt32(nudMillas.Value), txtModel.Text, Convert.ToDouble(nudPrecio.Value), Convert.ToInt32(txtPasajeros.Text));
             dataGridView1.Rows.Add(microbus.Marca, microbus.Modelo, microbus.Millaje, microbus.Precio.ToString("C2"), rdoMicrobus.Text, "", "", "", microbus.Pasajeros);
             txtMarca.Clear();
             txtModel.Clear();
             nudMillas.Value = 0;
             txtModel.Clear();
             nudPrecio.Value     = 0;
             rdoMicrobus.Checked = false;
             txtPasajeros.Clear();
             txtMarca.Focus();
         }
     }
 }
Example #2
0
 private void btnAgregar_Click(object sender, EventArgs e)
 {
     if (txtMarca.Text == string.Empty && txtModelo.Text == string.Empty && nudPrecio.Value == 0)
     {
         MessageBox.Show("Todos los campos son obligatorios");
     }
     if (txtMarca.Text == string.Empty)
     {
         MessageBox.Show("La marca es un campo obligatorio");
         txtMarca.Focus();
     }
     else if (txtModelo.Text == string.Empty)
     {
         MessageBox.Show("El modelo es un campo obligatorio");
         txtModelo.Focus();
     }
     else if (nudPrecio.Value == 0)
     {
         MessageBox.Show("El precio es un campo obligatorio");
         nudPrecio.Focus();
     }
     else if (!rdoCarro.Checked && !rdoCamion.Checked && !rdoMicrobus.Checked)
     {
         MessageBox.Show("Debe elegir un tipo de automovil");
     }
     else if (rdoCarro.Checked)
     {
         if (txtPuertas.Text == string.Empty)
         {
             MessageBox.Show("La cantidad de puertas es un campo obligatorio");
             txtPuertas.Focus();
         }
         else
         {
             Carro carro = new Carro(txtMarca.Text, Convert.ToInt32(nudMillaje.Value), txtModelo.Text, Convert.ToInt32(nudPrecio.Value), Convert.ToInt32(txtPuertas.Text));
             dataGridView1.Rows.Add(carro.Marca, carro.Modelo, carro.Millaje, carro.Precio, "Carro", carro.Puerta);
             dataGridView1.ClearSelection();
             txtMarca.Clear();
             txtModelo.Clear();
             nudMillaje.Value = 0;
             nudPrecio.Value  = 0;
             txtPuertas.Clear();
             txtMarca.Focus();
         }
     }
     else if (rdoCamion.Checked)
     {
         if (txtCapacidadCarga.Text == string.Empty)
         {
             MessageBox.Show("La capacidad de carga es un campo obligatorio");
             txtCapacidadCarga.Focus();
         }
         else if (txtTanqueCombustible.Text == string.Empty)
         {
             MessageBox.Show("La capacidad del tanque de combustible es un campo obligatorio");
             txtTanqueCombustible.Focus();
         }
         else
         {
             Camion camion = new Camion(txtMarca.Text, Convert.ToInt32(nudMillaje.Value), txtModelo.Text, Convert.ToInt32(nudPrecio.Value), Convert.ToInt32(txtCapacidadCarga.Text), Convert.ToInt32(txtTanqueCombustible.Text));
             dataGridView1.Rows.Add(camion.Marca, camion.Modelo, camion.Millaje, camion.Precio, "Camion", "", camion.CapacidadCarga, camion.TanqueCombustible);
             dataGridView1.ClearSelection();
             txtMarca.Clear();
             txtModelo.Clear();
             nudMillaje.Value = 0;
             nudPrecio.Value  = 0;
             txtCapacidadCarga.Clear();
             txtTanqueCombustible.Clear();
             txtMarca.Focus();
         }
     }
     else if (rdoMicrobus.Checked)
     {
         if (txtPasajeros.Text == string.Empty)
         {
             MessageBox.Show("La cantidad de pasajeros es un campo obligatorio");
             txtPasajeros.Focus();
         }
         else
         {
             Microbus microbus = new Microbus(txtMarca.Text, Convert.ToInt32(nudMillaje.Value), txtModelo.Text, Convert.ToInt32(nudPrecio.Value), Convert.ToInt32(txtPasajeros.Text));
             dataGridView1.Rows.Add(microbus.Marca, microbus.Modelo, microbus.Millaje, microbus.Precio, "Microbus", "", "", "", microbus.Pasajeros);
             dataGridView1.ClearSelection();
             txtMarca.Clear();
             txtModelo.Clear();
             nudMillaje.Value = 0;
             nudPrecio.Value  = 0;
             txtPasajeros.Clear();
             txtMarca.Focus();
         }
     }
 }