Imports System.Data.SqlClient
Public Class PrestamoPersonalDAO








    Public Function ProcesoDatos(ByVal Coleccion As Collection, ByVal Coleccion2 As Collection, ByVal Codigo As String, ByVal Diccionario As Dictionary(Of String, Collection), ByVal EstadoDeudor As String, ByVal EstadoDetalles As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim myTrans As SqlTransaction
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If

        myTrans = cn.BeginTransaction()
        Try


            If EstadoDeudor = "Nuevo" Then


                sql = "INSERT INTO [dbo].[PPER0](
           [CodInv]
           ,[nombredeudor]
           ,[numerodeudor]
           ,[fechaotorga]
           ,[fechapago]
           ,[periodogracia]
) VALUES(
           @CodInv
           ,@nombredeudor
           ,@numerodeudor
           ,@fechaotorga
           ,@fechapago
           ,@periodogracia
)
    "

            Else
                sql = "UPDATE [dbo].[PPER0] SET
           
           [nombredeudor]=@nombredeudor
           ,[numerodeudor]=@numerodeudor
           ,[fechaotorga]=@fechaotorga
           ,[fechapago]=@fechapago
           ,[periodogracia]=@periodogracia
           where [CodInv]=@CodInv

    "
            End If
            cmd = New SqlCommand
            cmd.CommandText = sql
            cmd.Connection = cn






            cmd.Transaction = myTrans

            With cmd.Parameters
                .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
                .Add("@nombredeudor", SqlDbType.VarChar).Value = Coleccion(1)
                .Add("@numerodeudor", SqlDbType.VarChar).Value = Coleccion(2)
                .Add("@fechaotorga", SqlDbType.DateTime).Value = CDate(Coleccion(3))
                .Add("@fechapago", SqlDbType.DateTime).Value = CDate(Coleccion(4))

                .Add("@periodogracia", SqlDbType.Float).Value = CDec(Coleccion(5))

            End With


            retorno = cmd.ExecuteNonQuery






            If EstadoDetalles = "Nuevo" Then

                sql = "INSERT INTO [dbo].[PPER1](        
           [CodInv]
           ,[tasainteres]
           ,[duracionprestamo]
           ,[totalcuotas]
           ,[montoprestamo]
           ,[seguro]
            ,[CuotaSinSeguro]
            ,[CuotaReal]

) VALUES(
           @CodInv
           ,@tasainteres
           ,@duracionprestamo
           ,@totalcuotas
           ,@montoprestamo
           ,@seguro
           ,@CuotaSinSeguro
           ,@CuotaReal

)
    "

            Else
                sql = "UPDATE  [dbo].[PPER1] SET       
           
           [tasainteres]=@tasainteres
           ,[duracionprestamo]=@duracionprestamo
           ,[totalcuotas]=@totalcuotas
           ,[montoprestamo]=@montoprestamo
           ,[seguro]=@seguro
            ,[CuotaSinSeguro]=@CuotaSinSeguro
            ,[CuotaReal]=@CuotaReal
           where [CodInv]=@CodInv
 


    
    "
            End If
            cmd = New SqlCommand
            cmd.CommandText = sql
            cmd.Connection = cn






            cmd.Transaction = myTrans
            With cmd.Parameters
                .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
                .Add("@tasainteres", SqlDbType.Float).Value = CDec(Coleccion2(1))
                .Add("@duracionprestamo", SqlDbType.Float).Value = CDec(Coleccion2(2))
                .Add("@totalcuotas", SqlDbType.Float).Value = CDec(Coleccion2(3))
                .Add("@montoprestamo", SqlDbType.Float).Value = CDec(Coleccion2(4))
                .Add("@seguro", SqlDbType.Float).Value = CDec(Coleccion2(5))
                .Add("@CuotaSinSeguro", SqlDbType.Float).Value = CDec(Coleccion2(6))
                .Add("@CuotaReal", SqlDbType.Float).Value = CDec(Coleccion2(7))
            End With


            retorno = cmd.ExecuteNonQuery

















            sql = "DELETE FROM [dbo].[PPER2]
      WHERE [CodInv]=@CodInv "


            cmd = New SqlCommand
            cmd.CommandText = sql
            cmd.Connection = cn
            cmd.Transaction = myTrans
            cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo

            retorno = cmd.ExecuteNonQuery









            If Not Diccionario Is Nothing Then


                For Each DatosDiccionario In Diccionario
                    Dim Coleccion3 As Collection = DatosDiccionario.Value
                    sql = "INSERT INTO [dbo].[PPER2](
           [CodInv]
           ,[fecha]
           ,[Periodo]
           ,[saldoinicial]
           ,[pagocuota]
           ,[pagointeresIVA]
           ,[IVAinteres]
           ,[pagointeres]
           ,[abono]
           ,[prestamoremanente]
           ,[pagodanos]
           ,[pagovivienta]
           ,[totalcuota]
           ,[totalpagado]
           ,[abonoextra]
           ,[correlativo]
           ,[fechacorte]
) VALUES(
           @CodInv
           ,@fecha
           ,@Periodo
           ,@saldoinicial
           ,@pagocuota
           ,@pagointeresIVA
           ,@IVAinteres
           ,@pagointeres
           ,@abono
           ,@prestamoremanente
           ,@pagodanos
           ,@pagovivienta
           ,@totalcuota
           ,@totalpagado
           ,@abonoextra
           ,@correlativo
           ,@fechacorte

)
    "

                    cmd = New SqlCommand
                    cmd.CommandText = sql
                    cmd.Connection = cn
                    cmd.Transaction = myTrans

                    With cmd.Parameters
                        .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
                        .Add("@correlativo", SqlDbType.Int).Value = CInt(Coleccion3(1))
                        .Add("@fecha", SqlDbType.DateTime).Value = CDate(Coleccion3(2))
                        .Add("@Periodo", SqlDbType.Int).Value = CInt(Coleccion3(3))
                        .Add("@saldoinicial", SqlDbType.Float).Value = CDec(Coleccion3(4))
                        .Add("@pagocuota", SqlDbType.Float).Value = CDec(Coleccion3(5))
                        .Add("@pagointeresIVA", SqlDbType.Float).Value = CDec(Coleccion3(6))
                        .Add("@IVAinteres", SqlDbType.Float).Value = CDec(Coleccion3(7))
                        .Add("@pagointeres", SqlDbType.Float).Value = CDec(Coleccion3(8))
                        .Add("@abono", SqlDbType.Float).Value = CDec(Coleccion3(9))
                        .Add("@prestamoremanente", SqlDbType.Float).Value = CDec(Coleccion3(10))
                        .Add("@pagodanos", SqlDbType.Float).Value = CDec(Coleccion3(11))
                        .Add("@pagovivienta", SqlDbType.Float).Value = CDec(Coleccion3(12))
                        .Add("@totalcuota", SqlDbType.Float).Value = CDec(Coleccion3(13))
                        .Add("@totalpagado", SqlDbType.Float).Value = CDec(Coleccion3(14))
                        .Add("@abonoextra", SqlDbType.Float).Value = CDec(Coleccion3(15))
                        If String.IsNullOrEmpty(Coleccion3(16).ToString) Then
                            .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
                        Else

                            .Add("@fechacorte", SqlDbType.Date).Value = Coleccion3(16)
                        End If

                    End With

                    retorno = cmd.ExecuteNonQuery





                Next


            End If



            ''''''''''''''''''












            myTrans.Commit()
            MsgBox("Datos Ingresados")
        Catch ex As Exception
            myTrans.Rollback()
            MsgBox(ex.Message)
        End Try
        cn.Close()

        Return retorno


    End Function



















    Public Function NuevoDeudor(ByVal Coleccion As Collection, ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "INSERT INTO [dbo].[PPER0](
           [CodInv]
           ,[nombredeudor]
           ,[numerodeudor]
           ,[fechaotorga]
           ,[fechapago]
           ,[periodogracia]
) VALUES(
           @CodInv
           ,@nombredeudor
           ,@numerodeudor
           ,@fechaotorga
           ,@fechapago
           ,@periodogracia
)
    "

        cmd = New SqlCommand
        cmd.CommandText = sql

        With cmd.Parameters
            .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
            .Add("@nombredeudor", SqlDbType.VarChar).Value = Coleccion(1)
            .Add("@numerodeudor", SqlDbType.VarChar).Value = Coleccion(2)
            .Add("@fechaotorga", SqlDbType.DateTime).Value = CDate(Coleccion(3))
            .Add("@fechapago", SqlDbType.DateTime).Value = CDate(Coleccion(4))

            .Add("@periodogracia", SqlDbType.Float).Value = CDec(Coleccion(5))

        End With


        cmd.Connection = cn

        retorno = cmd.ExecuteNonQuery

        cn.Dispose()
        cn.Close()
        Return retorno

    End Function







    Public Function ModificarDeudor(ByVal Coleccion As Collection, ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "UPDATE [dbo].[PPER0] SET
           
           [nombredeudor]=@nombredeudor
           ,[numerodeudor]=@numerodeudor
           ,[fechaotorga]=@fechaotorga
           ,[fechapago]=@fechapago
           ,[periodogracia]=@periodogracia
           where [CodInv]=@CodInv

    "

        cmd = New SqlCommand
        cmd.CommandText = sql

        With cmd.Parameters
            .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
            .Add("@nombredeudor", SqlDbType.VarChar).Value = Coleccion(1)
            .Add("@numerodeudor", SqlDbType.VarChar).Value = Coleccion(2)
            .Add("@fechaotorga", SqlDbType.DateTime).Value = CDate(Coleccion(3))
            .Add("@fechapago", SqlDbType.DateTime).Value = CDate(Coleccion(4))
            .Add("@periodogracia", SqlDbType.Float).Value = CDec(Coleccion(5))

        End With


        cmd.Connection = cn

        retorno = cmd.ExecuteNonQuery

        cn.Dispose()
        cn.Close()
        Return retorno

    End Function


















    Public Function NuevoDetalle(ByVal Coleccion As Collection, ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "INSERT INTO [dbo].[PPER1](        
           [CodInv]
           ,[tasainteres]
           ,[duracionprestamo]
           ,[totalcuotas]
           ,[montoprestamo]
           ,[seguro]
            ,[CuotaSinSeguro]
            ,[CuotaReal]

) VALUES(
           @CodInv
           ,@tasainteres
           ,@duracionprestamo
           ,@totalcuotas
           ,@montoprestamo
           ,@seguro
           ,@CuotaSinSeguro
           ,@CuotaReal

)
    "

        cmd = New SqlCommand
        cmd.CommandText = sql

        With cmd.Parameters
            .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
            .Add("@tasainteres", SqlDbType.Float).Value = CDec(Coleccion(1))
            .Add("@duracionprestamo", SqlDbType.Float).Value = CDec(Coleccion(2))
            .Add("@totalcuotas", SqlDbType.Float).Value = CDec(Coleccion(3))
            .Add("@montoprestamo", SqlDbType.Float).Value = CDec(Coleccion(4))
            .Add("@seguro", SqlDbType.Float).Value = CDec(Coleccion(5))
            .Add("@CuotaSinSeguro", SqlDbType.Float).Value = CDec(Coleccion(6))
            .Add("@CuotaReal", SqlDbType.Float).Value = CDec(Coleccion(7))
        End With


        cmd.Connection = cn

        retorno = cmd.ExecuteNonQuery
        cn.Dispose()
        cn.Close()

        Return retorno

    End Function

    Public Function ModificarDetalle(ByVal Coleccion As Collection, ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "UPDATE  [dbo].[PPER1] SET       
           
           [tasainteres]=@tasainteres
           ,[duracionprestamo]=@duracionprestamo
           ,[totalcuotas]=@totalcuotas
           ,[montoprestamo]=@montoprestamo
           ,[seguro]=@seguro
            ,[CuotaSinSeguro]=@CuotaSinSeguro
            ,[CuotaReal]=@CuotaReal
           where [CodInv]=@CodInv
 


    "

        cmd = New SqlCommand
        cmd.CommandText = sql

        With cmd.Parameters
            .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
            .Add("@tasainteres", SqlDbType.Float).Value = CDec(Coleccion(1))
            .Add("@duracionprestamo", SqlDbType.Float).Value = CDec(Coleccion(2))
            .Add("@totalcuotas", SqlDbType.Float).Value = CDec(Coleccion(3))
            .Add("@montoprestamo", SqlDbType.Float).Value = CDec(Coleccion(4))
            .Add("@seguro", SqlDbType.Float).Value = CDec(Coleccion(5))
            .Add("@CuotaSinSeguro", SqlDbType.Float).Value = CDec(Coleccion(6))
            .Add("@CuotaReal", SqlDbType.Float).Value = CDec(Coleccion(7))

        End With


        cmd.Connection = cn

        retorno = cmd.ExecuteNonQuery

        cn.Dispose()
        cn.Close()
        Return retorno

    End Function





    Public Function NuevaAmortizacion(ByVal Coleccion As Collection, ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "INSERT INTO [dbo].[PPER2](
           [CodInv]
           ,[fecha]
           ,[Periodo]
           ,[saldoinicial]
           ,[pagocuota]
           ,[pagointeresIVA]
           ,[IVAinteres]
           ,[pagointeres]
           ,[abono]
           ,[prestamoremanente]
           ,[pagodanos]
           ,[pagovivienta]
           ,[totalcuota]
           ,[totalpagado]
           ,[abonoextra]
           ,[correlativo]
           ,[fechacorte]
) VALUES(
           @CodInv
           ,@fecha
           ,@Periodo
           ,@saldoinicial
           ,@pagocuota
           ,@pagointeresIVA
           ,@IVAinteres
           ,@pagointeres
           ,@abono
           ,@prestamoremanente
           ,@pagodanos
           ,@pagovivienta
           ,@totalcuota
           ,@totalpagado
           ,@abonoextra
           ,@correlativo
           ,@fechacorte

)
    "

        cmd = New SqlCommand
        cmd.CommandText = sql

        With cmd.Parameters
            .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
            .Add("@correlativo", SqlDbType.Int).Value = CInt(Coleccion(1))
            .Add("@fecha", SqlDbType.DateTime).Value = CDate(Coleccion(2))
            .Add("@Periodo", SqlDbType.Int).Value = CInt(Coleccion(3))
            .Add("@saldoinicial", SqlDbType.Float).Value = CDec(Coleccion(4))
            .Add("@pagocuota", SqlDbType.Float).Value = CDec(Coleccion(5))
            .Add("@pagointeresIVA", SqlDbType.Float).Value = CDec(Coleccion(6))
            .Add("@IVAinteres", SqlDbType.Float).Value = CDec(Coleccion(7))
            .Add("@pagointeres", SqlDbType.Float).Value = CDec(Coleccion(8))
            .Add("@abono", SqlDbType.Float).Value = CDec(Coleccion(9))
            .Add("@prestamoremanente", SqlDbType.Float).Value = CDec(Coleccion(10))
            .Add("@pagodanos", SqlDbType.Float).Value = CDec(Coleccion(11))
            .Add("@pagovivienta", SqlDbType.Float).Value = CDec(Coleccion(12))
            .Add("@totalcuota", SqlDbType.Float).Value = CDec(Coleccion(13))
            .Add("@totalpagado", SqlDbType.Float).Value = CDec(Coleccion(14))
            .Add("@abonoextra", SqlDbType.Float).Value = CDec(Coleccion(15))
            If String.IsNullOrEmpty(Coleccion(16).ToString) Then
                .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
            Else

                .Add("@fechacorte", SqlDbType.date).Value = Coleccion(16)
            End If

        End With

        cmd.Connection = cn

        retorno = cmd.ExecuteNonQuery
        cn.Dispose()
        cn.Close()

        Return retorno

    End Function




    Public Function ModificarAmortizacion(ByVal Coleccion As Collection, ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "UPDATE [dbo].[PPER2] SET
           
           [fecha]=@fecha
           ,[Periodo]=@Periodo
           ,[saldoinicial]=@saldoinicial
           ,[pagocuota]=@pagocuota
           ,[pagointeresIVA]=@pagointeresIVA
           ,[IVAinteres]=@IVAinteres
           ,[pagointeres]=@pagointeres
           ,[abono]=@abono
           ,[prestamoremanente]=@prestamoremanente
           ,[pagodanos]=@pagodanos
           ,[pagovivienta]=@pagovivienta
           ,[totalcuota]=@totalcuota
           ,[totalpagado]=@totalpagado
           ,[abonoextra]=@abonoextra
           ,[correlativo]=@correlativo
           where [CodInv]=@CodInv 
    "

        cmd = New SqlCommand
        cmd.CommandText = sql

        With cmd.Parameters
            .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
            .Add("@fecha", SqlDbType.DateTime).Value = CDate(Coleccion(1))
            .Add("@Periodo", SqlDbType.Int).Value = CInt(Coleccion(2))
            .Add("@saldoinicial", SqlDbType.Float).Value = CDec(Coleccion(3))
            .Add("@pagocuota", SqlDbType.Float).Value = CDec(Coleccion(4))
            .Add("@pagointeresIVA", SqlDbType.Float).Value = CDec(Coleccion(5))
            .Add("@IVAinteres", SqlDbType.Float).Value = CDec(Coleccion(6))
            .Add("@pagointeres", SqlDbType.Float).Value = CDec(Coleccion(7))
            .Add("@abono", SqlDbType.Float).Value = CDec(Coleccion(8))
            .Add("@prestamoremanente", SqlDbType.Float).Value = CDec(Coleccion(9))
            .Add("@pagodanos", SqlDbType.Float).Value = CDec(Coleccion(10))
            .Add("@pagovivienta", SqlDbType.Float).Value = CDec(Coleccion(11))
            .Add("@totalcuota", SqlDbType.Float).Value = CDec(Coleccion(12))
            .Add("@totalpagado", SqlDbType.Float).Value = CDec(Coleccion(13))
            .Add("@abonoextra", SqlDbType.Float).Value = CDec(Coleccion(14))
            .Add("@correlativo", SqlDbType.Int).Value = CInt(Coleccion(15))

        End With

        cmd.Connection = cn

        retorno = cmd.ExecuteNonQuery
        cn.Dispose()
        cn.Close()
        Return retorno

    End Function







    Public Function CargarDeudor(ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim sql As String
        Dim cmd As SqlCommand
        Dim Coleccion As New Collection
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "SELECT * FROM [dbo].[PPER0] WHERE CodInv=@Codigo"
        cmd = New SqlCommand


        cmd.CommandText = sql
        cmd.Parameters.Add("@Codigo", SqlDbType.VarChar).Value = Codigo
        cmd.Connection = cn

        ' Dim Datos = cmd.ExecuteScalar
        Dim Datos = cmd.ExecuteReader
        If Datos.HasRows Then
            'SE ENCONTRO EL REGISTRO


            If Datos.Read Then

                Coleccion.Add(Datos.Item("nombredeudor"))
                Coleccion.Add(Datos.Item("numerodeudor"))
                Coleccion.Add(Datos.Item("fechaotorga"))
                Coleccion.Add(Datos.Item("fechapago"))
                Coleccion.Add(Datos.Item("periodogracia"))

                cn.Close()
                Return Coleccion
            End If
        End If
        cn.Close()
        Return False
    End Function








    Public Function CargarDetalles(ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim sql As String
        Dim cmd As SqlCommand
        Dim Coleccion As New Collection
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "SELECT * FROM [dbo].[PPER1] WHERE CodInv=@Codigo"


        cmd = New SqlCommand

        cmd.CommandText = sql
        cmd.Parameters.Add("@Codigo", SqlDbType.VarChar).Value = Codigo
        cmd.Connection = cn

        ' Dim Datos = cmd.ExecuteScalar
        Dim Datos = cmd.ExecuteReader
        If Datos.HasRows Then
            'SE ENCONTRO EL REGISTRO


            If Datos.Read Then

                Coleccion.Add(Datos.Item("tasainteres"))
                Coleccion.Add(Datos.Item("duracionprestamo"))
                Coleccion.Add(Datos.Item("totalcuotas"))
                Coleccion.Add(Datos.Item("montoprestamo"))
                Coleccion.Add(Datos.Item("seguro"))
                cn.Close()
                Return Coleccion
            End If
        End If
        cn.Close()
        Return False
    End Function





    Public Function CargarAmortizacion(ByVal codigo As String)
        Dim objCon As New Conexion
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "select * from PPER2 where CodInv='" + codigo + "' order by Correlativo"


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function
    Public Sub Eliminar(ByVal Codigo As String)




        Dim objCon As New Conexion
        Dim retorno As Integer
        Dim sql As String
        Dim cmd As SqlCommand
        Dim myTrans As SqlTransaction
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        myTrans = cn.BeginTransaction()
        Try

            sql = "DELETE FROM [dbo].[PPER0]
      WHERE [CodInv]=@CodInv"


            cmd = New SqlCommand
            cmd.CommandText = sql
            cmd.Connection = cn
            cmd.Transaction = myTrans
            cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo


            retorno = cmd.ExecuteNonQuery



            sql = "DELETE FROM [dbo].[PPER1]
      WHERE [CodInv]=@CodInv"


            cmd = New SqlCommand
            cmd.CommandText = sql
            cmd.Connection = cn
            cmd.Transaction = myTrans
            cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo


            retorno = cmd.ExecuteNonQuery


            sql = "DELETE FROM [dbo].[PPER2]
      WHERE [CodInv]=@CodInv"


            cmd = New SqlCommand
            cmd.CommandText = sql
            cmd.Connection = cn
            cmd.Transaction = myTrans
            cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo


            retorno = cmd.ExecuteNonQuery

            myTrans.Commit()
            MsgBox("Datos Eliminados")
        Catch ex As Exception
            myTrans.Rollback()
            MsgBox(ex.Message)
        End Try
        cn.Close()

    End Sub

    Public Sub EliminarDetalle(ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim sql As String
        Dim cmd As SqlCommand
        Dim res As Integer
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "DELETE FROM [dbo].[PPER1]
      WHERE [CodInv]=@CodInv"



        cmd = New SqlCommand
        cmd.CommandText = sql
        cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
        cmd.Connection = cn

        res = cmd.ExecuteNonQuery
        cn.Close()
    End Sub


    Public Sub EliminarAmortizacion(ByVal Codigo As String)
        Dim objCon As New Conexion
        Dim sql As String
        Dim cmd As SqlCommand
        Dim res As Integer
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "DELETE FROM [dbo].[PPER2]
      WHERE [CodInv]=@CodInv "



        cmd = New SqlCommand
        cmd.CommandText = sql
        cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
        cmd.Connection = cn

        res = cmd.ExecuteNonQuery
        cn.Close()
    End Sub
End Class
