Ejemplo n.º 1
0
 private void buttonGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToDecimal(textBoxImporteTotal.Text) == 0)
         {
             throw new Exception("El importe no puede ser cero");
         }
         Rendicion rendicion     = new Rendicion();
         Chofer    chofer_mapper = new Chofer();
         Turno     turno_mapper  = new Turno();
         Viaje     viaje_mapper  = new Viaje();
         Chofer    chofer        = chofer_mapper.Mapear((comboBoxChofer.SelectedItem as dynamic).Value);
         Turno     turno         = turno_mapper.Mapear((comboBoxTurno.SelectedItem as dynamic).Value);
         rendicion.fecha   = dateTimePickerFecha.Value;
         rendicion.chofer  = chofer;
         rendicion.turno   = turno;
         rendicion.importe = Convert.ToDecimal(textBoxImporteTotal.Text);
         rendicion.viajes  = new List <Viaje>();
         foreach (DataGridViewRow row in dataGridView1.Rows)
         {
             int   viaje_id = Convert.ToInt32(row.Cells[0].Value);
             Viaje viaje    = viaje_mapper.Mapear(viaje_id);
             rendicion.viajes.Add(viaje);
         }
         string respuesta = rendicion.Guardar();
         MessageBox.Show(respuesta, "Guardado de rendicion", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         Hide();
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "Error en guardado de rendicion", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }