PrestamoEmpresarialDAO.vb 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. Imports System.Data.SqlClient
  2. Public Class PrestamoEmpresarialDAO
  3. Public Function ProcesoDatos(ByVal Coleccion As Collection, ByVal Codigo As String, ByVal Diccionario2 As Dictionary(Of String, Collection), ByVal Estado As String)
  4. Dim objCon As New Conexion
  5. Dim retorno As Integer
  6. Dim sql As String
  7. Dim cmd As SqlCommand
  8. Dim myTrans As SqlTransaction
  9. Dim cn As SqlConnection = objCon.Conectar
  10. If cn.State = ConnectionState.Closed Then
  11. cn.Open()
  12. End If
  13. myTrans = cn.BeginTransaction()
  14. Try
  15. If Estado = "Nuevo" Then
  16. sql = "INSERT INTO [dbo].[PEMP0](
  17. [CodInv]
  18. ,[monto]
  19. ,[fechaoper]
  20. ,[fechaven]
  21. ,[tasa]
  22. ,[periodicidad]
  23. ,[base]
  24. ,[tipotasa]
  25. ,[comisiondesembolso]
  26. ,[plazodias]
  27. ) VALUES(
  28. @CodInv
  29. ,@monto
  30. ,@fechaoper
  31. ,@fechaven
  32. ,@tasa
  33. ,@periodicidad
  34. ,@base
  35. ,@tipotasa
  36. ,@comisiondesembolso
  37. ,@plazodias
  38. )
  39. "
  40. Else
  41. sql = "UPDATE [dbo].[PEMP0] SET
  42. [monto]=@monto
  43. ,[fechaoper]=@fechaoper
  44. ,[fechaven]=@fechaven
  45. ,[tasa]=@tasa
  46. ,[periodicidad]=@periodicidad
  47. ,[base]=@base
  48. ,[tipotasa]=@tipotasa
  49. ,[comisiondesembolso]=@comisiondesembolso
  50. ,[plazodias]=@plazodias
  51. where [CodInv]=@CodInv
  52. "
  53. End If
  54. cmd = New SqlCommand
  55. cmd.CommandText = sql
  56. cmd.Connection = cn
  57. cmd.Transaction = myTrans
  58. With cmd.Parameters
  59. .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  60. .Add("@monto", SqlDbType.Float).Value = CDec(Coleccion(1))
  61. .Add("@fechaoper", SqlDbType.DateTime).Value = CDate(Coleccion(2))
  62. .Add("@fechaven", SqlDbType.DateTime).Value = CDate(Coleccion(3))
  63. .Add("@tasa", SqlDbType.Float).Value = CDec(Coleccion(4))
  64. .Add("@periodicidad", SqlDbType.VarChar).Value = Coleccion(5)
  65. .Add("@base", SqlDbType.Int).Value = CInt(Coleccion(6))
  66. .Add("@tipotasa", SqlDbType.VarChar).Value = Coleccion(7)
  67. .Add("@comisiondesembolso", SqlDbType.Float).Value = CDec(Coleccion(8))
  68. .Add("@plazodias", SqlDbType.Int).Value = CInt(Coleccion(9))
  69. End With
  70. retorno = cmd.ExecuteNonQuery
  71. sql = "DELETE FROM [dbo].[PEMP1]
  72. WHERE [CodInv]=@CodInv "
  73. cmd = New SqlCommand
  74. cmd.CommandText = sql
  75. cmd.Connection = cn
  76. cmd.Transaction = myTrans
  77. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  78. retorno = cmd.ExecuteNonQuery
  79. If Not Diccionario2 Is Nothing Then
  80. For Each DatosDiccionario In Diccionario2
  81. Dim Coleccion2 As Collection = DatosDiccionario.Value
  82. sql = "INSERT INTO [dbo].[PEMP1](
  83. [CodInv]
  84. ,[correlativo]
  85. ,[plazo]
  86. ,[fechapago]
  87. ,[ingresarcomision]
  88. ,[ingresarinteres]
  89. ,[IVA]
  90. ,[amortizacion]
  91. ,[montorecibir]
  92. ,[saldopendiente]
  93. ,[fechacorte]
  94. ) VALUES(
  95. @CodInv
  96. ,@correlativo
  97. ,@plazo
  98. ,@fechapago
  99. ,@ingresarcomision
  100. ,@ingresarinteres
  101. ,@IVA
  102. ,@amortizacion
  103. ,@montorecibir
  104. ,@saldopendiente
  105. ,@fechacorte
  106. )
  107. "
  108. cmd = New SqlCommand
  109. cmd.CommandText = sql
  110. cmd.Connection = cn
  111. cmd.Transaction = myTrans
  112. With cmd.Parameters
  113. .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  114. .Add("@correlativo", SqlDbType.Int).Value = Coleccion2(1)
  115. .Add("@plazo", SqlDbType.Int).Value = Coleccion2(2)
  116. .Add("@fechapago", SqlDbType.Date).Value = Coleccion2(3)
  117. .Add("@ingresarcomision", SqlDbType.Float).Value = Coleccion2(4)
  118. .Add("@ingresarinteres", SqlDbType.Float).Value = Coleccion2(5)
  119. .Add("@IVA", SqlDbType.Float).Value = Coleccion2(6)
  120. .Add("@amortizacion", SqlDbType.Float).Value = Coleccion2(7)
  121. .Add("@saldopendiente", SqlDbType.Float).Value = Coleccion2(8)
  122. .Add("@montorecibir", SqlDbType.Float).Value = Coleccion2(9)
  123. If Coleccion2(10) Is DBNull.Value Then
  124. .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
  125. Else
  126. If String.IsNullOrEmpty(Coleccion2(10)) Then
  127. .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
  128. Else
  129. .Add("@fechacorte", SqlDbType.Date).Value = Coleccion2(10)
  130. End If
  131. End If
  132. End With
  133. retorno = cmd.ExecuteNonQuery
  134. Next
  135. End If
  136. ''''''''''''''''''
  137. myTrans.Commit()
  138. MsgBox("Datos Ingresados")
  139. Catch ex As Exception
  140. myTrans.Rollback()
  141. MsgBox(ex.Message)
  142. End Try
  143. cn.Close()
  144. Return retorno
  145. End Function
  146. Public Function NuevoDato(ByVal Coleccion As Collection, ByVal Codigo As String)
  147. Dim objCon As New Conexion
  148. Dim retorno As Integer
  149. Dim sql As String
  150. Dim cmd As SqlCommand
  151. Dim cn As SqlConnection = objCon.Conectar
  152. If cn.State = ConnectionState.Closed Then
  153. cn.Open()
  154. End If
  155. sql = "INSERT INTO [dbo].[PEMP0](
  156. [CodInv]
  157. ,[monto]
  158. ,[fechaoper]
  159. ,[fechaven]
  160. ,[tasa]
  161. ,[periodicidad]
  162. ,[base]
  163. ,[tipotasa]
  164. ,[comisiondesembolso]
  165. ,[plazodias]
  166. ) VALUES(
  167. @CodInv
  168. ,@monto
  169. ,@fechaoper
  170. ,@fechaven
  171. ,@tasa
  172. ,@periodicidad
  173. ,@base
  174. ,@tipotasa
  175. ,@comisiondesembolso
  176. ,@plazodias
  177. )
  178. "
  179. cmd = New SqlCommand
  180. cmd.CommandText = sql
  181. With cmd.Parameters
  182. .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  183. .Add("@monto", SqlDbType.Float).Value = CDec(Coleccion(1))
  184. .Add("@fechaoper", SqlDbType.DateTime).Value = CDate(Coleccion(2))
  185. .Add("@fechaven", SqlDbType.DateTime).Value = CDate(Coleccion(3))
  186. .Add("@tasa", SqlDbType.Float).Value = CDec(Coleccion(4))
  187. .Add("@periodicidad", SqlDbType.VarChar).Value = Coleccion(5)
  188. .Add("@base", SqlDbType.Int).Value = CInt(Coleccion(6))
  189. .Add("@tipotasa", SqlDbType.VarChar).Value = Coleccion(7)
  190. .Add("@comisiondesembolso", SqlDbType.Float).Value = CDec(Coleccion(8))
  191. .Add("@plazodias", SqlDbType.Int).Value = CInt(Coleccion(9))
  192. End With
  193. cmd.Connection = cn
  194. retorno = cmd.ExecuteNonQuery
  195. cn.Close()
  196. Return retorno
  197. End Function
  198. Public Function ModificarDato(ByVal Coleccion As Collection, ByVal Codigo As String)
  199. Dim objCon As New Conexion
  200. Dim retorno As Integer
  201. Dim sql As String
  202. Dim cmd As SqlCommand
  203. Dim cn As SqlConnection = objCon.Conectar
  204. If cn.State = ConnectionState.Closed Then
  205. cn.Open()
  206. End If
  207. sql = "UPDATE [dbo].[PEMP0] SET
  208. [monto]=@monto
  209. ,[fechaoper]=@fechaoper
  210. ,[fechaven]=@fechaven
  211. ,[tasa]=@tasa
  212. ,[periodicidad]=@periodicidad
  213. ,[base]=@base
  214. ,[tipotasa]=@tipotasa
  215. ,[comisiondesembolso]=@comisiondesembolso
  216. ,[plazodias]=@plazodias
  217. where [CodInv]=@CodInv
  218. "
  219. cmd = New SqlCommand
  220. cmd.CommandText = sql
  221. With cmd.Parameters
  222. .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  223. .Add("@monto", SqlDbType.Float).Value = CDec(Coleccion(1))
  224. .Add("@fechaoper", SqlDbType.DateTime).Value = CDate(Coleccion(2))
  225. .Add("@fechaven", SqlDbType.DateTime).Value = CDate(Coleccion(3))
  226. .Add("@tasa", SqlDbType.Float).Value = CDec(Coleccion(4))
  227. .Add("@periodicidad", SqlDbType.VarChar).Value = Coleccion(5)
  228. .Add("@base", SqlDbType.Int).Value = CInt(Coleccion(6))
  229. .Add("@tipotasa", SqlDbType.VarChar).Value = Coleccion(7)
  230. .Add("@comisiondesembolso", SqlDbType.Float).Value = CDec(Coleccion(8))
  231. .Add("@plazodias", SqlDbType.Int).Value = CInt(Coleccion(9))
  232. End With
  233. cmd.Connection = cn
  234. retorno = cmd.ExecuteNonQuery
  235. cn.Close()
  236. Return retorno
  237. End Function
  238. Public Function NuevoDetalle(ByVal Coleccion As Collection, ByVal Codigo As String)
  239. Dim objCon As New Conexion
  240. Dim retorno As Integer
  241. Dim sql As String
  242. Dim cmd As SqlCommand
  243. Dim cn As SqlConnection = objCon.Conectar
  244. If cn.State = ConnectionState.Closed Then
  245. cn.Open()
  246. End If
  247. sql = "INSERT INTO [dbo].[PEMP1](
  248. [CodInv]
  249. ,[correlativo]
  250. ,[plazo]
  251. ,[fechapago]
  252. ,[ingresarcomision]
  253. ,[ingresarinteres]
  254. ,[IVA]
  255. ,[amortizacion]
  256. ,[montorecibir]
  257. ,[saldopendiente]
  258. ,[fechacorte]
  259. ) VALUES(
  260. @CodInv
  261. ,@correlativo
  262. ,@plazo
  263. ,@fechapago
  264. ,@ingresarcomision
  265. ,@ingresarinteres
  266. ,@IVA
  267. ,@amortizacion
  268. ,@montorecibir
  269. ,@saldopendiente
  270. ,@fechacorte
  271. )
  272. "
  273. cmd = New SqlCommand
  274. cmd.CommandText = sql
  275. With cmd.Parameters
  276. .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  277. .Add("@correlativo", SqlDbType.Int).Value = Coleccion(1)
  278. .Add("@plazo", SqlDbType.Int).Value = Coleccion(2)
  279. .Add("@fechapago", SqlDbType.Date).Value = Coleccion(3)
  280. .Add("@ingresarcomision", SqlDbType.Float).Value = Coleccion(4)
  281. .Add("@ingresarinteres", SqlDbType.Float).Value = Coleccion(5)
  282. .Add("@IVA", SqlDbType.Float).Value = Coleccion(6)
  283. .Add("@amortizacion", SqlDbType.Float).Value = Coleccion(7)
  284. .Add("@saldopendiente", SqlDbType.Float).Value = Coleccion(8)
  285. .Add("@montorecibir", SqlDbType.Float).Value = Coleccion(9)
  286. If String.IsNullOrEmpty(Coleccion(10)) Then
  287. .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
  288. Else
  289. .Add("@fechacorte", SqlDbType.Date).Value = Coleccion(10)
  290. End If
  291. End With
  292. cmd.Connection = cn
  293. retorno = cmd.ExecuteNonQuery
  294. cn.Close()
  295. Return retorno
  296. End Function
  297. Public Function ModificarDetalle(ByVal Coleccion As Collection, ByVal Codigo As String)
  298. Dim objCon As New Conexion
  299. Dim retorno As Integer
  300. Dim sql As String
  301. Dim cmd As SqlCommand
  302. Dim cn As SqlConnection = objCon.Conectar
  303. If cn.State = ConnectionState.Closed Then
  304. cn.Open()
  305. End If
  306. sql = "UPDATE [dbo].[PEMP1] SET
  307. [plazo]=@plazo
  308. ,[fechapago]=@fechapago
  309. ,[ingresarcomision]=@ingresarcomision
  310. ,[ingresarinteres]=@ingresarinteres
  311. ,[IVA]=@IVA
  312. ,[amortizacion]=@amortizacion
  313. ,[montorecibir]=@montorecibir
  314. ,[saldopendiente]=@saldopendiente
  315. ,[fechacorte]=@fechacorte
  316. where [CodInv]=@CodInv AND [correlativo]=@correlativo
  317. "
  318. cmd = New SqlCommand
  319. cmd.CommandText = sql
  320. Try
  321. With cmd.Parameters
  322. .Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  323. .Add("@correlativo", SqlDbType.Int).Value = Coleccion(1)
  324. .Add("@plazo", SqlDbType.Int).Value = Coleccion(2)
  325. .Add("@fechapago", SqlDbType.Date).Value = Coleccion(3)
  326. .Add("@ingresarcomision", SqlDbType.Float).Value = Coleccion(4)
  327. .Add("@ingresarinteres", SqlDbType.Float).Value = Coleccion(5)
  328. .Add("@IVA", SqlDbType.Float).Value = Coleccion(6)
  329. .Add("@amortizacion", SqlDbType.Float).Value = Coleccion(7)
  330. .Add("@saldopendiente", SqlDbType.Float).Value = Coleccion(8)
  331. .Add("@montorecibir", SqlDbType.Float).Value = Coleccion(9)
  332. If Coleccion(10) Is DBNull.Value Then
  333. .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
  334. Else
  335. If String.IsNullOrEmpty(Coleccion(10)) Then
  336. .Add("@fechacorte", SqlDbType.Date).Value = DBNull.Value
  337. Else
  338. .Add("@fechacorte", SqlDbType.Date).Value = Coleccion(10)
  339. End If
  340. End If
  341. End With
  342. cmd.Connection = cn
  343. retorno = cmd.ExecuteNonQuery
  344. Catch ex As Exception
  345. Return Nothing
  346. End Try
  347. cn.Close()
  348. Return retorno
  349. End Function
  350. Public Function CargarDato(ByVal Codigo As String)
  351. Dim objCon As New Conexion
  352. Dim sql As String
  353. Dim cmd As SqlCommand
  354. Dim Coleccion As New Collection
  355. Dim cn As SqlConnection = objCon.Conectar
  356. If cn.State = ConnectionState.Closed Then
  357. cn.Open()
  358. End If
  359. sql = "SELECT * FROM [dbo].[PEMP0] WHERE CodInv=@Codigo"
  360. cmd = New SqlCommand
  361. cmd.CommandText = sql
  362. cmd.Parameters.Add("@Codigo", SqlDbType.VarChar).Value = Codigo
  363. cmd.Connection = cn
  364. ' Dim Datos = cmd.ExecuteScalar
  365. Dim Datos = cmd.ExecuteReader
  366. If Datos.HasRows Then
  367. 'SE ENCONTRO EL REGISTRO
  368. If Datos.Read Then
  369. Coleccion.Add(Datos.Item("monto"))
  370. Coleccion.Add(Datos.Item("fechaoper"))
  371. Coleccion.Add(Datos.Item("fechaven"))
  372. Coleccion.Add(Datos.Item("tasa").ToString + "%")
  373. Coleccion.Add(Datos.Item("periodicidad"))
  374. Coleccion.Add(Datos.Item("base"))
  375. Coleccion.Add(Datos.Item("tipotasa"))
  376. Coleccion.Add(Datos.Item("comisiondesembolso").ToString + "%")
  377. Coleccion.Add(Datos.Item("plazodias"))
  378. cn.Close()
  379. Return Coleccion
  380. End If
  381. End If
  382. cn.Close()
  383. Return False
  384. End Function
  385. Public Function CargarDetalles(ByVal codigo As String)
  386. Dim objCon As New Conexion
  387. Dim cn As SqlConnection = objCon.Conectar
  388. If cn.State = ConnectionState.Closed Then
  389. cn.Open()
  390. End If
  391. Dim sql = "select * from PEMP1 where CodInv='" + codigo + "' order by Correlativo"
  392. Dim cmd As New SqlCommand(sql, cn)
  393. Dim dr As SqlDataReader
  394. dr = cmd.ExecuteReader
  395. Return dr
  396. End Function
  397. Public Sub Eliminar(ByVal Codigo As String)
  398. Dim objCon As New Conexion
  399. Dim retorno As Integer
  400. Dim sql As String
  401. Dim cmd As SqlCommand
  402. Dim myTrans As SqlTransaction
  403. Dim cn As SqlConnection = objCon.Conectar
  404. If cn.State = ConnectionState.Closed Then
  405. cn.Open()
  406. End If
  407. myTrans = cn.BeginTransaction()
  408. Try
  409. sql = "DELETE FROM [dbo].[PEMP0]
  410. WHERE [CodInv]=@CodInv"
  411. cmd = New SqlCommand
  412. cmd.CommandText = sql
  413. cmd.Connection = cn
  414. cmd.Transaction = myTrans
  415. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  416. retorno = cmd.ExecuteNonQuery
  417. sql = "DELETE FROM [dbo].[PEMP1]
  418. WHERE [CodInv]=@CodInv"
  419. cmd = New SqlCommand
  420. cmd.CommandText = sql
  421. cmd.Connection = cn
  422. cmd.Transaction = myTrans
  423. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  424. retorno = cmd.ExecuteNonQuery
  425. myTrans.Commit()
  426. MsgBox("Datos Eliminados")
  427. Catch ex As Exception
  428. myTrans.Rollback()
  429. MsgBox(ex.Message)
  430. End Try
  431. cn.Close()
  432. End Sub
  433. Public Function EliminarDetalles(ByVal Correlativo As Integer, ByVal Codigo As String)
  434. Dim objCon As New Conexion
  435. Dim sql As String
  436. Dim cmd As SqlCommand
  437. Dim res As Integer
  438. Dim cn As SqlConnection = objCon.Conectar
  439. If cn.State = ConnectionState.Closed Then
  440. cn.Open()
  441. End If
  442. sql = "DELETE FROM [dbo].[PEMP1]
  443. WHERE [CodInv]=@CodInv and [Correlativo]=@Correlativo"
  444. Try
  445. cmd = New SqlCommand
  446. cmd.CommandText = sql
  447. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  448. cmd.Parameters.Add("@Correlativo", SqlDbType.VarChar).Value = Correlativo
  449. cmd.Connection = cn
  450. res = cmd.ExecuteNonQuery
  451. Catch ex As Exception
  452. cn.Close()
  453. Return Nothing
  454. End Try
  455. cn.Close()
  456. Return 1
  457. End Function
  458. End Class