| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- Imports System.Data.SqlClient
- Public Class PrestamoEmpresarialDAO
- Dim Operaciones As New Operaciones
- Public Function ProcesoDatos(ByVal Coleccion As Collection, ByVal Codigo As String, ByVal Diccionario2 As Dictionary(Of String, Collection), ByVal Estado 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 Estado = "Nuevo" Then
- sql = "INSERT INTO [dbo].[PEMP0](
- [CodInv]
- ,[monto]
- ,[fechaoper]
- ,[fechaven]
- ,[tasa]
- ,[periodicidad]
- ,[base]
- ,[tipotasa]
- ,[comisiondesembolso]
- ,[plazodias]
- ) VALUES(
- @CodInv
- ,@monto
- ,@fechaoper
- ,@fechaven
- ,@tasa
- ,@periodicidad
- ,@base
- ,@tipotasa
- ,@comisiondesembolso
- ,@plazodias
- )
- "
- Else
- sql = "UPDATE [dbo].[PEMP0] SET
-
- [monto]=@monto
- ,[fechaoper]=@fechaoper
- ,[fechaven]=@fechaven
- ,[tasa]=@tasa
- ,[periodicidad]=@periodicidad
- ,[base]=@base
- ,[tipotasa]=@tipotasa
- ,[comisiondesembolso]=@comisiondesembolso
- ,[plazodias]=@plazodias
- 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("@monto", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(1).ToString)
- .Add("@fechaoper", SqlDbType.DateTime).Value = Operaciones.ConvertirFecha(Coleccion(2).ToString)
- .Add("@fechaven", SqlDbType.DateTime).Value = Operaciones.ConvertirFecha(Coleccion(3).ToString)
- .Add("@tasa", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(4).ToString)
- .Add("@periodicidad", SqlDbType.VarChar).Value = Coleccion(5).ToString
- .Add("@base", SqlDbType.Int).Value = Operaciones.ConvertirEntero(Coleccion(6).ToString)
- .Add("@tipotasa", SqlDbType.VarChar).Value = Coleccion(7).ToString
- .Add("@comisiondesembolso", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(8).ToString)
- .Add("@plazodias", SqlDbType.Int).Value = Operaciones.ConvertirEntero(Coleccion(9).ToString)
- End With
- retorno = cmd.ExecuteNonQuery
- sql = "DELETE FROM [dbo].[PEMP1]
- 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 Diccionario2 Is Nothing Then
- For Each DatosDiccionario In Diccionario2
- Dim Coleccion2 As Collection = DatosDiccionario.Value
- sql = "INSERT INTO [dbo].[PEMP1](
- [CodInv]
- ,[correlativo]
- ,[plazo]
- ,[fechapago]
- ,[ingresarcomision]
- ,[ingresarinteres]
- ,[IVA]
- ,[amortizacion]
- ,[montorecibir]
- ,[saldopendiente]
- ,[fechacorte]
- ) VALUES(
- @CodInv
- ,@correlativo
- ,@plazo
- ,@fechapago
- ,@ingresarcomision
- ,@ingresarinteres
- ,@IVA
- ,@amortizacion
- ,@montorecibir
- ,@saldopendiente
- ,@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 = Operaciones.ConvertirEntero(Coleccion2(1).ToString)
- .Add("@plazo", SqlDbType.Int).Value = Operaciones.ConvertirEntero(Coleccion2(2).ToString)
- .Add("@fechapago", SqlDbType.Date).Value = Operaciones.ConvertirFecha(Coleccion2(3).ToString)
- .Add("@ingresarcomision", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion2(4).ToString)
- .Add("@ingresarinteres", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion2(5).ToString)
- .Add("@IVA", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion2(6).ToString)
- .Add("@amortizacion", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion2(7).ToString)
- .Add("@saldopendiente", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion2(8))
- .Add("@montorecibir", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion2(9).ToString)
- .Add("@fechacorte", SqlDbType.Date).Value = Operaciones.ConvertirFechaBaseDatos(Coleccion2(10).ToString)
- 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 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].[PEMP1](
- [CodInv]
- ,[correlativo]
- ,[plazo]
- ,[fechapago]
- ,[ingresarcomision]
- ,[ingresarinteres]
- ,[IVA]
- ,[amortizacion]
- ,[montorecibir]
- ,[saldopendiente]
- ,[fechacorte]
- ) VALUES(
- @CodInv
- ,@correlativo
- ,@plazo
- ,@fechapago
- ,@ingresarcomision
- ,@ingresarinteres
- ,@IVA
- ,@amortizacion
- ,@montorecibir
- ,@saldopendiente
- ,@fechacorte
- )
- "
- cmd = New SqlCommand
- cmd.CommandText = sql
- With cmd.Parameters
- .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
- .Add("@correlativo", SqlDbType.Int).Value = Operaciones.ConvertirEntero(Coleccion(1).ToString)
- .Add("@plazo", SqlDbType.Int).Value = Operaciones.ConvertirEntero(Coleccion(2).ToString)
- .Add("@fechapago", SqlDbType.Date).Value = Operaciones.ConvertirFecha(Coleccion(3).ToString)
- .Add("@ingresarcomision", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(4).ToString)
- .Add("@ingresarinteres", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(5).ToString)
- .Add("@IVA", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(6).ToString)
- .Add("@amortizacion", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(7).ToString)
- .Add("@saldopendiente", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(8))
- .Add("@montorecibir", SqlDbType.Float).Value = Operaciones.ConvertirDecimal(Coleccion(9).ToString)
- .Add("@fechacorte", SqlDbType.Date).Value = Operaciones.ConvertirFechaBaseDatos(Coleccion(10).ToString)
- End With
- cmd.Connection = cn
- retorno = cmd.ExecuteNonQuery
- cn.Close()
- Return retorno
- End Function
- Public Function CargarDato(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].[PEMP0] 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("monto"))
- Coleccion.Add(Datos.Item("fechaoper"))
- Coleccion.Add(Datos.Item("fechaven"))
- Coleccion.Add(Datos.Item("tasa").ToString + "%")
- Coleccion.Add(Datos.Item("periodicidad"))
- Coleccion.Add(Datos.Item("base"))
- Coleccion.Add(Datos.Item("tipotasa"))
- Coleccion.Add(Datos.Item("comisiondesembolso").ToString + "%")
- Coleccion.Add(Datos.Item("plazodias"))
- 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 cn As SqlConnection = objCon.Conectar
- If cn.State = ConnectionState.Closed Then
- cn.Open()
- End If
- Dim sql = "select * from PEMP1 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].[PEMP0]
- 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].[PEMP1]
- 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 Function EliminarDetalles(ByVal Correlativo As Integer, 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].[PEMP1]
- WHERE [CodInv]=@CodInv and [Correlativo]=@Correlativo"
- Try
- cmd = New SqlCommand
- cmd.CommandText = sql
- cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
- cmd.Parameters.Add("@Correlativo", SqlDbType.VarChar).Value = Correlativo
- cmd.Connection = cn
- res = cmd.ExecuteNonQuery
- Catch ex As Exception
- cn.Close()
- Return Nothing
- End Try
- cn.Close()
- Return 1
- End Function
- End Class
|