frmFuturos.vb 36 KB

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