DAONotaEstructurada.vb 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. Imports System.Data.SqlClient
  2. Public Class DAONotaEstructurada
  3. Function Nuevo(ByVal oNESTCE As NotaEstructuradaCE) As Integer
  4. Dim objCon As New Conexion
  5. Dim retorno As Integer
  6. Dim sql As String
  7. Dim cmd As SqlCommand
  8. Dim cn As SqlConnection = objCon.Conectar
  9. If cn.State = ConnectionState.Closed Then
  10. cn.Open()
  11. End If
  12. sql = "INSERT INTO [dbo].[NEST0]
  13. ([CodInv]
  14. ,[MontoInv]
  15. ,[FOper]
  16. ,[FVenc]
  17. ,[Tasa]
  18. ,[Plazo]
  19. --,[AnBase]
  20. ,[Periodic])
  21. VALUES
  22. (@CodInv
  23. ,@MontoInv
  24. ,@FOper
  25. ,@FVenc
  26. ,@Tasa
  27. ,@Plazo
  28. --,@AnBase
  29. ,@Periodic)
  30. "
  31. cmd = New SqlCommand
  32. cmd.Connection = cn
  33. cmd.CommandText = sql
  34. With cmd.Parameters
  35. .Add("@CodInv", SqlDbType.VarChar).Value = oNESTCE.CodigoInversion
  36. .Add("@MontoInv", SqlDbType.Float).Value = oNESTCE.MontoDeInversion
  37. .Add("@FOper", SqlDbType.Date).Value = oNESTCE.FechaOperacion
  38. .Add("@FVenc", SqlDbType.Date).Value = oNESTCE.FechaVencimiento
  39. .Add("@Tasa", SqlDbType.Float).Value = oNESTCE.Tasa
  40. .Add("@Plazo", SqlDbType.Int).Value = oNESTCE.Plazo
  41. '.Add("@AnBase",SqlDbType.VarChar).Value = oDAPCE.CodigoInversion
  42. .Add("@Periodic", SqlDbType.VarChar).Value = oNESTCE.Periodicidad
  43. End With
  44. retorno = cmd.ExecuteNonQuery
  45. cmd.Dispose()
  46. cn.Dispose()
  47. GuardaIntereses(oNESTCE.CodigoInversion, oNESTCE.dtIntereses)
  48. Return retorno
  49. End Function
  50. Function Nuevo(ByVal oNEST As NotaEstructuradaCE, DocId As Integer, Tipo As String) As Integer
  51. Dim objCon As New Conexion
  52. Dim retorno As Integer = -1
  53. Dim Transaccion As SqlTransaction
  54. Dim query As String
  55. Dim Tabla As String = ""
  56. Dim cn As SqlConnection = objCon.Conectar
  57. If cn.State = ConnectionState.Closed Then
  58. cn.Open()
  59. End If
  60. If Tipo = "P" Then
  61. Tabla = "PDAP0"
  62. End If
  63. If Tipo = "I" Then
  64. Tabla = "IDAP0"
  65. End If
  66. Dim cmd As SqlCommand = cn.CreateCommand
  67. Transaccion = cn.BeginTransaction("NuevoDAP")
  68. cmd.Connection = cn
  69. cmd.Transaction = Transaccion
  70. query = "INSERT INTO [dbo].[" & Tabla & "]
  71. ([DocId]
  72. ,[MontoInv]
  73. ,[FOper]
  74. ,[FVenc]
  75. ,[Tasa]
  76. ,[Plazo]
  77. ,[AnBase]
  78. ,[Periodic]
  79. ,[RendBruto]
  80. ,[RendNeto]
  81. ,[IngrBruto]
  82. ,[Impuestos]
  83. ,[IngrNeto])
  84. VALUES
  85. (@DocId
  86. ,@MontoInv
  87. ,@FOper
  88. ,@FVenc
  89. ,@Tasa
  90. ,@Plazo
  91. ,@AnBase
  92. ,@Periodic
  93. ,@RendBruto
  94. ,@RendNeto
  95. ,@IngrBruto
  96. ,@Impuestos
  97. ,@IngrNeto
  98. )"
  99. cmd.CommandText = query
  100. With cmd.Parameters
  101. .Add("@DocId", SqlDbType.Int).Value = DocId
  102. .Add("@MontoInv", SqlDbType.Decimal).Value = oNEST.MontoDeInversion
  103. .Add("@FOper", SqlDbType.Date).Value = oNEST.FechaOperacion
  104. .Add("@FVenc", SqlDbType.Date).Value = oNEST.FechaVencimiento
  105. .Add("@Tasa", SqlDbType.Decimal).Value = oNEST.Tasa
  106. .Add("@Plazo", SqlDbType.Int).Value = oNEST.Plazo
  107. .Add("@AnBase", SqlDbType.Int).Value = oNEST.AnioBase
  108. .Add("@Periodic", SqlDbType.NVarChar).Value = oNEST.Periodicidad
  109. .Add("@RendBruto", SqlDbType.Decimal).Value = oNEST.RendimientoBruto
  110. .Add("@RendNeto", SqlDbType.Decimal).Value = oNEST.RendimientoNeto
  111. .Add("@IngrBruto", SqlDbType.Decimal).Value = oNEST.IngresoBruto
  112. .Add("@Impuestos", SqlDbType.Decimal).Value = oNEST.Impuestos
  113. .Add("@IngrNeto", SqlDbType.Decimal).Value = oNEST.IngresoNeto
  114. End With
  115. Try
  116. cmd.ExecuteNonQuery()
  117. Transaccion.Commit()
  118. retorno = 0
  119. Catch ex As Exception
  120. MsgBox("Error al Guardar DAP : " & ex.GetType.ToString)
  121. MsgBox("Mensaje: " & ex.Message)
  122. retorno = 1
  123. Try
  124. Transaccion.Rollback()
  125. retorno = 2
  126. Catch ex2 As Exception
  127. MsgBox("Error en Rollback: " & ex2.GetType.ToString)
  128. MsgBox("Mensaje Rollbak: " & ex2.Message)
  129. retorno = 3
  130. End Try
  131. End Try
  132. cmd.Dispose()
  133. cn.Dispose()
  134. Return retorno
  135. End Function
  136. Public Sub CargarRegistro(ByVal oNEST As NotaEstructuradaCE, Tipo As String, IdRegistro As Integer)
  137. Dim objCon As New Conexion
  138. Dim drd As SqlDataReader
  139. Dim cmd As SqlCommand
  140. Dim sql As String
  141. Dim Tabla As String
  142. Dim cn As SqlConnection = objCon.Conectar
  143. If cn.State = ConnectionState.Closed Then
  144. cn.Open()
  145. End If
  146. If Tipo = "P" Then
  147. Tabla = "PDAP0"
  148. End If
  149. If Tipo = "I" Then
  150. Tabla = "IDAP0"
  151. End If
  152. sql = "SELECT * FROM [dbo].[" & Tabla & "] T0 WHERE T0.[DocId]=@DocId"
  153. cmd = New SqlCommand
  154. cmd.CommandText = sql
  155. cmd.Parameters.Add("@DocId", SqlDbType.Int).Value = IdRegistro
  156. cmd.Connection = cn
  157. drd = cmd.ExecuteReader
  158. If drd.HasRows Then
  159. 'SE ENCONTRO EL REGISTRO
  160. If drd.Read Then
  161. oNEST.MontoDeInversion = drd.Item("MontoInv")
  162. oNEST.FechaOperacion = drd.Item("FOper")
  163. oNEST.FechaVencimiento = drd.Item("FVenc")
  164. oNEST.Tasa = drd.Item("Tasa")
  165. oNEST.Plazo = drd.Item("Plazo")
  166. oNEST.AnioBase = drd.Item("AnBase")
  167. oNEST.Periodicidad = drd.Item("Periodic")
  168. 'oDAP.RendimientoBruto = drd.Item("RendBruto")
  169. 'oDAP.RendimientoNeto = drd.Item("RendNeto")
  170. oNEST.IngresoBruto = drd.Item("IngrBruto")
  171. oNEST.Impuestos = drd.Item("Impuestos")
  172. oNEST.IngresoNeto = drd.Item("IngrNeto")
  173. End If
  174. Else
  175. 'NO SE ENCONTRO EL REGISTRO
  176. End If
  177. drd.Close()
  178. cmd.Dispose()
  179. cn.Dispose()
  180. End Sub
  181. Public Function CargarRegistro(ByVal vCodigoInversion As String) As NotaEstructuradaCE
  182. Dim objCon As New Conexion
  183. Dim oNESTCE As New NotaEstructuradaCE
  184. Dim drd As SqlDataReader
  185. Dim cmd As SqlCommand
  186. Dim da As SqlDataAdapter
  187. Dim sql As String
  188. Dim dtIntereses As New DataTable
  189. Dim cn As SqlConnection = objCon.Conectar
  190. If cn.State = ConnectionState.Closed Then
  191. cn.Open()
  192. End If
  193. 'INTERESES
  194. sql = "SELECT * FROM [dbo].[NEST1] T0 WHERE T0.CodInv=@CodInv"
  195. da = New SqlDataAdapter(sql, cn)
  196. da.SelectCommand.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = vCodigoInversion
  197. da.Fill(dtIntereses)
  198. oNESTCE.dtIntereses = dtIntereses
  199. sql = "SELECT * FROM [dbo].[NEST0] T0 WHERE T0.CodInv=@CodInv"
  200. cmd = New SqlCommand
  201. cmd.CommandText = sql
  202. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = vCodigoInversion
  203. cmd.Connection = cn
  204. drd = cmd.ExecuteReader
  205. If drd.HasRows Then
  206. 'SE ENCONTRO EL REGISTRO
  207. If drd.Read Then
  208. oNESTCE.CodigoInversion = vCodigoInversion.ToString
  209. oNESTCE.MontoDeInversion = drd.Item("MontoInv").ToString
  210. oNESTCE.FechaOperacion = drd.Item("FOper").ToString
  211. oNESTCE.FechaVencimiento = drd.Item("FVenc").ToString
  212. oNESTCE.Tasa = drd.Item("Tasa").ToString
  213. oNESTCE.Plazo = drd.Item("Plazo").ToString
  214. oNESTCE.Periodicidad = drd.Item("Periodic").ToString
  215. End If
  216. drd.Close()
  217. Else
  218. 'NO ENCONTRO EL REGISTRO
  219. End If
  220. cmd.Dispose()
  221. cn.Dispose()
  222. Return oNESTCE
  223. End Function
  224. Public Function Actualizar(ByVal oNESTCE As NotaEstructuradaCE) As Integer
  225. Dim objCon As New Conexion
  226. Dim sql As String
  227. Dim cmd As SqlCommand
  228. Dim retorno As Integer
  229. Dim cn As SqlConnection = objCon.Conectar
  230. If cn.State = ConnectionState.Closed Then
  231. cn.Open()
  232. End If
  233. sql = "UPDATE [dbo].[NEST0]
  234. SET [MontoInv] = @MontoInv
  235. ,[FOper] = @FOper
  236. ,[FVenc] = @FVenc
  237. ,[Tasa] = @Tasa
  238. ,[Plazo] = @Plazo
  239. --,[AnBase] = @AnBase
  240. ,[Periodic] = @Periodic
  241. WHERE [CodInv] = @CodInv"
  242. cmd = New SqlCommand
  243. cmd.CommandText = sql
  244. With cmd.Parameters
  245. .Add("@MontoInv", SqlDbType.Float).Value = oNESTCE.MontoDeInversion
  246. .Add("@FOper", SqlDbType.Date).Value = oNESTCE.FechaOperacion
  247. .Add("@FVenc", SqlDbType.Date).Value = oNESTCE.FechaVencimiento
  248. .Add("@Tasa", SqlDbType.Float).Value = oNESTCE.Tasa
  249. .Add("@Plazo", SqlDbType.Int).Value = oNESTCE.Plazo
  250. .Add("@Periodic", SqlDbType.VarChar).Value = oNESTCE.Periodicidad
  251. End With
  252. cmd.Connection = cn
  253. retorno = cmd.ExecuteNonQuery
  254. cmd.Dispose()
  255. cn.Dispose()
  256. GuardaIntereses(oNESTCE.CodigoInversion, oNESTCE.dtIntereses)
  257. Return retorno
  258. End Function
  259. Private Sub GuardaIntereses(ByVal vCodInversion As String, dt As DataTable)
  260. Dim objCon As New Conexion
  261. Dim sql As String
  262. Dim cmd As SqlCommand
  263. Dim cn As SqlConnection = objCon.Conectar
  264. If cn.State = ConnectionState.Closed Then
  265. cn.Open()
  266. End If
  267. Dim res As Integer
  268. sql = "DELETE FROM [dbo].[NEST1]
  269. WHERE [CodInv]=@CodInv"
  270. cmd = New SqlCommand
  271. cmd.CommandText = sql
  272. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = vCodInversion
  273. cmd.Connection = cn
  274. res = cmd.ExecuteNonQuery
  275. sql = String.Empty
  276. If dt.Rows.Count > 0 Then
  277. For Each dr In dt.Rows
  278. cmd = New SqlCommand
  279. sql = "INSERT INTO [dbo].[NEST1]
  280. ([CodInv]
  281. ,[Plazo]
  282. ,[Fecha]
  283. ,[IngrBruto]
  284. ,[PorcImp]
  285. ,[MontoImp]
  286. ,[IngrNeto]
  287. ,[Estado])
  288. VALUES
  289. (@CodInv
  290. ,@Plazo
  291. ,@Fecha
  292. ,@IngrBruto
  293. ,@PorcImp
  294. ,@MontoImp
  295. ,@IngrNeto
  296. ,@Estado)"
  297. cmd.CommandText = sql
  298. With cmd.Parameters
  299. .AddWithValue("@CodInv", vCodInversion)
  300. .AddWithValue("@Plazo", dr("Plazo"))
  301. .AddWithValue("@Fecha", dr("Fecha"))
  302. .AddWithValue("@IngrBruto", dr("IngrBruto"))
  303. .AddWithValue("@PorcImp", dr("PorcImp"))
  304. .AddWithValue("@MontoImp", dr("MontoImp"))
  305. .AddWithValue("@IngrNeto", dr("IngrNeto"))
  306. .AddWithValue("@Estado", dr("Estado"))
  307. End With
  308. cmd.Connection = cn
  309. res = cmd.ExecuteNonQuery
  310. Next
  311. End If
  312. cmd.Dispose()
  313. cn.Dispose()
  314. End Sub
  315. Public Function NuevoDato(ByVal Coleccion As Collection, ByVal Diccionario As Dictionary(Of String, Collection), ByVal Codigo As String)
  316. Dim objCon As New Conexion
  317. Dim retorno As Integer
  318. Dim sql As String
  319. Dim cmd As SqlCommand
  320. Dim myTrans As SqlTransaction
  321. Dim cn As SqlConnection = objCon.Conectar
  322. If cn.State = ConnectionState.Closed Then
  323. cn.Open()
  324. End If
  325. myTrans = cn.BeginTransaction()
  326. Try
  327. sql = "INSERT INTO [dbo].[NEST0](
  328. [CodInv]
  329. ,[MontoInv]
  330. ,[FOper]
  331. ,[FVenc]
  332. ,[Tasa]
  333. ,[Plazo]
  334. ,[Periodic]
  335. ,[RendBr]
  336. ,[RendNet]
  337. ,[IngrBrutoTot]
  338. ,[IngrNetoTot]
  339. ,[Renta]
  340. ) VALUES(
  341. @CodInv
  342. ,@MontoInv
  343. ,@FOper
  344. ,@FVenc
  345. ,@Tasa
  346. ,@Plazo
  347. ,@Periodic
  348. ,@RendBr
  349. ,@RendNet
  350. ,@IngrBrutoTot
  351. ,@IngrNetoTot
  352. ,@Renta
  353. )
  354. "
  355. cmd = New SqlCommand
  356. cmd.CommandText = sql
  357. cmd.Connection = cn
  358. cmd.Transaction = myTrans
  359. With cmd.Parameters
  360. .Add("@CodInv ", SqlDbType.VarChar).Value = Codigo.ToString
  361. .Add("@MontoInv", SqlDbType.Decimal).Value = Coleccion(1)
  362. .Add("@FOper", SqlDbType.DateTime).Value = Coleccion(2)
  363. .Add("@FVenc", SqlDbType.DateTime).Value = Coleccion(3)
  364. .Add("@Tasa", SqlDbType.Decimal).Value = Coleccion(4)
  365. .Add("@Plazo", SqlDbType.Int).Value = Coleccion(5)
  366. .Add("@Periodic", SqlDbType.VarChar).Value = Coleccion(6)
  367. .Add("@RendBr", SqlDbType.VarChar).Value = Coleccion(7)
  368. .Add("@RendNet", SqlDbType.VarChar).Value = Coleccion(8)
  369. .Add("@IngrBrutoTot", SqlDbType.Float).Value = Coleccion(9)
  370. .Add("@IngrNetoTot", SqlDbType.Float).Value = Coleccion(10)
  371. .Add("@Renta", SqlDbType.Float).Value = Coleccion(11)
  372. End With
  373. retorno = cmd.ExecuteNonQuery
  374. sql = "INSERT INTO [dbo].[NEST1](
  375. [CodInv]
  376. ,[Correlativo]
  377. ,[Plazo]
  378. ,[Fecha]
  379. ,[IngrBruto]
  380. ,[PorcImp]
  381. ,[MontoImp]
  382. ,[IngrNeto]
  383. ) VALUES(
  384. @CodInv
  385. ,@Correlativo
  386. ,@Plazo
  387. ,@Fecha
  388. ,@IngrBruto
  389. ,@PorcImp
  390. ,@MontoImp
  391. ,@IngrNeto
  392. )
  393. "
  394. If Not Diccionario Is Nothing Then
  395. For Each DatosDiccionario In Diccionario
  396. Dim Coleccion2 As Collection = DatosDiccionario.Value
  397. cmd = New SqlCommand
  398. cmd.CommandText = sql
  399. cmd.Connection = cn
  400. cmd.Transaction = myTrans
  401. With cmd.Parameters
  402. .Add("@CodInv ", SqlDbType.VarChar).Value = Codigo.ToString
  403. .Add("@Correlativo", SqlDbType.Int).Value = Coleccion2(1)
  404. .Add("@Plazo", SqlDbType.Int).Value = Coleccion2(2)
  405. .Add("@Fecha", SqlDbType.DateTime).Value = Coleccion2(3)
  406. .Add("@IngrBruto", SqlDbType.Decimal).Value = Coleccion2(4)
  407. .Add("@PorcImp", SqlDbType.Decimal).Value = Coleccion2(5)
  408. .Add("@MontoImp", SqlDbType.Decimal).Value = Coleccion2(6)
  409. .Add("@IngrNeto", SqlDbType.Decimal).Value = Coleccion2(7)
  410. End With
  411. retorno = cmd.ExecuteNonQuery
  412. Next
  413. End If
  414. myTrans.Commit()
  415. MsgBox("Datos Ingresados")
  416. Catch ex As Exception
  417. myTrans.Rollback()
  418. MsgBox(ex.Message)
  419. End Try
  420. cn.Close()
  421. Return retorno
  422. End Function
  423. Public Function NuevoElemento(ByVal Coleccion As Collection, ByVal Codigo As String)
  424. Dim objCon As New Conexion
  425. Dim retorno As Integer
  426. Dim sql As String
  427. Dim cmd As SqlCommand
  428. Dim cn As SqlConnection = objCon.Conectar
  429. If cn.State = ConnectionState.Closed Then
  430. cn.Open()
  431. End If
  432. sql = "INSERT INTO [dbo].[NEST1](
  433. [CodInv]
  434. ,[Correlativo]
  435. ,[Plazo]
  436. ,[Fecha]
  437. ,[IngrBruto]
  438. ,[PorcImp]
  439. ,[MontoImp]
  440. ,[IngrNeto]
  441. ) VALUES(
  442. @CodInv
  443. ,@Correlativo
  444. ,@Plazo
  445. ,@Fecha
  446. ,@IngrBruto
  447. ,@PorcImp
  448. ,@MontoImp
  449. ,@IngrNeto
  450. )
  451. "
  452. cmd = New SqlCommand
  453. cmd.CommandText = sql
  454. With cmd.Parameters
  455. .Add("@CodInv ", SqlDbType.VarChar).Value = Codigo.ToString
  456. .Add("@Correlativo", SqlDbType.Int).Value = Coleccion(1)
  457. .Add("@Plazo", SqlDbType.Int).Value = Coleccion(2)
  458. .Add("@Fecha", SqlDbType.DateTime).Value = Coleccion(3)
  459. .Add("@IngrBruto", SqlDbType.Decimal).Value = Coleccion(4)
  460. .Add("@PorcImp", SqlDbType.Decimal).Value = Coleccion(5)
  461. .Add("@MontoImp", SqlDbType.Decimal).Value = Coleccion(6)
  462. .Add("@IngrNeto", SqlDbType.Decimal).Value = Coleccion(7)
  463. End With
  464. cmd.Connection = cn
  465. retorno = cmd.ExecuteNonQuery
  466. cn.Close()
  467. Return retorno
  468. End Function
  469. Public Function ModificarElemento(ByVal Coleccion As Collection, ByVal Codigo As String)
  470. Dim objCon As New Conexion
  471. Dim retorno As Integer
  472. Dim sql As String
  473. Dim cmd As SqlCommand
  474. Dim cn As SqlConnection = objCon.Conectar
  475. If cn.State = ConnectionState.Closed Then
  476. cn.Open()
  477. End If
  478. sql = "UPDATE [dbo].[NEST1] SET
  479. [Plazo]=@Plazo
  480. ,[Fecha]=@Fecha
  481. ,[IngrBruto]=@IngrBruto
  482. ,[PorcImp]=@PorcImp
  483. ,[MontoImp]=@MontoImp
  484. ,[IngrNeto]=@IngrNeto
  485. where [CodInv]=@CodInv AND [Correlativo]=@Correlativo
  486. "
  487. cmd = New SqlCommand
  488. cmd.CommandText = sql
  489. With cmd.Parameters
  490. .Add("@CodInv ", SqlDbType.VarChar).Value = Codigo.ToString
  491. .Add("@Correlativo", SqlDbType.Int).Value = Coleccion(1)
  492. .Add("@Plazo", SqlDbType.Int).Value = Coleccion(2)
  493. .Add("@Fecha", SqlDbType.DateTime).Value = Coleccion(3)
  494. .Add("@IngrBruto", SqlDbType.Decimal).Value = Coleccion(4)
  495. .Add("@PorcImp", SqlDbType.Decimal).Value = Coleccion(5)
  496. .Add("@MontoImp", SqlDbType.Decimal).Value = Coleccion(6)
  497. .Add("@IngrNeto", SqlDbType.Decimal).Value = Coleccion(7)
  498. End With
  499. cmd.Connection = cn
  500. retorno = cmd.ExecuteNonQuery
  501. cn.Close()
  502. Return retorno
  503. End Function
  504. Public Sub EliminarElemento(ByVal Codigo As String)
  505. Dim objCon As New Conexion
  506. Dim sql As String
  507. Dim cmd As SqlCommand
  508. Dim res As Integer
  509. Dim cn As SqlConnection = objCon.Conectar
  510. If cn.State = ConnectionState.Closed Then
  511. cn.Open()
  512. End If
  513. sql = "DELETE FROM [dbo].[NEST1]
  514. WHERE [CodInv]=@CodInv "
  515. cmd = New SqlCommand
  516. cmd.CommandText = sql
  517. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  518. cmd.Connection = cn
  519. res = cmd.ExecuteNonQuery
  520. cn.Close()
  521. End Sub
  522. Public Function ModificarDato(ByVal Coleccion As Collection, ByVal Codigo As String, ByVal Diccionario As Dictionary(Of String, Collection))
  523. Dim objCon As New Conexion
  524. Dim retorno As Integer
  525. Dim sql As String
  526. Dim cmd As SqlCommand
  527. Dim myTrans As SqlTransaction
  528. Dim cn As SqlConnection = objCon.Conectar
  529. If cn.State = ConnectionState.Closed Then
  530. cn.Open()
  531. End If
  532. myTrans = cn.BeginTransaction()
  533. Try
  534. sql = "UPDATE [dbo].[NEST0] SET
  535. [MontoInv]=@MontoInv
  536. ,[FOper]=@FOper
  537. ,[FVenc]=@FVenc
  538. ,[Tasa]=@Tasa
  539. ,[Plazo]=@Plazo
  540. ,[Periodic]=@Periodic
  541. ,[RendBr]=@RendBr
  542. ,[RendNet]=@RendNet
  543. ,[IngrBrutoTot]=@IngrBrutoTot
  544. ,[IngrNetoTot]=@IngrNetoTot
  545. ,[Renta]=@Renta
  546. where [CodInv]= @CodInv
  547. "
  548. cmd = New SqlCommand
  549. cmd.CommandText = sql
  550. cmd.Connection = cn
  551. cmd.Transaction = myTrans
  552. With cmd.Parameters
  553. .Add("@CodInv ", SqlDbType.VarChar).Value = Codigo.ToString
  554. .Add("@MontoInv", SqlDbType.Decimal).Value = Coleccion(1)
  555. .Add("@FOper", SqlDbType.DateTime).Value = Coleccion(2)
  556. .Add("@FVenc", SqlDbType.DateTime).Value = Coleccion(3)
  557. .Add("@Tasa", SqlDbType.Decimal).Value = Coleccion(4)
  558. .Add("@Plazo", SqlDbType.Int).Value = Coleccion(5)
  559. .Add("@Periodic", SqlDbType.VarChar).Value = Coleccion(6)
  560. .Add("@RendBr", SqlDbType.VarChar).Value = Coleccion(7)
  561. .Add("@RendNet", SqlDbType.VarChar).Value = Coleccion(8)
  562. .Add("@IngrBrutoTot", SqlDbType.Float).Value = Coleccion(9)
  563. .Add("@IngrNetoTot", SqlDbType.Float).Value = Coleccion(10)
  564. .Add("@Renta", SqlDbType.Float).Value = Coleccion(11)
  565. End With
  566. retorno = cmd.ExecuteNonQuery
  567. sql = "INSERT INTO [dbo].[NEST1](
  568. [CodInv]
  569. ,[Correlativo]
  570. ,[Plazo]
  571. ,[Fecha]
  572. ,[IngrBruto]
  573. ,[PorcImp]
  574. ,[MontoImp]
  575. ,[IngrNeto]
  576. ) VALUES(
  577. @CodInv
  578. ,@Correlativo
  579. ,@Plazo
  580. ,@Fecha
  581. ,@IngrBruto
  582. ,@PorcImp
  583. ,@MontoImp
  584. ,@IngrNeto
  585. )
  586. "
  587. sql = "delete from NEST1 Where CodInv='" + Codigo + "'"
  588. cmd = New SqlCommand
  589. cmd.CommandText = sql
  590. cmd.Connection = cn
  591. cmd.Transaction = myTrans
  592. retorno = cmd.ExecuteNonQuery
  593. If Not Diccionario Is Nothing Then
  594. For Each DatosDiccionario In Diccionario
  595. Dim Coleccion2 As Collection = DatosDiccionario.Value
  596. sql = "INSERT INTO [dbo].[NEST1](
  597. [CodInv]
  598. ,[Correlativo]
  599. ,[Plazo]
  600. ,[Fecha]
  601. ,[IngrBruto]
  602. ,[PorcImp]
  603. ,[MontoImp]
  604. ,[IngrNeto]
  605. ) VALUES(
  606. @CodInv
  607. ,@Correlativo
  608. ,@Plazo
  609. ,@Fecha
  610. ,@IngrBruto
  611. ,@PorcImp
  612. ,@MontoImp
  613. ,@IngrNeto
  614. )
  615. "
  616. cmd = New SqlCommand
  617. cmd.CommandText = sql
  618. cmd.Connection = cn
  619. cmd.Transaction = myTrans
  620. With cmd.Parameters
  621. .Add("@CodInv ", SqlDbType.VarChar).Value = Codigo.ToString
  622. .Add("@Correlativo", SqlDbType.Int).Value = Coleccion2(1)
  623. .Add("@Plazo", SqlDbType.Int).Value = Coleccion2(2)
  624. .Add("@Fecha", SqlDbType.DateTime).Value = Coleccion2(3)
  625. .Add("@IngrBruto", SqlDbType.Decimal).Value = Coleccion2(4)
  626. .Add("@PorcImp", SqlDbType.Decimal).Value = Coleccion2(5)
  627. .Add("@MontoImp", SqlDbType.Decimal).Value = Coleccion2(6)
  628. .Add("@IngrNeto", SqlDbType.Decimal).Value = Coleccion2(7)
  629. End With
  630. retorno = cmd.ExecuteNonQuery
  631. Next
  632. End If
  633. myTrans.Commit()
  634. MsgBox("Datos Ingresados")
  635. Catch ex As Exception
  636. myTrans.Rollback()
  637. MsgBox(ex.Message)
  638. End Try
  639. cn.Close()
  640. Return retorno
  641. End Function
  642. 'Public Sub EliminarDato(ByVal Codigo As String)
  643. ' Dim sql As String
  644. ' Dim cmd As SqlCommand
  645. ' Dim res As Integer
  646. ' sql = "DELETE FROM [dbo].[DAP0]
  647. ' WHERE [CodInv]=@CodInv"
  648. ' cn = objCon.Conectar
  649. ' If Not cn.State = ConnectionState.Open Then
  650. ' cn.Open()
  651. ' End If
  652. ' cmd = New SqlCommand
  653. ' cmd.CommandText = sql
  654. ' cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  655. ' cmd.Connection = cn
  656. ' res = cmd.ExecuteNonQuery
  657. 'End Sub
  658. Public Sub Eliminar(ByVal Codigo As String)
  659. Dim objCon As New Conexion
  660. Dim retorno As Integer
  661. Dim sql As String
  662. Dim cmd As SqlCommand
  663. Dim myTrans As SqlTransaction
  664. Dim cn As SqlConnection = objCon.Conectar
  665. If cn.State = ConnectionState.Closed Then
  666. cn.Open()
  667. End If
  668. myTrans = cn.BeginTransaction()
  669. Try
  670. sql = "DELETE FROM [dbo].[NEST0]
  671. WHERE [CodInv]=@CodInv"
  672. cmd = New SqlCommand
  673. cmd.CommandText = sql
  674. cmd.Connection = cn
  675. cmd.Transaction = myTrans
  676. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  677. retorno = cmd.ExecuteNonQuery
  678. sql = "DELETE FROM [dbo].[NEST1]
  679. WHERE [CodInv]=@CodInv"
  680. cmd = New SqlCommand
  681. cmd.CommandText = sql
  682. cmd.Connection = cn
  683. cmd.Transaction = myTrans
  684. cmd.Parameters.Add("@CodInv", SqlDbType.VarChar).Value = Codigo
  685. retorno = cmd.ExecuteNonQuery
  686. myTrans.Commit()
  687. MsgBox("Datos Eliminados")
  688. Catch ex As Exception
  689. myTrans.Rollback()
  690. MsgBox(ex.Message)
  691. End Try
  692. cn.Close()
  693. End Sub
  694. End Class