frmFuturos.vb 35 KB

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