Пример #1
0
 private void buttonGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         if ((comboBoxMarca.SelectedItem as dynamic).Value == 0)
         {
             throw new Exception("Debe seleccionar una marca");
         }
         if ((comboBoxTurno.SelectedItem as dynamic).Value == 0)
         {
             throw new Exception("Debe seleccionar un turno");
         }
         if ((comboBoxChofer.SelectedItem as dynamic).Value == 0)
         {
             throw new Exception("Debe seleccionar un chofer");
         }
         if (textBoxModelo.Text == "")
         {
             throw new Exception("Debe ingresar un modelo de automovil");
         }
         if (textBoxPatente.Text == "")
         {
             throw new Exception("Debe ingresar una patente");
         }
         Marca  marca_mapper  = new Marca();
         Turno  turno_mapper  = new Turno();
         Chofer chofer_mapper = new Chofer();
         int    marca_id      = (int)(comboBoxMarca.SelectedItem as dynamic).Value;
         int    turno_id      = (int)(comboBoxTurno.SelectedItem as dynamic).Value;
         int    chofer_id     = (int)(comboBoxChofer.SelectedItem as dynamic).Value;
         automovil.marca      = marca_mapper.Mapear(marca_id);
         automovil.modelo     = textBoxModelo.Text;
         automovil.patente    = textBoxPatente.Text;
         automovil.turno      = turno_mapper.Mapear(turno_id);
         automovil.chofer     = chofer_mapper.Mapear(chofer_id);
         automovil.habilitado = checkBoxHabilitado.Checked;
         string respuesta = automovil.Guardar();
         MessageBox.Show(respuesta, "Guardado de automovil", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         Hide();
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "Guardado de automovil error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }