frmFuturos.vb 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. Public Class frmFuturos
  2. Dim Estado As String = String.Empty
  3. Dim FuturosConsulta As New FuturosDAO
  4. Dim General As New DAOGeneral
  5. Dim InstrumentoFinanciero As String = General.ObtenerInstrumento(Variables.Codigo)
  6. Dim CambiarOperacionApoyo As Boolean = False
  7. Dim Numero As Integer = -1
  8. Dim Operaciones As New Operaciones
  9. Private TipoOperacion As String = String.Empty
  10. Sub New()
  11. ' Esta llamada es exigida por el diseñador.
  12. InitializeComponent()
  13. ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
  14. End Sub
  15. Sub New(TipOper As String)
  16. Me.New
  17. TipoOperacion = TipOper
  18. End Sub
  19. Private Sub btnAceptar_Click(sender As Object, e As EventArgs)
  20. End Sub
  21. Private Sub frmFuturos_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  22. Dim VExisteInversion As Boolean = False
  23. If Variables.TipoOperacionCMVTA = "C" Then
  24. GrpVenta.Enabled = False
  25. GrpCompra.Enabled = True
  26. Else
  27. GrpVenta.Enabled = True
  28. GrpCompra.Enabled = False
  29. End If
  30. If Variables.Codigo.IndexOf("OPC") > -1 Then
  31. lblTitulo.Text = "Opciones"
  32. InstrumentoFinanciero = "OPC"
  33. ElseIf Variables.Codigo.IndexOf("FUTU") > -1 Then
  34. InstrumentoFinanciero = "FUTU"
  35. End If
  36. CargarDatos()
  37. VExisteInversion = ExisteInversion()
  38. ValidarExistencia()
  39. RellenarDatos()
  40. CargarTransladoNuevo()
  41. ConfiguracionCMVTA(VExisteInversion)
  42. End Sub
  43. Sub ConfiguracionCMVTA(ByRef VExisteInversion As Boolean)
  44. Dim Codigo As String = Variables.Codigo
  45. Dim ExisteCMVTA As Boolean = General.ExisteCMVTA(Codigo)
  46. If Not ExisteCMVTA And Variables.InvocadorProInv = "frmINV" Then
  47. btnVenderTitulo.Visible = True
  48. End If
  49. If CantFormAbierto = False And Not VExisteInversion Then
  50. If Not Variables.TrasladarCMVTA Is Nothing Then
  51. txtCantidadContratosCompra.Text = Variables.TrasladarCMVTA.CantidadContratosFUTU
  52. txtComisionBrokerCompra.Text = Variables.TrasladarCMVTA.ComisionBrokerFUTU
  53. dtpLiquidacionCompra.Value = Variables.TrasladarCMVTA.FechaLiquidacionFUTU
  54. dtpOperacionCompra.Value = Variables.TrasladarCMVTA.FechaOperacionFUTU
  55. dtpVencimientoCompra.Value = Variables.TrasladarCMVTA.FechaVencimientoFUTU
  56. txtIdentificacionContratoCompra.Text = Variables.TrasladarCMVTA.IdContratoFUTU
  57. txtValorUnidadCompra.Text = Variables.TrasladarCMVTA.PrecioUnitarioFUTU
  58. txtUnidadesContratoCompra.Text = Variables.TrasladarCMVTA.UnidadesPorContratoFUTU
  59. End If
  60. End If
  61. End Sub
  62. Function ExisteVenta()
  63. Dim Ventas As Boolean = False
  64. Dim General As New DAOGeneral
  65. Dim Codigo As String = Variables.Codigo
  66. Ventas = General.ExisteVenta(Codigo)
  67. Return Ventas
  68. End Function
  69. Function ExisteInversion()
  70. Dim Codigo As String = Variables.Codigo
  71. Dim TablaINV As String = "INV0"
  72. Dim TablaPINV As String = "PIN0"
  73. Dim General As New DAOGeneral
  74. Dim InvPro = Variables.InvPro
  75. If InvPro = "I" Then
  76. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  77. If INV0 Then
  78. navNuevo.Visible = True
  79. Return True
  80. Else
  81. navNuevo.Visible = False
  82. Return False
  83. End If
  84. End If
  85. If InvPro = "P" Then
  86. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  87. If PINV0 Then
  88. navNuevo.Visible = True
  89. Return True
  90. Else
  91. navNuevo.Visible = False
  92. Return False
  93. End If
  94. End If
  95. Return False
  96. End Function
  97. Sub ValidarExistencia()
  98. Dim General As New DAOGeneral
  99. Dim Codigo As String = Variables.Codigo
  100. Dim Tabla As String = String.Empty
  101. If (InstrumentoFinanciero = "FUTU") Then
  102. Tabla = "FUT0"
  103. ElseIf (InstrumentoFinanciero = "OPC") Then
  104. Tabla = "OPC0"
  105. End If
  106. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  107. If (Existe) Then
  108. navNuevo.Enabled = False
  109. navModificar.Enabled = True
  110. navEliminar.Enabled = True
  111. Else
  112. navNuevo.Enabled = True
  113. navModificar.Enabled = False
  114. navEliminar.Enabled = False
  115. End If
  116. Estado = String.Empty
  117. btnAceptar.Text = "Aceptar"
  118. End Sub
  119. Function ExisteValidacion()
  120. Dim General As New DAOGeneral
  121. Dim Codigo As String = Variables.Codigo
  122. Dim Tabla As String = String.Empty
  123. If (InstrumentoFinanciero = "FUTU") Then
  124. Tabla = "FUT0"
  125. ElseIf (InstrumentoFinanciero = "OPC") Then
  126. Tabla = "OPC0"
  127. End If
  128. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  129. Return Existe
  130. End Function
  131. Sub CambiarPosicion()
  132. If (CambiarOperacionApoyo) Then
  133. Dim NuevaPosicionCompraH, NuevaPosicionVentaH, NuevaPosicionCompraV, NuevaPosicionVentaV
  134. NuevaPosicionCompraH = GrpCompra.Left
  135. NuevaPosicionCompraV = GrpCompra.Top
  136. NuevaPosicionVentaH = GrpVenta.Left
  137. NuevaPosicionVentaV = GrpVenta.Top
  138. GrpVenta.Left = NuevaPosicionCompraH
  139. GrpVenta.Top = NuevaPosicionCompraV
  140. GrpCompra.Left = NuevaPosicionVentaH
  141. GrpCompra.Top = NuevaPosicionVentaV
  142. CambiarOperacionApoyo = False
  143. Calculos()
  144. End If
  145. End Sub
  146. Sub Calculos()
  147. Dim CantContCompra, UnidadContratoCompra, ValorUnidadCompra, ComisionBrokerCompra As Double
  148. Dim CantContVenta, UnidadContratoVenta, ValorUnidadVenta, ComisionBrokerVenta As Double
  149. If String.IsNullOrEmpty(txtCantidadContratosCompra.Text.ToString) Then
  150. CantContCompra = 0
  151. Else
  152. CantContCompra = txtCantidadContratosCompra.Text
  153. End If
  154. If String.IsNullOrEmpty(txtUnidadesContratoCompra.Text.ToString) Then
  155. UnidadContratoCompra = 0
  156. Else
  157. UnidadContratoCompra = txtUnidadesContratoCompra.Text
  158. End If
  159. If String.IsNullOrEmpty(txtValorUnidadCompra.Text.ToString) Then
  160. ValorUnidadCompra = 0
  161. Else
  162. ValorUnidadCompra = txtValorUnidadCompra.Text
  163. End If
  164. If String.IsNullOrEmpty(txtComisionBrokerCompra.Text.ToString) Then
  165. ComisionBrokerCompra = 0
  166. Else
  167. ComisionBrokerCompra = txtComisionBrokerCompra.Text
  168. End If
  169. If String.IsNullOrEmpty(txtCantidadContratosVenta.Text.ToString) Then
  170. CantContVenta = 0
  171. Else
  172. CantContVenta = txtCantidadContratosVenta.Text
  173. End If
  174. If String.IsNullOrEmpty(txtUnidadesContratoVenta.Text.ToString) Then
  175. UnidadContratoVenta = 0
  176. Else
  177. UnidadContratoVenta = txtUnidadesContratoVenta.Text
  178. End If
  179. If String.IsNullOrEmpty(txtValorUnidadVenta.Text.ToString) Then
  180. ValorUnidadVenta = 0
  181. Else
  182. ValorUnidadVenta = txtValorUnidadVenta.Text
  183. End If
  184. If String.IsNullOrEmpty(txtComisionBrokerVenta.Text.ToString) Then
  185. ComisionBrokerVenta = 0
  186. Else
  187. ComisionBrokerVenta = txtComisionBrokerVenta.Text
  188. End If
  189. Dim ValorTransadoCompra = ValorTransado(CantContCompra, UnidadContratoCompra, ValorUnidadCompra)
  190. Dim ValorTransadoVenta = ValorTransado(CantContVenta, UnidadContratoVenta, ValorUnidadVenta)
  191. Dim ValorRecibidoCompra = ValorRecibido(ValorTransadoCompra, ComisionBrokerCompra)
  192. Dim ValorRecibidoVenta = ValorPagado(ValorTransadoVenta, ComisionBrokerVenta)
  193. If Double.IsInfinity(ValorTransadoCompra) Or Double.IsNaN(ValorTransadoCompra) Then
  194. txtValorTransadoCompra.Text = 0
  195. Else
  196. txtValorTransadoCompra.Text = ValorTransadoCompra
  197. End If
  198. If Double.IsInfinity(ValorTransadoVenta) Or Double.IsNaN(ValorTransadoVenta) Then
  199. txtValorTransadoVenta.Text = 0
  200. Else
  201. txtValorTransadoVenta.Text = ValorTransadoVenta
  202. End If
  203. If Double.IsInfinity(ValorRecibidoCompra) Or Double.IsNaN(ValorRecibidoCompra) Then
  204. txtValorRecibidoCompra.Text = 0
  205. Else
  206. txtValorRecibidoCompra.Text = ValorRecibidoCompra
  207. End If
  208. If Double.IsInfinity(ValorRecibidoVenta) Or Double.IsNaN(ValorRecibidoVenta) Then
  209. txtValorRecibidoVenta.Text = 0
  210. Else
  211. txtValorRecibidoVenta.Text = ValorRecibidoVenta
  212. End If
  213. If (cboOperacionVenta.SelectedIndex = 0) Then
  214. Dim GananciaPerdida = Format(Me.GananciaPerdida(txtValorRecibidoVenta.Text, txtValorRecibidoCompra.Text), "0.0000")
  215. If Double.IsInfinity(GananciaPerdida) Or Double.IsNaN(GananciaPerdida) Then
  216. txtGananciaPerdida.Text = 0
  217. Else
  218. txtGananciaPerdida.Text = GananciaPerdida
  219. End If
  220. ElseIf (cboOperacionVenta.SelectedIndex = 1) Then
  221. Dim GananciaPerdida = Format(Me.GananciaPerdida(txtValorRecibidoCompra.Text, txtValorRecibidoVenta.Text), "0.0000")
  222. If Double.IsInfinity(GananciaPerdida) Or Double.IsNaN(GananciaPerdida) Then
  223. txtGananciaPerdida.Text = 0
  224. Else
  225. txtGananciaPerdida.Text = GananciaPerdida
  226. End If
  227. Else
  228. txtGananciaPerdida.Text = "0.0"
  229. End If
  230. Dim Dias = DiasFechas(dtpLiquidacionCompra.Value, dtpLiquidacionVenta.Value)
  231. Dim Rendimientos = Format((Rendimiento(txtGananciaPerdida.Text, txtValorRecibidoVenta.Text, Dias) * 100), "0.0000")
  232. If Double.IsInfinity(Rendimientos) Or Double.IsNaN(Rendimientos) Then
  233. txtRendimiento.Text = "0.0%"
  234. Else
  235. txtRendimiento.Text = CStr(Rendimientos) + "%"
  236. End If
  237. End Sub
  238. Function ValorTransado(ByVal CantidadContratos As Double, ByVal UnidadesContrato As Double, ByVal ValorUnidad As Double)
  239. Dim ValorTrans As Double = 0
  240. If (String.IsNullOrEmpty(CantidadContratos.ToString) And String.IsNullOrEmpty(UnidadesContrato.ToString) And String.IsNullOrEmpty(ValorUnidad.ToString)) Then
  241. ValorTrans = 0
  242. Else
  243. ValorTrans = CantidadContratos * UnidadesContrato * ValorUnidad
  244. End If
  245. Return ValorTrans
  246. End Function
  247. Function ValorRecibido(ByVal ValorTransado As Double, ByVal ComisionBroker As Double)
  248. Dim ValorRec As Double = 0
  249. ValorRec = ValorTransado + ComisionBroker
  250. Return ValorRec
  251. End Function
  252. Function ValorPagado(ByVal ValorTransado As Double, ByVal ComisionBroker As Double)
  253. Dim ValorRec As Double = 0
  254. ValorRec = ValorTransado - ComisionBroker
  255. Return ValorRec
  256. End Function
  257. Function GananciaPerdida(ByVal ValorTraCompra As Double, ByVal ValorPagado As Double)
  258. Dim Valor As Double
  259. Valor = ValorTraCompra - ValorPagado
  260. Return Valor
  261. End Function
  262. Function Rendimiento(ByVal GananciaPerdida As Double, ByVal ValorRecibidoVenta As Double, ByVal Dias As Double)
  263. Dim Valor As Double
  264. If (ValorRecibidoVenta = 0 Or Dias = 0) Then
  265. Valor = 0
  266. Else
  267. Valor = GananciaPerdida / ValorRecibidoVenta * 365 / Dias
  268. End If
  269. Return Valor
  270. End Function
  271. Function DiasFechas(ByVal FechaLiC As Date, ByVal FechaLiV As Date)
  272. Dim Dias As Integer
  273. Dias = DateDiff(DateInterval.Day, FechaLiV, FechaLiC)
  274. Return Dias
  275. End Function
  276. Private Sub txtCantidadContratosCompra_TextChanged(sender As Object, e As EventArgs) Handles txtCantidadContratosCompra.TextChanged
  277. CopiarDatosAVenta()
  278. Calculos()
  279. End Sub
  280. Private Sub txtCantidadContratosVenta_TextChanged(sender As Object, e As EventArgs) Handles txtCantidadContratosVenta.TextChanged
  281. CopiarDatosACompra()
  282. Calculos()
  283. End Sub
  284. Private Sub txtUnidadesContratoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtUnidadesContratoCompra.TextChanged
  285. CopiarDatosAVenta()
  286. Calculos()
  287. End Sub
  288. Private Sub txtUnidadesContratoVenta_TextChanged(sender As Object, e As EventArgs) Handles txtUnidadesContratoVenta.TextChanged
  289. CopiarDatosACompra()
  290. Calculos()
  291. End Sub
  292. Private Sub txtValorUnidadCompra_TextChanged(sender As Object, e As EventArgs) Handles txtValorUnidadCompra.TextChanged
  293. Calculos()
  294. End Sub
  295. Private Sub txtValorUnidadVenta_TextChanged(sender As Object, e As EventArgs) Handles txtValorUnidadVenta.TextChanged
  296. Calculos()
  297. End Sub
  298. Private Sub txtComisionBrokerCompra_TextChanged(sender As Object, e As EventArgs) Handles txtComisionBrokerCompra.TextChanged
  299. Calculos()
  300. End Sub
  301. Private Sub txtComisionBrokerVenta_TextChanged(sender As Object, e As EventArgs) Handles txtComisionBrokerVenta.TextChanged
  302. Calculos()
  303. End Sub
  304. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  305. btnAceptar.Text = "Modificar"
  306. Estado = "M"
  307. End Sub
  308. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  309. btnAceptar.Text = "Nuevo"
  310. Estado = "N"
  311. End Sub
  312. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  313. btnAceptar.Text = "Eliminar"
  314. Estado = "B"
  315. End Sub
  316. Function ColeccionDatos()
  317. Dim coleccion As New Collection
  318. Dim FOperC, FLiqC, FVenC, VaUnidadC, ValorTransadoC, CoBrokerC, VaRecC, IdContratoC, CantidadContC, UnidadesContC
  319. Dim FOperV, FLiqV, FVenV, VaUnidadV, ValorTransadoV, CoBrokerV, VaRecV, IdContratoV, CantidadContV, UnidadesContV
  320. Dim TipoOperacion As String = "Corto"
  321. If (cboOperacionVenta.SelectedIndex = 1) Then
  322. TipoOperacion = "Largo"
  323. End If
  324. Dim GananciaPerdida, Rendimiento
  325. FOperC = dtpOperacionCompra.Value
  326. FLiqC = dtpLiquidacionCompra.Value
  327. FVenC = dtpVencimientoCompra.Value
  328. VaUnidadC = txtValorUnidadCompra.Text
  329. ValorTransadoC = txtValorTransadoCompra.Text
  330. CoBrokerC = txtComisionBrokerCompra.Text
  331. VaRecC = txtValorRecibidoCompra.Text
  332. IdContratoC = txtIdentificacionContratoCompra.Text
  333. CantidadContC = txtCantidadContratosCompra.Text
  334. UnidadesContC = txtUnidadesContratoCompra.Text
  335. FOperV = dtpOperacionVenta.Value
  336. FLiqV = dtpLiquidacionVenta.Value
  337. FVenV = dtpVencimientoVenta.Value
  338. VaUnidadV = txtValorUnidadVenta.Text
  339. ValorTransadoV = txtValorTransadoVenta.Text
  340. CoBrokerV = txtComisionBrokerVenta.Text
  341. VaRecV = txtValorRecibidoVenta.Text
  342. IdContratoV = txtIdentificacionContratoVenta.Text
  343. CantidadContV = txtCantidadContratosVenta.Text
  344. UnidadesContV = txtUnidadesContratoVenta.Text
  345. GananciaPerdida = txtGananciaPerdida.Text
  346. Rendimiento = txtRendimiento.Text.Trim("%") / 100
  347. coleccion.Add(FOperC)
  348. coleccion.Add(FLiqC)
  349. coleccion.Add(FVenC)
  350. coleccion.Add(VaUnidadC)
  351. coleccion.Add(ValorTransadoC)
  352. coleccion.Add(CoBrokerC)
  353. coleccion.Add(VaRecC)
  354. coleccion.Add(IdContratoC)
  355. coleccion.Add(CantidadContC)
  356. coleccion.Add(UnidadesContC)
  357. coleccion.Add(FOperV)
  358. coleccion.Add(FLiqV)
  359. coleccion.Add(FVenV)
  360. coleccion.Add(VaUnidadV)
  361. coleccion.Add(ValorTransadoV)
  362. coleccion.Add(CoBrokerV)
  363. coleccion.Add(VaRecV)
  364. coleccion.Add(IdContratoV)
  365. coleccion.Add(CantidadContV)
  366. coleccion.Add(UnidadesContV)
  367. coleccion.Add(GananciaPerdida)
  368. coleccion.Add(Rendimiento)
  369. coleccion.Add(TipoOperacion)
  370. Return coleccion
  371. End Function
  372. Sub RellenarDatos()
  373. If (cboOperacionVenta.SelectedIndex = -1) Then
  374. cboOperacionVenta.SelectedIndex = 1
  375. End If
  376. If (String.IsNullOrEmpty(txtValorUnidadCompra.Text.ToString)) Then
  377. txtValorUnidadCompra.Text = "0.0"
  378. End If
  379. If (String.IsNullOrEmpty(txtValorTransadoCompra.Text.ToString)) Then
  380. txtValorTransadoCompra.Text = "0.0"
  381. End If
  382. If (String.IsNullOrEmpty(txtComisionBrokerCompra.Text.ToString)) Then
  383. txtComisionBrokerCompra.Text = "0.0"
  384. End If
  385. If (String.IsNullOrEmpty(txtValorRecibidoCompra.Text.ToString)) Then
  386. txtValorRecibidoCompra.Text = "0.0"
  387. End If
  388. If (String.IsNullOrEmpty(txtIdentificacionContratoCompra.Text.ToString)) Then
  389. txtIdentificacionContratoCompra.Text = " "
  390. End If
  391. If (String.IsNullOrEmpty(txtCantidadContratosCompra.Text.ToString)) Then
  392. txtCantidadContratosCompra.Text = "0.0"
  393. End If
  394. If (String.IsNullOrEmpty(txtUnidadesContratoCompra.Text.ToString)) Then
  395. txtUnidadesContratoCompra.Text = "0.0"
  396. End If
  397. If (String.IsNullOrEmpty(txtValorUnidadVenta.Text.ToString)) Then
  398. txtValorUnidadVenta.Text = "0.0"
  399. End If
  400. If (String.IsNullOrEmpty(txtValorTransadoVenta.Text.ToString)) Then
  401. txtValorTransadoVenta.Text = "0.0"
  402. End If
  403. If (String.IsNullOrEmpty(txtComisionBrokerVenta.Text.ToString)) Then
  404. txtComisionBrokerVenta.Text = "0.0"
  405. End If
  406. If (String.IsNullOrEmpty(txtValorRecibidoVenta.Text.ToString)) Then
  407. txtValorRecibidoVenta.Text = "0.0"
  408. End If
  409. If (String.IsNullOrEmpty(txtIdentificacionContratoVenta.Text.ToString)) Then
  410. txtIdentificacionContratoVenta.Text = " "
  411. End If
  412. If (String.IsNullOrEmpty(txtCantidadContratosVenta.Text.ToString)) Then
  413. txtCantidadContratosVenta.Text = "0.0"
  414. End If
  415. If (String.IsNullOrEmpty(txtUnidadesContratoVenta.Text.ToString)) Then
  416. txtUnidadesContratoVenta.Text = "0.0"
  417. End If
  418. If (String.IsNullOrEmpty(txtGananciaPerdida.Text.ToString)) Then
  419. txtGananciaPerdida.Text = "0.0"
  420. End If
  421. If (String.IsNullOrEmpty(txtRendimiento.Text.Trim("%").ToString)) Then
  422. txtRendimiento.Text = "0.0%"
  423. End If
  424. End Sub
  425. Sub CargarDatos()
  426. Dim codigo = Variables.Codigo
  427. Dim coleccion As New Collection
  428. If (InstrumentoFinanciero = "FUTU") Then
  429. coleccion = FuturosConsulta.CargarDatos(codigo)
  430. ElseIf (InstrumentoFinanciero = "OPC") Then
  431. coleccion = FuturosConsulta.CargarDatosOpciones(codigo)
  432. End If
  433. If (Not coleccion.Count = 1) Then
  434. If (InstrumentoFinanciero = "FUTU" Or InstrumentoFinanciero = "OPC") Then
  435. dtpOperacionCompra.Value = CDate(coleccion(1))
  436. dtpLiquidacionCompra.Value = CDate(coleccion(2))
  437. dtpVencimientoCompra.Value = CDate(coleccion(3))
  438. txtValorUnidadCompra.Text = CDec(coleccion(4))
  439. txtValorTransadoCompra.Text = CDec(coleccion(5))
  440. txtComisionBrokerCompra.Text = CDec(coleccion(6))
  441. txtValorRecibidoCompra.Text = CDec(coleccion(7))
  442. txtIdentificacionContratoCompra.Text = CStr(coleccion(8))
  443. txtCantidadContratosCompra.Text = CInt(coleccion(9))
  444. txtUnidadesContratoCompra.Text = CInt(coleccion(10))
  445. dtpOperacionVenta.Value = CDate(coleccion(11))
  446. dtpLiquidacionVenta.Value = CDate(coleccion(12))
  447. dtpVencimientoVenta.Value = CDate(coleccion(13))
  448. txtValorUnidadVenta.Text = CDec(coleccion(14))
  449. txtValorTransadoVenta.Text = CDec(coleccion(15))
  450. txtComisionBrokerVenta.Text = CDec(coleccion(16))
  451. txtValorRecibidoVenta.Text = CDec(coleccion(17))
  452. txtIdentificacionContratoVenta.Text = CStr(coleccion(18))
  453. txtCantidadContratosVenta.Text = CInt(coleccion(19))
  454. txtUnidadesContratoVenta.Text = CInt(coleccion(20))
  455. txtGananciaPerdida.Text = CDec(coleccion(21))
  456. txtRendimiento.Text = CDec(coleccion(22))
  457. If (coleccion(23).ToString = "Corto") Then
  458. cboOperacionVenta.SelectedIndex = 0
  459. ElseIf (coleccion(23).ToString = "Largo") Then
  460. cboOperacionVenta.SelectedIndex = 1
  461. End If
  462. End If
  463. End If
  464. End Sub
  465. Sub Nuevo()
  466. Dim codigo = Variables.Codigo
  467. Dim Coleccion = ColeccionDatos()
  468. FuturosConsulta.Nuevo(codigo, Coleccion)
  469. End Sub
  470. Sub NuevoOpciones()
  471. Dim codigo = Variables.Codigo
  472. Dim Coleccion = ColeccionDatos()
  473. FuturosConsulta.NuevoOpciones(codigo, Coleccion)
  474. End Sub
  475. Sub Modificar()
  476. Dim codigo = Variables.Codigo
  477. Dim Coleccion = ColeccionDatos()
  478. FuturosConsulta.Modificar(codigo, Coleccion)
  479. End Sub
  480. Sub ModificarOpciones()
  481. Dim codigo = Variables.Codigo
  482. Dim Coleccion = ColeccionDatos()
  483. FuturosConsulta.ModificarOpciones(codigo, Coleccion)
  484. End Sub
  485. Sub Eliminar()
  486. Dim codigo = Variables.Codigo
  487. FuturosConsulta.Eliminar(codigo)
  488. End Sub
  489. Sub EliminarOpciones()
  490. Dim codigo = Variables.Codigo
  491. FuturosConsulta.EliminarOpciones(codigo)
  492. End Sub
  493. Private Sub btnAceptar_Click_1(sender As Object, e As EventArgs) Handles btnAceptar.Click
  494. Dim Instrumento As String = Variables.Codigo
  495. If Instrumento.IndexOf("FUTU") > -1 Then
  496. If (Estado = "N") Then
  497. Nuevo()
  498. ElseIf (Estado = "M") Then
  499. Modificar()
  500. ElseIf (Estado = "B") Then
  501. Eliminar()
  502. ElseIf Not ExisteValidacion() Then
  503. Variables.ColeccionFUTU = ColeccionDatos()
  504. Me.Close()
  505. End If
  506. End If
  507. If Instrumento.IndexOf("OPC") > -1 Then
  508. If (Estado = "N") Then
  509. NuevoOpciones()
  510. ElseIf (Estado = "M") Then
  511. ModificarOpciones()
  512. ElseIf (Estado = "B") Then
  513. EliminarOpciones()
  514. ElseIf Not ExisteValidacion() Then
  515. Variables.ColeccionFUTU = ColeccionDatos()
  516. Me.Close()
  517. End If
  518. End If
  519. ValidarExistencia()
  520. End Sub
  521. Private Sub dtpLiquidacionCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpLiquidacionCompra.ValueChanged
  522. Calculos()
  523. RellenarDatos()
  524. End Sub
  525. Private Sub dtpLiquidacionVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpLiquidacionVenta.ValueChanged
  526. RellenarDatos()
  527. Calculos()
  528. End Sub
  529. Private Sub txtGananciaPerdida_TextChanged(sender As Object, e As EventArgs) Handles txtGananciaPerdida.TextChanged
  530. Calculos()
  531. End Sub
  532. Private Sub txtRendimiento_TextChanged(sender As Object, e As EventArgs) Handles txtRendimiento.TextChanged
  533. Calculos()
  534. End Sub
  535. Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems
  536. End Sub
  537. Private Sub cboOperacionVenta_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboOperacionVenta.SelectedIndexChanged
  538. If (Not Numero = cboOperacionVenta.SelectedIndex) Then
  539. CambiarOperacionApoyo = True
  540. Numero = cboOperacionVenta.SelectedIndex
  541. End If
  542. CambiarPosicion()
  543. End Sub
  544. Private Sub txtValorUnidadCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtValorUnidadCompra.KeyPress
  545. If String.IsNullOrEmpty(txtValorUnidadCompra.Text) Then
  546. If e.KeyChar = "." Then
  547. txtValorUnidadCompra.Text = "0"
  548. Exit Sub
  549. End If
  550. End If
  551. If (Not txtValorUnidadCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  552. Operaciones.ValidarEntrada(sender, e, True)
  553. Else
  554. Operaciones.ValidarEntrada(sender, e, False)
  555. End If
  556. End Sub
  557. Private Sub txtValorUnidadVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtValorUnidadVenta.KeyPress
  558. If String.IsNullOrEmpty(txtValorUnidadVenta.Text) Then
  559. If e.KeyChar = "." Then
  560. txtValorUnidadVenta.Text = "0"
  561. Exit Sub
  562. End If
  563. End If
  564. If (Not txtValorUnidadVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  565. Operaciones.ValidarEntrada(sender, e, True)
  566. Else
  567. Operaciones.ValidarEntrada(sender, e, False)
  568. End If
  569. End Sub
  570. Private Sub txtComisionBrokerCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionBrokerCompra.KeyPress
  571. If String.IsNullOrEmpty(txtComisionBrokerCompra.Text) Then
  572. If e.KeyChar = "." Then
  573. txtComisionBrokerCompra.Text = "0"
  574. Exit Sub
  575. End If
  576. End If
  577. If (Not txtComisionBrokerCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  578. Operaciones.ValidarEntrada(sender, e, True)
  579. Else
  580. Operaciones.ValidarEntrada(sender, e, False)
  581. End If
  582. End Sub
  583. Private Sub txtComisionBrokerVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionBrokerVenta.KeyPress
  584. If String.IsNullOrEmpty(txtComisionBrokerVenta.Text) Then
  585. If e.KeyChar = "." Then
  586. txtComisionBrokerVenta.Text = "0"
  587. Exit Sub
  588. End If
  589. End If
  590. If (Not txtComisionBrokerVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  591. Operaciones.ValidarEntrada(sender, e, True)
  592. Else
  593. Operaciones.ValidarEntrada(sender, e, False)
  594. End If
  595. End Sub
  596. Private Sub txtIdentificacionContratoCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtIdentificacionContratoCompra.KeyPress
  597. 'If String.IsNullOrEmpty(txtIdentificacionContratoCompra.Text) Then
  598. ' If e.KeyChar = "." Then
  599. ' txtIdentificacionContratoCompra.Text = "0"
  600. ' Exit Sub
  601. ' End If
  602. 'End If
  603. 'If (Not txtIdentificacionContratoCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  604. ' Operaciones.ValidarEntrada(sender, e, True)
  605. 'Else
  606. ' Operaciones.ValidarEntrada(sender, e, False)
  607. 'End If
  608. End Sub
  609. Private Sub txtIdentificacionContratoVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtIdentificacionContratoVenta.KeyPress
  610. 'If String.IsNullOrEmpty(txtIdentificacionContratoVenta.Text) Then
  611. ' If e.KeyChar = "." Then
  612. ' txtIdentificacionContratoVenta.Text = "0"
  613. ' Exit Sub
  614. ' End If
  615. 'End If
  616. 'If (Not txtIdentificacionContratoVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  617. ' Operaciones.ValidarEntrada(sender, e, True)
  618. 'Else
  619. ' Operaciones.ValidarEntrada(sender, e, False)
  620. 'End If
  621. End Sub
  622. Private Sub txtCantidadContratosCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCantidadContratosCompra.KeyPress
  623. If String.IsNullOrEmpty(txtCantidadContratosCompra.Text) Then
  624. If e.KeyChar = "." Then
  625. txtCantidadContratosCompra.Text = "0"
  626. Exit Sub
  627. End If
  628. End If
  629. If (Not txtCantidadContratosCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  630. Operaciones.ValidarEntrada(sender, e, True)
  631. Else
  632. Operaciones.ValidarEntrada(sender, e, False)
  633. End If
  634. End Sub
  635. Private Sub txtCantidadContratosVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtCantidadContratosVenta.KeyPress
  636. If String.IsNullOrEmpty(txtCantidadContratosVenta.Text) Then
  637. If e.KeyChar = "." Then
  638. txtCantidadContratosVenta.Text = "0"
  639. Exit Sub
  640. End If
  641. End If
  642. If (Not txtCantidadContratosVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  643. Operaciones.ValidarEntrada(sender, e, True)
  644. Else
  645. Operaciones.ValidarEntrada(sender, e, False)
  646. End If
  647. End Sub
  648. Private Sub txtUnidadesContratoCompra_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUnidadesContratoCompra.KeyPress
  649. If String.IsNullOrEmpty(txtUnidadesContratoCompra.Text) Then
  650. If e.KeyChar = "." Then
  651. txtUnidadesContratoCompra.Text = "0"
  652. Exit Sub
  653. End If
  654. End If
  655. If (Not txtUnidadesContratoCompra.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  656. Operaciones.ValidarEntrada(sender, e, True)
  657. Else
  658. Operaciones.ValidarEntrada(sender, e, False)
  659. End If
  660. End Sub
  661. Private Sub txtUnidadesContratoVenta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUnidadesContratoVenta.KeyPress
  662. If String.IsNullOrEmpty(txtUnidadesContratoVenta.Text) Then
  663. If e.KeyChar = "." Then
  664. txtUnidadesContratoVenta.Text = "0"
  665. Exit Sub
  666. End If
  667. End If
  668. If (Not txtUnidadesContratoVenta.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  669. Operaciones.ValidarEntrada(sender, e, True)
  670. Else
  671. Operaciones.ValidarEntrada(sender, e, False)
  672. End If
  673. End Sub
  674. Sub CopiarDatosACompra()
  675. If (cboOperacionVenta.SelectedIndex = 0) Then
  676. txtCantidadContratosCompra.Text = txtCantidadContratosVenta.Text
  677. txtUnidadesContratoCompra.Text = txtUnidadesContratoVenta.Text
  678. End If
  679. End Sub
  680. Sub CopiarDatosAVenta()
  681. If (cboOperacionVenta.SelectedIndex = 1) Then
  682. txtCantidadContratosVenta.Text = txtCantidadContratosCompra.Text
  683. txtUnidadesContratoVenta.Text = txtUnidadesContratoCompra.Text
  684. End If
  685. End Sub
  686. Private Sub txtIdentificacionContratoCompra_TextChanged(sender As Object, e As EventArgs) Handles txtIdentificacionContratoCompra.TextChanged
  687. End Sub
  688. Private Sub dtpOperacionCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpOperacionCompra.ValueChanged
  689. RellenarDatos()
  690. End Sub
  691. Private Sub dtpVencimientoCompra_ValueChanged(sender As Object, e As EventArgs) Handles dtpVencimientoCompra.ValueChanged
  692. RellenarDatos()
  693. End Sub
  694. Private Sub txtValorUnidadCompra_Leave(sender As Object, e As EventArgs) Handles txtValorUnidadCompra.Leave
  695. RellenarDatos()
  696. End Sub
  697. Private Sub txtComisionBrokerCompra_Leave(sender As Object, e As EventArgs) Handles txtComisionBrokerCompra.Leave
  698. RellenarDatos()
  699. End Sub
  700. Private Sub txtIdentificacionContratoCompra_Leave(sender As Object, e As EventArgs) Handles txtIdentificacionContratoCompra.Leave
  701. RellenarDatos()
  702. End Sub
  703. Private Sub txtCantidadContratosCompra_Leave(sender As Object, e As EventArgs) Handles txtCantidadContratosCompra.Leave
  704. RellenarDatos()
  705. End Sub
  706. Private Sub txtUnidadesContratoCompra_Leave(sender As Object, e As EventArgs) Handles txtUnidadesContratoCompra.Leave
  707. RellenarDatos()
  708. End Sub
  709. Private Sub dtpOperacionVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpOperacionVenta.ValueChanged
  710. RellenarDatos()
  711. End Sub
  712. Private Sub dtpVencimientoVenta_ValueChanged(sender As Object, e As EventArgs) Handles dtpVencimientoVenta.ValueChanged
  713. RellenarDatos()
  714. End Sub
  715. Private Sub txtValorUnidadVenta_Leave(sender As Object, e As EventArgs) Handles txtValorUnidadVenta.Leave
  716. RellenarDatos()
  717. End Sub
  718. Private Sub txtComisionBrokerVenta_Leave(sender As Object, e As EventArgs) Handles txtComisionBrokerVenta.Leave
  719. RellenarDatos()
  720. End Sub
  721. Private Sub txtIdentificacionContratoVenta_Leave(sender As Object, e As EventArgs) Handles txtIdentificacionContratoVenta.Leave
  722. RellenarDatos()
  723. End Sub
  724. Private Sub txtCantidadContratosVenta_Leave(sender As Object, e As EventArgs) Handles txtCantidadContratosVenta.Leave
  725. RellenarDatos()
  726. End Sub
  727. Private Sub txtUnidadesContratoVenta_Leave(sender As Object, e As EventArgs) Handles txtUnidadesContratoVenta.Leave
  728. RellenarDatos()
  729. End Sub
  730. Private Sub txtValorUnidadCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtValorUnidadCompra.KeyUp
  731. If txtValorUnidadCompra.Text = "." Then
  732. txtValorUnidadCompra.Text = ".0"
  733. End If
  734. End Sub
  735. Private Sub txtComisionBrokerCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionBrokerCompra.KeyUp
  736. If txtComisionBrokerCompra.Text = "." Then
  737. txtComisionBrokerCompra.Text = ".0"
  738. End If
  739. End Sub
  740. Private Sub txtCantidadContratosCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCantidadContratosCompra.KeyUp
  741. If txtCantidadContratosCompra.Text = "." Then
  742. txtCantidadContratosCompra.Text = ".0"
  743. End If
  744. End Sub
  745. Private Sub txtUnidadesContratoCompra_KeyUp(sender As Object, e As KeyEventArgs) Handles txtUnidadesContratoCompra.KeyUp
  746. If txtUnidadesContratoCompra.Text = "." Then
  747. txtUnidadesContratoCompra.Text = ".0"
  748. End If
  749. End Sub
  750. Private Sub txtValorUnidadVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtValorUnidadVenta.KeyUp
  751. If txtValorUnidadVenta.Text = "." Then
  752. txtValorUnidadVenta.Text = ".0"
  753. End If
  754. End Sub
  755. Private Sub txtComisionBrokerVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionBrokerVenta.KeyUp
  756. If txtComisionBrokerVenta.Text = "." Then
  757. txtComisionBrokerVenta.Text = ".0"
  758. End If
  759. End Sub
  760. Private Sub txtIdentificacionContratoVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtIdentificacionContratoVenta.KeyUp
  761. End Sub
  762. Private Sub txtCantidadContratosVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtCantidadContratosVenta.KeyUp
  763. If txtCantidadContratosVenta.Text = "." Then
  764. txtCantidadContratosVenta.Text = ".0"
  765. End If
  766. End Sub
  767. Private Sub txtUnidadesContratoVenta_KeyUp(sender As Object, e As KeyEventArgs) Handles txtUnidadesContratoVenta.KeyUp
  768. If txtUnidadesContratoVenta.Text = "." Then
  769. txtUnidadesContratoVenta.Text = ".0"
  770. End If
  771. End Sub
  772. Sub CargarTransladoNuevo()
  773. Dim Existe As Boolean = ExisteInversion()
  774. If CantFormAbierto = False Then
  775. If Not RetCodigoInversionExiste And Not Existe Then
  776. Dim TipoTransaccionCompraVenta As String = Variables.TipoTransaccionCompraVenta
  777. If TipoTransaccionCompraVenta = "C" Then
  778. txtValorUnidadCompra.Text = Variables.RetPrecio
  779. txtCantidadContratosCompra.Text = Variables.RetCantidadContratosFuturos
  780. txtUnidadesContratoCompra.Text = Variables.RetUnidadesContratosFuturos
  781. ElseIf TipoTransaccionCompraVenta = "V" Then
  782. txtValorUnidadVenta.Text = Variables.RetPrecio
  783. txtCantidadContratosVenta.Text = Variables.RetCantidadContratosFuturos
  784. txtUnidadesContratoVenta.Text = Variables.RetUnidadesContratosFuturos
  785. End If
  786. End If
  787. End If
  788. End Sub
  789. Private Sub btnVenderTitulo_Click(sender As Object, e As EventArgs) Handles btnVenderTitulo.Click
  790. If Variables.InvocadorProInv = "frmINV" Then
  791. Dim TrasladarDatos As New TrasladarDatosCMVTA
  792. Dim General As New DAOGeneral
  793. Dim Codigo = Variables.Codigo
  794. Dim Tabla As String = "INV0"
  795. TrasladarDatos = RellenarDatosCMVTA()
  796. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  797. If Existe Then
  798. Dim CodigoInversion As String = Variables.Codigo
  799. Dim frmPINVCMVTA As New frmPIN("V", CodigoInversion, TrasladarDatos)
  800. frmINV.Close()
  801. Me.Close()
  802. frmPINVCMVTA.ShowDialog()
  803. End If
  804. End If
  805. End Sub
  806. Function RellenarDatosCMVTA()
  807. Dim TrasladarDatos As New TrasladarDatosCMVTA
  808. TrasladarDatos.CantidadContratosFUTU = Operaciones.ConvertirEntero(txtCantidadContratosCompra.Text.ToString)
  809. TrasladarDatos.ComisionBrokerFUTU = Operaciones.ConvertirDecimal(txtComisionBrokerCompra.Text.ToString)
  810. TrasladarDatos.FechaLiquidacionFUTU = Operaciones.ConvertirFecha(dtpLiquidacionCompra.Value.ToString)
  811. TrasladarDatos.FechaOperacionFUTU = Operaciones.ConvertirFecha(dtpOperacionCompra.Value.ToString)
  812. TrasladarDatos.FechaVencimientoFUTU = Operaciones.ConvertirFecha(dtpVencimientoCompra.Value.ToString)
  813. TrasladarDatos.UnidadesPorContratoFUTU = Operaciones.ConvertirDecimal(txtUnidadesContratoCompra.Text.ToString)
  814. TrasladarDatos.IdContratoFUTU = Operaciones.ConvertirDecimal(txtIdentificacionContratoCompra.Text.ToString)
  815. TrasladarDatos.PrecioUnitarioFUTU = Operaciones.ConvertirDecimal(txtValorUnidadCompra.Text.ToString)
  816. TrasladarDatos.NombreInstrumento = "FUTU"
  817. TrasladarDatos.AgregarCMVTA = True
  818. Return TrasladarDatos
  819. End Function
  820. End Class