frmSeleccionPoolTitulos.vb 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. Public Class frmSeleccionPoolTitulos
  2. Private Operaciones As New Operaciones
  3. Dim oDAOGeneral As New DAOGeneral
  4. Dim PoolTitulos As New PoolTitulosDAO
  5. Private Sub frmSeleccionPoolTitulos_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  6. CargarCodigo()
  7. CargarInstrumentos()
  8. CargarEmpresas()
  9. OcultarColumnas()
  10. End Sub
  11. Sub OcultarColumnas()
  12. dgvTitulos.Columns("IdFlujo").Visible = False
  13. dgvTitulos.Columns("IdEspLR").Visible = False
  14. dgvTitulos.Columns("CodigoInstrumento").Visible = False
  15. dgvTitulos.Columns("CodigoEmpresa").Visible = False
  16. dgvTitulos.Columns("Estado").Visible = False
  17. dgvPool.Columns("IdFlujo").Visible = False
  18. dgvPool.Columns("IdEspLR").Visible = False
  19. dgvPool.Columns("Instrumento").Visible = False
  20. dgvPool.Columns("Empresa").Visible = False
  21. End Sub
  22. Sub CargarCodigo()
  23. Dim CodigoAsociacion As String = String.Empty
  24. CodigoAsociacion = PoolTitulos.NuevoCodigo()
  25. txtcodigo.Text = CodigoAsociacion
  26. End Sub
  27. Sub CargarInstrumentos()
  28. If Me.cboInstrumentos.Items.Count = 0 Or Me.cboInstrumentos.Items.Count = 1 Then
  29. Me.cboInstrumentos.DataSource = oDAOGeneral.ListaInstrumentos("Propuesta")
  30. Me.cboInstrumentos.DisplayMember = "Descripcion"
  31. Me.cboInstrumentos.ValueMember = "Codigo"
  32. Me.cboInstrumentos.SelectedIndex = 0
  33. End If
  34. End Sub
  35. Private Sub CargarEmpresas()
  36. Me.cboEmpresa.DataSource = oDAOGeneral.ListaEmpresas
  37. Me.cboEmpresa.DisplayMember = "Descripcion"
  38. Me.cboEmpresa.ValueMember = "Codigo"
  39. Me.cboEmpresa.SelectedIndex = 0
  40. End Sub
  41. Sub CargarDatosBusqueda()
  42. Dim ds As New DataSet
  43. Dim FechaOperacion1 As Date = Date.Today.Date
  44. Dim FechaOperacion2 As Date = Date.Today.Date
  45. Dim Empresa As String = ""
  46. Dim Instrumento As String = ""
  47. Dim Estado As String = ""
  48. If Not cboEmpresa.SelectedValue Is Nothing Then
  49. Empresa = cboEmpresa.SelectedValue.ToString()
  50. End If
  51. If Not cboInstrumentos.SelectedValue Is Nothing Then
  52. Instrumento = cboInstrumentos.SelectedValue.ToString()
  53. End If
  54. Dim TipoFecha As Integer = 0
  55. If rdbVigente.Checked Then
  56. Estado = "A"
  57. End If
  58. If rdbFecha.Checked Then
  59. FechaOperacion1 = Format(dtpFechaOperacion.Value, "dd/MM/yyyy")
  60. ElseIf rdbRangoFechas.Checked Then
  61. FechaOperacion1 = Format(dtpFechaOperacion1.Value, "dd/MM/yyyy")
  62. FechaOperacion2 = Format(dtpFechaOperacion2.Value, "dd/MM/yyyy")
  63. TipoFecha = 1
  64. Else
  65. TipoFecha = 2
  66. End If
  67. If TipoFecha = 0 Then
  68. ds = PoolTitulos.FiltroReportoVenta(FechaOperacion1, "", Estado, Empresa, Instrumento)
  69. ElseIf TipoFecha = 1 Then
  70. ds = PoolTitulos.FiltroReportoVenta(FechaOperacion1, FechaOperacion2, Estado, Empresa, Instrumento)
  71. Else
  72. ds = PoolTitulos.FiltroReportoVenta("", "", Estado, Empresa, Instrumento)
  73. End If
  74. dgvTitulos.DataSource = ds.Tables(0)
  75. End Sub
  76. Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged
  77. CargarDatosBusqueda()
  78. End Sub
  79. Private Sub dtpFechaOperacion1_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion1.ValueChanged
  80. CargarDatosBusqueda()
  81. End Sub
  82. Private Sub dtpFechaOperacion2_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion2.ValueChanged
  83. CargarDatosBusqueda()
  84. End Sub
  85. Private Sub rdbVigente_CheckedChanged(sender As Object, e As EventArgs) Handles rdbVigente.CheckedChanged
  86. CargarDatosBusqueda()
  87. End Sub
  88. Private Sub rdbTodosVigencia_CheckedChanged(sender As Object, e As EventArgs) Handles rdbTodosVigencia.CheckedChanged
  89. CargarDatosBusqueda()
  90. End Sub
  91. Private Sub cboEmpresa_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboEmpresa.SelectedIndexChanged
  92. dgvPool.Rows.Clear()
  93. CargarDatosBusqueda()
  94. End Sub
  95. Private Sub cboInstrumentos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboInstrumentos.SelectedIndexChanged
  96. CargarDatosBusqueda()
  97. End Sub
  98. Sub VerDetalles()
  99. If MsgBox("¿Desea Ver los Detalles del Instrumento?", MsgBoxStyle.OkCancel) = DialogResult.OK Then
  100. If Not dgvTitulos.CurrentRow Is Nothing Then
  101. Dim Instrumento As String = String.Empty
  102. Dim codigo As String = String.Empty
  103. Instrumento = dgvTitulos.CurrentRow.Cells("CodigoInstrumento").Value.ToString
  104. codigo = dgvTitulos.CurrentRow.Cells("CodigoInversion").Value.ToString
  105. If Instrumento = "FINV" Then
  106. Variables.Codigo = codigo
  107. frmFOIN.ShowDialog()
  108. End If
  109. ''#########################################################################
  110. ''#########################################################################
  111. If Instrumento = "FUTU" Or Instrumento = "OPC" Then
  112. Variables.Codigo = codigo
  113. frmFuturos.ShowDialog()
  114. End If
  115. ''#########################################################################
  116. ''#########################################################################
  117. ''#########################################################################
  118. ''#########################################################################
  119. If Instrumento = "PPER" Then
  120. Variables.Codigo = codigo
  121. frmPrestamoPersonal.ShowDialog()
  122. End If
  123. ''#########################################################################
  124. ''#########################################################################
  125. ''#########################################################################
  126. ''#########################################################################
  127. If Instrumento = "PEMP" Then
  128. Variables.Codigo = codigo
  129. frmPrestamoEmpresariales.ShowDialog()
  130. End If
  131. ''#########################################################################
  132. ''#########################################################################
  133. ''#########################################################################
  134. ''#########################################################################
  135. If Instrumento = "LETE" Or Instrumento = "PBUR" Or Instrumento = "VCN" Or Instrumento = "CETE" Then
  136. Variables.Codigo = codigo
  137. frmLetes.ShowDialog()
  138. End If
  139. ''#########################################################################
  140. ''#########################################################################
  141. ''#########################################################################
  142. ''#########################################################################
  143. If Instrumento = "BONO" Or Instrumento = "CINV" Or Instrumento = "TIT" Or Instrumento = "EURB" Then
  144. Variables.Codigo = codigo
  145. frmCertificadosDeInversion.ShowDialog()
  146. End If
  147. ''#########################################################################
  148. ''#########################################################################
  149. If Instrumento = "DAP" Then
  150. Variables.Codigo = codigo
  151. frmDepositosAPlazo.Show()
  152. End If
  153. ''#########################################################################
  154. ''#########################################################################
  155. ''#########################################################################
  156. ''#########################################################################
  157. If Instrumento = "NEST" Then
  158. Variables.Codigo = codigo
  159. frmNotaEstructurada.ShowDialog()
  160. End If
  161. Else
  162. MsgBox("No se ha seleccionado ninguna fila")
  163. End If
  164. End If
  165. End Sub
  166. Private Sub dgvTitulos_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvTitulos.CellClick
  167. End Sub
  168. Private Sub btnVer_Click(sender As Object, e As EventArgs) Handles btnVer.Click
  169. VerDetalles()
  170. End Sub
  171. Sub PasarDatos()
  172. If txtMontoUsar.Text <= 0 Then
  173. MsgBox("El Monto no puede ser 0")
  174. Else
  175. Dim MontoUsado As Double = Operaciones.ConvertirDecimal(txtMontoUsar.Text.ToString)
  176. Dim MontoTotal As Double = Operaciones.ConvertirDecimal(dgvTitulos.CurrentRow.Cells("MontoActual").Value.ToString)
  177. If MontoUsado >= MontoTotal Then
  178. MsgBox("La Cantidad supera el monto disponible")
  179. txtMontoUsar.Text = MontoTotal * 0.95
  180. Else
  181. If dgvTitulos.CurrentRow Is Nothing Then
  182. MsgBox("No se ha seleccionado ninguna fila")
  183. Else
  184. Dim CodigoTitulo As String = String.Empty
  185. Dim Instrumento As String = String.Empty
  186. Dim Empresa As String = String.Empty
  187. Dim NombreInstrumento As String = String.Empty
  188. Dim NombreEmpresa As String = String.Empty
  189. Dim Porcentaje As String = "0 %"
  190. Dim FechaCreacion As Date = Date.Now.Date
  191. Dim CodigoInversion As String = String.Empty
  192. Dim IdFlujo As Integer = 0
  193. Dim IdEspLR As Integer = 0
  194. Dim ExisteRegistro As Boolean = False
  195. Dim Total As Double = 0
  196. CodigoTitulo = dgvTitulos.CurrentRow.Cells("CodigoInversion").Value.ToString
  197. Instrumento = dgvTitulos.CurrentRow.Cells("CodigoInstrumento").Value.ToString
  198. Empresa = dgvTitulos.CurrentRow.Cells("CodigoEmpresa").Value.ToString
  199. NombreEmpresa = dgvTitulos.CurrentRow.Cells("Empresa").Value.ToString
  200. NombreInstrumento = dgvTitulos.CurrentRow.Cells("Instrumento").Value.ToString
  201. Porcentaje = ((MontoUsado / MontoTotal) * 100).ToString + " %"
  202. IdFlujo = dgvTitulos.CurrentRow.Cells("IdFlujo").Value.ToString
  203. IdEspLR = dgvTitulos.CurrentRow.Cells("IdEspLR").Value.ToString
  204. For Each Rows As DataGridViewRow In dgvPool.Rows
  205. If Rows.Cells("CodigoTitulo").Value.ToString = CodigoTitulo Then
  206. ExisteRegistro = True
  207. End If
  208. Next
  209. If ExisteRegistro Then
  210. MsgBox("El Registro ya esta se esta usando")
  211. Else
  212. dgvPool.Rows.Add(CodigoTitulo, Instrumento, NombreInstrumento, Empresa, NombreEmpresa, MontoTotal, MontoUsado, Porcentaje, Format(FechaCreacion, "dd/MM/yyyy").ToString, IdFlujo, IdEspLR)
  213. End If
  214. End If
  215. End If
  216. End If
  217. End Sub
  218. Private Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles btnAgregar.Click
  219. PasarDatos()
  220. End Sub
  221. Sub Guardar()
  222. If dgvPool.Rows.Count = 0 Then
  223. MsgBox("No se ha ingresado ninguna fila")
  224. Else
  225. Dim Valores As New Collection
  226. Valores = GuardarValores()
  227. PoolTitulos.ProcesoDatos(Valores)
  228. End If
  229. End Sub
  230. Function GuardarValores() As Collection
  231. Dim ColRegistros As New Collection
  232. Dim Tipo As String = String.Empty
  233. Dim CantidadFilas = dgvPool.Rows.Count - 1
  234. Dim Index As Integer = 0
  235. While (CantidadFilas >= Index)
  236. Dim DicRegistrosInstrumentos As New Dictionary(Of String, Object)
  237. Dim CodigoTitulo As String = dgvPool.Rows(Index).Cells("CodigoTitulo").Value.ToString
  238. Dim Instrumento As String = dgvPool.Rows(Index).Cells("Instrumento").Value.ToString
  239. Dim Empresa As String = dgvPool.Rows(Index).Cells("Empresa").Value.ToString
  240. Dim MontoTotal As Double = Operaciones.ConvertirDecimal(dgvPool.Rows(Index).Cells("MontoTotal").Value.ToString)
  241. Dim MontoUsado As Double = Operaciones.ConvertirDecimal(dgvPool.Rows(Index).Cells("MontoUsado").Value.ToString)
  242. Dim Porcentaje As Double = Operaciones.ConvertirDecimal(dgvPool.Rows(Index).Cells("Porcentaje").Value.ToString)
  243. Dim FechaCreacion As Date = Operaciones.ConvertirFecha(dgvPool.Rows(Index).Cells("FechaCreacion").Value.ToString)
  244. Dim Asociado As String = "No"
  245. Dim CodigoAsociacion As String = txtcodigo.Text.ToString
  246. Dim IdFlujo As Integer = Operaciones.ConvertirEntero(dgvPool.Rows(Index).Cells("IdFlujo").Value.ToString)
  247. Dim IdEspLR As Integer = Operaciones.ConvertirEntero(dgvPool.Rows(Index).Cells("IdEspLR").Value.ToString)
  248. ''AgregarCampos al Dicionario
  249. DicRegistrosInstrumentos.Add("CodigoTitulo", CodigoTitulo)
  250. DicRegistrosInstrumentos.Add("CodigoAsociacion", CodigoAsociacion)
  251. DicRegistrosInstrumentos.Add("Instrumento", Instrumento)
  252. DicRegistrosInstrumentos.Add("Empresa", Empresa)
  253. DicRegistrosInstrumentos.Add("MontoTotal", MontoTotal)
  254. DicRegistrosInstrumentos.Add("MontoUsado", MontoUsado)
  255. DicRegistrosInstrumentos.Add("Porcentaje", Porcentaje / 100)
  256. DicRegistrosInstrumentos.Add("FechaCreacion", FechaCreacion)
  257. DicRegistrosInstrumentos.Add("Asociado", Asociado)
  258. DicRegistrosInstrumentos.Add("IdFlujo", IdFlujo)
  259. DicRegistrosInstrumentos.Add("IdEspLR", IdEspLR)
  260. ColRegistros.Add(DicRegistrosInstrumentos)
  261. Index += 1
  262. End While
  263. Return ColRegistros
  264. End Function
  265. Private Sub btnGenerarPool_Click(sender As Object, e As EventArgs) Handles btnGenerarPool.Click
  266. Guardar()
  267. frmColaTitulos.Inicializacion()
  268. frmColaTitulos.dgvDetalles.DataSource = Nothing
  269. Me.Close()
  270. End Sub
  271. Private Sub dgvTitulos_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvTitulos.CellContentClick
  272. End Sub
  273. Private Sub txtPorcentaje_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMontoUsar.KeyPress
  274. If String.IsNullOrEmpty(txtMontoUsar.Text) Then
  275. If e.KeyChar = "." Then
  276. txtMontoUsar.Text = "0"
  277. Exit Sub
  278. End If
  279. End If
  280. If (Not txtMontoUsar.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  281. Operaciones.ValidarEntrada(sender, e, True)
  282. Else
  283. Operaciones.ValidarEntrada(sender, e, False)
  284. End If
  285. End Sub
  286. Private Sub txtPorcentaje_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMontoUsar.KeyUp
  287. If txtMontoUsar.Text = "." Then
  288. txtMontoUsar.Text = ".0"
  289. End If
  290. End Sub
  291. Private Sub txtPorcentaje_Leave(sender As Object, e As EventArgs) Handles txtMontoUsar.Leave
  292. End Sub
  293. Private Sub txtPorcentaje_TextChanged(sender As Object, e As EventArgs) Handles txtMontoUsar.TextChanged
  294. End Sub
  295. Private Sub txtcodigo_TextChanged(sender As Object, e As EventArgs) Handles txtcodigo.TextChanged
  296. End Sub
  297. Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles btnLimpiar.Click
  298. txtMontoUsar.Text = 0
  299. dgvPool.Rows.Clear()
  300. End Sub
  301. End Class