private void btnGuardar_Click(object sender, EventArgs e) { //Validar Selecciones bool txts, cbos; txts = TextosValidos(); cbos = CombosValidos(); //fechas = FechasValidas(); if (txts && cbos) { try { //Obtencion de la informacion para registrar una carrera int id_cajero = MainContainer.sesion.Personas.Id_persona; int id_conductor = ((Conductor)cboConductor.SelectedItem).Id_conductor; int id_vehiculo = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo; DateTime Fecha = dtFecha.Value.Date; TimeSpan salida = dtSalida.Value.TimeOfDay; TimeSpan llegada = dtLlegada.Value.TimeOfDay; bool vuelta = cbVueltaCompleta.Checked; //Agregando Transaccion int t = TransaccionController.agregar(id_cajero, id_vehiculo, Fecha, true); //Comprobamos que se haya insertado la transaccion if (t > 0) { //Obtenemos el id de la ultima transaccion int idTransaccion = TransaccionController.getUltima().IdTransaccion; t = CarreraController.Agregar(idTransaccion, id_vehiculo, id_conductor, salida, llegada, Fecha, vuelta); //Si se inserto correctamente la carrera, procedemos a ingresar los gastos if (t > 0) { t = 0; decimal ingreso = Decimal.Parse(QuitarEspacios(txtIngreso.Text)); //Registrando Ingreso t = DetalleController.agregar(idTransaccion, TipoDetalleController.leer("CICLO").IdTipoDetalle, "CICLO", ingreso, 0, true); //Verificando y registrando los egresos decimal totalEgreso = 0; if (dgvEgresos.Rows.Count > 0) // Si hay egresos { for (int j = 0; j < dgvEgresos.RowCount; j++) { int id_egreso = (int)dgvEgresos.Rows[j].Cells[0].Value; string descripcion = dgvEgresos.Rows[j].Cells[2].Value.ToString(); decimal monto = (decimal)dgvEgresos.Rows[j].Cells[3].Value; totalEgreso += monto; t += DetalleController.agregar(idTransaccion, id_egreso, descripcion, monto, 1, true); } } if (t == 0) //Si no se registraron transacciones { throw new Exception("No se registraron las transacciones de Entrada/Salida!"); } //Se imprime la factura else { var result = MessageBox.Show("Imprimir factura?", "Confirme Impresion", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result.Equals(DialogResult.Yes)) { var ultima = CarreraController.getUltima(); //var cond = ConductorController.leer(ultima.Id_conductor); //Creando instancia de reporte TicketFisicoForm ticket = new TicketFisicoForm( CapaControlador.TransaccionController.getUltima().IdTransaccion, ultima.FechaCarrera.ToShortDateString(), MainContainer.sesion.ToString(), ultima.Vehiculo.Placa, ultima.Vehiculo.Socio.ToString(), cboConductor.SelectedItem.ToString(), ingreso, totalEgreso, (ingreso - totalEgreso) ); ticket.ShowDialog(); } limpiarControles(); actualizarNoFactura(); } } else { throw new Exception("No se Completo el registro de la carrera"); } } else { throw new Exception("No se Ingreso la carrera"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Todos los campos son requeridos!", "Faltan campos por completar", MessageBoxButtons.OK, MessageBoxIcon.Information); } }