private void button2_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtSerie.Text)) { MessageBox.Show("Debe ingresar la serie del documento"); return; } if (String.IsNullOrEmpty(txtNumero.Text)) { MessageBox.Show("Debe ingresar el numero del documento"); return; } if (String.IsNullOrEmpty(txtSaldoAmortizado.Text)) { MessageBox.Show("Debe ingresar el saldo a pagar"); return; } try { var saldo = decimal.Parse(txtSaldoAmortizado.Text); if (saldo.CompareTo(new Decimal(15)) != 0) { MessageBox.Show("El saldo a pagar debe de ser 15"); return; } } catch (Exception ex) { MessageBox.Show("El saldo debe de ser un numero"); return; } try { PagoSolicitud pago = new PagoSolicitud(); pago.solicitud = solicitud; pago.fechaPago = dtFechaPago.Value; pago.monto = Decimal.Parse(txtSaldoAmortizado.Text); pago.serie = txtSerie.Text; pago.numero = txtNumero.Text; pago.fotoAdjunta = txtRutaArchivo.Text; FormaDePago formaSeleccionada = listaFormaPago .Find(p => p.id.Equals(int.Parse(cboFormaPago.SelectedValue.ToString()))); pago.formaDePago = formaSeleccionada; gestionTesis.registrarPagoSolicitud(pago); MessageBox.Show("Se registro correctamente el pago de la solicitud " + solicitud.codigo , "Operacion correcta", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception exp) { MessageBox.Show(exp.Message, "ocurrio un error"); } }
public void registrarPago(PagoSolicitud pago, SqlConnection conexion, SqlTransaction transaccion) { String nombreProcedure = "REGISTRAR_PAGO"; SqlCommand comando = new SqlCommand(nombreProcedure, conexion); if (transaccion != null) { comando.Transaction = transaccion; } comando.CommandType = System.Data.CommandType.StoredProcedure; comando.Parameters.AddWithValue("@SOLICITUD_ID", SqlDbType.Int).Value = pago.solicitud.id; comando.Parameters.AddWithValue("@FORMA_PAGO_ID", SqlDbType.VarChar).Value = pago.formaDePago.id; comando.Parameters.AddWithValue("@SERIE", SqlDbType.VarChar).Value = pago.serie; comando.Parameters.AddWithValue("@NUMERO", SqlDbType.VarChar).Value = pago.serie; comando.Parameters.AddWithValue("@MONTO", SqlDbType.Decimal).Value = pago.monto; comando.Parameters.AddWithValue("@FECHA_PAGO", SqlDbType.DateTime).Value = pago.fechaPago; comando.Parameters.AddWithValue("@FOTO_ADJUNTA", SqlDbType.VarChar).Value = pago.fotoAdjunta == null ? "" : pago.fotoAdjunta; comando.ExecuteNonQuery(); }
public void registrarPagoSolicitud(PagoSolicitud pagoSolicitud) { SqlConnection cn = null; SqlTransaction transaccion = null; try { cn = HelperDB.GetSqlConnection(); //Inicio de la transaccion transaccion = cn.BeginTransaction(); //Estado 3= Cancelado SolicitudEstado estadoPagado = estadoSolicitudRepository.obtenerPorId(3, cn, transaccion); if (estadoPagado == null) { throw new ArgumentNullException("No se encontro el estado PAGADO para la solicitud"); } pagoSolicitudRepository.registrarPago(pagoSolicitud, cn, transaccion); //Modificar el estado de la solicitud solicitudRepository.cambiarEstadoPagadoSolicitud(pagoSolicitud.solicitud, estadoPagado, cn, transaccion); transaccion.Commit(); } catch (Exception e) { Console.WriteLine(e.Message); transaccion.Rollback(); throw new Exception(e.Message); } finally { if (cn != null) { cn.Close(); cn.Dispose(); } } }