Public Class frmPrestamoEmpresariales Dim Prestamo As New PrestamoEmpresarialCE Dim PrestamoConsulta As New PrestamoEmpresarialDAO Dim oDAOGeneral As New DAOGeneral Dim Operaciones As New Operaciones Dim Base As Integer Dim FinCarga As Boolean = False Dim Estado As String = String.Empty Dim IndexCorte As Integer = 0 Dim FechaCorte As Date Const IVA = 1.13 Private Sub CargarTipoTasa() If cboTipoTasa.Items.Count = 0 Or cboTipoTasa.Items.Count = 1 Then Me.cboTipoTasa.DataSource = oDAOGeneral.ListaTipoTasa Me.cboTipoTasa.DisplayMember = "Descripcion" Me.cboTipoTasa.ValueMember = "Codigo" Me.cboTipoTasa.SelectedIndex = 0 End If End Sub Private Sub CargarPeriodicidades() If cboPeriodicidad.Items.Count = 0 Or cboPeriodicidad.Items.Count = 1 Then Me.cboPeriodicidad.DataSource = oDAOGeneral.ListaPeriodicidad Me.cboPeriodicidad.DisplayMember = "Descripcion" Me.cboPeriodicidad.ValueMember = "Codigo" Me.cboPeriodicidad.SelectedIndex = 0 End If End Sub Sub CargarBase() If cboBase.Items.Count = 0 Or cboBase.Items.Count = 1 Then Me.cboBase.DataSource = oDAOGeneral.ListaBase Me.cboBase.DisplayMember = "Descripcion" Me.cboBase.ValueMember = "Codigo" Me.cboBase.SelectedIndex = 0 End If End Sub Private Sub frmPrestamoEmpresariales_Load(sender As Object, e As EventArgs) Handles MyBase.Load dgvDetalles.Columns.Clear() Dias() AgregarCampos() CargarTipoTasa() CargarPeriodicidades() CargarBase() CargarDato() Dim Datos = CargarDetalles() RellenarDatos() If (Not Datos) Then Calculos(False, False) End If FinCarga = True ExisteInversion() ValidarExistencia() End Sub Function ExisteInversion() Dim Codigo As String = Variables.Codigo Dim TablaINV As String = "INV0" Dim TablaPINV As String = "PIN0" Dim General As New DAOGeneral Dim InvPro = Variables.InvPro If InvPro = "I" Then Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV) If INV0 Then navNuevo.Visible = True Return True Else navNuevo.Visible = False Calculos(False, False) Return False End If End If If InvPro = "P" Then Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV) If PINV0 Then navNuevo.Visible = True Return True Else navNuevo.Visible = False Calculos(False, False) Return False End If End If Return False End Function Function CanRegistros() Dim Tabla As String = String.Empty Tabla = "PEMP1" Dim Codigo = Variables.Codigo Dim Cantidad As Integer = oDAOGeneral.CantidadRegistros(Codigo, Tabla) Return Cantidad End Function Sub ValidarExistencia() Dim General As New DAOGeneral Dim Codigo As String = Variables.Codigo Dim Tabla As String = String.Empty Tabla = "PEMP0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) If (Existe) Then navNuevo.Enabled = False TbDetalles.Enabled = True navModificar.Enabled = True navEliminar.Enabled = True Else navNuevo.Enabled = True TbDetalles.Enabled = True navModificar.Enabled = False navEliminar.Enabled = False End If Estado = String.Empty btnAccion.Text = "Aceptar" End Sub Function ExisteValidacion() Dim General As New DAOGeneral Dim Codigo As String = Variables.Codigo Dim Tabla As String = String.Empty Tabla = "PEMP0" Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla) Return Existe End Function Sub Dias() Dim fecha1, fecha2 fecha1 = dtpFechaOperacion.Value.ToString fecha2 = dtpFechaVencimiento.Value.ToString txtPlazoDias.Text = Prestamo.FechaDias(fecha1, fecha2) End Sub Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged Formato() Dias() If (FinCarga) Then Calculos(False, False) End If End Sub Private Sub dtpFechaVencimiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimiento.ValueChanged Formato() Dias() If (FinCarga) Then Calculos(False, False) End If End Sub Sub AgregarCampos() Dim plazo, fechapago, fechacorte, Contador, SaldoPendiente, ingresarcomision, ingresarinteres, IVA, amortizacion, montorecibir As New DataGridViewTextBoxColumn plazo.Name = "Plazo (Desembolso)" fechacorte.Name = "Fecha de corte" fechapago.Name = "Fechas de Pago" ingresarcomision.Name = "Ingreso por Comision" ingresarinteres.Name = "Ingreso por Interes" IVA.Name = "IVA" amortizacion.Name = "Amortizacion" SaldoPendiente.Name = "Saldo Pendiente" montorecibir.Name = "Monto a Recibir" Contador.Name = "Correlativo" dgvDetalles.Columns.Add(Contador) dgvDetalles.Columns.Add(plazo) dgvDetalles.Columns.Add(fechacorte) dgvDetalles.Columns.Add(fechapago) dgvDetalles.Columns.Add(ingresarcomision) dgvDetalles.Columns.Add(ingresarinteres) dgvDetalles.Columns.Add(IVA) dgvDetalles.Columns.Add(amortizacion) dgvDetalles.Columns.Add(SaldoPendiente) dgvDetalles.Columns.Add(montorecibir) End Sub Sub Formato() If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then txtMonto.Text = Format(txtMonto.Text, "0.0") End If If (String.IsNullOrEmpty(txtTasa.Text.ToString.TrimEnd("%"))) Then txtTasa.Text = Format(txtTasa.Text, "0.0") End If If (String.IsNullOrEmpty(txtComisionDesembolso.Text.ToString.Trim("%"))) Then txtComisionDesembolso.Text = Format(txtComisionDesembolso.Text, "0.0") End If If (txtTasa.Text.ToString.IndexOf("%") = -1) Then txtTasa.Text = txtTasa.Text.ToString + "%" End If If (txtComisionDesembolso.Text.ToString.IndexOf("%") = -1) Then txtComisionDesembolso.Text = txtComisionDesembolso.Text.ToString + "%" End If End Sub Sub Calculos(ByVal Modificar As Boolean, ByVal Corte As Boolean) Dim V_txtMonto = 0.0, V_txtTasa = 0.0, V_txtComisionDesembolso = 0.0 V_txtMonto = Operaciones.ConvertirDecimal(txtMonto.Text.ToString) V_txtTasa = Operaciones.ConvertirDecimal(txtTasa.Text.ToString) / 100 V_txtComisionDesembolso = Operaciones.ConvertirDecimal(txtComisionDesembolso.Text.ToString) / 100 If (cboTipoTasa.SelectedIndex = -1) Then cboTipoTasa.SelectedIndex = 0 End If If (cboBase.SelectedIndex = -1) Then cboBase.SelectedIndex = 0 End If If (cboPeriodicidad.SelectedIndex = -1) Then cboPeriodicidad.SelectedIndex = 0 End If Dim FechaInicial = dtpFechaOperacion.Value Dim FechaFinal = dtpFechaOperacion.Value Dim FechaVencimiento = dtpFechaOperacion.Value Dim FechaVen = dtpFechaVencimiento.Value Dim FechaAux = dtpFechaOperacion.Value Dim Index = 0 Dim Contador As Integer = 0 Dim Borrar As Boolean = True Dim diccionario As New Dictionary(Of String, String) While (True) If (Not Modificar And Borrar) Then Dim Cantidad As Integer = dgvDetalles.Rows.Count If (Cantidad > 1) Then Dim CantidadReal = Cantidad - 2 Dim i As Integer = 0 While i <= CantidadReal Dim FechaCort = dgvDetalles.Rows(i).Cells("fecha de corte").Value If Not FechaCort Is DBNull.Value Then If Not String.IsNullOrEmpty(FechaCort) Then diccionario.Add(i, FechaCort) End If End If i += 1 End While dgvDetalles.Rows.Clear() End If Borrar = False End If Dim Mes As Integer If (Index = 0) Then Mes = FechaFinal.Month Else FechaFinal = FechaFinal.AddDays(1) Mes = FechaFinal.Month End If Dim Salir As Boolean = False FechaAux = FechaFinal While (Mes = FechaFinal.Month) FechaFinal = Format(FechaFinal, "dd/MM/yyyy") FechaVen = Format(FechaVen, "dd/MM/yyyy") FechaFinal = FechaFinal.AddDays(1) If (FechaFinal > FechaVen) Then Salir = True Exit While End If End While If (Corte) Then If (Index >= IndexCorte) Then While FechaFinal.Date < FechaCorte.Date FechaCorte = FechaCorte.AddDays(-1) End While FechaFinal = FechaCorte Salir = True End If End If If (Index = 0) Then FechaInicial = dtpFechaOperacion.Value FechaFinal = dtpFechaOperacion.Value FechaAux = dtpFechaOperacion.Value ElseIf (Index = 1) Then Dim MesAño, Dia As Integer FechaAux = dtpFechaOperacion.Value MesAño = FechaAux.Month Dia = FechaAux.Day If (MesAño = 12 And Dia = 31) Then FechaInicial = FechaAux.AddDays(1) End If FechaFinal = FechaFinal.AddDays(-1) Else FechaInicial = FechaAux FechaFinal = FechaFinal.AddDays(-1) End If Dim FechaProv As Date = Date.Now.Date Dim CambioFecha As Boolean = False If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then FechaProv = FechaFinal FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value CambioFecha = True End If End If Dim PlazoDatos = Plazo(Index, FechaFinal) Dim IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto) Dim IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, V_txtMonto) Dim CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt) Dim CalculoAmort = CalculoAmortizacion(Salir, V_txtMonto) Dim MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort) Dim SaldoPendi = SaldoPendiente(Index, CalculoAmort, V_txtMonto) If CambioFecha Then FechaFinal = FechaProv CambioFecha = False End If If Modificar Then Dim Fila = dgvDetalles.CurrentRow.Index Dim SalAnterior As Double = 0 Dim SumaAmortizado = 0 Dim CantidadFilas As Integer = dgvDetalles.Rows.Count - 2 Dim Filas As Integer = dgvDetalles.Rows.Count - 2 If (Index >= Fila) Then If (SaldoPendi > V_txtMonto) Then dgvDetalles.Rows(Index).Cells("Amortizacion").Value = 0 SaldoPendi = 0 Else For j As Integer = 0 To CantidadFilas - 1 SumaAmortizado += Operaciones.ConvertirDecimal(dgvDetalles.Rows(j).Cells("Amortizacion").Value) Next SaldoPendi = SaldoPendiente(Index, SumaAmortizado, V_txtMonto) If (SumaAmortizado > V_txtMonto) Then Dim PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value SaldoPendi = PagoPendienteAnterior dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi End If If (Index = CantidadFilas) Then Dim PagoPendienteAnterior = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value) SaldoPendi = PagoPendienteAnterior dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi End If End If If (Salir) Then End If Dim FechaProv2 As Date = Date.Now.Date Dim CambioFecha2 As Boolean = False If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then FechaProv2 = FechaFinal FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value CambioFecha2 = True End If End If PlazoDatos = Plazo(Index, FechaFinal) IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto) IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, SaldoPendi) CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt) MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort) If CambioFecha2 Then FechaFinal = FechaProv2 CambioFecha2 = False End If dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir End If Else Dim FechaCorte As String = String.Empty For Each Valor In diccionario If Valor.Key = Index Then FechaCorte = Valor.Value End If Next If String.IsNullOrEmpty(FechaCorte) Then dgvDetalles.Rows.Add(Index + 1, PlazoDatos, "", FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir) Else dgvDetalles.Rows.Add(Index + 1, PlazoDatos, FechaCorte, FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir) PlazoDatos = Plazo(Index, FechaCorte) IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto) IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaCorte, V_txtTasa, SaldoPendi) CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt) MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort) dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir End If Contador += 1 End If If (Salir) Then Exit While End If Index += 1 Dim IndexFin = dgvDetalles.Rows.Count - 3 If (Index = IndexFin) Then Salir = True End If End While End Sub Function SaldoPendiente(ByVal Index As Integer, ByVal Amortizado As Double, ByVal Monto As Double) Dim Saldo As Double = 0 Dim FilaAnterior As Integer = Index - 1 Dim SaldoAnterior As Double = 0 Dim PagoPendienteAnterior As Double = 0 Dim PagoPendiente As Double = 0 Dim Amortizacion As Double = 0 If (Index = 0) Then Saldo = Monto - Amortizado ElseIf (Index > 0) Then SaldoAnterior = Monto PagoPendienteAnterior = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value) Amortizacion = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index - 1).Cells("Amortizacion").Value) If (SaldoAnterior = Amortizado) Then Saldo = 0 ElseIf (SaldoAnterior = Amortizado) Then Saldo = PagoPendienteAnterior ElseIf (SaldoAnterior < Amortizado) Then Saldo = 0 ElseIf (PagoPendienteAnterior = Amortizacion) Then Saldo = 0 Else Saldo = SaldoAnterior - Amortizado End If End If If (PagoPendienteAnterior = Amortizacion And Not Amortizacion = 0) Then Saldo = 0 End If Return Saldo End Function Function Plazo(ByVal Index As Integer, ByVal fecha2 As Date) Dim fecha1 As Date Dim Valor Dim Anterior = Index - 1 If (Index = 0) Then Valor = 0 ElseIf (Index > 0) Then fecha1 = dgvDetalles.Rows(Anterior).Cells("Fechas de Pago").Value fecha1 = Format(fecha1, "yyyy/MM/dd") fecha2 = Format(fecha2, "yyyy/MM/dd") Valor = Prestamo.FechaDias(fecha1, fecha2) Else Valor = 0 End If Return Valor End Function Function IngresoComision(ByVal Index As Integer, ByVal V_txtComisionDesembolso As Double, ByVal V_txtMonto As Double) Dim Valor If (Index = 0) Then Valor = Operaciones.ConvertirDecimal(V_txtComisionDesembolso.ToString) * Operaciones.ConvertirDecimal(V_txtMonto.ToString) Else Valor = 0 End If Return Valor End Function Function IngresoInteres(ByVal Index As Integer, ByVal plazo As Integer, ByVal FechaInicial As Date, ByVal FechaFinal As Date, ByVal V_txtTasa As Double, ByVal V_txtMonto As Double) If (Index = 0) Then Return 0 Else Dim CambioDeFecha As Integer = Operaciones.CambioBase(FechaInicial, FechaFinal) Dim PrimeraFechaUltima = Operaciones.PrimeraFechaCambioBase(FechaInicial) Dim UltimaFechaPrimero = Operaciones.FinalFechaCambioBase(FechaFinal) Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0 Dim Valor1 = 0.0, Valor2 = 0.0, Valor = 0.0 If (Not CambioDeFecha = 0) Then If CambioDeFecha = 1 Then DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(FechaInicial, PrimeraFechaUltima, CambioDeFecha) DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha) Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 366 Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 365 ElseIf CambioDeFecha = 2 Then DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha) DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha) Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 365 Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 366 End If Valor = Valor1 + Valor2 Else If (Operaciones.AñoBisiesto(FechaInicial) = 364) Then Valor = V_txtMonto * V_txtTasa * plazo / 365 End If If (Operaciones.AñoBisiesto(FechaInicial) = 365) Then Valor = V_txtMonto * V_txtTasa * plazo / 366 End If End If Return Valor End If End Function Function CalculoIVA(ByVal Index As Integer, ByVal IngresoCom As Double, ByVal IngresoInteres As Double) Dim Valor As Double = 0 If Index = 0 Then Valor = Operaciones.ConvertirDecimal(IngresoCom.ToString) - (Operaciones.ConvertirDecimal(IngresoCom.ToString) / (1.13)) Else Valor = (Operaciones.ConvertirDecimal(IngresoCom.ToString) + Operaciones.ConvertirDecimal(IngresoInteres.ToString)) * 0.13 End If Return Valor End Function Function CalculoAmortizacion(ByVal Ultimo As Integer, ByVal V_txtMonto As Double) Dim Monto As Integer = 0 If (Ultimo) Then Monto = V_txtMonto End If Return Monto End Function Function MontoARecibir(ByVal IngresoComision As Double, ByVal IngresoInteres As Double, ByVal CalculoIVA As Double, ByVal Amortizacion As Double) Dim Monto As Double = Operaciones.ConvertirDecimal(txtMonto.Text.ToString) Dim Valor As Double = 0.0 Valor = IngresoComision + IngresoInteres + CalculoIVA + Amortizacion If Amortizacion > Monto Then Valor = 0 End If Return Valor End Function Function Coleccion() Dim colec As New Collection Dim fechaoper, fechaven, tasa, periodicidad, base, tipotasa, comisiondesembolso, plazodias, monto monto = Operaciones.ConvertirDecimal(txtMonto.Text.ToString) fechaoper = dtpFechaOperacion.Value fechaven = dtpFechaVencimiento.Value tasa = Operaciones.ConvertirDecimal(txtTasa.Text.ToString) / 100 periodicidad = cboPeriodicidad.SelectedValue base = Me.Base tipotasa = cboTipoTasa.SelectedValue comisiondesembolso = Operaciones.ConvertirDecimal(txtComisionDesembolso.Text.ToString) / 100 plazodias = Operaciones.ConvertirDecimal(txtPlazoDias.Text.ToString) colec.Add(monto) colec.Add(fechaoper) colec.Add(fechaven) colec.Add(tasa) colec.Add(periodicidad) colec.Add(base) colec.Add(tipotasa) colec.Add(comisiondesembolso) colec.Add(plazodias) Return colec End Function Sub RellenarDatos() If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then txtMonto.Text = "0.0" End If If (String.IsNullOrEmpty(txtTasa.Text.TrimEnd("%").ToString)) Then txtTasa.Text = "0.0%" End If If (cboTipoTasa.SelectedIndex = -1) Then cboTipoTasa.SelectedIndex = 0 End If If (cboBase.SelectedIndex = -1) Then cboBase.SelectedIndex = 0 End If If (cboPeriodicidad.SelectedIndex = -1) Then cboPeriodicidad.SelectedIndex = 0 End If If (String.IsNullOrEmpty(txtComisionDesembolso.Text.Trim("%").ToString)) Then txtComisionDesembolso.Text = "0.0%" End If If (String.IsNullOrEmpty(txtPlazoDias.Text.ToString)) Then txtPlazoDias.Text = "0.0" End If End Sub Function ColeccionDetalle(ByVal Index As Integer) Dim Coleccion As New Collection Dim plazo, fecha, fechacorte, ingresocomision, ingresointeres, IVA, amortizacion, montorecibir, saldopendiente, correlativo correlativo = Operaciones.ConvertirEntero(dgvDetalles.Rows(Index).Cells("Correlativo").Value) plazo = Operaciones.ConvertirEntero(dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value) fecha = Operaciones.ConvertirFecha(dgvDetalles.Rows(Index).Cells("Fechas de Pago").Value) ingresocomision = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value) ingresointeres = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value) IVA = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("IVA").Value) amortizacion = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Amortizacion").Value) saldopendiente = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value) montorecibir = Operaciones.ConvertirDecimal(dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value) fechacorte = Operaciones.ConvertirFechaBaseDatos(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Coleccion.Add(correlativo) Coleccion.Add(plazo) Coleccion.Add(fecha) Coleccion.Add(ingresocomision) Coleccion.Add(ingresointeres) Coleccion.Add(IVA) Coleccion.Add(amortizacion) Coleccion.Add(saldopendiente) Coleccion.Add(montorecibir) Coleccion.Add(fechacorte) Return Coleccion End Function Sub NuevoDetalle(ByVal AgregarModificar As Boolean, ByVal Cantidad As Integer) Dim i As Integer = 0 Dim Index = dgvDetalles.Rows.Count - 2 i = Cantidad While i <= Index Dim coleccion = ColeccionDetalle(i) If PrestamoConsulta.NuevoDetalle(coleccion, Codigo) Is Nothing Then Exit Sub End If i += 1 End While MsgBox("Registro de ingresos actualizados") End Sub Function ColeccionCampos() Dim i As Integer = 0 Dim diccionario As New Dictionary(Of String, Collection) Dim Index = dgvDetalles.Rows.Count - 2 While i <= Index Dim coleccion = ColeccionDetalle(i) diccionario.Add(i, coleccion) i += 1 End While Return diccionario End Function Sub EliminarDetalles(ByVal CantidadRegistros As Integer, ByVal Cantidad As Integer) Dim i As Integer = 0 Dim Index = CantidadRegistros + 1 i = Cantidad While i >= Index If PrestamoConsulta.EliminarDetalles(Index, Codigo) Is Nothing Then Exit Sub End If Index += 1 End While End Sub Function ColeccionNuevo(ByVal codigo As String) Dim i As Integer = 0 Dim diccionario As New Dictionary(Of String, Collection) Dim Index = dgvDetalles.Rows.Count - 2 While i <= Index Dim coleccion = ColeccionDetalle(i) diccionario.Add(i, coleccion) i += 1 End While Return diccionario End Function Function ColeccionEliminar(ByVal codigo As String) Dim CantidadRegistros As Integer = dgvDetalles.Rows.Count - 1 Dim Cantidad As Integer = CanRegistros() Dim i As Integer = 0 Dim diccionario As New Dictionary(Of Integer, String) Dim Index = CantidadRegistros + 1 i = Cantidad While i >= Index diccionario.Add(Index, codigo) Index += 1 End While Return diccionario End Function Sub EliminarDatos(ByVal codigo As String) PrestamoConsulta.Eliminar(codigo) End Sub Private Sub dgvDetalles_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellContentClick End Sub Private Sub dgvDetalles_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellEndEdit Calculos(True, False) End Sub Private Sub cboBase_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboBase.SelectedIndexChanged Formato() If (cboBase.SelectedIndex = 0) Then Base = 360 Else Base = 365 End If End Sub Sub CargarDato() Dim codigo As String = Variables.Codigo Dim Retorno = PrestamoConsulta.CargarDato(codigo) Dim coleccion As New Collection If (TypeOf Retorno Is Boolean) Then Exit Sub Else coleccion = PrestamoConsulta.CargarDato(codigo) End If Dim Index As Integer = 0 If (coleccion(6).ToString = "360") Then Index = 0 Else Index = 1 End If txtMonto.Text = Operaciones.ConvertirDecimal(coleccion(1).ToString) dtpFechaOperacion.Value = Operaciones.ConvertirFecha(coleccion(2).ToString) dtpFechaVencimiento.Value = Operaciones.ConvertirFecha(coleccion(3).ToString) txtTasa.Text = (Operaciones.ConvertirDecimal(coleccion(4).ToString) * 100).ToString + "%" cboPeriodicidad.SelectedValue = coleccion(5).ToString cboBase.SelectedIndex = Index cboTipoTasa.SelectedValue = coleccion(7).ToString txtComisionDesembolso.Text = (Operaciones.ConvertirDecimal(coleccion(8).ToString) * 100).ToString + "%" txtPlazoDias.Text = Operaciones.ConvertirEntero(coleccion(9).ToString) End Sub Function CargarDetalles() Dim codigo As String = Variables.Codigo Dim dr = PrestamoConsulta.CargarDetalles(codigo) Dim Datos As Boolean = False If (Not dr Is Nothing) Then Dim Iterador As Integer = 0 Dim ConvertirString As String While dr.Read ConvertirString = Format(Operaciones.ConvertirFecha(dr("fechapago").ToString), "dd/MM/yyyy") dgvDetalles.Rows.Add(Operaciones.ConvertirEntero(dr("correlativo").ToString), Operaciones.ConvertirEntero(dr("plazo").ToString), Operaciones.ConvertirFechaBaseDatos(dr("fechacorte").ToString), Operaciones.ConvertirFecha(ConvertirString), Operaciones.ConvertirDecimal(dr("ingresarcomision").ToString), Operaciones.ConvertirDecimal(dr("ingresarinteres").ToString), Operaciones.ConvertirDecimal(dr("IVA").ToString), Operaciones.ConvertirDecimal(dr("amortizacion").ToString), Operaciones.ConvertirDecimal(dr("saldopendiente").ToString), Operaciones.ConvertirDecimal(dr("montorecibir").ToString)) End While Datos = True End If Return Datos End Function Private Sub btnAccion_Click(sender As Object, e As EventArgs) Handles btnAccion.Click Dim codigo As String = Variables.Codigo Dim Colec As Collection = Coleccion() Dim Diccionario As Dictionary(Of Integer, String) = ColeccionEliminar(codigo) Dim Diccionario2 As Dictionary(Of String, Collection) = ColeccionNuevo(codigo) If (Estado = "N") Then PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Nuevo") ElseIf Not ExisteValidacion() Then Variables.ColeccionPEMP = Coleccion() Variables.ColeccionPEMPDi = ColeccionCampos() Me.Close() End If If (Estado = "M") Then PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Modificar") End If If (Estado = "B") Then EliminarDatos(codigo) End If ValidarExistencia() End Sub Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click Estado = "M" btnAccion.Text = "Modificar" End Sub Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click Estado = "N" btnAccion.Text = "Agregar" ' btnagregar.Text = "Agregar" End Sub Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click Estado = "B" btnAccion.Text = "Eliminar" End Sub Private Sub btnagregar_Click(sender As Object, e As EventArgs) End Sub Private Sub txtMonto_TextChanged(sender As Object, e As EventArgs) Handles txtMonto.TextChanged If (FinCarga) Then Calculos(False, False) End If End Sub Private Sub txtTasa_TextChanged(sender As Object, e As EventArgs) Handles txtTasa.TextChanged If (FinCarga) Then Calculos(False, False) End If End Sub Private Sub txtComisionDesembolso_TextChanged(sender As Object, e As EventArgs) Handles txtComisionDesembolso.TextChanged If (FinCarga) Then Calculos(False, False) End If End Sub Private Sub txtMonto_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonto.KeyPress If String.IsNullOrEmpty(txtMonto.Text) Then If e.KeyChar = "." Then txtMonto.Text = "0" Exit Sub End If End If If (Not txtMonto.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtTasa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasa.KeyPress If String.IsNullOrEmpty(txtTasa.Text) Then If e.KeyChar = "." Then txtTasa.Text = "0" Exit Sub End If End If If (Not txtTasa.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub txtComisionDesembolso_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionDesembolso.KeyPress If String.IsNullOrEmpty(txtComisionDesembolso.Text) Then If e.KeyChar = "." Then txtComisionDesembolso.Text = "0" Exit Sub End If End If If (Not txtComisionDesembolso.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then Operaciones.ValidarEntrada(sender, e, True) Else Operaciones.ValidarEntrada(sender, e, False) End If End Sub Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Cancelar() End Sub Sub Cancelar() End Sub Private Sub txtMonto_Leave(sender As Object, e As EventArgs) Handles txtMonto.Leave Formato() End Sub Private Sub txtTasa_Leave(sender As Object, e As EventArgs) Handles txtTasa.Leave Formato() End Sub Private Sub cboTipoTasa_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTipoTasa.SelectedIndexChanged Formato() End Sub Private Sub cboPeriodicidad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPeriodicidad.SelectedIndexChanged Formato() End Sub Private Sub txtComisionDesembolso_Leave(sender As Object, e As EventArgs) Handles txtComisionDesembolso.Leave Formato() End Sub Private Sub txtPlazoDias_Leave(sender As Object, e As EventArgs) Handles txtPlazoDias.Leave Formato() End Sub Private Sub txtMonto_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMonto.KeyUp If txtMonto.Text = "." Then txtMonto.Text = ".0" End If End Sub Private Sub txtTasa_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasa.KeyUp If txtTasa.Text = "." Then txtTasa.Text = ".0" End If End Sub Private Sub txtComisionDesembolso_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionDesembolso.KeyUp If txtComisionDesembolso.Text = "." Then txtComisionDesembolso.Text = ".0" End If End Sub Private Sub txtPlazoDias_TextChanged(sender As Object, e As EventArgs) Handles txtPlazoDias.TextChanged End Sub End Class