Ejemplo n.º 1
0
        private void btnFacturar_Click(object sender, EventArgs e)
        {
            String Fecha = textBox_Fecha.Text;
            String Total = textBox_importe.Text;

            try
            {
                {
                    Rendicion rendicion = new Rendicion();
                    rendicion.SetFechaRendicion(Fecha);
                    String ChoferDNI = this.obtenerDNIaPartirDetextBox(comboBox_chofer.Text);
                    rendicion.SetIdChofer(ChoferDNI);
                    this.ideTurno = this.obtenerIdTurnoaPartirDeCombobox(comboBox_Turnos.Text);
                    rendicion.SetIdTurno(ideTurno);


                    if (!mapper.ExisteRendicion(Fecha, rendicion.GetIdChofer()))
                    {
                        rendicion.SetImporteTotalRendicion(Total);
                        int idRendicion = mapper.Crear(rendicion);
                        if (idRendicion > 0)
                        {
                            MessageBox.Show("Se creo correctamente la Rendición");

                            mapper.ActualizarRendicionIdenRegistrViaje(idRendicion, rendicion.GetFechaRendicion(), rendicion.GetIdChofer(), ideTurno);

                            this.Hide();
                            new MenuPrincipal().ShowDialog();
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ya se realizo la rendicion diaria para ese chofer o no posee registros en esa fecha ", "Rendicion existente", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (CampoVacioException exception)
            {
                MessageBox.Show("Falta completar campo: " + exception.Message);
                return;
            }
            catch (NoHayViajesException exception)
            {
                MessageBox.Show(exception.Message, "Error al registrar", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }